@@ -339,6 +339,111 @@ it.effect("launches an installed editor with platform-safe arguments", () =>
339339 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
340340) ;
341341
342+ it . live . skipIf ( ! windowsHost ) ( "opens Windows folders through the default shell handler" , ( ) =>
343+ Effect . gen ( function * ( ) {
344+ let spawned : ChildProcess . StandardCommand | undefined ;
345+ yield * Effect . gen ( function * ( ) {
346+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
347+ yield * launcher . launchEditor ( {
348+ editor : "file-manager" ,
349+ cwd : "C:/workspace [draft]/author's ‘left’ ‚low‛ $media/’; Write-Output injected; #" ,
350+ } ) ;
351+ } ) . pipe (
352+ Effect . provide (
353+ layerTest ( {
354+ platform : "win32" ,
355+ env : { PATH : "C:\\Windows" , PATHEXT : ".EXE" } ,
356+ onSpawn : ( command ) => {
357+ spawned = command ;
358+ } ,
359+ } ) ,
360+ ) ,
361+ ) ;
362+ assert . ok ( spawned ) ;
363+ assert . equal ( spawned . options . detached , false ) ;
364+ const source = Buffer . from ( String ( spawned . args . at ( - 1 ) ?? "" ) , "base64" ) . toString ( "utf16le" ) ;
365+ const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
366+ const output = yield * spawner . string (
367+ ChildProcess . make ( spawned . command , [
368+ ...spawned . args . slice ( 0 , - 1 ) ,
369+ Buffer . from (
370+ `[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false); function Invoke-Item { param($LiteralPath) Write-Output $LiteralPath }; ${ source } ` ,
371+ "utf16le" ,
372+ ) . toString ( "base64" ) ,
373+ ] ) ,
374+ ) ;
375+ assert . equal (
376+ output . trim ( ) ,
377+ "C:\\workspace [draft]\\author's ‘left’ ‚low‛ $media\\’; Write-Output injected; #" ,
378+ ) ;
379+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
380+ ) ;
381+
382+ for ( const [ replacement , verb , handler , target , expected ] of [
383+ [ "none" , "none" , "" , "C:/repo/file.txt" , 'explorer.exe /select,"C:\\repo\\file.txt"' ] ,
384+ [ "Directory" , "openindopus" , "dopusrt.exe" , "C:/repo/file.txt" , "shell:C:\\repo" ] ,
385+ [ "Folder" , "openindopus" , "dopusrt.exe" , "C:/repo/file.txt" , "shell:C:\\repo" ] ,
386+ [
387+ "Folder" ,
388+ "open" ,
389+ '"C:\\Windows\\explorer.exe"' ,
390+ "C:/repo/file.txt" ,
391+ 'explorer.exe /select,"C:\\repo\\file.txt"' ,
392+ ] ,
393+ [
394+ "Folder" ,
395+ "open" ,
396+ "ExplorerDelegate" ,
397+ "C:/repo/file.txt" ,
398+ 'explorer.exe /select,"C:\\repo\\file.txt"' ,
399+ ] ,
400+ [
401+ "Drive" ,
402+ "openindopus" ,
403+ "dopusrt.exe" ,
404+ "C:/repo/file.txt" ,
405+ 'explorer.exe /select,"C:\\repo\\file.txt"' ,
406+ ] ,
407+ [ "Drive" , "openindopus" , "dopusrt.exe" , "C:/file.txt" , "shell:C:\\" ] ,
408+ ] as const ) {
409+ it . live . skipIf ( ! windowsHost ) (
410+ `reveals ${ target } with ${ replacement } /${ verb } handled by ${ handler } ` ,
411+ ( ) =>
412+ Effect . gen ( function * ( ) {
413+ let spawned : ChildProcess . StandardCommand | undefined ;
414+ yield * Effect . gen ( function * ( ) {
415+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
416+ yield * launcher . launchEditor ( {
417+ editor : "file-manager" ,
418+ cwd : target ,
419+ reveal : true ,
420+ } ) ;
421+ } ) . pipe (
422+ Effect . provide (
423+ layerTest ( {
424+ platform : "win32" ,
425+ env : { PATH : "C:\\Windows" , PATHEXT : ".EXE" } ,
426+ onSpawn : ( command ) => {
427+ spawned = command ;
428+ } ,
429+ } ) ,
430+ ) ,
431+ ) ;
432+ assert . ok ( spawned ) ;
433+ const source = Buffer . from ( String ( spawned . args . at ( - 1 ) ?? "" ) , "base64" ) . toString ( "utf16le" ) ;
434+ const stubs = `function Get-ItemProperty { param($LiteralPath, $ErrorAction) @{ '(default)' = if ($LiteralPath -eq 'Registry::HKEY_CLASSES_ROOT\\${ replacement } \\shell') { '${ verb } ' } elseif ($LiteralPath -eq 'Registry::HKEY_CLASSES_ROOT\\${ replacement } \\shell\\${ verb } \\command') { '${ handler } ' } else { 'none' }; DelegateExecute = if ('${ handler } ' -eq 'ExplorerDelegate') { '{11dbb47c-a525-400b-9e80-a54615a090c0}' } else { '' } } }; function Invoke-Item { param($LiteralPath) Write-Output "shell:$LiteralPath" }; function Start-Process { param($FilePath, $ArgumentList) Write-Output "$FilePath $ArgumentList" }; ` ;
435+ const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
436+ const output = yield * spawner . string (
437+ ChildProcess . make ( spawned . command , [
438+ ...spawned . args . slice ( 0 , - 1 ) ,
439+ Buffer . from ( stubs + source , "utf16le" ) . toString ( "base64" ) ,
440+ ] ) ,
441+ ) ;
442+ assert . equal ( output . trim ( ) , expected ) ;
443+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
444+ ) ;
445+ }
446+
342447it . effect . skipIf ( windowsHost ) (
343448 "reveals a WSL file in Windows File Explorer through its UNC path" ,
344449 ( ) =>
@@ -359,7 +464,7 @@ it.effect.skipIf(windowsHost)(
359464 const editors = yield * launcher . resolveAvailableEditors ( ) ;
360465 yield * launcher . launchEditor ( {
361466 editor : "file-manager" ,
362- cwd : "/home/t3/workspace [draft]/author's $media/clip|draft.mp4" ,
467+ cwd : "/home/t3/workspace [draft]/author's ‘ $media/clip|draft.mp4" ,
363468 reveal : true ,
364469 } ) ;
365470 return { kind, editors } ;
@@ -386,9 +491,14 @@ it.effect.skipIf(windowsHost)(
386491 assert . equal ( spawned . options . detached , true ) ;
387492 const encodedCommand = String ( spawned . args [ spawned . args . length - 1 ] ?? "" ) ;
388493 const decodedCommand = Buffer . from ( encodedCommand , "base64" ) . toString ( "utf16le" ) ;
389- assert . equal (
494+ assert . include ( decodedCommand , "'Directory', 'Folder'" ) ;
495+ assert . include (
496+ decodedCommand ,
497+ "Invoke-Item -LiteralPath '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s ‘‘$media'" ,
498+ ) ;
499+ assert . include (
390500 decodedCommand ,
391- "$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath '\\\\ wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s $media' } else { Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s $media\\ clip|draft.mp4' + '\"') } " ,
501+ "'\\\\ wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s ‘‘ $media\\ clip|draft.mp4'" ,
392502 ) ;
393503 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
394504) ;
0 commit comments