Skip to content

Commit 09b4aae

Browse files
committed
test: reviewer-table contract — the README verdict lines matched against live runner output
New contract test parses the adversarial-runner rows FROM the reviewer commands table in examples/delivery-fixture/README.md (no duplicated expectations), runs each documented command against the live runner, and demands the table's expected verdict line appear verbatim after folding only the inherently variable values (commit-derived seed, seed-list contents, max/total cycle timing) into the table's placeholders. A 1:1 check between table commands and live handlers keeps coverage honest: a new runner row without a handler — or a removed row with a stale handler — goes red by name, and the 66-cycle count stays a structural literal so an added mutation forces an honest table edit. Proven both ways: on first run the test caught two real drift defects in the perf-budget row I had written (wrong cycle count 70 vs 66; a broken max placeholder), and a deliberate table tamper goes red. Fixed the row to the literal live shape. Suite 905/905.
1 parent bde6d40 commit 09b4aae

2 files changed

Lines changed: 102 additions & 1 deletion

File tree

‎examples/delivery-fixture/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ runs, and the exit is 1 if ANY run has a survivor.
9494
| `adversarial-runner.mjs --fuzz 50` | random seed-deterministic stacks hold too | `fuzz : seed 424242 · 50 stacks · survived: 0` |
9595
| `adversarial-runner.mjs --fuzz 25 --seed <commit-derived>` | CI explores a new deterministic combination on every push (seed = first 8 hex of the pushed commit, modulo 2³¹−1 — replayable by re-running with the seed the log prints) | `fuzz : seed <N> · 25 stacks · survived: 0` |
9696
| `adversarial-runner.mjs --fuzz 50 --seeds <s1,s2,…>` | wider discovery in one command: every seed gets a full labeled run (`run i/N — seed s`), replayable per seed, exit 1 if any run has a survivor | `fuzz xN : 50 stacks/seed over seeds […] · survived total: 0` |
97-
| `adversarial-runner.mjs --fuzz 50 --budget-ms 250` | per-cycle time budget: engine slowdown under combinational load surfaces as named `PERF WARNING`s and a summary count — without ever touching the correctness verdict | `perf : 70 gate cycles · budget 250ms/cycle · max <budget ms · over budget: 0` |
97+
| `adversarial-runner.mjs --fuzz 50 --budget-ms 250` | per-cycle time budget: engine slowdown under combinational load surfaces as named `PERF WARNING`s and a summary count — without ever touching the correctness verdict | `perf : 66 gate cycles · budget 250ms/cycle · max <max-ms>ms · total <total-ms>ms · over budget: 0` |
9898
| `make-fixture.mjs` | the evidence factory is deterministic | `git diff` empty — byte-identical regeneration |
9999

100100
| `node --test test/delivery/doc-curl-contract.test.js` | the docs cannot drift from the wire: every documented bash fence (incl. every `INTEGRATION.md` one) is executed against a live documented endpoint — a rewritten response shape or renamed decision string goes red by name | 1 pass · fences match the wire |
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Reviewer-table contract — the README's expected verdict lines are matched
3+
* against the LIVE runner output, so the table cannot drift from behavior.
4+
*
5+
* The reviewer-commands table in examples/delivery-fixture/README.md quotes
6+
* exact verdict lines ("mutations: 10 · caught: 10 · survived: 0", …). This
7+
* test parses those rows FROM THE TABLE ITSELF (no duplicated expectations
8+
* here), runs each documented command against the real adversarial runner,
9+
* normalizes only the inherently variable values (commit-derived seed,
10+
* seed-list contents, max-cycle timing) into the table's placeholders, and
11+
* demands the documented line appear verbatim in the live output.
12+
*
13+
* Drift this catches: a reworded or re-spaced summary line, a changed
14+
* default (rounds/budget/cycle count), a broken placeholder, a renamed
15+
* field — the table goes stale, this goes red naming the row. The table is
16+
* the expectation; the runner is the truth; the cycle-count literal (66 =
17+
* 1 control + 10 mutations + 5 batteries + 50 fuzz rounds) is structural
18+
* and MUST stay literal so an added mutation forces an honest table update.
19+
*/
20+
21+
import { test } from "node:test";
22+
import assert from "node:assert/strict";
23+
import { spawnSync } from "node:child_process";
24+
import { readFileSync } from "node:fs";
25+
import { join, dirname } from "node:path";
26+
import { fileURLToPath } from "node:url";
27+
28+
const REPO = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
29+
const README = join(REPO, "examples", "delivery-fixture", "README.md");
30+
const RUNNER = join(REPO, "examples", "delivery-fixture", "adversarial-runner.mjs");
31+
32+
/** The reviewer-commands table's adversarial-runner rows, parsed live from
33+
* the README. Each row: { cmd (first backtick span of the command cell),
34+
* expected (first backtick span of the expected-verdict cell) }. */
35+
function parseRunnerRows() {
36+
const md = readFileSync(README, "utf8").replaceAll("\r\n", "\n");
37+
return md
38+
.split("\n")
39+
.filter((l) => l.startsWith("| `adversarial-runner.mjs"))
40+
.map((line) => {
41+
const cells = line.split("|");
42+
const cmd = (cells[1].match(/`([^`]+)`/) || [])[1];
43+
const expected = (cells[3].match(/`([^`]+)`/) || [])[1];
44+
return { cmd, expected };
45+
});
46+
}
47+
48+
test("reviewer table: adversarial-runner verdict lines match live runner output", () => {
49+
const rows = parseRunnerRows();
50+
assert.ok(rows.length >= 6, `expected >=6 adversarial-runner rows in the reviewer table, found ${rows.length} — the table lost coverage`);
51+
52+
// Group rows by documented command; the two "(same run)" rows share one
53+
// command and therefore one live run.
54+
const groups = new Map();
55+
for (const row of rows) {
56+
if (!groups.has(row.cmd)) groups.set(row.cmd, []);
57+
groups.get(row.cmd).push(row);
58+
}
59+
60+
// Per documented command: the live invocation and the normalizer that
61+
// folds variable values into the table's placeholders. Nothing else is
62+
// normalized — a reworded or re-spaced verdict line must fail here.
63+
const cases = {
64+
"adversarial-runner.mjs": { args: [], normalize: (s) => s },
65+
"adversarial-runner.mjs --fuzz 50": { args: ["--fuzz", "50"], normalize: (s) => s },
66+
"adversarial-runner.mjs --fuzz 25 --seed <commit-derived>": {
67+
args: ["--fuzz", "25", "--seed", "777000"],
68+
normalize: (s) => s.replace(/seed \d+/, "seed <N>"),
69+
},
70+
"adversarial-runner.mjs --fuzz 50 --seeds <s1,s2,…>": {
71+
args: ["--fuzz", "50", "--seeds", "424242,777"],
72+
normalize: (s) => s.replace(/fuzz x\d+/, "fuzz xN").replace(/over seeds \[[^\]]*\]/, "over seeds […]"),
73+
},
74+
"adversarial-runner.mjs --fuzz 50 --budget-ms 250": {
75+
args: ["--fuzz", "50", "--budget-ms", "250"],
76+
normalize: (s) => s.replace(/max [\d.]+ms/, "max <max-ms>ms").replace(/total \d+ms/, "total <total-ms>ms"),
77+
},
78+
};
79+
80+
assert.deepEqual(
81+
[...groups.keys()].sort(),
82+
Object.keys(cases).sort(),
83+
"table commands and live handlers must correspond 1:1 — a new runner row needs a live handler, a removed row needs its handler dropped",
84+
);
85+
86+
for (const [cmd, rowsForCmd] of groups) {
87+
const spec = cases[cmd];
88+
const r = spawnSync(process.execPath, [RUNNER, ...spec.args], { cwd: REPO, encoding: "utf8" });
89+
assert.equal(r.status, 0, `live run for "${cmd}" must succeed:\n${r.stdout}\n${r.stderr}`);
90+
const lines = ((r.stdout ?? "") + (r.stderr ?? "")).split("\n").map(spec.normalize);
91+
for (const row of rowsForCmd) {
92+
assert.ok(
93+
lines.includes(row.expected),
94+
`reviewer table drifted from live behavior:\n` +
95+
` command : ${cmd}\n` +
96+
` table says : ${row.expected}\n` +
97+
` live summary : ${lines.filter((l) => /survived|perf|gate cycles/.test(l)).join(" ⏎ ")}`,
98+
);
99+
}
100+
}
101+
});

0 commit comments

Comments
 (0)