Skip to content

Commit 1f684af

Browse files
committed
fix(scripts): evaluate the census self-test's battery floor before its verdict
`selfTest()` printed its verdict line, set the handshake flag, and only then evaluated its battery floor. Two consequences, both measured on the source: a floor breach printed "all cases passed" and then its own FAIL lines (a transcript that contradicts itself), and any early exit inside the floor region left a run that had printed the success line, set the handshake and exited 0 with its floor never evaluated. The floor's own comment already claimed it was "Evaluated ... BEFORE the verdict"; the code order said otherwise. The floor block moves above the verdict write, byte-identical (its rules, the roster and SELF_TEST_BATTERY_FLOOR are untouched), so the `failures` the verdict reads already includes any floor breach. The handshake flag becomes the last statement of the function, after the success line prints, which is the landed shape scripts/check-agent-model-declared.mjs carries and what the AGENTS.md --self-test band requires. The comment now describes the order it relies on. The ordering is a STATIC property -- the floor prints only when it fails, so a passing run's bytes are identical either way and no mutation of a green tree exposes it -- so a new self-test case reads it off this file's own text: the floor above the verdict, the floor feeding the counter the verdict reads, the flag below the verdict with no exit between them, and the flag as the last statement before the return. Filed under the battery already open; the roster is not widened. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BTeBejoPUvRHN8WdAJC6oF
1 parent b22db51 commit 1f684af

1 file changed

Lines changed: 75 additions & 10 deletions

File tree

‎scripts/check-system-context-census.mjs‎

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,21 +2838,73 @@ function selfTest() {
28382838
!/[A-Za-z_$][\w$]*\s*\./.test(declSites[0][1]),
28392839
JSON.stringify(declSites.map((d) => d[1].replace(/\s+/g, ' ')))
28402840
);
2841+
2842+
// ⭐ The VERDICT ORDER is a STATIC property, so it is read here off this
2843+
// file's own text. The floor prints only when it FAILS, so a passing run's
2844+
// bytes are identical whichever side of the verdict the floor sits on: no
2845+
// mutation of a green tree can expose the order and the fleet's injection
2846+
// probe correctly reports that it observed nothing (#19029). What this pins
2847+
// is the chain that makes a breach loud -- the floor adds to the same
2848+
// `failures` the verdict reads, the verdict prints after it, and the
2849+
// handshake flag is the statement immediately below the verdict -- so the
2850+
// ordering cannot regress silently back to a success line printed over an
2851+
// unevaluated floor. ⛔ Filed under the battery opened above: the roster is
2852+
// frozen, and adding a name to it is not this case's to do.
2853+
const orderIndex = (re) => {
2854+
const hits = [...ownSource.matchAll(re)];
2855+
return hits.length === 1 ? hits[0].index : -1;
2856+
};
2857+
const floorAt = orderIndex(/^ {2}const floorFailure = \(message\) => \{$/gm);
2858+
const verdictAt = orderIndex(/^ {2}process\.stdout\.write\(\n {4}failures === 0$/gm);
2859+
const flagAt = orderIndex(/^ {2}selfTestReachedVerdict = true;$/gm);
2860+
const returnAt = orderIndex(/^ {2}return failures === 0 \? 0 : 1;$/gm);
2861+
const between = (from, to) => (from >= 0 && to > from ? ownSource.slice(from, to) : '');
2862+
// Comments are stripped before the two ADJACENCY reads below, in both
2863+
// directions: prose between the verdict and the flag must not red them, and
2864+
// prose must not be able to hide a statement from them either. ⛔ An
2865+
// exit spelled `if (x) return 0;` is not caught by a line-anchored
2866+
// `^return`, so the test is for the TOKEN in the surviving code.
2867+
const codeOnly = (text) => text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
2868+
const order = {
2869+
floorBeforeVerdict: floorAt >= 0 && verdictAt > floorAt,
2870+
floorAddsToTheCounterTheVerdictReads: /failures \+= 1;/.test(between(floorAt, verdictAt)),
2871+
flagAfterVerdictLine: verdictAt >= 0 && flagAt > verdictAt,
2872+
nothingExitsBetweenVerdictAndFlag:
2873+
flagAt > verdictAt && !/\breturn\b|process\.exit\(/.test(codeOnly(between(verdictAt, flagAt))),
2874+
flagIsTheLastStatement:
2875+
flagAt >= 0 && returnAt > flagAt
2876+
&& codeOnly(between(flagAt, returnAt)).trim() === 'selfTestReachedVerdict = true;',
2877+
};
2878+
t(
2879+
'⭐ VERDICT ORDER: the battery floor is evaluated ABOVE the verdict line and the handshake flag is '
2880+
+ 'the last statement after it -- so a breached floor prints the FAILED line and returns non-zero, '
2881+
+ 'and no exit between the two can report a run that never evaluated its floor as one that passed',
2882+
Object.values(order).every(Boolean),
2883+
JSON.stringify({
2884+
...order,
2885+
anchorsResolvedExactlyOnce: {
2886+
floor: floorAt >= 0, verdict: verdictAt >= 0, flag: flagAt >= 0, returnStatement: returnAt >= 0,
2887+
},
2888+
})
2889+
);
28412890
}
28422891

28432892
Object.assign(process.env, savedGitEnv);
2844-
process.stdout.write(
2845-
failures === 0
2846-
? '\ncheck-system-context-census --self-test: all cases passed\n'
2847-
: `\ncheck-system-context-census --self-test: ${failures} case(s) FAILED\n`
2848-
);
2849-
selfTestReachedVerdict = true;
2893+
28502894
// ── The floor: every declared battery RAN, and ran its cases (#13489) ───
28512895
//
2852-
// Evaluated after every battery has had its chance and BEFORE the verdict, so
2853-
// the success line below can only be printed by a run in which the set of
2854-
// batteries that registered assertions EQUALS the set declared. A set
2855-
// difference names WHICH battery stopped; a count says only that something did.
2896+
// Evaluated after every battery has had its chance and BEFORE the verdict, and
2897+
// the STATEMENT ORDER here is the whole of what makes that sentence true
2898+
// (#19029: this block used to sit BELOW a verdict that had already printed the
2899+
// success line and set the handshake, so a breach printed "all cases passed"
2900+
// and then its own FAIL lines -- a transcript that contradicted itself, and an
2901+
// early exit anywhere in here left a run that printed success, exited 0 and
2902+
// never evaluated its floor). `floorFailure` adds to the same `failures` the
2903+
// verdict below reads, so the success line can only be printed by a run in
2904+
// which the set of batteries that registered assertions EQUALS the set
2905+
// declared, and a breached floor can only print the FAILED line and return
2906+
// non-zero. A set difference names WHICH battery stopped; a count says only
2907+
// that something did.
28562908
const floorFailure = (message) => {
28572909
failures += 1;
28582910
process.stdout.write(` FAIL ${message}\n`);
@@ -2894,6 +2946,19 @@ function selfTest() {
28942946
);
28952947
}
28962948

2949+
process.stdout.write(
2950+
failures === 0
2951+
? '\ncheck-system-context-census --self-test: all cases passed\n'
2952+
: `\ncheck-system-context-census --self-test: ${failures} case(s) FAILED\n`
2953+
);
2954+
// The handshake (`AGENTS.md`, the `Writing a --self-test` band): the flag is
2955+
// set as the LAST statement of this function, after the verdict line above has
2956+
// printed. Every exit ABOVE this line -- including one inside the floor --
2957+
// therefore leaves it false, and the dispatch SAYS the self-test never reached
2958+
// its verdict rather than reading a 0 as a pass. ⛔ Nothing may be inserted
2959+
// between the write above and this line; the ⭐ VERDICT ORDER case pins both
2960+
// halves of the ordering off this file's own text.
2961+
selfTestReachedVerdict = true;
28972962
return failures === 0 ? 0 : 1;
28982963
}
28992964

0 commit comments

Comments
 (0)