@@ -511,6 +511,97 @@ it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
511511 } ) ,
512512 ) ;
513513
514+ it . effect . each ( [
515+ { name : "its directory is on PATH" , onPath : true , recorded : false , linkedHome : false } ,
516+ {
517+ name : "an earlier prune recorded its entry as a launcher" ,
518+ onPath : false ,
519+ recorded : true ,
520+ linkedHome : false ,
521+ } ,
522+ {
523+ name : "its real directory in a symlinked home is on PATH" ,
524+ onPath : true ,
525+ recorded : false ,
526+ linkedHome : true ,
527+ } ,
528+ ] ) ( "removes a runtime only its own entry names when $name" , ( { onPath, recorded, linkedHome } ) =>
529+ Effect . gen ( function * ( ) {
530+ const fs = yield * FileSystem . FileSystem ;
531+ const path = yield * Path . Path ;
532+ const { baseDir, versionsDir } = yield * setup ( [ "1.0.0" , "1.1.0" ] ) ;
533+ const binDir = path . join ( baseDir , "bin" ) ;
534+ yield * fs . makeDirectory ( binDir ) ;
535+ yield * fs . symlink ( path . join ( versionsDir , "1.1.0" , "t3" ) , path . join ( binDir , "t3" ) ) ;
536+ const ownDir = path . join ( versionsDir , "1.0.0" ) ;
537+ if ( recorded ) {
538+ yield * fs . writeFileString (
539+ path . join ( baseDir , "runtime" , "launchers" ) ,
540+ `${ path . join ( ownDir , "t3" ) } \n` ,
541+ ) ;
542+ }
543+
544+ const home = linkedHome
545+ ? path . join ( yield * fs . makeTempDirectoryScoped ( { prefix : "t3-pinned-link-" } ) , "home" )
546+ : baseDir ;
547+ if ( linkedHome ) yield * fs . symlink ( baseDir , home ) ;
548+
549+ // The launch agent puts the running runtime's own directory on PATH.
550+ const removed = yield * prunePinnedRuntimes ( { baseDir : home , keep : [ "2.0.0" ] } ) . pipe (
551+ Effect . provideService (
552+ ProcessRunner . ProcessRunner ,
553+ lsofRunner ( "p1\nftxt\nn/sbin/launchd\n" ) ,
554+ ) ,
555+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
556+ Effect . provideService ( HostProcess . Environment , {
557+ T3CODE_INSTALL_BIN_DIR : binDir ,
558+ PATH : onPath ? `${ ownDir } :/usr/bin:/bin` : "/usr/bin:/bin" ,
559+ } ) ,
560+ ) ;
561+ assert . deepEqual ( removed , [ "1.0.0" ] ) ;
562+ } ) ,
563+ ) ;
564+
565+ it . effect . each ( [
566+ { name : "a launcher inside the versions directory" , via : "bin" as const } ,
567+ { name : "a PATH directory linked to its version directory" , via : "linked dir" as const } ,
568+ {
569+ name : "a PATH directory in the versions directory linked to its version directory" ,
570+ via : "linked versions dir" as const ,
571+ } ,
572+ ] ) ( "keeps a runtime $name names" , ( { via } ) =>
573+ Effect . gen ( function * ( ) {
574+ const fs = yield * FileSystem . FileSystem ;
575+ const path = yield * Path . Path ;
576+ const { baseDir, versionsDir } = yield * setup ( [ "1.0.0" , "1.1.0" ] ) ;
577+ let pathDirs = "/usr/bin:/bin" ;
578+ if ( via === "bin" ) {
579+ // The installer accepts any bin directory, including one under the versions directory.
580+ const binDir = path . join ( versionsDir , "bin" ) ;
581+ yield * fs . makeDirectory ( binDir ) ;
582+ yield * fs . symlink ( path . join ( versionsDir , "1.0.0" , "t3" ) , path . join ( binDir , "t3" ) ) ;
583+ yield * fs . writeFileString (
584+ path . join ( baseDir , "runtime" , "launchers" ) ,
585+ `${ path . join ( binDir , "t3" ) } \n` ,
586+ ) ;
587+ } else {
588+ const linkedDir = path . join ( via === "linked dir" ? baseDir : versionsDir , "current" ) ;
589+ yield * fs . symlink ( path . join ( versionsDir , "1.0.0" ) , linkedDir ) ;
590+ pathDirs = `${ linkedDir } :${ pathDirs } ` ;
591+ }
592+
593+ const removed = yield * prunePinnedRuntimes ( { baseDir, keep : [ "2.0.0" ] } ) . pipe (
594+ Effect . provideService (
595+ ProcessRunner . ProcessRunner ,
596+ lsofRunner ( "p1\nftxt\nn/sbin/launchd\n" ) ,
597+ ) ,
598+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
599+ Effect . provideService ( HostProcess . Environment , { PATH : pathDirs } ) ,
600+ ) ;
601+ assert . deepEqual ( removed , [ "1.1.0" ] ) ;
602+ } ) ,
603+ ) ;
604+
514605 it . effect . each ( [
515606 // An interrupted append cut this record short.
516607 { name : "an unterminated launcher record" , recorded : "/opt/t" , cut : "" } ,
0 commit comments