@@ -2,35 +2,13 @@ type HostProcessModule = typeof import('@agent-device/host-kit/process');
22type HostProcessIdentityObservation =
33 import ( '@agent-device/host-kit/process' ) . HostProcessIdentityObservation ;
44
5- /**
6- * `vi.mock` factory for the host-kit `exec` seam in tests that seed a "live"
7- * owner from the test process's own identity (readCurrentOwnerIdentity and
8- * friends) and later have production code re-read it during classification.
9- *
10- * readProcessStartTime shells out to `ps` with a 1s timeout; under full-suite
11- * CPU contention a re-read can miss that deadline and return null, mismatching
12- * the seeded value and flipping a genuinely-live owner to 'owner-process-dead'.
13- * This factory assigns our own pid a stable synthetic start time, then serves
14- * that value so every read is self-consistent without a subprocess. Other pids read as null, same
15- * as a real `ps` miss. isProcessAlive stays real (a plain `kill(pid, 0)`
16- * syscall, not a subprocess), so fabricated dead-pid fixtures still classify
17- * as dead through that non-flaky check.
18- *
19- * Usage: `vi.mock('@agent-device/host-kit/process', async (importOriginal) =>
20- * (await import('<path>/test-utils/host-process-mock.ts')).pinOwnProcessStartTime(importOriginal))`
21- */
22- // Consumed by three suites, but only through `(await import(...)).pinOwnProcessStartTime`
23- // inside `vi.mock` factories — vitest hoists those above static imports, so the dynamic
24- // form is required and fallow cannot trace the consumers statically.
255export async function pinOwnProcessStartTime (
266 importOriginal : ( ) => Promise < HostProcessModule > ,
277) : Promise < HostProcessModule > {
288 const actual = await importOriginal ( ) ;
299 const ownStartTime = 'test-process-start-time' ;
3010 return {
3111 ...actual ,
32- // The seam mock cannot reach readCurrentOwnerIdentity's internal
33- // readProcessStartTime call, so the recorded identity is pinned here too.
3412 readCurrentOwnerIdentity : ( ) => ( { pid : process . pid , startTime : ownStartTime } ) ,
3513 readProcessStartTime : ( pid : number ) => {
3614 if ( pid !== process . pid ) return null ;
0 commit comments