@@ -3,6 +3,8 @@ 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" ;
7+ import * as TestClock from "effect/testing/TestClock" ;
68import { describe , expect , it , vi } from "vite-plus/test" ;
79
810import {
@@ -411,8 +413,8 @@ effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
411413 PATHEXT : ".COM;.EXE" ,
412414 } ) ;
413415
414- // Two distinct directories, two extensions. The repeats cost nothing .
415- expect ( probed ) . toHaveLength ( 4 ) ;
416+ // Two directories, two extensions, upper and lowercase spellings .
417+ expect ( probed ) . toHaveLength ( 8 ) ;
416418 expect ( new Set ( probed ) . size ) . toBe ( probed . length ) ;
417419 } ) ,
418420 ) ;
@@ -427,21 +429,71 @@ effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
427429 // Deliberately not folded together. Windows 10+ can mark a directory
428430 // case-sensitive, so the two spellings are not provably one directory and
429431 // skipping the second could hide a command that is really there.
430- expect ( probed ) . toHaveLength ( 4 ) ;
432+ expect ( probed ) . toHaveLength ( 8 ) ;
431433 } ) ,
432434 ) ;
433435
434- it . effect ( "probes one spelling per PATHEXT entry" , ( ) =>
436+ it . effect . each ( [ "audit-command" , "audit-command.CMD" ] ) (
437+ "resolves lowercase executable files for %s in a case-sensitive Windows PATH directory" ,
438+ ( command ) =>
439+ Effect . gen ( function * ( ) {
440+ const fs = yield * FileSystem . FileSystem ;
441+ const path = yield * Path . Path ;
442+ const cwd = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-case-sensitive-path-" } ) ;
443+ const executable = path . join ( cwd , "audit-command.cmd" ) ;
444+ yield * fs . writeFileString ( executable , "@echo off\n" ) ;
445+
446+ const resolved = yield * resolveCommandPath ( command , {
447+ env : { PATH : cwd , PATHEXT : ".CMD" } ,
448+ } ) . pipe (
449+ Effect . provideService ( HostProcessPlatform , "win32" ) ,
450+ Effect . provideService ( CommandResolutionCache , new Map ( ) ) ,
451+ Effect . provideService ( FileSystem . FileSystem , {
452+ ...fs ,
453+ // Keep this case-sensitive fixture portable to case-insensitive hosts.
454+ stat : ( filePath ) =>
455+ fs . stat ( filePath === executable ? filePath : path . join ( cwd , "missing" ) ) ,
456+ } ) ,
457+ ) ;
458+
459+ expect ( resolved ) . toBe ( executable ) ;
460+ } ) ,
461+ ) ;
462+
463+ it . effect ( "keeps cached misses until expiry while allowing explicit paths" , ( ) =>
464+ Effect . gen ( function * ( ) {
465+ const fs = yield * FileSystem . FileSystem ;
466+ const path = yield * Path . Path ;
467+ const cwd = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-path-cache-" } ) ;
468+ const executable = path . join ( cwd , "appeared.CMD" ) ;
469+ const options = { env : { PATH : `${ cwd } ;${ cwd } ` , PATHEXT : ".CMD" } } ;
470+
471+ expect ( ( yield * resolveCommandPath ( "appeared" , options ) . pipe ( Effect . result ) ) . _tag ) . toBe (
472+ "Failure" ,
473+ ) ;
474+ yield * fs . writeFileString ( executable , "@echo off\n" ) ;
475+ expect ( ( yield * resolveCommandPath ( "appeared" , options ) . pipe ( Effect . result ) ) . _tag ) . toBe (
476+ "Failure" ,
477+ ) ;
478+ expect ( yield * resolveCommandPath ( executable , options ) ) . toBe ( executable ) ;
479+ yield * TestClock . adjust ( "30 seconds" ) ;
480+ expect ( yield * resolveCommandPath ( "appeared" , options ) ) . toBe ( executable ) ;
481+ } ) . pipe (
482+ Effect . provideService ( HostProcessPlatform , "win32" ) ,
483+ Effect . provideService ( CommandResolutionCache , new Map ( ) ) ,
484+ ) ,
485+ ) ;
486+
487+ it . effect ( "keeps upper and lowercase PATHEXT candidates" , ( ) =>
435488 Effect . gen ( function * ( ) {
436489 const probed = yield * recordProbes ( {
437490 PATH : "C:\\bin" ,
438491 PATHEXT : ".COM;.EXE;.BAT;.CMD" ,
439492 } ) ;
440493
441- // Four extensions, not eight: Windows matches file names
442- // case-insensitively, so the lowercase spellings are the same question.
443- expect ( probed ) . toHaveLength ( 4 ) ;
494+ expect ( probed ) . toHaveLength ( 8 ) ;
444495 expect ( probed . filter ( ( filePath ) => / \. ( C O M | E X E | B A T | C M D ) $ / . test ( filePath ) ) ) . toHaveLength ( 4 ) ;
496+ expect ( probed . filter ( ( filePath ) => / \. ( c o m | e x e | b a t | c m d ) $ / . test ( filePath ) ) ) . toHaveLength ( 4 ) ;
445497 } ) ,
446498 ) ;
447499} ) ;
0 commit comments