@@ -809,26 +809,36 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
809809 } ) ,
810810 ) ;
811811
812- it . effect . each ( [ "linux" , "darwin" ] as const ) (
813- "leaves the service stopped if restoring its previous state fails on %s" ,
814- ( platform ) =>
812+ it . effect . each (
813+ ( [ "linux" , "darwin" ] as const ) . flatMap ( ( platform ) =>
814+ ( [ "state" , "unit" ] as const ) . flatMap ( ( failedRestore ) =>
815+ [ false , true ] . map ( ( hasMarker ) => ( { platform, failedRestore, hasMarker } ) ) ,
816+ ) ,
817+ ) ,
818+ ) (
819+ "restores remaining files and leaves the service stopped after $failedRestore restore failure on $platform (marker: $hasMarker)" ,
820+ ( { platform, failedRestore, hasMarker } ) =>
815821 Effect . gen ( function * ( ) {
816822 const { service, fs, baseDir, statePath, starts, commands, makeService } =
817823 yield * makeHarness ( platform ) ;
818824 const path = yield * Path . Path ;
819825 const plan = yield * service . install ( ) ;
826+ const markerPath = path . join ( baseDir , "runtime" , SERVICE_RESTART_PENDING_FILE ) ;
827+ if ( hasMarker ) yield * fs . writeFileString ( markerPath , "1.2.3\n" ) ;
820828 let stateWrites = 0 ;
821- let unitWritten = false ;
829+ let unitWrites = 0 ;
822830 const fileSystem = FileSystem . FileSystem . of ( {
823831 ...fs ,
824832 rename : ( from , to ) =>
825833 Effect . gen ( function * ( ) {
826- if ( to === statePath && ++ stateWrites === 2 ) {
834+ if ( to === statePath && ++ stateWrites === 2 && failedRestore === "state" ) {
835+ return yield * fs . rename ( path . join ( baseDir , "missing-restore-source" ) , to ) ;
836+ }
837+ if ( to === plan . unitPath && ++ unitWrites === 2 && failedRestore === "unit" ) {
827838 return yield * fs . rename ( path . join ( baseDir , "missing-restore-source" ) , to ) ;
828839 }
829840 yield * fs . rename ( from , to ) ;
830- if ( to === plan . unitPath && ! unitWritten ) {
831- unitWritten = true ;
841+ if ( to === plan . unitPath && unitWrites === 1 ) {
832842 yield * fs . rename ( from , to ) ;
833843 }
834844 } ) ,
@@ -845,6 +855,16 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
845855 ? "systemctl --user stop t3code.service"
846856 : "launchctl bootout --wait gui/501/com.t3tools.t3code.service" ,
847857 ) ;
858+ expect ( parseServiceState ( yield * fs . readFileString ( statePath ) ) ?. activeVersion ) . toBe (
859+ failedRestore === "state" ? "1.2.4" : "1.2.3" ,
860+ ) ;
861+ expect ( BootService . bootServiceProgramOf ( yield * fs . readFileString ( plan . unitPath ) ) ) . toBe (
862+ pinnedRuntimePaths ( path , baseDir , failedRestore === "unit" ? "1.2.4" : "1.2.3" , platform )
863+ . entryPath ,
864+ ) ;
865+ expect (
866+ yield * fs . readFileString ( markerPath ) . pipe ( Effect . orElseSucceed ( ( ) => undefined ) ) ,
867+ ) . toBe ( hasMarker ? "1.2.3\n" : undefined ) ;
848868 expect ( yield * fs . readFileString ( plan . logPath ) ) . toContain (
849869 "Could not set up the T3 Code background service." ,
850870 ) ;
0 commit comments