|
| 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