test: harden HTTP scenario execution evidence

This commit is contained in:
DongHyeonka
2026-08-02 11:36:27 +09:00
parent e08d8c2dd8
commit d2eb320936
6 changed files with 143 additions and 28 deletions
+70 -4
View File
@@ -11,6 +11,7 @@ import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
createBoundedChildInvocation,
createBoundedPnpmScriptInvocation,
formatPnpmScriptFailure,
} from "../../scripts/lib/bounded-pnpm-script.ts";
@@ -111,9 +112,9 @@ async function runFixture(
2,
)}\n`,
);
return spawnSync(
process.execPath,
[
const invocation = createBoundedChildInvocation({
command: process.execPath,
arguments: [
"scripts/check-test-evidence.ts",
"--scenario-only",
"--source-root",
@@ -127,11 +128,41 @@ async function runFixture(
"--artifact",
artifactPath,
],
{ encoding: "utf8", cwd: process.cwd() },
environment: process.env,
cwd: process.cwd(),
});
return spawnSync(
invocation.command,
[...invocation.arguments],
invocation.options,
);
}
describe("HTTP scenario evidence receipt schema", () => {
it("bounds checker fixture children with the shared process policy", () => {
const environment = { CI: "true" };
expect(
createBoundedChildInvocation({
command: "/runtime/node",
arguments: ["scripts/check-test-evidence.ts", "--scenario-only"],
environment,
cwd: "/workspace",
}),
).toEqual({
command: "/runtime/node",
arguments: ["scripts/check-test-evidence.ts", "--scenario-only"],
options: {
cwd: "/workspace",
encoding: "utf8",
env: environment,
killSignal: "SIGTERM",
maxBuffer: 16 * 1024 * 1024,
timeout: 60_000,
},
});
});
it("bounds every orchestration child by time and captured output", () => {
const environment = { CI: "true" };
@@ -175,6 +206,22 @@ describe("HTTP scenario evidence receipt schema", () => {
);
});
it("preserves output overflow codes in child diagnostics", () => {
const error = Object.assign(new Error("stdout maxBuffer exceeded"), {
code: "ENOBUFS",
});
expect(
formatPnpmScriptFailure("check:http-scenario-evidence", {
status: null,
signal: null,
error,
}),
).toBe(
"check:http-scenario-evidence failed: exit=null, signal=none, error=ENOBUFS: stdout maxBuffer exceeded",
);
});
it("rejects internally inconsistent assertion groups as schema drift", async () => {
const receipt = JSON.parse(
await readFile(
@@ -195,6 +242,18 @@ describe("HTTP scenario evidence receipt schema", () => {
expect.objectContaining({
path: ["rows", 0, "observed", "fetch", "agrees"],
}),
expect.objectContaining({
path: ["rows", 0, "expected", "retry", "count"],
}),
expect.objectContaining({
path: ["rows", 0, "expected", "retry", "reasons", 0],
}),
expect.objectContaining({
path: ["rows", 0, "observed", "retry", "count"],
}),
expect.objectContaining({
path: ["rows", 0, "observed", "retry", "reasons", 0],
}),
]),
);
}
@@ -275,6 +334,13 @@ describe("HTTP scenario evidence receipt schema", () => {
};
},
},
{
label: "a deadline override drift",
diagnostic: "[TEST-EVIDENCE-DEADLINE-DRIFT]",
mutate(_expectations: HttpScenarioExpectation[], receipt: MutableReceipt) {
receipt.rows[0]!.testDeadlineOverrideMs = 500;
},
},
])("rejects $label with its stable diagnostic", async (fixture) => {
const { expectations, receipt } = await validFixture();
fixture.mutate(expectations, receipt);