Skip to content

Commit 5617678

Browse files
committed
test(scripts): isolate the second point's LINE-START and DEPTH rules with a decoy each
An ablation of the LINE-START rule came back GREEN: the only mid-line decoy in the fixture was also nested, so the DEPTH rule covered for it and deleting a real rule moved no verdict -- the shape of false green this instrument exists to refuse, made by its own controls. Two decoys now isolate the rules, each a branch a passing run never enters: a one-line `if (...) return (async () => {` at the body's own depth (only LINE-START excludes it) and a line-anchored return one level deep inside an `if` block (only DEPTH does). Their validity is asserted the way the anchor reads them -- masked text, depth counted from the definition's own brace -- and an unanchored, depth-blind reading is pinned to land on a decoy. Re-measured after the change: ablating either rule reds the anchor control. Claude-Session: https://claude.ai/code/session_01BTeBejoPUvRHN8WdAJC6oF Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6a3075b commit 5617678

1 file changed

Lines changed: 52 additions & 4 deletions

File tree

‎scripts/measure-self-test-floor.mjs‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,17 @@ const AWAITED_BLOCK_GATE = [
15571557
* 2. the same line inside a fixture TEMPLATE -- MASKED
15581558
* 3. an async IIFE returned MID-LINE, from a nested arrow -- LINE-START
15591559
* 4. an `await (async () => {` at statement level -- not a RETURN
1560-
* 5. a returned block inside an `if` branch -- DEPTH 0
1560+
* 5. a one-line guarded return, MID-LINE at depth 0 -- LINE-START
1561+
* 6. a returned block inside an `if` BRANCH, line-anchored -- DEPTH 0
1562+
*
1563+
* Decoys 5 and 6 are what make each rule load-bearing ON ITS OWN, and they were
1564+
* added because the first fixture could not tell them apart: with only decoy 3,
1565+
* which is mid-line AND nested, deleting the LINE-START rule moved no verdict
1566+
* at all -- the depth rule covered for it, and an ablation of a real rule came
1567+
* back green. Decoy 5 is mid-line at depth 0, so only LINE-START excludes it;
1568+
* decoy 6 begins its line, so only DEPTH does. Both are branches that a
1569+
* normally-passing run never enters, which is why neither is the block whose
1570+
* statements run after the handshake.
15611571
*
15621572
* Then the real one. READ, never spawned.
15631573
*/
@@ -1574,6 +1584,7 @@ const INNER_ANCHOR_DECOY_GATE = [
15741584
'`;',
15751585
' const held = () => { return (async () => { return FIXTURE.length; })(); };',
15761586
' await (async () => { void held; })();',
1587+
' if (FIXTURE.length < 0) return (async () => { return 0; })();',
15771588
' if (FIXTURE.length < 1) {',
15781589
' return (async () => {',
15791590
" console.error('the fixture text went missing');",
@@ -1592,9 +1603,16 @@ const INNER_ANCHOR_DECOY_GATE = [
15921603
'',
15931604
].join('\n');
15941605

1595-
/** The decoy text the five decoys and the real block share, line-anchored. */
1606+
/** The decoy text the six decoys and the real block share, line-anchored. */
15961607
const INNER_ANCHOR_TEXT = 'return (async () => {';
15971608

1609+
/**
1610+
* The block an UNANCHORED, DEPTH-BLIND reading takes -- kept here as the thing
1611+
* the controls measure against, never as a second implementation:
1612+
* `returnedBlockAnchor` does not use it.
1613+
*/
1614+
const NAIVE_INNER_ANCHOR = /return\s*\(\s*async\s*\(\s*\)\s*=>\s*\{/;
1615+
15981616
/**
15991617
* The SLOW gate, reduced: a self-test that outlasts the budget it is probed
16001618
* under. It sleeps rather than spins -- a control that runs on EVERY invocation
@@ -2075,17 +2093,47 @@ export function runControls() {
20752093
const literalBlock = INNER_ANCHOR_DECOY_GATE.indexOf(INNER_ANCHOR_TEXT, commentBlock + 1);
20762094
const midLineBlock = INNER_ANCHOR_DECOY_GATE.indexOf('{ return (async () => { return FIXTURE.length');
20772095
const awaitedBlock = INNER_ANCHOR_DECOY_GATE.indexOf('await (async () => { void held');
2096+
const guardedLine = INNER_ANCHOR_DECOY_GATE.indexOf('if (FIXTURE.length < 0) return (async');
2097+
const guardedBlock = INNER_ANCHOR_DECOY_GATE.indexOf(INNER_ANCHOR_TEXT, guardedLine);
20782098
const branchBlock = INNER_ANCHOR_DECOY_GATE.indexOf(` ${INNER_ANCHOR_TEXT}`);
20792099
const realBlock = INNER_ANCHOR_DECOY_GATE.lastIndexOf(`\n ${INNER_ANCHOR_TEXT}`) + 1;
20802100
say(commentBlock >= 0 && literalBlock > commentBlock && midLineBlock > literalBlock
2081-
&& awaitedBlock > midLineBlock && branchBlock > awaitedBlock && realBlock > branchBlock,
2082-
'CONTROL FIXTURE INVALID: the five second-point decoys no longer all stand AHEAD of the real returned block, so an anchor taking the first text that reads like one would reach it anyway and every verdict below passes for the wrong reason');
2101+
&& awaitedBlock > midLineBlock && guardedBlock > awaitedBlock && branchBlock > guardedBlock
2102+
&& realBlock > branchBlock,
2103+
'CONTROL FIXTURE INVALID: the six second-point decoys no longer all stand AHEAD of the real returned block, so an anchor taking the first text that reads like one would reach it anyway and every verdict below passes for the wrong reason');
20832104
say(innerFlags.comment[commentBlock] === 1,
20842105
'CONTROL FIXTURE INVALID: the first second-point decoy is not COMMENT content, so it no longer reads the comment half of the mask');
20852106
say(innerFlags.literal[literalBlock] === 1,
20862107
'CONTROL FIXTURE INVALID: the second second-point decoy is not LITERAL content, so it no longer reads the half whose failure makes the copy a SyntaxError and earns a false HELD');
20872108
say(innerFlags.comment[midLineBlock] === 0 && innerFlags.literal[midLineBlock] === 0,
20882109
'CONTROL FIXTURE INVALID: the MID-LINE decoy is masked away, so it reads the mask a second time instead of the LINE-START rule it is there for');
2110+
// ⛔ ... and the two decoys that ISOLATE the two rules. Without them an
2111+
// ablation of either one comes back green: each covers for the other on a decoy
2112+
// that is both mid-line and nested, and a rule nothing measures is a rule the
2113+
// next author deletes.
2114+
say(innerFlags.comment[guardedBlock] === 0 && innerFlags.literal[guardedBlock] === 0
2115+
&& !/^[ \t]*return/.test(INNER_ANCHOR_DECOY_GATE.slice(guardedLine, guardedBlock + 1).split('\n').pop() ?? ''),
2116+
'CONTROL FIXTURE INVALID: the one-line GUARDED return is masked away or no longer mid-line, so the LINE-START rule has nothing isolating it and deleting that rule moves no verdict');
2117+
// Depth is read the way the anchor reads it: over the MASKED body, from the
2118+
// definition's own `{`. Counted over raw text it would be a different number
2119+
// -- every brace in the fixture template and the comments is still there.
2120+
const innerBody = definitionSpan(innerMasked, 'selfTest');
2121+
const depthAt = (end) => {
2122+
let depth = 0;
2123+
for (let i = innerBody.at; i < end; i += 1) {
2124+
if (innerMasked[i] === '{') depth += 1;
2125+
else if (innerMasked[i] === '}') depth -= 1;
2126+
}
2127+
return depth;
2128+
};
2129+
say(innerBody !== null && depthAt(guardedBlock) === 0,
2130+
'CONTROL FIXTURE INVALID: the one-line guarded return is no longer at the self-test body\'s own depth, so the DEPTH rule would exclude it too and the LINE-START rule is again unmeasured');
2131+
say(depthAt(branchBlock) === 1
2132+
&& INNER_ANCHOR_DECOY_GATE[branchBlock - 1] === '\n'
2133+
&& /^[ \t]*return/.test(INNER_ANCHOR_DECOY_GATE.slice(branchBlock, branchBlock + 30)),
2134+
'CONTROL FIXTURE INVALID: the `if` BRANCH decoy is no longer a line-anchored return one level deep, so the DEPTH rule has nothing isolating it and deleting that rule moves no verdict');
2135+
say(innerMasked.search(NAIVE_INNER_ANCHOR) < guardedBlock && innerMasked.search(NAIVE_INNER_ANCHOR) < realBlock,
2136+
'CONTROL FIXTURE INVALID: an unanchored, depth-blind reading no longer lands on a DECOY ahead of the real block, so neither rule is what the anchor verdict below is reading');
20892137
say(returnedBlockAnchor(innerMasked, 'selfTest') === INNER_ANCHOR_DECOY_GATE.indexOf('{', realBlock) + 1,
20902138
`INNER ANCHOR CONTROL FAILED: the second injection point did not land on the block the self-test RETURNS at its own statement level (got ${returnedBlockAnchor(innerMasked, 'selfTest')}, want ${INNER_ANCHOR_DECOY_GATE.indexOf('{', realBlock) + 1}); a comment, a fixture template, a mid-line IIFE, an awaited block or an \`if\` branch was preferred over it`);
20912139
say(injectEarlyReturn(INNER_ANCHOR_DECOY_GATE, 'selfTest', { point: 'inner' })

0 commit comments

Comments
 (0)