Skip to content

Commit b85f3ea

Browse files
thymikeeclaude
andcommitted
test(host-kit): pin Linux state to the /proc read that gave the start token
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 50182d6 commit b85f3ea

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎packages/host-kit/src/internal/host-process-liveness.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,41 @@ for (const probe of ['single', 'sync', 'async'] as const) {
297297
);
298298
}
299299

300+
for (const [psState, procState, zombie] of [
301+
['Z', 'S', false],
302+
['S', 'Z', true],
303+
] as const) {
304+
test.skipIf(process.platform !== 'linux')(
305+
`Linux state follows the /proc read that gave the start token (ps ${psState}, /proc ${procState})`,
306+
async () => {
307+
// A pid reused between the ps snapshot and the /proc read must not pair one lifetime's
308+
// start token with the other lifetime's state.
309+
vi.spyOn(fs, 'readFileSync').mockImplementation((path) => {
310+
if (String(path) === '/proc/sys/kernel/random/boot_id') return 'test-boot\n';
311+
if (String(path) === '/proc/4242/stat') {
312+
return `4242 (a) ${procState} ${Array(18).fill('0').join(' ')} 5371442 0`;
313+
}
314+
throw new Error('ENOENT');
315+
});
316+
const row = `4242 ${psState} Mon Nov 9 23:54:54 2026\n`;
317+
psReturns(row);
318+
psAnswersIdentity({ identity: row, command: '4242 y\n' });
319+
const expected = { state: procState, startTime: 'linux:test-boot:5371442' };
320+
321+
assert.deepEqual(readHostProcessIdentityObservations([4242]).get(4242), expected);
322+
assert.deepEqual(
323+
(await readHostProcessIdentityObservationsAsync([4242])).get(4242),
324+
expected,
325+
);
326+
assert.deepEqual(await readProcessIdentityFacts(4242), {
327+
startTime: 'linux:test-boot:5371442',
328+
command: 'y',
329+
zombie,
330+
});
331+
},
332+
);
333+
}
334+
300335
test.skipIf(process.platform !== 'linux')(
301336
'Linux identities fall back to lstart when proc is unreadable or malformed',
302337
async () => {

0 commit comments

Comments
 (0)