Skip to content

Commit abc10b2

Browse files
claude[bot]claude
andauthored
test(scripts): pin a battery roster floor on 40 more scripts/** self-tests (#14851)
* test(scripts): pin a battery roster floor on 40 self-tests `failures.length === 0` was the only success condition in these gates' self-tests, so "every case held" and "the cases never ran" printed the same line. Transplants the PR #13487 shape validated on check-doc-authoring and carried to check-self-test-wired / check-self-test-workflow-commands in PR #13797: every section opens with `battery('<name>')`, every assertion is attributed to the battery most recently opened, and a floor evaluated before the verdict requires the OPENED set to equal the DECLARED set with each battery at or above its own case count. The roster's own size is pinned too, so deleting an entry cannot silence a floor. Registered NAMES are what is pinned, never a total: a set difference says WHICH battery stopped, a count says only that something did. No case was rewritten — the only edits inside each self-test are the roster wiring (a `battery()` opener per existing section banner, one `registerCase()` line in the assertion helper, and the floor block before the verdict). Floors are the per-battery counts measured on this tree. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Swfxm6gT9ESmjSS7pqfVw * test(scripts): pin the structural invariant, not today's count, on two ledger-driven batteries Two batteries register one case per row of a list that is meant to shrink: `KNOWN_NUMBER_COLLISIONS` in check-adr-anchors (a resolved collision is deleted, and a stale entry already fails) and `ALLOW` in check-single-authz-resolver (an exemption that exempts nothing is dead weight). A floor at today's count would redden every legitimate removal and train the next author to edit the floor — the one habit these floors exist to prevent. Pinned instead is the part that does not move with the list: the structural cases ran AND at least one row was audited, said in place over each entry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Swfxm6gT9ESmjSS7pqfVw * test(scripts): reword the two ledger notes so neither reads as a ratchet-remedy offer The first spelling put `ALLOW` and the words "shrink-only" inside `anchorFor`'s window in check-single-authz-resolver, which flipped that file from `excluded` to `unmarked` under check:ratchet-remedy-authority (and then MISCLASSIFIED against its CONTROL row). Measured, both findings; the gate is green again with the same fact stated without the token. The adr-anchors note is reflowed for readability only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Swfxm6gT9ESmjSS7pqfVw * test(scripts): type the roster wiring in the .mts gate scripts/check-test-typecheck.mts is the one .mts file in the batch and it is reached by the root `tsc --noEmit`, so the untyped `battery()` / `registerCase()` / `floorFailure()` insertions added 7 raw errors and drifted the frozen DEBT entry for @objectstack/spec-monorepo upward (26 -> 33, measured). Typing the wiring and widening the roster to `Readonly<Record<string, number>>` puts the count back at its recorded 26 with check:type-check-debt green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Swfxm6gT9ESmjSS7pqfVw --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
1 parent 84b8190 commit abc10b2

40 files changed

Lines changed: 4265 additions & 8 deletions

scripts/check-adr-anchors.mjs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,47 @@ import { join } from 'node:path';
238238

239239
import { ANCHORS_DIR, assembleAnchors, loadAnchors, shardNameFor } from './adr-anchors.mjs';
240240

241+
// ── The self-test's own battery roster and floor (#13489) ──────────────────
242+
//
243+
// `failures.length === 0` used to be this self-test's ONLY success condition, so
244+
// "every case held" and "the cases never ran" printed the same line. Closed the
245+
// way PR #13487 validated on check-doc-authoring: what is pinned is the
246+
// registered NAMES, not a number. Every section opens with `battery('<name>')`,
247+
// every assertion is attributed to the battery most recently opened, and the
248+
// floor requires the OPENED set to equal the DECLARED set with each battery at
249+
// or above its own count.
250+
//
251+
// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3
252+
// keeps a total "right" the moment a sibling grows.
253+
//
254+
// The counts are a FLOOR, not an equality — adding cases is ordinary work and
255+
// must not red. A battery BELOW its floor means cases stopped running; the
256+
// remedy is to find what stopped registering.
257+
const SELF_TEST_BATTERIES = Object.freeze({
258+
'the base directory audit — collisions, allowlists and unparseable names': 14,
259+
'A tombstone resolves citations but is not anchorable (#7329)': 15,
260+
'Cited numbers resolve (#6634)': 15,
261+
'Cited decision LETTERS resolve (#9592)': 26,
262+
// ⛔ NOT today's count. This battery runs one case per `KNOWN_NUMBER_COLLISIONS`
263+
// row (3 today) on top of 20 structural cases, and entries only ever LEAVE that
264+
// list: a resolved collision is meant to be deleted, and the gate already fails
265+
// a stale entry. A floor at 23 would redden every legitimate removal and train
266+
// the next author to edit the floor, which is the one habit these floors exist
267+
// to prevent. Pinned instead is the part that does not move with the list: the
268+
// 20 structural cases ran AND at least one row was actually audited.
269+
'Live tree: green as shipped, red under ablation': 21,
270+
'the sharded registry\'s assembly (#6957)': 13,
271+
});
272+
273+
// DELETING an entry silences that battery's floor exactly as effectively as
274+
// zeroing it, so the roster's own size is pinned too.
275+
const SELF_TEST_BATTERY_FLOOR = 6;
276+
277+
// The key an assertion is filed under when no battery is open. It is not a
278+
// declared battery, so it reds by the same set difference rather than silently
279+
// inflating whichever battery happened to run last.
280+
const UNATTRIBUTED_BATTERY = '(no battery open)';
281+
241282
const ROOT = process.cwd();
242283
/** Where the registry lives. One shard per anchor — see `scripts/adr-anchors.mjs`. */
243284
const MAP_PATH = ANCHORS_DIR;
@@ -1130,13 +1171,28 @@ if (ambiguous.length) {
11301171
* has failed at its one job.
11311172
*/
11321173
function selfTest() {
1174+
// The battery ledger this self-test's floor is evaluated against (#13489).
1175+
// `battery()` opens a battery; every assertion below is attributed to the one
1176+
// most recently opened, so a section that stops running stops registering and
1177+
// names ITSELF at the floor rather than going quiet.
1178+
const seen = new Map();
1179+
let openBattery = null;
1180+
const battery = (name) => {
1181+
openBattery = name;
1182+
};
1183+
const registerCase = () => {
1184+
const b = openBattery ?? UNATTRIBUTED_BATTERY;
1185+
seen.set(b, (seen.get(b) ?? 0) + 1);
1186+
};
11331187
const failures = [];
11341188
let checked = 0;
11351189
/** @param {string} name @param {boolean} cond @param {string} detail */
11361190
const assert = (name, cond, detail) => {
1191+
registerCase();
11371192
checked++;
11381193
if (!cond) failures.push(`${name}${detail}`);
11391194
};
1195+
battery('the base directory audit — collisions, allowlists and unparseable names');
11401196
const audit = (files, allowlist = []) => auditAdrDirectory(files, allowlist);
11411197
const joined = (errs) => errs.join('\n');
11421198

@@ -1236,6 +1292,7 @@ function selfTest() {
12361292
// exactly why one `records` set was not enough — so both are pinned, and a
12371293
// test of only the red half would pass on an implementation that broke the
12381294
// citation resolution the tombstone exists for.
1295+
battery('A tombstone resolves citations but is not anchorable (#7329)');
12391296
{
12401297
const TOMB = [...BASE, '0003-withdrawn-something.md'];
12411298
const { errors: e, records, nonDecisions } = audit(TOMB);
@@ -1335,6 +1392,7 @@ function selfTest() {
13351392
// the tracked tree the real scan reads, so a literal `ADR-` + four digits in
13361393
// a fixture would be collected as a genuine citation and fail the gate it is
13371394
// testing. `id('0202')` keeps the token out of the source.
1395+
battery('Cited numbers resolve (#6634)');
13381396
{
13391397
const id = (n) => 'ADR-' + n;
13401398
const RECORDS = new Set(['0090', '0107']);
@@ -1446,6 +1504,7 @@ function selfTest() {
14461504
// citations (measured: without the sub-decision rule, ADR-0120's lettered
14471505
// gates and ADR-0020's numbered steps — 20 live citations — read as bad
14481506
// letters); one too loose passes anything. Both halves are asserted.
1507+
battery('Cited decision LETTERS resolve (#9592)');
14491508
{
14501509
const id = (n) => 'ADR-' + n;
14511510
const idx = decisionIndexFor;
@@ -1613,6 +1672,7 @@ function selfTest() {
16131672
}
16141673

16151674
// ── Live tree: green as shipped, red under ablation ──────────────────────
1675+
battery('Live tree: green as shipped, red under ablation');
16161676
let liveFiles = null;
16171677
try {
16181678
liveFiles = readdirSync(join(ROOT, ADR_DIR));
@@ -1825,6 +1885,7 @@ function selfTest() {
18251885
// Two of these are the properties the split was adopted for, and they pull in
18261886
// OPPOSITE directions — so testing only the happy one would leave a layout
18271887
// that merges everything cleanly, including the two edits that must not.
1888+
battery('the sharded registry\'s assembly (#6957)');
18281889
{
18291890
const shard = (file) => [shardNameFor(file), JSON.stringify({ file, adrs: ['ADR-0001'], invariant: 'x' })];
18301891
const from = (pairs) => {
@@ -1917,6 +1978,51 @@ function selfTest() {
19171978
failures.push(`self-test threw before finishing — ${e && e.stack ? e.stack : e}`);
19181979
}
19191980

1981+
// ── The floor: every declared battery RAN, and ran its cases (#13489) ───
1982+
//
1983+
// Evaluated after every battery has had its chance and BEFORE the verdict, so
1984+
// the success line below can only be printed by a run in which the set of
1985+
// batteries that registered assertions EQUALS the set declared. A set
1986+
// difference names WHICH battery stopped; a count says only that something did.
1987+
const floorFailure = (message) => {
1988+
failures.push(message);
1989+
};
1990+
const declaredBatteries = Object.keys(SELF_TEST_BATTERIES);
1991+
let floorBreached = false;
1992+
if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) {
1993+
floorBreached = true;
1994+
floorFailure(
1995+
`SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` +
1996+
`${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`,
1997+
);
1998+
}
1999+
for (const [name, count] of seen) {
2000+
if (declaredBatteries.includes(name)) continue;
2001+
floorBreached = true;
2002+
floorFailure(
2003+
`self-test battery "${name}" registered ${count} case(s) but is not declared in ` +
2004+
'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.',
2005+
);
2006+
}
2007+
for (const name of declaredBatteries) {
2008+
const count = seen.get(name) ?? 0;
2009+
if (count >= SELF_TEST_BATTERIES[name]) continue;
2010+
floorBreached = true;
2011+
floorFailure(
2012+
count === 0
2013+
? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` +
2014+
'The verdict below would have claimed those cases hold.'
2015+
: `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` +
2016+
`${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`,
2017+
);
2018+
}
2019+
if (floorBreached) {
2020+
floorFailure(
2021+
'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' +
2022+
'number. Find what stopped registering (an early return, a deleted block, a guard that now ' +
2023+
'skips) and restore it.',
2024+
);
2025+
}
19202026
if (failures.length) {
19212027
console.error(`✗ check-adr-anchors --self-test — ${failures.length} failure(s) of ${checked} assertion(s)\n`);
19222028
for (const f of failures) console.error(' • ' + f + '\n');

scripts/check-agent-test-spelling.mjs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,25 +818,82 @@ function baseFixtureFiles(extra = {}) {
818818
// handshake is a flag rather than a returned sentinel.
819819
let selfTestReachedVerdict = false;
820820

821+
// ── The self-test's own battery roster and floor (#13489) ──────────────────
822+
//
823+
// `failures.length === 0` used to be this self-test's ONLY success condition, so
824+
// "every case held" and "the cases never ran" printed the same line. Closed the
825+
// way PR #13487 validated on check-doc-authoring: what is pinned is the
826+
// registered NAMES, not a number. Every section opens with `battery('<name>')`,
827+
// every assertion is attributed to the battery most recently opened, and the
828+
// floor requires the OPENED set to equal the DECLARED set with each battery at
829+
// or above its own count.
830+
//
831+
// ⛔ A pinned TOTAL is not the repair: a battery dropping from 9 cases to 3
832+
// keeps a total "right" the moment a sibling grows.
833+
//
834+
// The counts are a FLOOR, not an equality — adding cases is ordinary work and
835+
// must not red. A battery BELOW its floor means cases stopped running; the
836+
// remedy is to find what stopped registering.
837+
const SELF_TEST_BATTERIES = Object.freeze({
838+
'classifier — forms that MUST be refused': 10,
839+
'classifier — forms that MUST be allowed (a false red here is worse than no gate)': 18,
840+
'the multi-line spelling a line-at-a-time reader misses': 2,
841+
'the command word is what pnpm would resolve': 5,
842+
'measured stripper carve-outs, both named': 2,
843+
'the SWEEP over a real temp tree — the walk, not the predicate': 5,
844+
'the escape hatch works — a declared counter-example is not a violation': 2,
845+
'the same tree WITHOUT the plant is green — the red above is the plant, not the fixture': 3,
846+
'anti-vacuity — every way a broken selector could wear a pass is a REFUSAL': 4,
847+
'the declared lists cannot quietly become mute buttons': 4,
848+
'the dispatch-gates declaration — both directions, derived from the scan roots': 8,
849+
'the derivation reads THIS workspace, and reads it non-empty': 4,
850+
});
851+
852+
// DELETING an entry silences that battery's floor exactly as effectively as
853+
// zeroing it, so the roster's own size is pinned too.
854+
const SELF_TEST_BATTERY_FLOOR = 12;
855+
856+
// The key an assertion is filed under when no battery is open. It is not a
857+
// declared battery, so it reds by the same set difference rather than silently
858+
// inflating whichever battery happened to run last.
859+
const UNATTRIBUTED_BATTERY = '(no battery open)';
860+
821861
function selfTest() {
862+
// The battery ledger this self-test's floor is evaluated against (#13489).
863+
// `battery()` opens a battery; every assertion below is attributed to the one
864+
// most recently opened, so a section that stops running stops registering and
865+
// names ITSELF at the floor rather than going quiet.
866+
const seen = new Map();
867+
let openBattery = null;
868+
const battery = (name) => {
869+
openBattery = name;
870+
};
871+
const registerCase = () => {
872+
const b = openBattery ?? UNATTRIBUTED_BATTERY;
873+
seen.set(b, (seen.get(b) ?? 0) + 1);
874+
};
822875
const failures = [];
823876
const t = (name, actual, expected) => {
877+
registerCase();
824878
const ok = JSON.stringify(actual) === JSON.stringify(expected);
825879
if (!ok) failures.push(`${name}\n expected ${JSON.stringify(expected)}\n actual ${JSON.stringify(actual)}`);
826880
console.log(` ${ok ? '✓' : '✗'} ${name}`);
827881
};
828882

829883
console.log('classifier — forms that MUST be refused');
884+
battery('classifier — forms that MUST be refused');
830885
for (const line of RED_CASES) {
831886
t(line, scanLine(line, VITEST_SCRIPTS).findings.length > 0, true);
832887
}
833888

834889
console.log('classifier — forms that MUST be allowed (a false red here is worse than no gate)');
890+
battery('classifier — forms that MUST be allowed (a false red here is worse than no gate)');
835891
for (const line of GREEN_CASES) {
836892
t(line, scanLine(line, VITEST_SCRIPTS).findings.length, 0);
837893
}
838894

839895
console.log('the multi-line spelling a line-at-a-time reader misses');
896+
battery('the multi-line spelling a line-at-a-time reader misses');
840897
t(
841898
'continuation join',
842899
scanLine(logicalLines('pnpm --filter <pkg> test \\\n -- --maxWorkers=2 <file>\n')[0].text, VITEST_SCRIPTS).findings.length,
@@ -846,17 +903,20 @@ function selfTest() {
846903
t('continuation keeps the FIRST line number', logicalLines('a \\\nb\nc\n').map((l) => l.line), [1, 3, 4]);
847904

848905
console.log('the command word is what pnpm would resolve');
906+
battery('the command word is what pnpm would resolve');
849907
t('--filter consumes its value', commandWord(['pnpm', '--filter', 'test', 'build']), 'build');
850908
t('run keyword is skipped', commandWord(['pnpm', 'run', 'test']), 'test');
851909
t('bare script', commandWord(['pnpm', 'test']), 'test');
852910
t('dev script', commandWord(['pnpm', 'dev:crm']), 'dev:crm');
853911
t('no command word', commandWord(['pnpm']), null);
854912

855913
console.log('measured stripper carve-outs, both named');
914+
battery('measured stripper carve-outs, both named');
856915
t('turbo', judgeRun(['pnpm', 'turbo', 'run', 'test'], VITEST_SCRIPTS).bound, false);
857916
t('npm', judgeRun(['pnpm', 'npm', 'run', 'test'], VITEST_SCRIPTS).bound, false);
858917

859918
console.log('the SWEEP over a real temp tree — the walk, not the predicate');
919+
battery('the SWEEP over a real temp tree — the walk, not the predicate');
860920
const redTree = makeFixtureTree(
861921
baseFixtureFiles({ '.claude/agents/bad.md': 'Run `pnpm --filter @objectstack/spec test -- --maxWorkers=2 <file>`.\n' }),
862922
);
@@ -870,6 +930,7 @@ function selfTest() {
870930
t('the message names the escape hatch', joined.includes('COUNTER_EXAMPLE_FILES'), true);
871931

872932
console.log('the escape hatch works — a declared counter-example is not a violation');
933+
battery('the escape hatch works — a declared counter-example is not a violation');
873934
const exempted = sweep(redTree, {
874935
counterExamples: [{ path: '.claude/agents/bad.md', reason: 'quotes the broken form as a warning' }],
875936
});
@@ -880,6 +941,7 @@ function selfTest() {
880941
}
881942

882943
console.log('the same tree WITHOUT the plant is green — the red above is the plant, not the fixture');
944+
battery('the same tree WITHOUT the plant is green — the red above is the plant, not the fixture');
883945
const greenTree = makeFixtureTree(baseFixtureFiles());
884946
try {
885947
const lines = [];
@@ -896,6 +958,7 @@ function selfTest() {
896958
}
897959

898960
console.log('anti-vacuity — every way a broken selector could wear a pass is a REFUSAL');
961+
battery('anti-vacuity — every way a broken selector could wear a pass is a REFUSAL');
899962
const noRoot = makeFixtureTree({ 'AGENTS.md': 'x\n' });
900963
try {
901964
t('a missing declared root refuses', run(noRoot, () => {}), EXIT_REFUSED);
@@ -946,6 +1009,7 @@ function selfTest() {
9461009
}
9471010

9481011
console.log('the declared lists cannot quietly become mute buttons');
1012+
battery('the declared lists cannot quietly become mute buttons');
9491013
t('exactly one rule-owning file', RULE_OWNING_FILES.length, 1);
9501014
t('and it is this file', RULE_OWNING_FILES[0], 'scripts/check-agent-test-spelling.mjs');
9511015
t('every counter-example carries a reason', COUNTER_EXAMPLE_FILES.every((e) => typeof e.reason === 'string' && e.reason.trim().length > 0), true);
@@ -972,6 +1036,7 @@ function selfTest() {
9721036
// The live `hintCovers` results are recorded in the docblock as a
9731037
// MEASUREMENT, taken at the command line where it costs nothing.
9741038
console.log('the dispatch-gates declaration — both directions, derived from the scan roots');
1039+
battery('the dispatch-gates declaration — both directions, derived from the scan roots');
9751040
{
9761041
const scanRoots = [...INSTRUCTION_ROOTS, ...EXECUTED_ROOTS];
9771042
// A root with no separator is refused by the extractor as too generic, so
@@ -1009,12 +1074,58 @@ function selfTest() {
10091074
}
10101075

10111076
console.log('the derivation reads THIS workspace, and reads it non-empty');
1077+
battery('the derivation reads THIS workspace, and reads it non-empty');
10121078
const derived = deriveVitestScripts(REPO_ROOT);
10131079
t('derives a non-empty script set', derived.names.size > 0, true);
10141080
t('derives `test`', derived.names.has('test'), true);
10151081
t('does NOT derive `dev` — the documented dev-server spelling is safe by measurement', derived.names.has('dev'), false);
10161082
t('does NOT derive `dev:crm`', derived.names.has('dev:crm'), false);
10171083

1084+
// ── The floor: every declared battery RAN, and ran its cases (#13489) ───
1085+
//
1086+
// Evaluated after every battery has had its chance and BEFORE the verdict, so
1087+
// the success line below can only be printed by a run in which the set of
1088+
// batteries that registered assertions EQUALS the set declared. A set
1089+
// difference names WHICH battery stopped; a count says only that something did.
1090+
const floorFailure = (message) => {
1091+
failures.push(message);
1092+
};
1093+
const declaredBatteries = Object.keys(SELF_TEST_BATTERIES);
1094+
let floorBreached = false;
1095+
if (declaredBatteries.length < SELF_TEST_BATTERY_FLOOR) {
1096+
floorBreached = true;
1097+
floorFailure(
1098+
`SELF_TEST_BATTERIES declares ${declaredBatteries.length} batteries, below the pinned ` +
1099+
`${SELF_TEST_BATTERY_FLOOR} — a battery deleted from the roster takes its own floor with it.`,
1100+
);
1101+
}
1102+
for (const [name, count] of seen) {
1103+
if (declaredBatteries.includes(name)) continue;
1104+
floorBreached = true;
1105+
floorFailure(
1106+
`self-test battery "${name}" registered ${count} case(s) but is not declared in ` +
1107+
'SELF_TEST_BATTERIES — an assertion attributed to no declared battery is one nothing floors.',
1108+
);
1109+
}
1110+
for (const name of declaredBatteries) {
1111+
const count = seen.get(name) ?? 0;
1112+
if (count >= SELF_TEST_BATTERIES[name]) continue;
1113+
floorBreached = true;
1114+
floorFailure(
1115+
count === 0
1116+
? `self-test battery "${name}" DID NOT RUN — 0 cases registered, ${SELF_TEST_BATTERIES[name]} pinned. ` +
1117+
'The verdict below would have claimed those cases hold.'
1118+
: `self-test battery "${name}" registered ${count} case(s), below its pinned floor of ` +
1119+
`${SELF_TEST_BATTERIES[name]} — cases that used to run no longer do.`,
1120+
);
1121+
}
1122+
if (floorBreached) {
1123+
floorFailure(
1124+
'A battery at or below its floor means cases STOPPED RUNNING — the battery is the bug, not the ' +
1125+
'number. Find what stopped registering (an early return, a deleted block, a guard that now ' +
1126+
'skips) and restore it.',
1127+
);
1128+
}
10181129
if (failures.length > 0) {
10191130
console.error(`\n✗ check-agent-test-spelling --self-test -- ${failures.length} failure(s)\n`);
10201131
for (const failure of failures) console.error(` ${failure}`);

0 commit comments

Comments
 (0)