From 124d27115955ef52aba5393652edc9045d81c179 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Sep 2026 08:39:08 +0000 Subject: [PATCH] test(scripts): floor five table-driven self-tests on their own row labels (#13799 batch 7a) Recipe A, as settled by the batch 7 pilot: each row's own label in the literal `cases` table becomes a declared battery with a floor of 1, `registerCase()` is the FIRST statement of the driving loop body, and the roster is a LITERAL the table is checked against with its own size pinned at the row count. Files and batteries: check-refd-timer-probe 11, check-skill-compatibility-version 18, check-skill-frame-sync 13, check-skills-token-ratchet 64, check-widget-option-census 16. No assertion condition touched, no control flow rewritten, no comment promoted to a section head, the verdict handshake kept as landed per file. The red-run failure line now reads `N failure(s) (cases and floor)`; the green line is unchanged. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk --- scripts/check-refd-timer-probe.mjs | 115 +++++++++++- scripts/check-skill-compatibility-version.mjs | 122 ++++++++++++- scripts/check-skill-frame-sync.mjs | 117 +++++++++++- scripts/check-skills-token-ratchet.mjs | 168 +++++++++++++++++- scripts/check-widget-option-census.mjs | 120 ++++++++++++- 5 files changed, 637 insertions(+), 5 deletions(-) diff --git a/scripts/check-refd-timer-probe.mjs b/scripts/check-refd-timer-probe.mjs index 98af9105ab6..11bd507f75c 100644 --- a/scripts/check-refd-timer-probe.mjs +++ b/scripts/check-refd-timer-probe.mjs @@ -271,6 +271,56 @@ export const refdTimeouts = () => // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// A zero failure count 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 (`failed += 1`) 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's own `label` is a declared battery, verbatim, with a floor of 1, and +// `registerCase()` 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. It stays first even where the body carries `continue`: the floor +// asserts REACH, and placing it after a guard reintroduces the very inversion +// this shape exists to avoid. 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({ + 'the approved module may read the probe → GREEN': 1, + 'a raw probe in another package → RED, naming file and line': 1, + 'a COMMENT naming the probe → GREEN (prose explains the rule; it does not break it)': 1, + 'a BLOCK comment is masked, and a real hit AFTER it keeps its line number → RED at :5': 1, + 'a DESTRUCTURED probe → RED': 1, + 'a NAMED IMPORT from node:process → RED': 1, + 'a BRACKETED member access → RED': 1, + 'a .md page discussing the probe is not scanned → GREEN': 1, + 'the approved module missing → RED even though no file breaks the rule': 1, + 'the approved module present but no longer reading the probe → RED': 1, + 'two raw sites → two problems, each named': 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 = 11; + function selfTest() { const cases = [ { @@ -374,8 +424,15 @@ function selfTest() { }, ]; + // 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 failed = 0; for (const c of cases) { + registerCase(c.label); const { problems } = judge(c.tree); const isRed = problems.length > 0; if (isRed !== (c.expect === 'red')) { @@ -423,8 +480,64 @@ function selfTest() { console.log(' ✓ the gate excludes itself by identity, not by a listed exemption'); } + // ── 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}`); + failed += 1; + }; + 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((c) => c.label); + 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 (failed > 0) { - console.error(`\n✗ check-refd-timer-probe self-test failed (${failed} case(s)).`); + console.error(`\n✗ check-refd-timer-probe self-test: ${failed} failure(s) (cases and floor).`); process.exit(1); } console.log(`\n✓ check-refd-timer-probe self-test: ${cases.length} cases pass, negative controls included.`); diff --git a/scripts/check-skill-compatibility-version.mjs b/scripts/check-skill-compatibility-version.mjs index 9a97cf79704..2b9f9ce6804 100644 --- a/scripts/check-skill-compatibility-version.mjs +++ b/scripts/check-skill-compatibility-version.mjs @@ -478,6 +478,63 @@ function report(problems) { // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// A zero failure count 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 (`failed += 1`) 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's own `label` is a declared battery, verbatim, with a floor of 1, and +// `registerCase()` 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. It stays first even where the body carries `continue`: the floor +// asserts REACH, and placing it after a guard reintroduces the very inversion +// this shape exists to avoid. 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({ + 'the landed wording (exact 17.x pin) → GREEN': 1, + 'R1 — a stale major (17.x → 16.x, the #5245 drift) → RED naming file/declared/actual/fix': 1, + 'R3 — no `compatibility:` key at all → RED (absence is never a skip, #4690)': 1, + 'an empty `compatibility:` value → RED': 1, + 'no frontmatter at all → RED': 1, + 'R4 — wording switched to an unpinned range (#5245 option ②) → RED, not a silent no-op': 1, + 'R4b — zero pins repo-wide with every file exempt → RED via the anti-no-op assertion': 1, + 'R5 — an exemption naming a file that is not scanned → RED (anti-dormancy)': 1, + 'R7 — an exempt file whose written justification is gone → RED (exemption self-invalidates)': 1, + 'an exempt file that grows a pin → RED (the exemption is now dead config)': 1, + 'an exempt file whose pin is ALSO wrong → RED on the pin (exemptions never cover a claim)': 1, + 'R8 — a half-pinned line (one pinned, one bare mention) → RED on the bare one': 1, + 'a pin naming a package the workspace does not have → RED': 1, + 'R6 — an empty scan → RED, never a green skip (#4690, the whole point)': 1, + 'no workspace packages discovered → RED': 1, + 'multi-package line, both pinned correctly → GREEN': 1, + 'wording reflowed around a correct pin → stays GREEN': 1, + 'a prerelease major still reconciles by major (17.0.0-rc.5 ↔ 17.x) → GREEN': 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 = 18; + function selfTest() { console.log('check-skill-compatibility-version self-test\n'); @@ -643,8 +700,15 @@ function selfTest() { }, ]; + // 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 failed = 0; for (const c of cases) { + registerCase(c.label); let problems; try { ({ problems } = runAllChecks(c.files, c.pkgs ?? PKGS, EXEMPT)); @@ -755,8 +819,64 @@ function selfTest() { for (const f of declFailures) console.error(` ✗ dispatch-gates declaration: ${f}`); failed += declFailures.length; + // ── 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}`); + failed += 1; + }; + 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((c) => c.label); + 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 (failed > 0) { - console.error(`\n✗ check-skill-compatibility-version self-test failed (${failed} case(s)).`); + console.error(`\n✗ check-skill-compatibility-version self-test: ${failed} failure(s) (cases and floor).`); process.exit(1); } console.log(`\n✓ check-skill-compatibility-version self-test: ${cases.length} cases pass, plus 7 dispatch-gates declaration cases.`); diff --git a/scripts/check-skill-frame-sync.mjs b/scripts/check-skill-frame-sync.mjs index 53f2d98858f..0a1d255edb6 100644 --- a/scripts/check-skill-frame-sync.mjs +++ b/scripts/check-skill-frame-sync.mjs @@ -719,6 +719,58 @@ function mutate(copies, id, from, to) { // handshake is a flag rather than a returned sentinel. let selfTestReachedVerdict = false; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// A zero failure count 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 (`failed += 1`) 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's own `label` is a declared battery, verbatim, with a floor of 1, and +// `registerCase()` 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. It stays first even where the body carries `continue`: the floor +// asserts REACH, and placing it after a guard reintroduces the very inversion +// this shape exists to avoid. 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({ + 'baseline: the two real copies are isomorphic': 1, + 'one copy loses an axis, its declared count unchanged → red (count vs entries)': 1, + 'one copy coherently rewritten to three axes → red (cross-copy count)': 1, + 'two-axis copy phrased "both axes" → red on the COUNT, not on extraction': 1, + 'an axis is renamed in one copy → red (unmapped axis name)': 1, + 'axes reordered in one copy → red (name sequence)': 1, + 'the binding sentence is removed → red (extraction failure, not a skip)': 1, + 'the declaring sentence is removed → red (extraction failure, not a skip)': 1, + 'a frame count mention drifts from the frame → red': 1, + 'AXIS_MAP misaligned (zh patterns swapped) → red, proving the map is load-bearing': 1, + 'an undeclared extra copy appears → red (anti-dormancy)': 1, + 'the dev-side copy returns to the now-undeclared agent definition → red (anti-dormancy)': 1, + 'wording-only divergence (the #5451 generalization) → stays GREEN': 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 = 13; + function selfTest() { const base = readCopies(); const scanOf = (copies) => { @@ -904,8 +956,15 @@ function selfTest() { }, ]; + // 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 failed = 0; for (const c of cases) { + registerCase(c.label); let problems; try { const copies = c.copies(); @@ -1017,8 +1076,64 @@ function selfTest() { for (const f of popFailures) console.error(` ✗ scan population: ${f}`); failed += popFailures.length; + // ── 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}`); + failed += 1; + }; + 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((c) => c.label); + 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 (failed > 0) { - console.error(`\n✗ check-skill-frame-sync self-test failed (${failed} case(s)).`); + console.error(`\n✗ check-skill-frame-sync self-test: ${failed} failure(s) (cases and floor).`); process.exit(1); } console.log( diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index e95ccbfa54a..6e3826f71b6 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -710,6 +710,109 @@ function fixtureTree() { // as one that passed (#13798). const SELF_TEST_VERDICT = 'check-skills-token-ratchet self-test reached its verdict'; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// A zero failure count 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 (`failed++`) 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's first column (its label) is a declared battery, verbatim, with a floor of 1, and +// `registerCase()` 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. It stays first even where the body carries `continue`: the floor +// asserts REACH, and placing it after a guard reintroduces the very inversion +// this shape exists to avoid. 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({ + 'under the ceiling -> green': 1, + 'at the ceiling -> green': 1, + 'over the ceiling -> red': 1, + 'empty read -> red, not a skip (#4690)': 1, + 'the red names the file': 1, + 'the red names the measured count': 1, + 'the red names the ceiling': 1, + 'the red names the rule: deletion in the same file': 1, + 'the red rejects a re-wrap as payment': 1, + 'shrink direction — a shrunk file is green and its headroom is reported': 1, + 'the gate declares its registry shrink-only in author-facing text': 1, + 'the over-ceiling remedy carries the authority token': 1, + 'the unpriced-file remedy carries the authority token': 1, + 'no remedy tells the author to raise a ceiling': 1, + 'the raise is bound to a quoted maintainer ruling': 1, + 'four ASCII bytes are one token': 1, + 'five ASCII bytes round up to two': 1, + 'the unit is UTF-8 BYTES, not JS characters (a 3-byte CJK char is not free)': 1, + 'empty text counts zero, which the verdict turns red': 1, + 'the catalog is discovered from disk': 1, + 'every discovered file lives under a published skill directory': 1, + 'a discovered file with no ceiling is RED': 1, + 'the unpriced red names the file and its measured count': 1, + 'every discovered AUTHORED file carries a ceiling today': 1, + 'every ceiling names a file the enumeration finds': 1, + 'every ceiling is a positive integer': 1, + 'the walk descends past SKILL.md into rules/': 1, + 'the walk descends arbitrarily deep': 1, + 'a directory carrying no SKILL.md is skipped whole': 1, + 'skills/README.md is outside the population (population 3)': 1, + 'the fixture walk finds exactly its four in-skill files': 1, + 'the real population is more than one file per skill': 1, + 'the real population reaches rules/ and hand-authored references/': 1, + 'a generated _index.md is recognised as generator-owned': 1, + 'the react-blocks contract is recognised as generator-owned': 1, + 'a hand-authored reference is NOT generator-owned': 1, + 'a hand-authored rule is NOT generator-owned': 1, + 'a SKILL.md is NOT generator-owned': 1, + 'a generator-owned file with no ceiling is GREEN, not an unpriced red': 1, + 'its green names the generator that owns it': 1, + 'its green says measured-but-not-ratcheted': 1, + 'a CEILINGS row on a generator-owned file is RED': 1, + 'that red explains the wrong-actor reason': 1, + 'no ceiling names a generator-owned path': 1, + 'the boundary does not swallow the population': 1, + 'the boundary excludes something (it is not inert)': 1, + 'the excluded set is exactly these generator-owned paths': 1, + 'the unpriced red covers a file INSIDE a skill, not just a new skill': 1, + 'the unpriced red routes a genuine generator output to the register, not to a second list': 1, + 'the main basis sha is recorded': 1, + 'the pending-#10402 basis sha is recorded': 1, + 'exactly the two #10402 files are pinned on the second basis': 1, + 'both second-basis files carry a ceiling': 1, + 'the internal-id-strip basis sha is recorded': 1, + 'the re-measure lowered the SKILL.md subtotal': 1, + 'the #12392 extension basis sha is recorded': 1, + 'the extension priced more than the eleven SKILL.md files': 1, + 'every SKILL.md still carries its own ceiling': 1, + 'the report prints a whole-bundle total': 1, + 'the report prints a per-file net delta against the ceiling': 1, + 'the report names the counting convention': 1, + 'a generator-owned file is counted in the bundle total': 1, + 'a generator-owned file is NOT counted into the ratcheted subtotal': 1, + 'the report separates the generator-owned subtotal': 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 = 64; + function selfTest() { const rel = 'skills/objectstack-ui/SKILL.md'; const over = verdict(rel, 26000, 25154).msg; @@ -917,14 +1020,77 @@ function selfTest() { reportLines([]).some((l) => l.includes('generator-owned (measured, not ratcheted)')), true], ]; + // 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 failed = 0; for (const [name, actual, expected] of cases) { + registerCase(name); const ok = JSON.stringify(actual) === JSON.stringify(expected); if (!ok) failed++; console.log(` ${ok ? '✓' : '✗'} ${name}${ok ? '' : ` (got ${JSON.stringify(actual)}, want ${JSON.stringify(expected)})`}`); } + // ── 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}`); + failed++; + }; + 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 (failed) { - console.error(`✗ check-skills-token-ratchet self-test: ${failed} of ${cases.length} case(s) failed.`); + console.error(`✗ check-skills-token-ratchet self-test: ${failed} failure(s) (cases and floor).`); process.exit(1); } console.log(`✓ check-skills-token-ratchet self-test: ${cases.length} cases pass.`); diff --git a/scripts/check-widget-option-census.mjs b/scripts/check-widget-option-census.mjs index 9cb66451765..21b2da24216 100644 --- a/scripts/check-widget-option-census.mjs +++ b/scripts/check-widget-option-census.mjs @@ -563,6 +563,61 @@ const EVIDENCE_FIXTURE = { 'if (subCaption) next.options = { ...w.options, description: subCaption };\n', }; +// ── The self-test's own battery roster and floor (#13489) ────────────────── +// +// A zero failure count 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 (`failed += 1`) 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's own `label` is a declared battery, verbatim, with a floor of 1, and +// `registerCase()` 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. It stays first even where the body carries `continue`: the floor +// asserts REACH, and placing it after a guard reintroduces the very inversion +// this shape exists to avoid. 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({ + 'the real shape, read cleanly → GREEN': 1, + 'a declared key the parser does not consume → RED, naming it': 1, + 'a fake key in a DOC COMMENT → GREEN (prose is not a declaration)': 1, + 'a property commented OUT in a block comment → GREEN': 1, + 'a property commented OUT on a line → GREEN': 1, + 'key-shaped text inside a .describe() STRING → GREEN': 1, + 'a nested inline z.object({}) → the reader still reaches the LAST key past it': 1, + 'a second undeclared census member with no ledger row → RED': 1, + '`description` alone stays legal — the ledgered exemption → GREEN': 1, + "the ledger row's witness gone from the evidence file → RED": 1, + 'the witness present only as PROSE in the evidence file → RED': 1, + '`description` removed from the census → RED as a stale row, not silence': 1, + 'the schema renamed away → REFUSE, never a clean run': 1, + 'the census array emptied → REFUSE, never a clean run': 1, + 'a spread inside the shape → REFUSE (the keys come from elsewhere)': 1, + 'an .extend() on the declaration → REFUSE (this reader sees only the literal)': 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 = 16; + function selfTest() { const base = { spec: SPEC_FIXTURE, parser: CENSUS_FIXTURE, evidence: EVIDENCE_FIXTURE }; const cases = [ @@ -697,8 +752,15 @@ function selfTest() { }, ]; + // 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 failed = 0; for (const c of cases) { + registerCase(c.label); // A fixture built with `.replace()` whose needle has drifted is a SILENT // no-op: the case then runs against the clean baseline, agrees with its // expectation for the wrong reason, and prints a tick. So every mutating @@ -763,8 +825,64 @@ function selfTest() { else { failed += 1; console.error(` ✗ ${line}`); } } + // ── 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}`); + failed += 1; + }; + 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((c) => c.label); + 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 (failed > 0) { - console.error(`\n✗ check-widget-option-census self-test failed (${failed} case(s)).`); + console.error(`\n✗ check-widget-option-census self-test: ${failed} failure(s) (cases and floor).`); process.exit(1); } console.log(