@@ -24,6 +24,7 @@ import {
2424 resolveSpawnCommand ,
2525 resolveWindowsEnvironment ,
2626 SpawnExecutableResolution ,
27+ type SpawnExecutableResolver ,
2728 WindowsShellEnvironment ,
2829 type WindowsShellEnvironmentReader ,
2930} from "./shell.ts" ;
@@ -550,13 +551,14 @@ effectIt.layer(NodeServices.layer)("resolveSpawnCommand", (it) => {
550551 it . effect ( "scans PATH once per command until the search environment changes" , ( ) =>
551552 Effect . gen ( function * ( ) {
552553 const scans : Array < string > = [ ] ;
553- const resolve = ( command : string , path : string ) =>
554+ const scan : SpawnExecutableResolver = ( name , _platform , env ) => {
555+ scans . push ( `${ name } @${ env . PATH } ` ) ;
556+ return name === "missing" ? undefined : `${ env . PATH } \\${ name } .exe` ;
557+ } ;
558+ const resolve = ( command : string , path : string , resolver = scan ) =>
554559 resolveSpawnCommand ( command , [ ] , { env : { PATH : path , PATHEXT : ".EXE" } } ) . pipe (
555560 Effect . provideService ( HostProcessPlatform , "win32" ) ,
556- Effect . provideService ( SpawnExecutableResolution , ( name , _platform , env ) => {
557- scans . push ( `${ name } @${ env . PATH } ` ) ;
558- return name === "missing" ? undefined : `${ env . PATH } \\${ name } .exe` ;
559- } ) ,
561+ Effect . provideService ( SpawnExecutableResolution , resolver ) ,
560562 ) ;
561563
562564 expect ( ( yield * resolve ( "git" , "C:\\one" ) ) . command ) . toBe ( "C:\\one\\git.exe" ) ;
@@ -581,6 +583,12 @@ effectIt.layer(NodeServices.layer)("resolveSpawnCommand", (it) => {
581583 yield * TestClock . adjust ( "31 seconds" ) ;
582584 yield * resolve ( "git" , "C:\\one" ) ;
583585 expect ( scans ) . toHaveLength ( 7 ) ;
586+
587+ // Another resolver sharing the cache gets its own answer, not the cached one.
588+ const elsewhere = yield * resolve ( "git" , "C:\\one" , ( ) => "D:\\elsewhere\\git.exe" ) ;
589+ expect ( elsewhere . command ) . toBe ( "D:\\elsewhere\\git.exe" ) ;
590+ expect ( ( yield * resolve ( "git" , "C:\\one" ) ) . command ) . toBe ( "C:\\one\\git.exe" ) ;
591+ expect ( scans ) . toHaveLength ( 7 ) ;
584592 } ) . pipe ( Effect . provideService ( CommandResolutionCache , new Map ( ) ) ) ,
585593 ) ;
586594
0 commit comments