@@ -5,7 +5,6 @@ import path from 'node:path';
55import { expect , test } from 'vitest' ;
66import { tryAcquireDaemonRegistration } from '@agent-device/daemon-contracts/daemon-registration-owner' ;
77import {
8- claimDaemonStartupPhasesFile ,
98 readDaemonStartupPhaseMarkers ,
109 recordDaemonStartupMarker ,
1110 removeDaemonStartupPhasesFile ,
@@ -50,19 +49,19 @@ test('marker reading ignores unknown phases and unparsable lines', () => {
5049} ) ;
5150
5251test ( 'the producer lifetime claim empties a same-pid leftover' , async ( ) => {
53- // Pid reuse after both the old client and daemon died before either cleanup: the entry claims
52+ // Pid reuse after both the old client and daemon died before either cleanup: the entry removes
5453 // its record before its first marker; this child repeats that producer sequence itself.
5554 const stateDir = await mkdtempForTest ( 'agent-device-markers-' ) ;
5655 writeFileSync ( path . join ( stateDir , 'package.json' ) , '{"type":"module"}' ) ;
5756 const entry = path . join ( stateDir , 'claim-producer.js' ) ;
5857 const registrationUrl = new URL ( './daemon-startup-phases.ts' , import . meta. url ) . href ;
5958 writeFileSync (
6059 entry ,
61- `import { claimDaemonStartupPhasesFile , recordDaemonStartupMarker, resolveDaemonStartupPhasesPath } from ${ JSON . stringify ( registrationUrl ) } ;
60+ `import { removeDaemonStartupPhasesFile , recordDaemonStartupMarker, resolveDaemonStartupPhasesPath } from ${ JSON . stringify ( registrationUrl ) } ;
6261const file = resolveDaemonStartupPhasesPath(${ JSON . stringify ( stateDir ) } , process.pid);
6362recordDaemonStartupMarker(file, 'listening');
6463recordDaemonStartupMarker(file, 'registered');
65- claimDaemonStartupPhasesFile (file);
64+ removeDaemonStartupPhasesFile (file);
6665recordDaemonStartupMarker(file, 'modules-loaded');
6766` ,
6867 ) ;
@@ -76,13 +75,19 @@ recordDaemonStartupMarker(file, 'modules-loaded');
7675 expect ( phases ) . toEqual ( { 'modules-loaded' : expect . any ( Number ) } ) ;
7776} ) ;
7877
79- test ( 'a refused claim reset reports through the callback instead of throwing' , async ( ) => {
78+ test . each ( [
79+ [ 'remove' , ( p : string , cb : ( e : unknown ) => void ) => removeDaemonStartupPhasesFile ( p , cb ) ] ,
80+ [
81+ 'record' ,
82+ ( p : string , cb : ( e : unknown ) => void ) => recordDaemonStartupMarker ( p , 'modules-loaded' , cb ) ,
83+ ] ,
84+ ] as const ) ( 'a refused %s reports through the callback instead of throwing' , async ( _name , run ) => {
8085 const stateDir = await mkdtempForTest ( 'agent-device-markers-' ) ;
81- const markerPath = resolveDaemonStartupPhasesPath ( stateDir , 778 ) ;
86+ const markerPath = resolveDaemonStartupPhasesPath ( stateDir , 777 ) ;
8287 mkdirSync ( markerPath , { recursive : true } ) ;
8388 const reported : unknown [ ] = [ ] ;
8489 expect ( ( ) =>
85- claimDaemonStartupPhasesFile ( markerPath , ( error ) => {
90+ run ( markerPath , ( error ) => {
8691 reported . push ( error ) ;
8792 } ) ,
8893 ) . not . toThrow ( ) ;
@@ -121,20 +126,6 @@ test('removeDaemonStartupPhasesFile removes a file and tolerates one already gon
121126 expect ( ( ) => removeDaemonStartupPhasesFile ( file ) ) . not . toThrow ( ) ;
122127} ) ;
123128
124- test ( 'a marker write failure reports through the callback, keeping startup running' , async ( ) => {
125- const stateDir = await mkdtempForTest ( 'agent-device-markers-' ) ;
126- const markerPath = resolveDaemonStartupPhasesPath ( stateDir , 777 ) ;
127- mkdirSync ( markerPath , { recursive : true } ) ;
128- const reported : unknown [ ] = [ ] ;
129- expect ( ( ) =>
130- recordDaemonStartupMarker ( markerPath , 'modules-loaded' , ( error ) => {
131- reported . push ( error ) ;
132- } ) ,
133- ) . not . toThrow ( ) ;
134- expect ( reported ) . toHaveLength ( 1 ) ;
135- expect ( reported [ 0 ] ) . toHaveProperty ( 'message' ) ;
136- } ) ;
137-
138129test ( 'a crash-replay append keeps the file valid JSONL' , async ( ) => {
139130 const stateDir = await mkdtempForTest ( 'agent-device-markers-' ) ;
140131 const markerPath = resolveDaemonStartupPhasesPath ( stateDir , 999 ) ;
0 commit comments