@@ -92,14 +92,15 @@ const launchdNotLoadedMessage =
9292 'Could not find service "com.t3tools.t3code.service" in domain for user gui: 501' ;
9393
9494const processResult = ( input ?: {
95- readonly code ?: number ;
95+ readonly code ?: number | null ;
9696 readonly stdout ?: string ;
9797 readonly stderr ?: string ;
98+ readonly timedOut ?: boolean ;
9899} ) : ProcessRunner . ProcessRunOutput => ( {
99100 stdout : input ?. stdout ?? "" ,
100101 stderr : input ?. stderr ?? "" ,
101- code : ChildProcessSpawner . ExitCode ( input ?. code ?? 0 ) ,
102- timedOut : false ,
102+ code : input ?. code === null ? null : ChildProcessSpawner . ExitCode ( input ?. code ?? 0 ) ,
103+ timedOut : input ?. timedOut ?? false ,
103104 stdoutTruncated : false ,
104105 stderrTruncated : false ,
105106 stdoutInvalidUtf8 : false ,
@@ -189,6 +190,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
189190
190191 const commands : string [ ] = [ ] ;
191192 const timeouts = new Map < string , unknown > ( ) ;
193+ const timeoutBehaviors = new Map < string , ProcessRunner . ProcessRunInput [ "timeoutBehavior" ] > ( ) ;
192194 const control : {
193195 failCommand : string | undefined ;
194196 fixtures : Map < string , ( call : number ) => ProcessRunner . ProcessRunOutput > ;
@@ -216,6 +218,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
216218 const command = `${ input . command } ${ input . args . join ( " " ) } ` ;
217219 commands . push ( command ) ;
218220 timeouts . set ( command , input . timeout ) ;
221+ timeoutBehaviors . set ( command , input . timeoutBehavior ) ;
219222 const call = ( control . callCounts . get ( command ) ?? 0 ) + 1 ;
220223 control . callCounts . set ( command , call ) ;
221224 const signal = control . signals . get ( command ) ;
@@ -310,7 +313,17 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
310313 ) ,
311314 ) ;
312315 const service = yield * makeService ( ) ;
313- return { service, makeService, fs, statePath, commands, timeouts, control, runtime } ;
316+ return {
317+ service,
318+ makeService,
319+ fs,
320+ statePath,
321+ commands,
322+ timeouts,
323+ timeoutBehaviors,
324+ control,
325+ runtime,
326+ } ;
314327} ) ;
315328
316329it . layer ( NodeServices . layer ) ( "boot service install" , ( it ) => {
@@ -925,6 +938,32 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
925938 } ) ,
926939 ) ;
927940
941+ it . effect . each ( [
942+ {
943+ command : `launchctl bootout ${ launchdServiceTarget } ` ,
944+ expectedStep : "stopping the installed launch agent" ,
945+ } ,
946+ {
947+ command : `launchctl print ${ launchdServiceTarget } ` ,
948+ expectedStep : "checking whether the launch agent stopped" ,
949+ } ,
950+ ] ) ( "preserves a timed-out result from $command" , ( { command, expectedStep } ) =>
951+ Effect . gen ( function * ( ) {
952+ const { service, control, timeoutBehaviors } = yield * makeHarness ( "darwin" ) ;
953+ yield * service . install ( ) ;
954+ control . fixtures . set ( command , ( ) => processResult ( { code : null , timedOut : true } ) ) ;
955+
956+ const error = yield * service . install ( ) . pipe ( Effect . flip ) ;
957+
958+ expect ( error ) . toMatchObject ( {
959+ _tag : "BootServiceCommandError" ,
960+ step : expectedStep ,
961+ timedOut : true ,
962+ } ) ;
963+ expect ( timeoutBehaviors . get ( command ) ) . toBe ( "timedOutResult" ) ;
964+ } ) ,
965+ ) ;
966+
928967 it . effect ( "times out instead of bootstrapping while the launch agent remains loaded" , ( ) =>
929968 Effect . gen ( function * ( ) {
930969 const { service, commands, control } = yield * makeHarness ( "darwin" ) ;
0 commit comments