| ... | @@ -20,6 +20,12 @@ import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; | ... | @@ -20,6 +20,12 @@ import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 20 | import { SpawnExecutableResolution } from "@t3tools/shared/shell"; | 20 | import { SpawnExecutableResolution } from "@t3tools/shared/shell"; |
| 21 | import * as ExternalLauncher from "./externalLauncher.ts"; | 21 | import * as ExternalLauncher from "./externalLauncher.ts"; |
| 22 | | 22 | |
| | 23 | // Tests below write `#!/bin/sh` stubs into a real temp dir and hand that |
| | 24 | // directory to a posix-mocked resolver as PATH. On a Windows host the temp |
| | 25 | // path carries a drive letter, so the posix `:` split shatters it; there is |
| | 26 | // no posix executable to find there anyway. |
| | 27 | const windowsHost = HostProcessPlatform.defaultValue() === "win32"; |
| | 28 | |
| 23 | interface MockSpawnResult { | 29 | interface MockSpawnResult { |
| 24 | readonly exitCode?: number; | 30 | readonly exitCode?: number; |
| 25 | readonly stdout?: string; | 31 | readonly stdout?: string; |
| ... | @@ -153,7 +159,7 @@ it.effect("launches an installed editor with platform-safe arguments", () => | ... | @@ -153,7 +159,7 @@ it.effect("launches an installed editor with platform-safe arguments", () => |
| 153 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 159 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 154 | ); | 160 | ); |
| 155 | | 161 | |
| 156 | it.effect("reveals a file in Finder with open -R on macOS", () => | 162 | it.effect.skipIf(windowsHost)("reveals a file in Finder with open -R on macOS", () => |
| 157 | Effect.gen(function* () { | 163 | Effect.gen(function* () { |
| 158 | const fileSystem = yield* FileSystem.FileSystem; | 164 | const fileSystem = yield* FileSystem.FileSystem; |
| 159 | const path = yield* Path.Path; | 165 | const path = yield* Path.Path; |
| ... | @@ -336,196 +342,208 @@ it.effect("does not advertise reveal on Windows when PowerShell is missing", () | ... | @@ -336,196 +342,208 @@ it.effect("does not advertise reveal on Windows when PowerShell is missing", () |
| 336 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 342 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 337 | ); | 343 | ); |
| 338 | | 344 | |
| 339 | it.effect("reveals a WSL file in Windows File Explorer through its UNC path", () => | 345 | it.effect.skipIf(windowsHost)( |
| 340 | Effect.gen(function* () { | 346 | "reveals a WSL file in Windows File Explorer through its UNC path", |
| 341 | const fileSystem = yield* FileSystem.FileSystem; | 347 | () => |
| 342 | const path = yield* Path.Path; | 348 | Effect.gen(function* () { |
| 343 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 349 | const fileSystem = yield* FileSystem.FileSystem; |
| 344 | for (const name of ["explorer.exe", "powershell.exe", "xdg-open"]) { | 350 | const path = yield* Path.Path; |
| 345 | const filePath = path.join(binDir, name); | 351 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 346 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 352 | for (const name of ["explorer.exe", "powershell.exe", "xdg-open"]) { |
| 347 | yield* fileSystem.chmod(filePath, 0o755); | 353 | const filePath = path.join(binDir, name); |
| 348 | } | 354 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 355 | yield* fileSystem.chmod(filePath, 0o755); |
| | 356 | } |
| 349 | | 357 | |
| 350 | let spawned: ChildProcess.StandardCommand | undefined; | 358 | let spawned: ChildProcess.StandardCommand | undefined; |
| 351 | const result = yield* Effect.gen(function* () { | 359 | const result = yield* Effect.gen(function* () { |
| 352 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 360 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 353 | const kind = yield* launcher.resolveFileManagerRevealKind(); | 361 | const kind = yield* launcher.resolveFileManagerRevealKind(); |
| 354 | const editors = yield* launcher.resolveAvailableEditors(); | 362 | const editors = yield* launcher.resolveAvailableEditors(); |
| 355 | yield* launcher.launchEditor({ | 363 | yield* launcher.launchEditor({ |
| 356 | editor: "file-manager", | 364 | editor: "file-manager", |
| 357 | cwd: "/home/t3/workspace/media/clip.mp4", | 365 | cwd: "/home/t3/workspace/media/clip.mp4", |
| 358 | reveal: true, | 366 | reveal: true, |
| 359 | }); | 367 | }); |
| 360 | return { kind, editors }; | 368 | return { kind, editors }; |
| 361 | }).pipe( | 369 | }).pipe( |
| 362 | Effect.provide( | 370 | Effect.provide( |
| 363 | testLayer({ | 371 | testLayer({ |
| 364 | platform: "linux", | 372 | platform: "linux", |
| 365 | env: { | 373 | env: { |
| 366 | PATH: binDir, | 374 | PATH: binDir, |
| 367 | WSL_DISTRO_NAME: "Ubuntu-24.04", | 375 | WSL_DISTRO_NAME: "Ubuntu-24.04", |
| 368 | WSL_INTEROP: "/run/WSL/1_interop", | 376 | WSL_INTEROP: "/run/WSL/1_interop", |
| 369 | }, | 377 | }, |
| 370 | onSpawn: (command) => { | 378 | onSpawn: (command) => { |
| 371 | spawned = command; | 379 | spawned = command; |
| 372 | }, | 380 | }, |
| 373 | }), | 381 | }), |
| 374 | ), | 382 | ), |
| 375 | ); | 383 | ); |
| 376 | | 384 | |
| 377 | assert.equal(result.kind, "file-explorer"); | 385 | assert.equal(result.kind, "file-explorer"); |
| 378 | assert.equal(result.editors.includes("file-manager"), true); | 386 | assert.equal(result.editors.includes("file-manager"), true); |
| 379 | assert.ok(spawned); | 387 | assert.ok(spawned); |
| 380 | // The reveal routes through interop PowerShell so Explorer receives its | 388 | // The reveal routes through interop PowerShell so Explorer receives its |
| 381 | // raw `/select,"<path>"` switch even for spaced paths. | 389 | // raw `/select,"<path>"` switch even for spaced paths. |
| 382 | assert.equal(spawned.command, "powershell.exe"); | 390 | assert.equal(spawned.command, "powershell.exe"); |
| 383 | const encodedCommand = spawned.args[spawned.args.length - 1] ?? ""; | 391 | const encodedCommand = spawned.args[spawned.args.length - 1] ?? ""; |
| 384 | const decodedCommand = Buffer.from(encodedCommand, "base64").toString("utf16le"); | 392 | const decodedCommand = Buffer.from(encodedCommand, "base64").toString("utf16le"); |
| 385 | assert.equal( | 393 | assert.equal( |
| 386 | decodedCommand, | 394 | decodedCommand, |
| 387 | "$ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace\\media\\clip.mp4' + '\"')", | 395 | "$ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace\\media\\clip.mp4' + '\"')", |
| 388 | ); | 396 | ); |
| 389 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 397 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 390 | ); | 398 | ); |
| 391 | | 399 | |
| 392 | it.effect("does not advertise reveal from WSL when interop PowerShell is missing", () => | 400 | it.effect.skipIf(windowsHost)( |
| 393 | Effect.gen(function* () { | 401 | "does not advertise reveal from WSL when interop PowerShell is missing", |
| 394 | const fileSystem = yield* FileSystem.FileSystem; | 402 | () => |
| 395 | const path = yield* Path.Path; | 403 | Effect.gen(function* () { |
| 396 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 404 | const fileSystem = yield* FileSystem.FileSystem; |
| 397 | const explorerPath = path.join(binDir, "explorer.exe"); | 405 | const path = yield* Path.Path; |
| 398 | yield* fileSystem.writeFileString(explorerPath, ""); | 406 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 399 | yield* fileSystem.chmod(explorerPath, 0o755); | 407 | const explorerPath = path.join(binDir, "explorer.exe"); |
| | 408 | yield* fileSystem.writeFileString(explorerPath, ""); |
| | 409 | yield* fileSystem.chmod(explorerPath, 0o755); |
| 400 | | 410 | |
| 401 | const result = yield* Effect.gen(function* () { | 411 | const result = yield* Effect.gen(function* () { |
| 402 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 412 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 403 | return { | 413 | return { |
| 404 | kind: yield* launcher.resolveFileManagerRevealKind(), | 414 | kind: yield* launcher.resolveFileManagerRevealKind(), |
| 405 | editors: yield* launcher.resolveAvailableEditors(), | 415 | editors: yield* launcher.resolveAvailableEditors(), |
| 406 | }; | 416 | }; |
| 407 | }).pipe( | 417 | }).pipe( |
| 408 | Effect.provide( | 418 | Effect.provide( |
| 409 | testLayer({ | 419 | testLayer({ |
| 410 | platform: "linux", | 420 | platform: "linux", |
| 411 | env: { | 421 | env: { |
| 412 | PATH: binDir, | 422 | PATH: binDir, |
| 413 | WSL_DISTRO_NAME: "Ubuntu-24.04", | 423 | WSL_DISTRO_NAME: "Ubuntu-24.04", |
| 414 | WSL_INTEROP: "/run/WSL/1_interop", | 424 | WSL_INTEROP: "/run/WSL/1_interop", |
| 415 | }, | 425 | }, |
| 416 | }), | 426 | }), |
| 417 | ), | 427 | ), |
| 418 | ); | 428 | ); |
| 419 | | 429 | |
| 420 | assert.equal(result.editors.includes("file-manager"), true); | 430 | assert.equal(result.editors.includes("file-manager"), true); |
| 421 | assert.isUndefined(result.kind); | 431 | assert.isUndefined(result.kind); |
| 422 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 432 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 423 | ); | 433 | ); |
| 424 | | 434 | |
| 425 | // When interop PowerShell is missing the capability advertises the Linux | 435 | // When interop PowerShell is missing the capability advertises the Linux |
| 426 | // "files" kind (or nothing), so the reveal must open the Linux file manager | 436 | // "files" kind (or nothing), so the reveal must open the Linux file manager |
| 427 | // the label promised even though plain open still prefers File Explorer. | 437 | // the label promised even though plain open still prefers File Explorer. |
| 428 | it.effect("reveals through the Linux file manager when WSL lacks interop PowerShell", () => | 438 | it.effect.skipIf(windowsHost)( |
| 429 | Effect.gen(function* () { | 439 | "reveals through the Linux file manager when WSL lacks interop PowerShell", |
| 430 | const fileSystem = yield* FileSystem.FileSystem; | 440 | () => |
| 431 | const path = yield* Path.Path; | 441 | Effect.gen(function* () { |
| 432 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 442 | const fileSystem = yield* FileSystem.FileSystem; |
| 433 | for (const name of ["explorer.exe", "xdg-open", "xdg-mime"]) { | 443 | const path = yield* Path.Path; |
| 434 | const filePath = path.join(binDir, name); | 444 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 435 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 445 | for (const name of ["explorer.exe", "xdg-open", "xdg-mime"]) { |
| 436 | yield* fileSystem.chmod(filePath, 0o755); | 446 | const filePath = path.join(binDir, name); |
| 437 | } | 447 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 448 | yield* fileSystem.chmod(filePath, 0o755); |
| | 449 | } |
| 438 | | 450 | |
| 439 | const spawnedCommands: ChildProcess.StandardCommand[] = []; | 451 | const spawnedCommands: ChildProcess.StandardCommand[] = []; |
| 440 | const kind = yield* Effect.gen(function* () { | 452 | const kind = yield* Effect.gen(function* () { |
| 441 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 453 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 442 | const revealKind = yield* launcher.resolveFileManagerRevealKind(); | 454 | const revealKind = yield* launcher.resolveFileManagerRevealKind(); |
| 443 | yield* launcher.launchEditor({ | 455 | yield* launcher.launchEditor({ |
| 444 | editor: "file-manager", | 456 | editor: "file-manager", |
| 445 | cwd: "/home/t3/workspace/media/clip.mp4", | 457 | cwd: "/home/t3/workspace/media/clip.mp4", |
| 446 | reveal: true, | 458 | reveal: true, |
| 447 | }); | 459 | }); |
| 448 | return revealKind; | 460 | return revealKind; |
| 449 | }).pipe( | 461 | }).pipe( |
| 450 | Effect.provide( | 462 | Effect.provide( |
| 451 | testLayer({ | 463 | testLayer({ |
| 452 | platform: "linux", | 464 | platform: "linux", |
| 453 | env: { | 465 | env: { |
| 454 | PATH: binDir, | 466 | PATH: binDir, |
| 455 | WSL_DISTRO_NAME: "Ubuntu-24.04", | 467 | WSL_DISTRO_NAME: "Ubuntu-24.04", |
| 456 | WSL_INTEROP: "/run/WSL/1_interop", | 468 | WSL_INTEROP: "/run/WSL/1_interop", |
| 457 | DISPLAY: ":0", | 469 | DISPLAY: ":0", |
| 458 | }, | 470 | }, |
| 459 | onSpawn: (command) => { | 471 | onSpawn: (command) => { |
| 460 | spawnedCommands.push(command); | 472 | spawnedCommands.push(command); |
| 461 | }, | 473 | }, |
| 462 | spawnResult: (command) => | 474 | spawnResult: (command) => |
| 463 | command.command === "xdg-mime" ? { stdout: "org.gnome.Nautilus.desktop\n" } : undefined, | 475 | command.command === "xdg-mime" |
| 464 | }), | 476 | ? { stdout: "org.gnome.Nautilus.desktop\n" } |
| 465 | ), | 477 | : undefined, |
| 466 | ); | 478 | }), |
| | 479 | ), |
| | 480 | ); |
| 467 | | 481 | |
| 468 | assert.equal(kind, "files"); | 482 | assert.equal(kind, "files"); |
| 469 | const launch = spawnedCommands.find((command) => command.command === "xdg-open"); | 483 | const launch = spawnedCommands.find((command) => command.command === "xdg-open"); |
| 470 | assert.ok(launch); | 484 | assert.ok(launch); |
| 471 | assert.deepEqual(launch.args, ["/home/t3/workspace/media"]); | 485 | assert.deepEqual(launch.args, ["/home/t3/workspace/media"]); |
| 472 | assert.isUndefined(spawnedCommands.find((command) => command.command === "explorer.exe")); | 486 | assert.isUndefined(spawnedCommands.find((command) => command.command === "explorer.exe")); |
| 473 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 487 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 474 | ); | 488 | ); |
| 475 | | 489 | |
| 476 | // Interop can exist without `explorer.exe` on PATH (appendWindowsPath=false) | 490 | // Interop can exist without `explorer.exe` on PATH (appendWindowsPath=false) |
| 477 | // while WSLg still provides a working Linux file manager; the host must keep | 491 | // while WSLg still provides a working Linux file manager; the host must keep |
| 478 | // the Linux open/reveal path instead of losing the editor entirely. | 492 | // the Linux open/reveal path instead of losing the editor entirely. |
| 479 | it.effect("falls back to the Linux file manager when WSL lacks the Explorer bridge", () => | 493 | it.effect.skipIf(windowsHost)( |
| 480 | Effect.gen(function* () { | 494 | "falls back to the Linux file manager when WSL lacks the Explorer bridge", |
| 481 | const fileSystem = yield* FileSystem.FileSystem; | 495 | () => |
| 482 | const path = yield* Path.Path; | 496 | Effect.gen(function* () { |
| 483 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 497 | const fileSystem = yield* FileSystem.FileSystem; |
| 484 | for (const name of ["xdg-open", "xdg-mime"]) { | 498 | const path = yield* Path.Path; |
| 485 | const filePath = path.join(binDir, name); | 499 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 486 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 500 | for (const name of ["xdg-open", "xdg-mime"]) { |
| 487 | yield* fileSystem.chmod(filePath, 0o755); | 501 | const filePath = path.join(binDir, name); |
| 488 | } | 502 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 503 | yield* fileSystem.chmod(filePath, 0o755); |
| | 504 | } |
| 489 | | 505 | |
| 490 | const spawnedCommands: ChildProcess.StandardCommand[] = []; | 506 | const spawnedCommands: ChildProcess.StandardCommand[] = []; |
| 491 | const result = yield* Effect.gen(function* () { | 507 | const result = yield* Effect.gen(function* () { |
| 492 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 508 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 493 | const editors = yield* launcher.resolveAvailableEditors(); | 509 | const editors = yield* launcher.resolveAvailableEditors(); |
| 494 | const kind = yield* launcher.resolveFileManagerRevealKind(); | 510 | const kind = yield* launcher.resolveFileManagerRevealKind(); |
| 495 | yield* launcher.launchEditor({ | 511 | yield* launcher.launchEditor({ |
| 496 | editor: "file-manager", | 512 | editor: "file-manager", |
| 497 | cwd: "/home/t3/workspace/media/clip.mp4", | 513 | cwd: "/home/t3/workspace/media/clip.mp4", |
| 498 | reveal: true, | 514 | reveal: true, |
| 499 | }); | 515 | }); |
| 500 | return { editors, kind }; | 516 | return { editors, kind }; |
| 501 | }).pipe( | 517 | }).pipe( |
| 502 | Effect.provide( | 518 | Effect.provide( |
| 503 | testLayer({ | 519 | testLayer({ |
| 504 | platform: "linux", | 520 | platform: "linux", |
| 505 | env: { | 521 | env: { |
| 506 | PATH: binDir, | 522 | PATH: binDir, |
| 507 | WSL_DISTRO_NAME: "Ubuntu-24.04", | 523 | WSL_DISTRO_NAME: "Ubuntu-24.04", |
| 508 | WSL_INTEROP: "/run/WSL/1_interop", | 524 | WSL_INTEROP: "/run/WSL/1_interop", |
| 509 | DISPLAY: ":0", | 525 | DISPLAY: ":0", |
| 510 | }, | 526 | }, |
| 511 | onSpawn: (command) => { | 527 | onSpawn: (command) => { |
| 512 | spawnedCommands.push(command); | 528 | spawnedCommands.push(command); |
| 513 | }, | 529 | }, |
| 514 | spawnResult: (command) => | 530 | spawnResult: (command) => |
| 515 | command.command === "xdg-mime" ? { stdout: "org.gnome.Nautilus.desktop\n" } : undefined, | 531 | command.command === "xdg-mime" |
| 516 | }), | 532 | ? { stdout: "org.gnome.Nautilus.desktop\n" } |
| 517 | ), | 533 | : undefined, |
| 518 | ); | 534 | }), |
| | 535 | ), |
| | 536 | ); |
| 519 | | 537 | |
| 520 | assert.equal(result.editors.includes("file-manager"), true); | 538 | assert.equal(result.editors.includes("file-manager"), true); |
| 521 | assert.equal(result.kind, "files"); | 539 | assert.equal(result.kind, "files"); |
| 522 | const launch = spawnedCommands.find((command) => command.command === "xdg-open"); | 540 | const launch = spawnedCommands.find((command) => command.command === "xdg-open"); |
| 523 | assert.ok(launch); | 541 | assert.ok(launch); |
| 524 | assert.deepEqual(launch.args, ["/home/t3/workspace/media"]); | 542 | assert.deepEqual(launch.args, ["/home/t3/workspace/media"]); |
| 525 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 543 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 526 | ); | 544 | ); |
| 527 | | 545 | |
| 528 | it.effect( | 546 | it.effect.skipIf(windowsHost)( |
| 529 | "falls back to opening the containing directory for WSL paths Explorer cannot select", | 547 | "falls back to opening the containing directory for WSL paths Explorer cannot select", |
| 530 | () => | 548 | () => |
| 531 | Effect.gen(function* () { | 549 | Effect.gen(function* () { |
| ... | @@ -570,7 +588,7 @@ it.effect( | ... | @@ -570,7 +588,7 @@ it.effect( |
| 570 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 588 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 571 | ); | 589 | ); |
| 572 | | 590 | |
| 573 | it.effect("reveals by opening the containing directory on Linux", () => | 591 | it.effect.skipIf(windowsHost)("reveals by opening the containing directory on Linux", () => |
| 574 | Effect.gen(function* () { | 592 | Effect.gen(function* () { |
| 575 | const fileSystem = yield* FileSystem.FileSystem; | 593 | const fileSystem = yield* FileSystem.FileSystem; |
| 576 | const path = yield* Path.Path; | 594 | const path = yield* Path.Path; |
| ... | @@ -609,127 +627,137 @@ it.effect("reveals by opening the containing directory on Linux", () => | ... | @@ -609,127 +627,137 @@ it.effect("reveals by opening the containing directory on Linux", () => |
| 609 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 627 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 610 | ); | 628 | ); |
| 611 | | 629 | |
| 612 | it.effect("does not advertise a Linux file manager without a graphical session", () => | 630 | it.effect.skipIf(windowsHost)( |
| 613 | Effect.gen(function* () { | 631 | "does not advertise a Linux file manager without a graphical session", |
| 614 | const fileSystem = yield* FileSystem.FileSystem; | 632 | () => |
| 615 | const path = yield* Path.Path; | 633 | Effect.gen(function* () { |
| 616 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 634 | const fileSystem = yield* FileSystem.FileSystem; |
| 617 | const xdgOpenPath = path.join(binDir, "xdg-open"); | 635 | const path = yield* Path.Path; |
| 618 | yield* fileSystem.writeFileString(xdgOpenPath, "#!/bin/sh\n"); | 636 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 619 | yield* fileSystem.chmod(xdgOpenPath, 0o755); | 637 | const xdgOpenPath = path.join(binDir, "xdg-open"); |
| | 638 | yield* fileSystem.writeFileString(xdgOpenPath, "#!/bin/sh\n"); |
| | 639 | yield* fileSystem.chmod(xdgOpenPath, 0o755); |
| 620 | | 640 | |
| 621 | const editors = yield* Effect.gen(function* () { | 641 | const editors = yield* Effect.gen(function* () { |
| 622 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 642 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 623 | return yield* launcher.resolveAvailableEditors(); | 643 | return yield* launcher.resolveAvailableEditors(); |
| 624 | }).pipe(Effect.provide(testLayer({ platform: "linux", env: { PATH: binDir } }))); | 644 | }).pipe(Effect.provide(testLayer({ platform: "linux", env: { PATH: binDir } }))); |
| 625 | | 645 | |
| 626 | assert.equal(editors.includes("file-manager"), false); | 646 | assert.equal(editors.includes("file-manager"), false); |
| 627 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 647 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 628 | ); | 648 | ); |
| 629 | | 649 | |
| 630 | it.effect("advertises a Linux file manager when a directory handler is installed", () => | 650 | it.effect.skipIf(windowsHost)( |
| 631 | Effect.gen(function* () { | 651 | "advertises a Linux file manager when a directory handler is installed", |
| 632 | const fileSystem = yield* FileSystem.FileSystem; | 652 | () => |
| 633 | const path = yield* Path.Path; | 653 | Effect.gen(function* () { |
| 634 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 654 | const fileSystem = yield* FileSystem.FileSystem; |
| 635 | for (const name of ["xdg-open", "xdg-mime"]) { | 655 | const path = yield* Path.Path; |
| 636 | const filePath = path.join(binDir, name); | 656 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 637 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 657 | for (const name of ["xdg-open", "xdg-mime"]) { |
| 638 | yield* fileSystem.chmod(filePath, 0o755); | 658 | const filePath = path.join(binDir, name); |
| 639 | } | 659 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 660 | yield* fileSystem.chmod(filePath, 0o755); |
| | 661 | } |
| 640 | | 662 | |
| 641 | let probe: ChildProcess.StandardCommand | undefined; | 663 | let probe: ChildProcess.StandardCommand | undefined; |
| 642 | const editors = yield* Effect.gen(function* () { | 664 | const editors = yield* Effect.gen(function* () { |
| 643 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 665 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 644 | return yield* launcher.resolveAvailableEditors(); | 666 | return yield* launcher.resolveAvailableEditors(); |
| 645 | }).pipe( | 667 | }).pipe( |
| 646 | Effect.provide( | 668 | Effect.provide( |
| 647 | testLayer({ | 669 | testLayer({ |
| 648 | platform: "linux", | 670 | platform: "linux", |
| 649 | env: { PATH: binDir, DISPLAY: ":0" }, | 671 | env: { PATH: binDir, DISPLAY: ":0" }, |
| 650 | onSpawn: (command) => { | 672 | onSpawn: (command) => { |
| 651 | probe = command; | 673 | probe = command; |
| 652 | }, | 674 | }, |
| 653 | spawnResult: (command) => | 675 | spawnResult: (command) => |
| 654 | command.command === "xdg-mime" ? { stdout: "org.gnome.Nautilus.desktop\n" } : undefined, | 676 | command.command === "xdg-mime" |
| 655 | }), | 677 | ? { stdout: "org.gnome.Nautilus.desktop\n" } |
| 656 | ), | 678 | : undefined, |
| 657 | ); | 679 | }), |
| | 680 | ), |
| | 681 | ); |
| 658 | | 682 | |
| 659 | assert.equal(editors.includes("file-manager"), true); | 683 | assert.equal(editors.includes("file-manager"), true); |
| 660 | assert.ok(probe); | 684 | assert.ok(probe); |
| 661 | assert.equal(probe.command, "xdg-mime"); | 685 | assert.equal(probe.command, "xdg-mime"); |
| 662 | assert.deepEqual(probe.args, ["query", "default", "inode/directory"]); | 686 | assert.deepEqual(probe.args, ["query", "default", "inode/directory"]); |
| 663 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 687 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 664 | ); | 688 | ); |
| 665 | | 689 | |
| 666 | // `xdg-open` with a display variable but no `inode/directory` handler exits | 690 | // `xdg-open` with a display variable but no `inode/directory` handler exits |
| 667 | // nonzero after the launch has already detached: without this gate the server | 691 | // nonzero after the launch has already detached: without this gate the server |
| 668 | // advertises a reveal that is a silent no-op. | 692 | // advertises a reveal that is a silent no-op. |
| 669 | it.effect("does not advertise a Linux file manager without a directory handler", () => | 693 | it.effect.skipIf(windowsHost)( |
| 670 | Effect.gen(function* () { | 694 | "does not advertise a Linux file manager without a directory handler", |
| 671 | const fileSystem = yield* FileSystem.FileSystem; | 695 | () => |
| 672 | const path = yield* Path.Path; | 696 | Effect.gen(function* () { |
| 673 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 697 | const fileSystem = yield* FileSystem.FileSystem; |
| 674 | for (const name of ["xdg-open", "xdg-mime"]) { | 698 | const path = yield* Path.Path; |
| 675 | const filePath = path.join(binDir, name); | 699 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 676 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 700 | for (const name of ["xdg-open", "xdg-mime"]) { |
| 677 | yield* fileSystem.chmod(filePath, 0o755); | 701 | const filePath = path.join(binDir, name); |
| 678 | } | 702 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 703 | yield* fileSystem.chmod(filePath, 0o755); |
| | 704 | } |
| 679 | | 705 | |
| 680 | const editors = yield* Effect.gen(function* () { | 706 | const editors = yield* Effect.gen(function* () { |
| 681 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 707 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 682 | return yield* launcher.resolveAvailableEditors(); | 708 | return yield* launcher.resolveAvailableEditors(); |
| 683 | }).pipe( | 709 | }).pipe( |
| 684 | Effect.provide( | 710 | Effect.provide( |
| 685 | testLayer({ | 711 | testLayer({ |
| 686 | platform: "linux", | 712 | platform: "linux", |
| 687 | env: { PATH: binDir, DISPLAY: ":0" }, | 713 | env: { PATH: binDir, DISPLAY: ":0" }, |
| 688 | spawnResult: (command) => (command.command === "xdg-mime" ? { stdout: "" } : undefined), | 714 | spawnResult: (command) => (command.command === "xdg-mime" ? { stdout: "" } : undefined), |
| 689 | }), | 715 | }), |
| 690 | ), | 716 | ), |
| 691 | ); | 717 | ); |
| 692 | | 718 | |
| 693 | assert.equal(editors.includes("file-manager"), false); | 719 | assert.equal(editors.includes("file-manager"), false); |
| 694 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 720 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 695 | ); | 721 | ); |
| 696 | | 722 | |
| 697 | it.effect("does not advertise a Linux file manager when the handler query fails", () => | 723 | it.effect.skipIf(windowsHost)( |
| 698 | Effect.gen(function* () { | 724 | "does not advertise a Linux file manager when the handler query fails", |
| 699 | const fileSystem = yield* FileSystem.FileSystem; | 725 | () => |
| 700 | const path = yield* Path.Path; | 726 | Effect.gen(function* () { |
| 701 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 727 | const fileSystem = yield* FileSystem.FileSystem; |
| 702 | for (const name of ["xdg-open", "xdg-mime"]) { | 728 | const path = yield* Path.Path; |
| 703 | const filePath = path.join(binDir, name); | 729 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 704 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); | 730 | for (const name of ["xdg-open", "xdg-mime"]) { |
| 705 | yield* fileSystem.chmod(filePath, 0o755); | 731 | const filePath = path.join(binDir, name); |
| 706 | } | 732 | yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n"); |
| | 733 | yield* fileSystem.chmod(filePath, 0o755); |
| | 734 | } |
| 707 | | 735 | |
| 708 | const editors = yield* Effect.gen(function* () { | 736 | const editors = yield* Effect.gen(function* () { |
| 709 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 737 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 710 | return yield* launcher.resolveAvailableEditors(); | 738 | return yield* launcher.resolveAvailableEditors(); |
| 711 | }).pipe( | 739 | }).pipe( |
| 712 | Effect.provide( | 740 | Effect.provide( |
| 713 | testLayer({ | 741 | testLayer({ |
| 714 | platform: "linux", | 742 | platform: "linux", |
| 715 | env: { PATH: binDir, DISPLAY: ":0" }, | 743 | env: { PATH: binDir, DISPLAY: ":0" }, |
| 716 | spawnResult: (command) => | 744 | spawnResult: (command) => |
| 717 | command.command === "xdg-mime" | 745 | command.command === "xdg-mime" |
| 718 | ? { exitCode: 47, stdout: "org.gnome.Nautilus.desktop\n" } | 746 | ? { exitCode: 47, stdout: "org.gnome.Nautilus.desktop\n" } |
| 719 | : undefined, | 747 | : undefined, |
| 720 | }), | 748 | }), |
| 721 | ), | 749 | ), |
| 722 | ); | 750 | ); |
| 723 | | 751 | |
| 724 | assert.equal(editors.includes("file-manager"), false); | 752 | assert.equal(editors.includes("file-manager"), false); |
| 725 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 753 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 726 | ); | 754 | ); |
| 727 | | 755 | |
| 728 | // The handler probe carries its own timeout because the editor scan's outer | 756 | // The handler probe carries its own timeout because the editor scan's outer |
| 729 | // timeout in server.getConfig degrades to an EMPTY editor list: a wedged | 757 | // timeout in server.getConfig degrades to an EMPTY editor list: a wedged |
| 730 | // xdg-mime must cost only the file manager, never the other editors. Runs on | 758 | // xdg-mime must cost only the file manager, never the other editors. Runs on |
| 731 | // the live clock so the probe's real timeout fires. | 759 | // the live clock so the probe's real timeout fires. |
| 732 | it.live("a stalled handler probe drops only the file manager", () => | 760 | it.live.skipIf(windowsHost)("a stalled handler probe drops only the file manager", () => |
| 733 | Effect.gen(function* () { | 761 | Effect.gen(function* () { |
| 734 | const fileSystem = yield* FileSystem.FileSystem; | 762 | const fileSystem = yield* FileSystem.FileSystem; |
| 735 | const path = yield* Path.Path; | 763 | const path = yield* Path.Path; |
| ... | @@ -758,22 +786,26 @@ it.live("a stalled handler probe drops only the file manager", () => | ... | @@ -758,22 +786,26 @@ it.live("a stalled handler probe drops only the file manager", () => |
| 758 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 786 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 759 | ); | 787 | ); |
| 760 | | 788 | |
| 761 | it.effect("does not advertise a Linux file manager when xdg-mime is missing", () => | 789 | it.effect.skipIf(windowsHost)( |
| 762 | Effect.gen(function* () { | 790 | "does not advertise a Linux file manager when xdg-mime is missing", |
| 763 | const fileSystem = yield* FileSystem.FileSystem; | 791 | () => |
| 764 | const path = yield* Path.Path; | 792 | Effect.gen(function* () { |
| 765 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); | 793 | const fileSystem = yield* FileSystem.FileSystem; |
| 766 | const xdgOpenPath = path.join(binDir, "xdg-open"); | 794 | const path = yield* Path.Path; |
| 767 | yield* fileSystem.writeFileString(xdgOpenPath, "#!/bin/sh\n"); | 795 | const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" }); |
| 768 | yield* fileSystem.chmod(xdgOpenPath, 0o755); | 796 | const xdgOpenPath = path.join(binDir, "xdg-open"); |
| | 797 | yield* fileSystem.writeFileString(xdgOpenPath, "#!/bin/sh\n"); |
| | 798 | yield* fileSystem.chmod(xdgOpenPath, 0o755); |
| 769 | | 799 | |
| 770 | const editors = yield* Effect.gen(function* () { | 800 | const editors = yield* Effect.gen(function* () { |
| 771 | const launcher = yield* ExternalLauncher.ExternalLauncher; | 801 | const launcher = yield* ExternalLauncher.ExternalLauncher; |
| 772 | return yield* launcher.resolveAvailableEditors(); | 802 | return yield* launcher.resolveAvailableEditors(); |
| 773 | }).pipe(Effect.provide(testLayer({ platform: "linux", env: { PATH: binDir, DISPLAY: ":0" } }))); | 803 | }).pipe( |
| | 804 | Effect.provide(testLayer({ platform: "linux", env: { PATH: binDir, DISPLAY: ":0" } })), |
| | 805 | ); |
| 774 | | 806 | |
| 775 | assert.equal(editors.includes("file-manager"), false); | 807 | assert.equal(editors.includes("file-manager"), false); |
| 776 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 808 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 777 | ); | 809 | ); |
| 778 | | 810 | |
| 779 | it.effect("discovers editors through the service API", () => | 811 | it.effect("discovers editors through the service API", () => |