@@ -23,12 +23,16 @@ import * as ExternalLauncher from "./externalLauncher.ts";
2323interface MockSpawnResult {
2424 readonly exitCode ?: number ;
2525 readonly stdout ?: string ;
26+ /** Never deliver an exit code, like a child wedged on a broken desktop session. */
27+ readonly stall ?: boolean ;
2628}
2729
2830function makeMockDetachedHandle ( input : MockSpawnResult & { readonly onUnref ?: ( ) => void } = { } ) {
2931 return ChildProcessSpawner . makeHandle ( {
3032 pid : ChildProcessSpawner . ProcessId ( 1 ) ,
31- exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( input . exitCode ?? 0 ) ) ,
33+ exitCode : input . stall
34+ ? Effect . never
35+ : Effect . succeed ( ChildProcessSpawner . ExitCode ( input . exitCode ?? 0 ) ) ,
3236 isRunning : Effect . succeed ( true ) ,
3337 kill : ( ) => Effect . void ,
3438 unref : Effect . sync ( ( ) => {
@@ -412,6 +416,57 @@ it.effect("does not advertise reveal from WSL when interop PowerShell is missing
412416 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
413417) ;
414418
419+ // When interop PowerShell is missing the capability advertises the Linux
420+ // "files" kind (or nothing), so the reveal must open the Linux file manager
421+ // the label promised even though plain open still prefers File Explorer.
422+ it . effect ( "reveals through the Linux file manager when WSL lacks interop PowerShell" , ( ) =>
423+ Effect . gen ( function * ( ) {
424+ const fileSystem = yield * FileSystem . FileSystem ;
425+ const path = yield * Path . Path ;
426+ const binDir = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-editors-" } ) ;
427+ for ( const name of [ "explorer.exe" , "xdg-open" , "xdg-mime" ] ) {
428+ const filePath = path . join ( binDir , name ) ;
429+ yield * fileSystem . writeFileString ( filePath , "#!/bin/sh\n" ) ;
430+ yield * fileSystem . chmod ( filePath , 0o755 ) ;
431+ }
432+
433+ const spawnedCommands : ChildProcess . StandardCommand [ ] = [ ] ;
434+ const kind = yield * Effect . gen ( function * ( ) {
435+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
436+ const revealKind = yield * launcher . resolveFileManagerRevealKind ( ) ;
437+ yield * launcher . launchEditor ( {
438+ editor : "file-manager" ,
439+ cwd : "/home/t3/workspace/media/clip.mp4" ,
440+ reveal : true ,
441+ } ) ;
442+ return revealKind ;
443+ } ) . pipe (
444+ Effect . provide (
445+ testLayer ( {
446+ platform : "linux" ,
447+ env : {
448+ PATH : binDir ,
449+ WSL_DISTRO_NAME : "Ubuntu-24.04" ,
450+ WSL_INTEROP : "/run/WSL/1_interop" ,
451+ DISPLAY : ":0" ,
452+ } ,
453+ onSpawn : ( command ) => {
454+ spawnedCommands . push ( command ) ;
455+ } ,
456+ spawnResult : ( command ) =>
457+ command . command === "xdg-mime" ? { stdout : "org.gnome.Nautilus.desktop\n" } : undefined ,
458+ } ) ,
459+ ) ,
460+ ) ;
461+
462+ assert . equal ( kind , "files" ) ;
463+ const launch = spawnedCommands . find ( ( command ) => command . command === "xdg-open" ) ;
464+ assert . ok ( launch ) ;
465+ assert . deepEqual ( launch . args , [ "/home/t3/workspace/media" ] ) ;
466+ assert . isUndefined ( spawnedCommands . find ( ( command ) => command . command === "explorer.exe" ) ) ;
467+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
468+ ) ;
469+
415470// Interop can exist without `explorer.exe` on PATH (appendWindowsPath=false)
416471// while WSLg still provides a working Linux file manager; the host must keep
417472// the Linux open/reveal path instead of losing the editor entirely.
@@ -664,6 +719,39 @@ it.effect("does not advertise a Linux file manager when the handler query fails"
664719 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
665720) ;
666721
722+ // The handler probe carries its own timeout because the editor scan's outer
723+ // timeout in server.getConfig degrades to an EMPTY editor list: a wedged
724+ // xdg-mime must cost only the file manager, never the other editors. Runs on
725+ // the live clock so the probe's real timeout fires.
726+ it . live ( "a stalled handler probe drops only the file manager" , ( ) =>
727+ Effect . gen ( function * ( ) {
728+ const fileSystem = yield * FileSystem . FileSystem ;
729+ const path = yield * Path . Path ;
730+ const binDir = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-editors-" } ) ;
731+ for ( const name of [ "xdg-open" , "xdg-mime" , "code" ] ) {
732+ const filePath = path . join ( binDir , name ) ;
733+ yield * fileSystem . writeFileString ( filePath , "#!/bin/sh\n" ) ;
734+ yield * fileSystem . chmod ( filePath , 0o755 ) ;
735+ }
736+
737+ const editors = yield * Effect . gen ( function * ( ) {
738+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
739+ return yield * launcher . resolveAvailableEditors ( ) ;
740+ } ) . pipe (
741+ Effect . provide (
742+ testLayer ( {
743+ platform : "linux" ,
744+ env : { PATH : binDir , DISPLAY : ":0" } ,
745+ spawnResult : ( command ) => ( command . command === "xdg-mime" ? { stall : true } : undefined ) ,
746+ } ) ,
747+ ) ,
748+ ) ;
749+
750+ assert . equal ( editors . includes ( "vscode" ) , true ) ;
751+ assert . equal ( editors . includes ( "file-manager" ) , false ) ;
752+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
753+ ) ;
754+
667755it . effect ( "does not advertise a Linux file manager when xdg-mime is missing" , ( ) =>
668756 Effect . gen ( function * ( ) {
669757 const fileSystem = yield * FileSystem . FileSystem ;
0 commit comments