From f943dddcad3596c9be1319006801ff37b9a98acd Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 07:45:19 +0000 Subject: [PATCH 1/2] test(scripts): floor check-sdui-manifest's table-driven self-test on its own row labels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Batch 7 pilot for the assertion-floor card: the first of the ten table-driven `scripts/**` self-tests, whose natural roster is the table's own named rows rather than sections. `failures === 0` was this self-test's only success condition, so "every case held" and "the cases never ran" printed the same line. The sink here (`failures++`) writes only on failure, so routing it through `registerCase()` would invert the floor rather than install it: a fully green run would register nothing. So each row label in the literal `cases` table becomes a declared battery with a floor of 1, and `registerCase(name)` is the first statement of the driving loop body — attributing the case to the row actually being run. The roster is a LITERAL the table is checked against, never derived from it: a derived roster lets a deleted row delete its own floor. The roster's own size is pinned, which is also what refuses a duplicate row label at declaration time; a table cross-check names which label collided. No assertion condition touched, no control flow rewritten, the verdict handshake kept as landed. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk --- scripts/check-sdui-manifest.mjs | 113 +++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/scripts/check-sdui-manifest.mjs b/scripts/check-sdui-manifest.mjs index 870703d578d..93ed905c34c 100644 --- a/scripts/check-sdui-manifest.mjs +++ b/scripts/check-sdui-manifest.mjs @@ -144,6 +144,49 @@ export function checkTree(root) { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-sdui-manifest self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// `failures === 0` used to be this self-test's ONLY success condition, so "every +// case held" and "the cases never ran" printed the same line. Closed the PR +// #13487 way: what is pinned is the registered NAMES, not a number. +// +// This self-test is TABLE-DRIVEN — one literal `cases` table, one loop over it, +// and a sink (`failures++`) that writes only when a case FAILS. Routing THAT +// sink through `registerCase()` would register a case only when it fails: a +// fully green run would register 0 and every battery would read DID NOT RUN, the +// floor inverted rather than installed. So the roster is the table's own rows. +// Each row LABEL is a declared battery, verbatim, with a floor of 1, and +// `registerCase(name)` is the first statement of the driving loop body — so the +// case is attributed to the row actually being run, whatever that row asserts +// afterwards. There is no `battery()` opener: for a table-driven self-test the +// ROW is the battery, so attribution is the loop variable rather than a +// most-recently-opened section. +// +// ⛔ A pinned TOTAL is not the repair, and neither is a roster DERIVED from the +// table: `cases.length` moves with the table, so a deleted row would delete its +// own floor. The roster below is a LITERAL the table is checked against, which +// is what lets a deleted or renamed row name ITSELF in the refusal. +// +// The counts are a FLOOR, not an equality — a row that grows into several +// registrations must not red. 1 is the honest floor for a table row: the loop +// reaches it exactly once per run. +const SELF_TEST_BATTERIES = Object.freeze({ + 'green fixture passes': 1, + 'missing artefact is RED': 1, + 'hand-edited artefact (hash mismatch) is RED': 1, + 'moved pin is RED': 1, + 'empty components is RED': 1, + 'missing record is RED': 1, +}); + +// DELETING an entry silences that battery's floor exactly as effectively as +// zeroing it, so the roster's own size is pinned too. This pin is also half of +// the duplicate-label refusal: two rows sharing a label collapse to ONE key in +// the literal above, so the roster falls below this number; the table +// cross-check in the floor block is the other half, and names WHICH label +// collided. +const SELF_TEST_BATTERY_FLOOR = 6; + function selfTest() { const mk = (mutate) => { const root = mkdtempSync(join(tmpdir(), 'sdui-manifest-check-')); @@ -187,8 +230,15 @@ function selfTest() { ['missing record is RED', mk((r) => rmSync(join(r, 'scripts', 'sdui-manifest.record.json'))), 1], ]; + // The ledger this self-test's floor is evaluated against (#13489). + const batterySeen = new Map(); + const registerCase = (name) => { + batterySeen.set(name, (batterySeen.get(name) ?? 0) + 1); + }; + let failures = 0; for (const [name, root, want] of cases) { + registerCase(name); const problems = checkTree(root); const got = problems.length ? 1 : 0; if (got !== want) { @@ -197,11 +247,70 @@ function selfTest() { for (const p of problems) console.error(` ${p}`); } } + // ── The floor: every declared row RAN, and ran its case (#13489) ─────── + // + // Evaluated after every row has had its chance and BEFORE the verdict, so the + // success line below can only be printed by a run in which the set of rows + // that registered EQUALS the set declared. A set difference names WHICH row + // stopped; a count says only that something did. + const floorFailure = (message) => { + console.error(`✗ self-test floor: ${message}`); + failures++; + }; + const declaredBatteries = Object.keys(SELF_TEST_BATTERIES); + let floorBreached = false; + if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) { + floorBreached = true; + floorFailure( + `SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` + + `${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`, + ); + } + const rowLabels = cases.map(([name]) => name); + const duplicated = [...new Set(rowLabels.filter((name, i) => rowLabels.indexOf(name) !== i))]; + if (duplicated.length > 0) { + floorBreached = true; + floorFailure( + `the cases table uses ${duplicated.map((n) => JSON.stringify(n)).join(', ')} as a row label more than once — ` + + 'two rows sharing a label are ONE battery, so the second can stop running while the first keeps the floor met.', + ); + } + for (const [name, count] of batterySeen) { + if (declaredBatteries.includes(name)) continue; + floorBreached = true; + floorFailure( + `self-test battery "${name}" registered ${count} case(s) but is not declared in ` + + 'SELF_TEST_BATTERIES — a case attributed to no declared battery is one nothing floors.', + ); + } + for (const name of declaredBatteries) { + const count = batterySeen.get(name) ?? 0; + if (count >= SELF_TEST_BATTERIES[name]) continue; + floorBreached = true; + floorFailure( + count === 0 + ? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` + + 'The verdict below would have claimed that case holds.' + : `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` + + `${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`, + ); + } + if (floorBreached) { + floorFailure( + 'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' + + 'number. Find what stopped registering (a deleted row, a renamed label, a loop that no longer ' + + 'reaches it) and restore it.', + ); + } + if (failures) { - console.error(`✗ check-sdui-manifest self-test: ${failures} case(s) failed.`); + console.error(`✗ check-sdui-manifest self-test: ${failures} failure(s) (cases and floor).`); process.exit(1); } - console.log(`✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, emptiness are RED).`); + console.log( + `✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, ` + + `emptiness are RED), each registered under its own declared row battery (${declaredBatteries.length} at floor 1).`, + ); return SELF_TEST_VERDICT; } From fbb42081ec79fd50c79024c1d7bceb4702291820 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 07:48:03 +0000 Subject: [PATCH 2/2] test(scripts): keep check-sdui-manifest's green self-test line byte-identical MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The floor's evidence is the refusal, not the success line, so the green-tree stdout stays exactly as landed. The failure line keeps its corrected wording — floor breaches are counted in the same sink as case failures, so "N case(s) failed" would have been inaccurate — but that line is only reachable on a red run. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk --- scripts/check-sdui-manifest.mjs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/check-sdui-manifest.mjs b/scripts/check-sdui-manifest.mjs index 93ed905c34c..a6dbac4d966 100644 --- a/scripts/check-sdui-manifest.mjs +++ b/scripts/check-sdui-manifest.mjs @@ -307,10 +307,7 @@ function selfTest() { console.error(`✗ check-sdui-manifest self-test: ${failures} failure(s) (cases and floor).`); process.exit(1); } - console.log( - `✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, ` + - `emptiness are RED), each registered under its own declared row battery (${declaredBatteries.length} at floor 1).`, - ); + console.log(`✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, emptiness are RED).`); return SELF_TEST_VERDICT; }