Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(test): improve capture reliability and runner cleanup (#609)
morlutod19686a2a512
diff --git a/docs/testing.md b/docs/testing.mdindex fa9ec63fc..208ad11da 100644--- a/docs/testing.md+++ b/docs/testing.md@@ -38,7 +38,9 @@ with the suite and excluded from package builds; broader runtime and providerfixtures remain under `tests/fixtures/**`.`tests/process-global/**` is reserved for cases with a demonstrated dependency-on process-global state. Those tests run without file parallelism. Reusable,+on process-global state. Those tests use isolated forks so environment and+exit-status changes cannot leak between files. Serialize a case only when it+demonstrably shares an external resource that cannot be isolated. Reusable,test-scoped fixtures live under `tests/support/**`; immutable source artifactsremain under `tests/fixtures/**`.The process-global Vitest configuration contract rejects new direct temporary-root@@ -194,8 +196,10 @@ npm run test:changed -- --dry-run`test:focused` accepts exact repository-relative test file paths. Source-onlypaths do not build; boundary, acceptance, process-global, or unfamiliar `tests/`-paths build conservatively. The build and test run share the repository test-lock. Explicit selections do not use `--changed` or permit zero-test success.+paths build conservatively. Tests use Vitest concurrency and isolated+workspaces; commands do not hold a broad test lock. Build and documentation+writers retain checkout-local locks for their shared output files. Explicit+selections do not use `--changed` or permit zero-test success.The dry-run option reports the chosen merge base, scope and build prerequisitewithout executing tests or building. A missing Git base reports how to fetchit or select another revision.diff --git a/package.json b/package.jsonindex c827277c2..111a7285c 100644--- a/package.json+++ b/package.json@@ -61,8 +61,9 @@"mcp-registry:check": "node scripts/verify-mcp-registry-metadata.mjs","mcp-catalog:generate": "npm run build:cached && node scripts/generate-mcp-tool-catalog.mjs","mcp-catalog:check": "node scripts/generate-mcp-tool-catalog.mjs --check",- "prebuild": "npm run deps:check && npm run metadata:check && node scripts/clean-build-output.mjs",- "build": "tsc -p tsconfig.build.json",+ "prebuild": "npm run deps:check && npm run metadata:check",+ "build": "node scripts/run-exclusive.mjs build npm run build:unlocked",+ "build:unlocked": "node scripts/clean-build-output.mjs && tsc -p tsconfig.build.json","precheck": "npm run deps:check","check": "turbo run typecheck lint format:check knip metadata:check","precheck:fast": "npm run deps:check",@@ -85,10 +86,10 @@"jscpd": "jscpd src/ tests/","scan:todos": "node scripts/scan-todos.mjs","start": "node scripts/rea.mjs mcp",- "test": "node scripts/run-exclusive.mjs test npm run test:with-build",+ "test": "npm run test:with-build","test:with-build": "npm run build:cached && vitest run",- "test:run": "node scripts/run-exclusive.mjs test vitest run",- "test:local": "node scripts/run-exclusive.mjs test node scripts/run-development-tests.mjs local",+ "test:run": "vitest run",+ "test:local": "node scripts/run-development-tests.mjs local","test:fast": "vitest run --project domain --project services --project adapters --project composition --project conformance --project evaluation","pretest:boundary": "npm run build:cached","test:boundary": "vitest run --project boundary --project process-boundary --project mcp-boundary --project process-global",@@ -96,7 +97,7 @@"test:mcp": "vitest run --project mcp-boundary","pretest:acceptance": "npm run build:cached","test:acceptance": "vitest run --project acceptance",- "test:changed": "node scripts/run-exclusive.mjs test node scripts/run-development-tests.mjs changed",+ "test:changed": "node scripts/run-development-tests.mjs changed","pretest:integration": "npm run build:cached","test:integration": "vitest run --project boundary --project process-boundary --project mcp-boundary --project process-global --project acceptance","pretest:coverage": "npm run build:cached",@@ -155,7 +156,7 @@"prepare": "node scripts/prepare.mjs","verify:asset-catalog": "npm run build:cached && node scripts/verify-asset-catalog.mjs","verify:native-ui:permissions": "npm run build:cached && node scripts/verify-native-ui.mjs --allow-permission-denial",- "test:focused": "node scripts/run-exclusive.mjs test node scripts/run-development-tests.mjs focused"+ "test:focused": "node scripts/run-development-tests.mjs focused"},"lint-staged": {"*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}": [diff --git a/scripts/lib/development-tests.mjs b/scripts/lib/development-tests.mjsindex 0bbd5ed1e..8146fb4f4 100644--- a/scripts/lib/development-tests.mjs+++ b/scripts/lib/development-tests.mjs@@ -62,7 +62,6 @@ export const developmentTestPlan = (request, baseCommit) => {needsBuild: request.paths.some((path) => !sourceTest(path)),vitestArguments: ["run",- "--maxWorkers=1",...projects.flatMap((project) => ["--project", project]),...(explicit? request.pathsdiff --git a/scripts/run-development-tests.mjs b/scripts/run-development-tests.mjsindex 2b1ac5a3f..a2329f040 100644--- a/scripts/run-development-tests.mjs+++ b/scripts/run-development-tests.mjs@@ -8,12 +8,18 @@ import {} from "./lib/development-tests.mjs";let child;+let forceTimer;let shutdownSignal;const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };for (const signal of Object.keys(signalExitCodes))process.on(signal, () => {- shutdownSignal ??= signal;- child?.kill(signal);+ if (shutdownSignal !== undefined) return;+ shutdownSignal = signal;+ if (child !== undefined && child.exitCode === null) {+ child.kill(signal);+ forceTimer = setTimeout(() => child?.kill("SIGKILL"), 1_000);+ forceTimer.unref?.();+ }});try {@@ -71,20 +77,19 @@ function run(executable, arguments_, capture = false) {code: signalExitCodes[shutdownSignal],output: "",});+ child = spawn(executable, arguments_, {+ stdio: capture ? ["ignore", "pipe", "pipe"] : "inherit",+ });+ let output = "";+ if (capture) {+ child.stdout.on("data", (data) => (output += data.toString()));+ child.stderr.on("data", (data) => (output += data.toString()));+ }return new Promise((resolveResult, reject) => {- let output = "";- child = spawn(executable, arguments_, {- stdio: capture ? ["ignore", "pipe", "pipe"] : "inherit",- });- if (capture) {- child.stdout.on("data", (data) => {- output += data.toString();- });- child.stderr.on("data", (data) => {- output += data.toString();- });- }child.once("error", reject);- child.once("close", (code) => resolveResult({ code: code ?? 1, output }));+ child.once("close", (code) => {+ clearTimeout(forceTimer);+ resolveResult({ code: code ?? 1, output });+ });});}diff --git a/scripts/run-exclusive.mjs b/scripts/run-exclusive.mjsindex 3f62c338c..cdeceee21 100644--- a/scripts/run-exclusive.mjs+++ b/scripts/run-exclusive.mjs@@ -12,6 +12,7 @@ const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };let lockHeld = false;let child;+let forceTimer;let shutdownSignal;process.on("SIGINT", () => handleSignal("SIGINT"));@@ -96,14 +97,21 @@ function runCommand() {stdio: "inherit",});child.once("error", reject);- child.once("close", (code) => resolveResult({ code }));+ child.once("close", (code) => {+ clearTimeout(forceTimer);+ resolveResult({ code });+ });});}function handleSignal(signal) {if (shutdownSignal !== undefined) return;shutdownSignal = signal;- if (child !== undefined && child.exitCode === null) child.kill(signal);+ if (child !== undefined && child.exitCode === null) {+ child.kill(signal);+ forceTimer = setTimeout(() => child?.kill("SIGKILL"), 1_000);+ forceTimer.unref?.();+ }}async function readOwner() {diff --git a/tests/acceptance/applications/applicationEvidenceMcp.test.ts b/tests/acceptance/applications/applicationEvidenceMcp.test.tsindex ada4ee25c..8034b0c6b 100644--- a/tests/acceptance/applications/applicationEvidenceMcp.test.ts+++ b/tests/acceptance/applications/applicationEvidenceMcp.test.ts@@ -111,6 +111,17 @@ async function runInlineWorkflowScenarios(harness: TestHarness): Promise<void> {},});expect(tracedInline.isError).not.toBe(true);+ expect(tracedInline.structuredContent).toMatchObject({+ result: {+ seed: { kind: "module", value: "renderer.js", match: "exact" },+ summary: { matched_seeds: 1, traced_nodes: 1, unknown_facts: 0 },+ coverage: {+ status: "complete-within-source",+ source_graph_status: "complete",+ total_seed_matches: 1,+ },+ },+ });const comparedInline = await harness.client.callTool({name: "compare_application_versions",@@ -147,6 +158,24 @@ async function runInlineWorkflowScenarios(harness: TestHarness): Promise<void> {},});expect(sourceComparedById.isError).not.toBe(true);+ expect(sourceComparedById.structuredContent).toMatchObject({+ result: {+ reference: {+ root_sha256: SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE.reference.root_sha256,+ inventory_state: "complete",+ },+ scoring: { algorithm: "rea-source-to-bundle-signals" },+ summary: { unchanged: 0, modified: 0, removed: 1, unknown: 0 },+ items: [+ {+ source_path: "src/main.ts",+ status: "removed",+ current_node_ids: [],+ candidates: [],+ },+ ],+ },+ });}async function assertRejectedEvidenceReferences(diff --git a/tests/boundary/browser/webSourceMapFetcher.test.ts b/tests/boundary/browser/webSourceMapFetcher.test.tsindex 95ba31652..15b25752a 100644--- a/tests/boundary/browser/webSourceMapFetcher.test.ts+++ b/tests/boundary/browser/webSourceMapFetcher.test.ts@@ -407,7 +407,7 @@ describe("source-map dependency coverage of hard-to-parse sources", () => {it("keeps recovered edges from a partly recovered source and reports them as partial", async () => {const result = await fetchWithSources([- 'with (scope) { require("./c.js"); }\nimport "./a.js";',+ 'with (scope) { require("./c.js"); }\nrequire("./b.js");\nimport "./a.js";',]);expect(result.status).toBe("partial");expect(result.items[0]?.status).toBe("partial");@@ -416,7 +416,7 @@ describe("source-map dependency coverage of hard-to-parse sources", () => {);expect(result.items[0]?.original_module_edges.map(({ specifier }) => specifier),- ).toEqual(["./c.js", "./a.js"]);+ ).toEqual(["./b.js", "./a.js"]);});it("distinguishes an unparsable source from a source with no imports", async () => {diff --git a/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts b/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.tsindex 112a26339..a2c2bd225 100644--- a/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts+++ b/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts@@ -224,8 +224,16 @@ describe("enhanced MCP tools", () => {jsonResult(await client.callTool({ name, arguments: arguments_ })),),);- expect(results[0]).toMatchObject({ count: 1 });- expect(results[1]).toMatchObject({ count: 1 });+ expect(results[0]).toMatchObject({+ count: 1,+ classes: [{ address: "0x10", name: "_OBJC_CLASS_$_Fixture" }],+ });+ expect(results[1]).toMatchObject({+ count: 1,+ protocols: [+ { address: "0x12", name: "_OBJC_PROTOCOL_$_FixtureDelegate" },+ ],+ });expect(results[2]).toEqual({items: [{ address: "0x1", status: "ok", pseudocode: "pseudo:0x1" },diff --git a/tests/boundary/process/processCaptureLifecycle.test.ts b/tests/boundary/process/processCaptureLifecycle.test.tsindex 64bbf2675..6e16c4524 100644--- a/tests/boundary/process/processCaptureLifecycle.test.ts+++ b/tests/boundary/process/processCaptureLifecycle.test.ts@@ -83,10 +83,8 @@ itWithCaptureCapability(},);-// Events are scheduled relative to PTY startup, so the child is already live-// before the input, resize, and signal are delivered.itWithCaptureCapability(- "captures source-owned interactive, resize, Unicode, and signal behavior",+ "captures input, Unicode, and resize across PTY startup",async () => {const result = await captureProcessScenario(parseProcessScenario({@@ -94,9 +92,8 @@ itWithCaptureCapability(arguments: [processFixture, "interactive"],working_directory: dirname(processFixture),events: [- { type: "input", at_ms: 200, data: "answer" },- { type: "resize", at_ms: 400, columns: 100, rows: 40 },- { type: "signal", at_ms: 700, signal: "SIGINT" },+ { type: "resize", at_ms: 0, columns: 100, rows: 40 },+ { type: "input", at_ms: 0, data: "answer\n" },],normalization: { time_bucket_ms: 10 },timeout_ms: 20_000,@@ -109,9 +106,15 @@ itWithCaptureCapability(expect(output).toContain("prompt>");expect(output).toContain("input:answer unicode:雪");expect(output).toContain("resize:100x40");- expect(output).toContain("signal:SIGINT");+ expect(result.value.interaction_events).toMatchObject([+ { type: "resize", outcome: "dispatched", scheduled_at_ms: 0 },+ { type: "input", outcome: "dispatched", scheduled_at_ms: 0 },+ ]);const resized = result.value.rendered_frames.find(- ({ columns, rows }) => columns === 100 && rows === 40,+ ({ columns, rows, lines }) =>+ columns === 100 &&+ rows === 40 &&+ lines.join("\n").includes("input:answer unicode:雪"),);expect(resized).toBeDefined();expect(resized?.lines.join("\n")).toContain("input:answer unicode:雪");@@ -120,7 +123,29 @@ itWithCaptureCapability();itWithCaptureCapability(- "dispatches scheduled events before a silent PTY produces output",+ "dispatches an external signal without depending on child startup output",+ async () => {+ const result = await captureProcessScenario(+ parseProcessScenario({+ executable: process.execPath,+ arguments: [processFixture, "hang"],+ working_directory: dirname(processFixture),+ events: [{ type: "signal", at_ms: 0, signal: "SIGTERM" }],+ timeout_ms: 2_000,+ idle_timeout_ms: 2_000,+ }),+ );+ expect(result.ok).toBe(true);+ if (!result.ok) throw result.error;+ expect(result.value.interaction_events).toMatchObject([+ { type: "signal", data: "SIGTERM", outcome: "dispatched" },+ ]);+ expect(result.value.exit).toMatchObject({ signal: 15, reason: "exited" });+ },+);++itWithCaptureCapability(+ "buffers newline input until a silent PTY fixture is ready to read it",async () => {const result = await captureProcessScenario(parseProcessScenario({@@ -129,10 +154,10 @@ itWithCaptureCapability(working_directory: dirname(processFixture),events: [{ type: "resize", at_ms: 25, columns: 100, rows: 40 },- { type: "input", at_ms: 50, data: "answer" },+ { type: "input", at_ms: 50, data: "answer\n" },],- timeout_ms: 2_000,- idle_timeout_ms: 2_000,+ timeout_ms: 20_000,+ idle_timeout_ms: 20_000,}),);expect(result.ok).toBe(true);@@ -141,9 +166,19 @@ itWithCaptureCapability("input:answer",);expect(result.value.interaction_events).toMatchObject([- { type: "resize", outcome: "dispatched" },- { type: "input", outcome: "dispatched" },+ { type: "resize", scheduled_at_ms: 25, outcome: "dispatched" },+ { type: "input", scheduled_at_ms: 50, outcome: "dispatched" },]);+ expect(+ result.value.interaction_events.every(+ ({ scheduled_at_ms, dispatched_at_ms }) =>+ dispatched_at_ms >= scheduled_at_ms,+ ),+ ).toBe(true);+ expect(+ result.value.frames.find(({ data }) => data.includes("input:answer"))+ ?.at_ms,+ ).toBeGreaterThanOrEqual(50);},);@@ -155,12 +190,16 @@ itWithCaptureCapability(executable: process.execPath,arguments: [processFixture, "tree"],working_directory: dirname(processFixture),- timeout_ms: 2_000,- idle_timeout_ms: 2_000,+ timeout_ms: 20_000,+ idle_timeout_ms: 20_000,}),);expect(result.ok).toBe(true);if (!result.ok) throw result.error;+ expect(result.value.exit).toMatchObject({ code: 0, reason: "exited" });+ expect(result.value.frames.map(({ data }) => data).join("")).toContain(+ "tree-ready",+ );const commands = result.value.process_samples.map(({ command }) => command);expect(commands.some((command) => command.includes("tree-child"))).toBe(true,diff --git a/tests/fixtures/processFidelity.mjs b/tests/fixtures/processFidelity.mjsindex 27227f602..83f130359 100644--- a/tests/fixtures/processFidelity.mjs+++ b/tests/fixtures/processFidelity.mjs@@ -3,26 +3,28 @@ import { spawn } from "node:child_process";const mode = process.argv[2];if (mode === "interactive") {- process.stdin.setRawMode?.(true);process.stdin.resume();+ let inputObserved = false;+ let resizeObserved = false;+ const reportResize = () => {+ const columns = String(process.stdout.columns);+ const rows = String(process.stdout.rows);+ process.stdout.write(`resize:${columns}x${rows}\n`);+ resizeObserved = columns === "100" && rows === "40";+ if (inputObserved && resizeObserved) process.exit(0);+ };process.stdout.write("prompt> ");- process.on("SIGWINCH", () => {- process.stdout.write(- `resize:${String(process.stdout.columns)}x${String(process.stdout.rows)}\n`,- );- });- process.on("SIGINT", () => {- process.stdout.write("signal:SIGINT\n");- process.exit(0);- });+ process.on("SIGWINCH", reportResize);+ reportResize();process.stdin.on("data", (value) => {- process.stdout.write(`input:${value.toString()} unicode:雪\n`);+ process.stdout.write(`input:${value.toString().trimEnd()} unicode:雪\n`);+ inputObserved = value.toString().trimEnd() === "answer";+ if (inputObserved && resizeObserved) process.exit(0);});} else if (mode === "silent-interactive") {- process.stdin.setRawMode?.(true);process.stdin.resume();process.stdin.on("data", (value) => {- process.stdout.write(`input:${value.toString()}\n`);+ process.stdout.write(`input:${value.toString().trimEnd()}\n`);process.exit(0);});} else if (mode === "partial") {@@ -32,16 +34,30 @@ if (mode === "interactive") {process.exit(0);}, 25);} else if (mode === "tree-child") {- spawn(process.execPath, [process.argv[1], "tree-grandchild"], {- stdio: "ignore",+ const grandchild = spawn(+ process.execPath,+ [process.argv[1], "tree-grandchild"],+ { stdio: ["ignore", "ignore", "ignore", "ipc"] },+ );+ grandchild.on("message", (message) => {+ if (message !== "ready") return;+ process.send?.("ready");+ grandchild.disconnect();});setInterval(() => undefined, 1_000);} else if (mode === "tree-grandchild") {+ process.send?.("ready");setInterval(() => undefined, 1_000);} else if (mode === "tree") {- spawn(process.execPath, [process.argv[1], "tree-child"], { stdio: "ignore" });- process.stdout.write("tree-ready\n");- setInterval(() => undefined, 1_000);+ const child = spawn(process.execPath, [process.argv[1], "tree-child"], {+ stdio: ["ignore", "ignore", "ignore", "ipc"],+ });+ child.on("message", (message) => {+ if (message !== "ready") return;+ process.stdout.write("tree-ready\n");+ child.disconnect();+ setTimeout(() => process.exit(0), 2_000);+ });} else if (mode === "crash") {process.stderr.write("intentional-crash\n");process.exit(23);diff --git a/tests/process-global/runnerCancellation.test.ts b/tests/process-global/runnerCancellation.test.tsnew file mode 100644index 000000000..32fab5924--- /dev/null+++ b/tests/process-global/runnerCancellation.test.ts@@ -0,0 +1,64 @@+import { spawn } from "node:child_process";+import { access } from "node:fs/promises";+import { join } from "node:path";++import { expect, it } from "vitest";++it.runIf(process.platform !== "win32")(+ "escalates cancellation when an owned command ignores SIGTERM",+ async () => {+ const lockName = `runner-cancel-${String(process.pid)}`;+ const lockPath = join(".cache", "rea-command-locks", `${lockName}.lock`);+ const runner = spawn(+ process.execPath,+ [+ "scripts/run-exclusive.mjs",+ lockName,+ process.execPath,+ "-e",+ 'process.on("SIGTERM", () => {}); process.stdout.write("ready"); setInterval(() => {}, 1000);',+ ],+ { stdio: ["ignore", "pipe", "pipe"] },+ );+ let output = "";+ const ready = new Promise<void>((resolveReady) => {+ runner.stdout.on("data", (chunk) => {+ output += chunk.toString();+ if (output.includes("ready")) resolveReady();+ });+ });+ const closed = new Promise<{+ code: number | null;+ signal: NodeJS.Signals | null;+ }>((resolveClosed) => {+ runner.once("close", (code, signal) => resolveClosed({ code, signal }));+ });++ try {+ await withTimeout(ready, "runner child did not start");+ runner.kill("SIGTERM");+ const result = await withTimeout(+ closed,+ "runner did not finish cancellation",+ );++ expect(result).toEqual({ code: 143, signal: null });+ } finally {+ if (runner.exitCode === null) runner.kill("SIGKILL");+ await withTimeout(closed, "runner cleanup did not finish");+ }++ expect(output).toContain("ready");+ await expect(access(lockPath)).rejects.toMatchObject({ code: "ENOENT" });+ },+);++function withTimeout<T>(promise: Promise<T>, message: string): Promise<T> {+ let timeout: NodeJS.Timeout | undefined;+ return Promise.race([+ promise,+ new Promise<never>((_, reject) => {+ timeout = setTimeout(() => reject(new Error(message)), 5_000);+ }),+ ]).finally(() => clearTimeout(timeout));+}diff --git a/tests/process-global/verifierRun.test.ts b/tests/process-global/verifierRun.test.tsindex 655873914..88b5cfe35 100644--- a/tests/process-global/verifierRun.test.ts+++ b/tests/process-global/verifierRun.test.ts@@ -9,6 +9,7 @@ import {} from "../../scripts/lib/verifier-run.mjs";const execFileAsync = promisify(execFile);+const CHILD_SHUTDOWN_GRACE_MS = 1_000;describe.sequential("verifier run identity", () => {it("allocates, propagates, and reuses one process-local identity", async () => {@@ -102,6 +103,26 @@ describe.sequential("verifier run identity", () => {}},);++ it.runIf(process.platform !== "win32")(+ "bounds cleanup when a verifier child ignores SIGTERM",+ async () => {+ const child = spawn(+ process.execPath,+ [+ "-e",+ "process.on('SIGTERM', () => {}); process.stdout.write('ready'); setInterval(() => {}, 1000)",+ ],+ { stdio: ["ignore", "pipe", "ignore"] },+ );+ try {+ await childReady(child);+ } finally {+ await stopChild(child);+ }+ expect(child.signalCode).toBe("SIGKILL");+ },+ );});const spawnReadyChild = (env: NodeJS.ProcessEnv): ChildProcess =>@@ -123,13 +144,37 @@ const childReady = async (child: ChildProcess): Promise<void> => {const stopChild = async (child: ChildProcess): Promise<void> => {if (child.exitCode !== null || child.signalCode !== null) return;- const exited = new Promise<void>((resolve) =>- child.once("exit", () => resolve()),- );child.kill("SIGTERM");- await exited;+ if (await waitForExit(child, CHILD_SHUTDOWN_GRACE_MS)) return;+ child.kill("SIGKILL");+ if (!(await waitForExit(child, CHILD_SHUTDOWN_GRACE_MS))) {+ throw new Error(+ `verifier child ${String(child.pid)} did not exit after SIGKILL`,+ );+ }};+const waitForExit = (+ child: ChildProcess,+ timeoutMs: number,+): Promise<boolean> =>+ new Promise((resolve) => {+ if (child.exitCode !== null || child.signalCode !== null) {+ resolve(true);+ return;+ }+ const timer = setTimeout(() => {+ child.removeListener("exit", onExit);+ resolve(false);+ }, timeoutMs);+ timer.unref();+ const onExit = (): void => {+ clearTimeout(timer);+ resolve(true);+ };+ child.once("exit", onExit);+ });+const restoreRunId = (runId: string | undefined): void => {if (runId === undefined) delete process.env.REA_PROCESS_RUN_ID;else process.env.REA_PROCESS_RUN_ID = runId;diff --git a/tests/support/process/processFixture.ts b/tests/support/process/processFixture.tsindex fbcd964ed..ef0466c19 100644--- a/tests/support/process/processFixture.ts+++ b/tests/support/process/processFixture.ts@@ -60,12 +60,12 @@ const waitForExit = (const stopChild = async (child: ChildProcessWithoutNullStreams,-): Promise<void> => {- if (child.exitCode !== null || child.signalCode !== null) return;+): Promise<boolean> => {+ if (child.exitCode !== null || child.signalCode !== null) return true;child.kill("SIGTERM");- if (await waitForExit(child, SHUTDOWN_GRACE_MS)) return;+ if (await waitForExit(child, SHUTDOWN_GRACE_MS)) return true;child.kill("SIGKILL");- await waitForExit(child, SHUTDOWN_GRACE_MS);+ return waitForExit(child, SHUTDOWN_GRACE_MS);};/** Create a child-process registry for a fixture composition root. */@@ -136,9 +136,28 @@ export const createTestProcessRegistry = (): TestProcesses => {return result;},shutdown: async () => {- await Promise.allSettled([...children].reverse().map(stopChild));+ const results = await Promise.allSettled(+ [...children].reverse().map(async (child) => {+ if (!(await stopChild(child))) {+ throw new Error(+ `test child process ${String(child.pid)} did not exit after SIGKILL`,+ );+ }+ }),+ );+ const failures = results.flatMap((result) =>+ result.status === "rejected" ? [result.reason] : [],+ );if (children.size > 0) {- throw new Error(`${children.size} test child process(es) leaked`);+ failures.push(+ new Error(`${children.size} test child process(es) leaked`),+ );+ }+ if (failures.length > 0) {+ throw new AggregateError(+ failures,+ "Test child process shutdown failed",+ );}},};diff --git a/vitest.config.ts b/vitest.config.tsindex fd72b37f3..8b9f19b97 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -11,21 +11,9 @@ const COVERAGE_ENABLED = process.argv.some((argument) =>const COVERAGE_SHARD = process.argv.some((argument) =>argument.startsWith("--shard="),);-// Local runs share the host with TypeScript, docs, and package checks under-// Turbo. Running the suite on a single worker made a full local run cost ~140s-// of wall time at ~100% CPU on a 10-core machine, which was the single largest-// dev-cycle cost in the repository. Two workers matches the budget CI already-// proves green, so local and CI now execute the same concurrency.-//-// Do not raise this without first removing the wall-clock-sensitive PTY-// scenarios in tests/boundary/process, which fail under host contention-// because they schedule actions by `at_ms` instead of observed output.+// Keep local and CI concurrency bounded by the runner rather than command locks.const MAX_TEST_WORKERS = Math.min(2, availableParallelism());-// Cross-project scheduling is a local-host concern only. CI shards projects-// across separate runners and already proves this concurrency green.-const LOCAL_ONLY = process.env.CI !== "true";-const TEST_PROJECTS = [{name: "domain",@@ -71,16 +59,14 @@ const TEST_PROJECTS = [maxWorkers: MAX_TEST_WORKERS,},{- // Real PTY capture scenarios contend for host process and terminal- // resources, and several still schedule actions by wall-clock `at_ms`- // rather than observed output. Running them concurrently with the rest of- // the boundary suite makes them drop input and lose resize echoes. They- // serialise until those scenarios trigger on observed terminal text.+ // Process-tree observations share host sampling resources; keep this small+ // lane serial while the independent projects run together.name: "process-boundary",include: ["tests/boundary/process/**/*.test.ts"],pool: "forks" as const,maxWorkers: MAX_TEST_WORKERS,fileParallelism: false,+ sequence: { groupOrder: 1 },},{name: "mcp-boundary",@@ -96,14 +82,12 @@ const TEST_PROJECTS = [include: ["tests/acceptance/**/*.test.ts"],pool: "forks" as const,maxWorkers: MAX_TEST_WORKERS,- fileParallelism: false,},{name: "process-global",include: ["tests/process-global/**/*.test.ts"],pool: "forks" as const,maxWorkers: MAX_TEST_WORKERS,- fileParallelism: false,},{name: "conformance",@@ -117,17 +101,7 @@ const TEST_PROJECTS = [pool: "threads" as const,maxWorkers: MAX_TEST_WORKERS,},- // Acceptance, process-boundary, and process-global declare- // `fileParallelism: false` above because they own host-level process, stdio,- // and terminal state. That flag only serialises files inside one project, so- // each project also needs its own `sequence.groupOrder` locally: without it- // Vitest runs projects concurrently and a project that mutates host process- // or terminal state overlaps with projects that observe it.-].map((project, groupOrder) => ({- ...project,- maxWorkers: MAX_TEST_WORKERS,- ...(LOCAL_ONLY ? { sequence: { groupOrder } } : {}),-}));+];const ZERO_COVERAGE_THRESHOLDS = {statements: 0,