@@ -87,20 +87,17 @@ const launchdServiceTarget = "gui/501/com.t3tools.t3code.service";
8787const launchdNotLoadedMessage =
8888 'Could not find service "com.t3tools.t3code.service" in domain for user gui: 501' ;
8989
90- const processResult = ( input ?: {
91- readonly code ?: number | null ;
92- readonly stdout ?: string ;
93- readonly stderr ?: string ;
94- readonly timedOut ?: boolean ;
95- } ) : ProcessRunner . ProcessRunOutput => ( {
90+ const processResult = (
91+ input ?: Partial < Omit < ProcessRunner . ProcessRunOutput , "code" > > & { readonly code ?: number | null } ,
92+ ) : ProcessRunner . ProcessRunOutput => ( {
9693 stdout : input ?. stdout ?? "" ,
9794 stderr : input ?. stderr ?? "" ,
9895 code : input ?. code === null ? null : ChildProcessSpawner . ExitCode ( input ?. code ?? 0 ) ,
9996 timedOut : input ?. timedOut ?? false ,
100- stdoutTruncated : false ,
101- stderrTruncated : false ,
102- stdoutInvalidUtf8 : false ,
103- stderrInvalidUtf8 : false ,
97+ stdoutTruncated : input ?. stdoutTruncated ?? false ,
98+ stderrTruncated : input ?. stderrTruncated ?? false ,
99+ stdoutInvalidUtf8 : input ?. stdoutInvalidUtf8 ?? false ,
100+ stderrInvalidUtf8 : input ?. stderrInvalidUtf8 ?? false ,
104101} ) ;
105102
106103it ( "recognizes only confirmed launchd not-loaded responses" , ( ) => {
@@ -982,6 +979,125 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
982979 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
983980 ) ;
984981
982+ it . effect . each ( [ "install" , "restart" , "uninstall" ] as const ) (
983+ "preserves a probe timeout after an idempotent bootout during $0" ,
984+ ( operation ) =>
985+ Effect . gen ( function * ( ) {
986+ const { service, commands, control, fs } = yield * makeHarness ( "darwin" ) ;
987+ const plan = yield * service . install ( ) ;
988+ commands . length = 0 ;
989+ control . fixtures . set ( `launchctl bootout ${ launchdServiceTarget } ` , ( ) =>
990+ processResult ( { code : 3 , stderr : "Boot-out failed: 3: No such process\n" } ) ,
991+ ) ;
992+ control . fixtures . set ( `launchctl print ${ launchdServiceTarget } ` , ( ) =>
993+ processResult ( { code : null , timedOut : true } ) ,
994+ ) ;
995+
996+ const action =
997+ operation === "install"
998+ ? service . install ( ) . pipe ( Effect . asVoid )
999+ : service [ operation ] . pipe ( Effect . asVoid ) ;
1000+ const error = yield * action . pipe ( Effect . flip ) ;
1001+
1002+ expect ( error ) . toMatchObject ( {
1003+ _tag : "BootServiceCommandError" ,
1004+ step : "checking whether the launch agent stopped" ,
1005+ timedOut : true ,
1006+ } ) ;
1007+ expect ( error . message ) . toContain ( "timed out" ) ;
1008+ expect ( commands . filter ( ( command ) => command . startsWith ( "launchctl " ) ) ) . toEqual ( [
1009+ `launchctl bootout ${ launchdServiceTarget } ` ,
1010+ `launchctl print ${ launchdServiceTarget } ` ,
1011+ ] ) ;
1012+ expect ( yield * fs . exists ( plan . unitPath ) ) . toBe ( true ) ;
1013+ } ) ,
1014+ ) ;
1015+
1016+ it . effect . each ( [
1017+ {
1018+ name : "permission denied" ,
1019+ result : processResult ( { code : 1 , stderr : "Operation not permitted" } ) ,
1020+ } ,
1021+ { name : "empty failure" , result : processResult ( { code : 113 } ) } ,
1022+ {
1023+ name : "wrong label" ,
1024+ result : processResult ( {
1025+ code : 113 ,
1026+ stderr : launchdNotLoadedMessage . replace ( ".service" , ".other" ) ,
1027+ } ) ,
1028+ } ,
1029+ {
1030+ name : "missing GUI domain" ,
1031+ result : processResult ( { code : 125 , stderr : "Could not find domain for user gui: 501" } ) ,
1032+ } ,
1033+ {
1034+ name : "extra error" ,
1035+ result : processResult ( {
1036+ code : 113 ,
1037+ stderr : `${ launchdNotLoadedMessage } \nOperation not permitted` ,
1038+ } ) ,
1039+ } ,
1040+ { name : "signal exit" , result : processResult ( { code : null , stderr : launchdNotLoadedMessage } ) } ,
1041+ {
1042+ name : "truncated stderr" ,
1043+ result : processResult ( { code : 113 , stderr : launchdNotLoadedMessage , stderrTruncated : true } ) ,
1044+ } ,
1045+ {
1046+ name : "truncated stdout" ,
1047+ result : processResult ( { code : 113 , stderr : launchdNotLoadedMessage , stdoutTruncated : true } ) ,
1048+ } ,
1049+ {
1050+ name : "invalid stderr" ,
1051+ result : processResult ( {
1052+ code : 113 ,
1053+ stderr : launchdNotLoadedMessage ,
1054+ stderrInvalidUtf8 : true ,
1055+ } ) ,
1056+ } ,
1057+ {
1058+ name : "invalid stdout" ,
1059+ result : processResult ( {
1060+ code : 113 ,
1061+ stderr : launchdNotLoadedMessage ,
1062+ stdoutInvalidUtf8 : true ,
1063+ } ) ,
1064+ } ,
1065+ ] ) ( "fails closed on $name during absence verification" , ( { result } ) =>
1066+ Effect . gen ( function * ( ) {
1067+ const { service, commands, control, fs } = yield * makeHarness ( "darwin" ) ;
1068+ const plan = yield * service . install ( ) ;
1069+ commands . length = 0 ;
1070+ control . fixtures . set ( `launchctl print ${ launchdServiceTarget } ` , ( ) => result ) ;
1071+
1072+ const error = yield * service . install ( ) . pipe ( Effect . flip ) ;
1073+
1074+ expect ( error ) . toMatchObject ( {
1075+ _tag : "BootServiceCommandError" ,
1076+ step : "checking whether the launch agent stopped" ,
1077+ } ) ;
1078+ expect ( commands . filter ( ( command ) => command . startsWith ( "launchctl " ) ) ) . toEqual ( [
1079+ `launchctl bootout ${ launchdServiceTarget } ` ,
1080+ `launchctl print ${ launchdServiceTarget } ` ,
1081+ ] ) ;
1082+ expect ( yield * fs . exists ( plan . unitPath ) ) . toBe ( true ) ;
1083+ } ) ,
1084+ ) ;
1085+
1086+ it . effect ( "keeps the plist when uninstall cannot confirm absence" , ( ) =>
1087+ Effect . gen ( function * ( ) {
1088+ const { service, commands, control, fs } = yield * makeHarness ( "darwin" ) ;
1089+ const plan = yield * service . install ( ) ;
1090+ commands . length = 0 ;
1091+ control . fixtures . set ( `launchctl print ${ launchdServiceTarget } ` , ( ) =>
1092+ processResult ( { code : 1 , stderr : "Operation not permitted" } ) ,
1093+ ) ;
1094+
1095+ expect ( ( yield * service . uninstall . pipe ( Effect . flip ) ) . _tag ) . toBe ( "BootServiceCommandError" ) ;
1096+ expect ( yield * fs . exists ( plan . unitPath ) ) . toBe ( true ) ;
1097+ expect ( commands ) . not . toContain ( `launchctl bootstrap gui/501 ${ plan . unitPath } ` ) ;
1098+ } ) ,
1099+ ) ;
1100+
9851101 it . effect ( "shares one stop timeout across bootout and absence verification" , ( ) =>
9861102 Effect . gen ( function * ( ) {
9871103 const { service, commands, control } = yield * makeHarness ( "darwin" ) ;
0 commit comments