@@ -580,13 +580,20 @@ it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
580580 const path = yield * Path . Path ;
581581 const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-pinned-prune-" } ) ;
582582 const versionsDir = path . join ( baseDir , "runtime" , "versions" ) ;
583- const install = Effect . fn ( function * ( version : string , complete = true ) {
583+ const now = Duration . toMillis ( Duration . days ( 1 ) ) ;
584+ yield * TestClock . setTime ( now ) ;
585+ const install = Effect . fn ( function * (
586+ version : string ,
587+ completed : "long ago" | "just now" | "never" = "long ago" ,
588+ ) {
584589 const directory = path . join ( versionsDir , version ) ;
585590 yield * fs . makeDirectory ( directory , { recursive : true } ) ;
586591 yield * fs . writeFileString ( path . join ( directory , "t3" ) , "" ) ;
587- if ( complete ) {
588- yield * fs . writeFileString ( path . join ( directory , ".install-complete" ) , `${ version } \n` ) ;
589- }
592+ if ( completed === "never" ) return ;
593+ const sentinel = path . join ( directory , ".install-complete" ) ;
594+ yield * fs . writeFileString ( sentinel , `${ version } \n` ) ;
595+ const at = completed === "just now" ? now : 0 ;
596+ yield * fs . utimes ( sentinel , at , at ) ;
590597 } ) ;
591598 for ( const version of versions ) yield * install ( version ) ;
592599 return { baseDir, versionsDir, install } ;
@@ -608,10 +615,12 @@ it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
608615 "2.0.0" ,
609616 "2.1.0" ,
610617 ] ) ;
611- yield * install ( "1.0.1" , false ) ;
612- yield * install ( ".staging-abc" , false ) ;
618+ // A downgrade another process installed but has not pointed anything at yet.
619+ yield * install ( "0.5.0" , "just now" ) ;
620+ yield * install ( "1.0.1" , "never" ) ;
621+ yield * install ( ".staging-abc" , "never" ) ;
613622 yield * install ( ".pruned-0.8.0" ) ;
614- yield * install ( "other" , false ) ;
623+ yield * install ( "other" , "never" ) ;
615624 yield * fs . symlink ( path . join ( versionsDir , "other" ) , path . join ( versionsDir , "0.9.0" ) ) ;
616625 const binDir = path . join ( baseDir , "bin" ) ;
617626 const customBinDir = path . join ( baseDir , "custom-bin" ) ;
@@ -648,15 +657,17 @@ it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
648657 ) ;
649658
650659 // 1.2.0 is the default launcher, 1.2.5 a recorded one, 1.3.0 running, 1.3.5 in the unit,
651- // 1.4.0 active, 1.5.0 the rolled-back target, 2.0.0 the caller's and 2.1.0 newer.
652- assert . deepEqual ( removed . toSorted ( ) , [ "0.8.0" , "1.0.0" , "1.1.0" ] ) ;
660+ // 1.4.0 active, 1.5.0 the rolled-back target, 2.0.0 the caller's, 0.5.0 just installed.
661+ // Being newer than the caller's version does not keep 2.1.0.
662+ assert . deepEqual ( removed . toSorted ( ) , [ "0.8.0" , "1.0.0" , "1.1.0" , "2.1.0" ] ) ;
653663 // The launcher found on PATH is remembered for a service that cannot see it.
654664 assert . equal (
655665 yield * fs . readFileString ( path . join ( baseDir , "runtime" , "launchers" ) ) ,
656666 `${ path . join ( customBinDir , "t3" ) } \n${ path . join ( binDir , "t3" ) } \n` ,
657667 ) ;
658668 assert . deepEqual ( ( yield * fs . readDirectory ( versionsDir ) ) . toSorted ( ) , [
659669 ".staging-abc" ,
670+ "0.5.0" ,
660671 "0.9.0" ,
661672 "1.0.1" ,
662673 "1.2.0" ,
@@ -666,12 +677,35 @@ it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
666677 "1.4.0" ,
667678 "1.5.0" ,
668679 "2.0.0" ,
669- "2.1.0" ,
670680 "other" ,
671681 ] ) ;
672682 } ) ,
673683 ) ;
674684
685+ it . effect ( "matches a Windows shim whatever its casing" , ( ) =>
686+ Effect . gen ( function * ( ) {
687+ const fs = yield * FileSystem . FileSystem ;
688+ const path = yield * Path . Path ;
689+ const { baseDir, versionsDir } = yield * setup ( [ "1.0.0" , "1.1.0" ] ) ;
690+ const shim = path . join ( baseDir , "t3.cmd" ) ;
691+ yield * fs . writeFileString (
692+ shim ,
693+ `@echo off\r\n"${ path . join ( versionsDir , "1.0.0" , "t3.exe" ) . toUpperCase ( ) } " %*` ,
694+ ) ;
695+ yield * fs . writeFileString ( path . join ( baseDir , "runtime" , "launchers" ) , `${ shim } \n` ) ;
696+
697+ const removed = yield * prunePinnedRuntimes ( { baseDir, keep : [ "2.0.0" ] } ) . pipe (
698+ Effect . provideService (
699+ ProcessRunner . ProcessRunner ,
700+ lsofRunner ( "C:\\Windows\\explorer.exe\n" ) ,
701+ ) ,
702+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
703+ Effect . provideService ( HostProcess . Environment , { } ) ,
704+ ) ;
705+ assert . deepEqual ( removed , [ "1.1.0" ] ) ;
706+ } ) ,
707+ ) ;
708+
675709 it . effect . each ( [
676710 { name : "the process list is unavailable" , state : undefined , lsof : "" } ,
677711 { name : "the service state is unparseable" , state : "{" , lsof : "p1\nftxt\nn/sbin/launchd\n" } ,
0 commit comments