From 8698989b5734158975e52c6552f63f1ff5640af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 14 Nov 2026 13:24:18 +0100 Subject: [PATCH] test(host-kit): isolate ps process fixtures from host proc identity --- .../host-kit/src/internal/host-process-liveness.test.ts | 7 +++++++ .../src/internal/host-process-stop-confirm.test.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/packages/host-kit/src/internal/host-process-liveness.test.ts b/packages/host-kit/src/internal/host-process-liveness.test.ts index a2e6b212f8..69a4a8ddf1 100644 --- a/packages/host-kit/src/internal/host-process-liveness.test.ts +++ b/packages/host-kit/src/internal/host-process-liveness.test.ts @@ -21,6 +21,8 @@ import { readProcessIdentityFacts, } from './host-process.ts'; +const readFile = fs.readFileSync; + function psReturns(stdout: string, exitCode = 0): void { mockRunCmdSync.mockReturnValue({ stdout, stderr: '', exitCode }); } @@ -44,6 +46,11 @@ function psInstalledAt(installed: readonly string[]): void { beforeEach(() => { mockRunCmdSync.mockReset(); mockRunCmd.mockReset(); + vi.spyOn(fs, 'readFileSync').mockImplementation((...args) => { + // The ps fixture must not borrow the real host's identity for a fabricated pid. + if (String(args[0]) === '/proc/sys/kernel/random/boot_id') throw new Error('ENOENT'); + return readFile(...args); + }); }); afterEach(() => { diff --git a/packages/host-kit/src/internal/host-process-stop-confirm.test.ts b/packages/host-kit/src/internal/host-process-stop-confirm.test.ts index 4d59d70012..f156670cbe 100644 --- a/packages/host-kit/src/internal/host-process-stop-confirm.test.ts +++ b/packages/host-kit/src/internal/host-process-stop-confirm.test.ts @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; +import fs from 'node:fs'; import { afterEach, test, vi } from 'vitest'; // Every claim the stopper makes is about what the host answers, so one double answers both syscalls it @@ -16,6 +17,7 @@ import { type ProcessStopTarget, } from './host-process.ts'; +const readFile = fs.readFileSync; const PID = 4242; const BUDGET = { termTimeoutMs: 1_000, killTimeoutMs: 500 }; type Signal = 'SIGTERM' | 'SIGINT' | 'SIGKILL'; @@ -256,6 +258,11 @@ const STOP_CASES: HostCase[] = [ ]; function driveHost(model: HostCase): { signals: Signal[] } { + vi.spyOn(fs, 'readFileSync').mockImplementation((...args) => { + // This host model supplies process identity through its ps answers. + if (String(args[0]) === '/proc/sys/kernel/random/boot_id') throw new Error('ENOENT'); + return readFile(...args); + }); const signals: Signal[] = []; let psRefused = false; let ended = false;