@@ -3,6 +3,7 @@ import { it as effectIt } from "@effect/vitest";
33import { HostProcessEnvironment , HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
44import * as Effect from "effect/Effect" ;
55import * as FileSystem from "effect/FileSystem" ;
6+ import * as Path from "effect/Path" ;
67import * as PlatformError from "effect/PlatformError" ;
78import { describe , expect , it , vi } from "vite-plus/test" ;
89
@@ -371,7 +372,46 @@ effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
371372 } ) ,
372373 ) ;
373374
374- it . effect ( "preserves filesystem failures while probing PATH candidates" , ( ) =>
375+ it . effect ( "continues past a failed PATH probe when a later executable exists" , ( ) =>
376+ Effect . gen ( function * ( ) {
377+ const fileSystem = yield * FileSystem . FileSystem ;
378+ const path = yield * Path . Path ;
379+ const baseDirectory = yield * fileSystem . makeTempDirectoryScoped ( {
380+ prefix : "t3-command-resolution-" ,
381+ } ) ;
382+ const blockedDirectory = path . join ( baseDirectory , "blocked" ) ;
383+ const workingDirectory = path . join ( baseDirectory , "working" ) ;
384+ const blockedCandidate = path . join ( blockedDirectory , "available-command" ) ;
385+ const workingCandidate = path . join ( workingDirectory , "available-command" ) ;
386+ yield * fileSystem . makeDirectory ( blockedDirectory ) ;
387+ yield * fileSystem . makeDirectory ( workingDirectory ) ;
388+ yield * fileSystem . writeFileString ( workingCandidate , "#!/bin/sh\nexit 0\n" ) ;
389+ yield * fileSystem . chmod ( workingCandidate , 0o755 ) ;
390+
391+ const cause = PlatformError . systemError ( {
392+ _tag : "PermissionDenied" ,
393+ module : "FileSystem" ,
394+ method : "stat" ,
395+ pathOrDescriptor : blockedCandidate ,
396+ } ) ;
397+ const failingFileSystem = FileSystem . FileSystem . of ( {
398+ ...fileSystem ,
399+ stat : ( candidate ) =>
400+ candidate === blockedCandidate ? Effect . fail ( cause ) : fileSystem . stat ( candidate ) ,
401+ } ) ;
402+
403+ const resolved = yield * resolveCommandPath ( "available-command" , {
404+ env : { PATH : `${ blockedDirectory } :${ workingDirectory } ` } ,
405+ } ) . pipe (
406+ Effect . provideService ( HostProcessPlatform , "linux" ) ,
407+ Effect . provideService ( FileSystem . FileSystem , failingFileSystem ) ,
408+ ) ;
409+
410+ expect ( resolved ) . toBe ( workingCandidate ) ;
411+ } ) ,
412+ ) ;
413+
414+ it . effect ( "preserves filesystem failures after exhausting PATH candidates" , ( ) =>
375415 Effect . gen ( function * ( ) {
376416 const fileSystem = yield * FileSystem . FileSystem ;
377417 const cause = PlatformError . systemError ( {
0 commit comments