feat(process): record provider and verifier run lineage

This commit is contained in:
morluto
2026-07-22 14:01:47 +00:00
parent f5b3e22e72
commit 513fa294a4
200 changed files with 2808 additions and 546 deletions
+20
View File
@@ -1,3 +1,5 @@
import { spawn } from "node:child_process";
const [mode, value = "0"] = process.argv.slice(2);
const keepAlive = () => {
@@ -35,6 +37,24 @@ switch (mode) {
await write(process.stdout, "ready\n");
keepAlive();
break;
case "detached-child": {
const child = spawn(
process.execPath,
[
"-e",
"setInterval(() => undefined, 1000); setTimeout(() => process.exit(0), 10000)",
],
{ detached: true, stdio: "ignore" },
);
await new Promise((resolve, reject) => {
child.once("spawn", resolve);
child.once("error", reject);
});
await write(process.stdout, `ready:${child.pid}\n`);
child.unref();
keepAlive();
break;
}
default:
process.stderr.write(`unknown provider-process fixture mode: ${mode}\n`);
process.exitCode = 64;
+37 -1
View File
@@ -7,7 +7,7 @@ const fixturePath = fileURLToPath(
/** Spawn one deterministic process-lifecycle fixture with piped diagnostics. */
export const spawnProviderProcessFixture = (
mode: "burst" | "exit" | "graceful" | "stubborn",
mode: "burst" | "detached-child" | "exit" | "graceful" | "stubborn",
value?: number,
): ChildProcess =>
spawn(
@@ -52,6 +52,42 @@ export const waitForProviderProcessReady = (
child.once("exit", onExit);
});
/** Read the distinct process-group leader created by the detached-child mode. */
export const waitForDetachedProviderChild = (
child: ChildProcess,
timeoutMs = 2_000,
): Promise<number> =>
new Promise((resolve, reject) => {
const stdout = child.stdout;
if (stdout === null) {
reject(new Error("Provider process fixture stdout is unavailable"));
return;
}
let output = "";
const detach = (): void => {
clearTimeout(timer);
stdout.off("data", onData);
child.off("exit", onExit);
};
const onData = (chunk: Buffer | string): void => {
output += chunk.toString();
const match = /(?:^|\n)ready:(\d+)\n/u.exec(output);
if (match?.[1] === undefined) return;
detach();
resolve(Number(match[1]));
};
const onExit = (): void => {
detach();
reject(new Error("Provider process fixture exited before readiness"));
};
const timer = setTimeout(() => {
detach();
reject(new Error("Provider process fixture readiness timed out"));
}, timeoutMs);
stdout.on("data", onData);
child.once("exit", onExit);
});
/** Kill a fixture if necessary and wait for its process handle to settle. */
export const stopProviderProcessFixture = async (
child: ChildProcess,