test: derive gate-sd-p4's test count, and make both gates' floors reachable
gate-sd-p4.sh ARM 01 asserted a hardcoded Tests: 17 passed (17 total). It matched, so it was green -- and green is what a stale literal looks like right up until someone adds a test. Its sibling had already gone the whole way: gate-sd-p1.sh hardcoded 11, a twelfth test was added to test-root-profile.sgl, and that gate sat red on master accusing a suite passing 12/12. This one was next.
ARM 01 now derives the count from the suite file and makes TWO assertions where there was one: every test the FILE declares must have been COLLECTED, which catches a test that silently stopped running, and every test collected must have PASSED, which catches a failure the summary would otherwise bury. pass 1 prints all three derived numbers, so the gate's transcript shows what it measured:
SD_P4_GATE_01 passive suite 17 passed / 17 collected / 17 declared, ...Adding a test no longer requires editing a number here.
TWO DEAD GUARDS FIXED, in both gates. Under set -euo pipefail a command substitution whose command fails aborts the script; grep -c and rg both exit 1 on zero matches. So the derivation floor ("the DERIVATION is broken, not the suite") and the no-summary guard ("passive suite printed no summary line") both died at their own assignments and never spoke. Exit 1 with no message is indistinguishable from a gate that never ran, which is the confusion this file's header says the estate has been fooled by twice -- and on a summary-less suite the derived form was therefore STRICTLY WORSE than the hardcoded literal it replaced, which did print a message and a log tail. Demonstrated by removing the two words again:
fixed rc=1 output=[passive suite printed no summary line]
broken rc=1 output=[]A COMPLETENESS CHECK runs before the count. The anchor is column-0 (test " forms, so a test indented inside another form is still collected and invisible to it. Indenting one surfaces as "declares 16 but collected 17" -- the gate accusing a healthy suite for a defect in its own anchor, which is the same lie the literal told, one size smaller.
test/sabotage-sd-p4-counts.sh drives one red per assertion:
LEG 1 product declared > collected -> "declares 18 tests but the runner
collected 17"
LEG 2 product a test FAILS -> red, but via the pre-existing exit-status
check; the runner exits non-zero, so assertion two is not
reachable this way. Reported rather than dressed up.
LEG 2b assertion the gate's summary assertions SLICED OUT OF THE GATE FILE by
sentinel comments and run under the same shell options, on
ANSI-coloured fixtures: fires on a buried failure, fires on a
missing summary, stands down on a healthy one. Slicing rather
than retyping is the point -- a copy agrees by construction,
and the first version of this leg certified semantics the
gate did not have.
LEG 3 assertion the derivation's anchor defeated while the suite still passes
-> "the DERIVATION is broken, not the suite"
LEG 4 assertion ONE form indented, which the floor cannot see
-> "has 1 INDENTED (test ..." forms"Every restore is verified by SHA256 under a trap that fires on abort as well as exit, and every plant asserts it moved the thing it claims to move.
WHAT CHANGES IN gate-sd-p1.sh, and why it is in a gate-sd-p4 commit. Three things, none of them cosmetic:
expected_tests=$(grep -cE ... test-root-profile.sgl)gains|| true. It shipped the dead derivation floor described above. This is the line gate-sd-p4.sh was told to copy, so copying it faithfully reproduced the defect -- which is how it was found at all.reported=$(rg ...)andcollected=$(rg ...)gain|| true, the same dead-guard fix on the same class of input.- The NOTE FOR WHOEVER TOUCHES THE SIBLING comment is rewritten. It pointed at gate-sd-p4.sh's hardcoded 17 as an outstanding defect; that defect is fixed by this commit, so the pointer would have been a lie. It now names the CLASS that outlived both instances rather than the instance.
Each || true carries its reason in a comment directly above it, so blame on those lines lands on the mechanism rather than on this ticket.
Fixing a defect class in one file while leaving its source in the file next door is the sibling-gate pattern this repo keeps paying for: gate-sd-p1.sh went red on master for a whole ticket's worth of work because the lesson from a sibling never crossed over.
test/gate-sd-p1.sh | 28 ++++++++++++++----
test/gate-sd-p4.sh | 72 +++++++++++++++++++++++++++++++++++++++++++--
test/sabotage-sd-p4-counts.sh | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 352 insertions(+), 9 deletions(-)test/gate-sd-p1.shmodified
# most common defect in this estate's gates." Adding a test must not require# editing a number here, and now it does not.## NOTE FOR WHOEVER TOUCHES THE SIBLING: test/gate-sd-p4.sh:45 hardcodes 17 the# same way. It still matches its suite, so it is green today and is the next one# to go stale. Surveyed, deliberately not changed in this branch.expected_tests=$(grep -cE '^\(test "' test/test-root-profile.sgl)# NOTE FOR WHOEVER TOUCHES THE SIBLING: test/gate-sd-p4.sh hardcoded 17 in# exactly this way and was fixed the same way, so this pointer no longer names# an outstanding defect. It is kept because the DEFECT CLASS outlived both# instances: a count written in rather than derived goes stale silently and the# gate then accuses healthy product code. Before adding a count to any gate in# this directory, derive it from the artifact it describes.## `|| true` is load-bearing. Under `set -e` a command substitution whose command# fails ABORTS THE SCRIPT, and `grep -c` exits 1 when it matches nothing, so# without it a broken derivation kills this gate at this line and the guard# below never speaks. Exit 1 with no message is indistinguishable from a gate# that never ran. Same fix, same reason, in test/gate-sd-p4.sh; found there by# sabotage rather than by reading either file.expected_tests=$(grep -cE '^\(test "' test/test-root-profile.sgl || true)test "$expected_tests" -ge 1 || { echo "derived 0 tests from test/test-root-profile.sgl; the DERIVATION is broken, not the suite" >&2 exit 1; }reported=$(rg -o 'Tests:[[:space:]]+[0-9]+ passed' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1)collected=$(rg -o '\([0-9]+ total\)' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1)# `|| true` for the reason given above the derivation, and on the same class of# input: `rg` exits 1 when it matches nothing, `pipefail` propagates that out of# the substitution, and `set -e` would kill the gate on THIS line before the# guard below could say the suite printed no summary. Exit 1 with no message is# the least informative red available. Found by adversarial review of# test/gate-sd-p4.sh's equivalent block, not by running either gate.reported=$(rg -o 'Tests:[[:space:]]+[0-9]+ passed' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)collected=$(rg -o '\([0-9]+ total\)' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)test -n "$reported" -a -n "$collected" || { echo "root-profile suite printed no summary line" >&2 tail -40 "$suite_log.clean" >&2; exit 1; }test/gate-sd-p4.shmodified
test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }test -f src/sigil/doc/private/parser.sgltest -f src/sigil/doc/inspect.sgltest -f test/test-passive-parse.sgltest -f test/fixtures/sd-p4-witness.sgd"$sigil" --version# Strip ANSI colour before matching, so the assertion depends on the runner's# words rather than on its escape sequences.sed -e 's/\x1b\[[0-9;]*m//g' "$suite_log" >"$suite_log.clean"rg -q 'Tests:\s+17 passed \(17 total\)' "$suite_log.clean" || { echo "passive suite did not report 17 of 17 tests" >&2; tail -40 "$suite_log.clean" >&2; exit 1; }# THE COUNT IS DERIVED FROM THE SUITE FILE, NOT WRITTEN IN.## This line asserted a hardcoded `Tests: 17 passed (17 total)`. It matched, so# it was green -- and green is exactly what a stale literal looks like right up# until someone adds a test. Its sibling had already gone the whole way:# test/gate-sd-p1.sh hardcoded 11, a TWELFTH test was added to# test/test-root-profile.sgl, and that gate sat RED ON MASTER accusing a suite# that passes 12/12 -- the gate lying about healthy product code. It cost a# pristine-HEAD attribution run before anyone could even tell whose diff broke# it. Nothing about this file made it the second one rather than the first.## folio's test/gate-f1a.sh states the rule in its own header and derives its# count exactly like this: "Every count this gate checks is DERIVED FROM THE# ARTIFACT it describes, never written in as a literal. [...] That drift is the# single most common defect in this estate's gates." Adding a test must not# require editing a number here, and now it does not.## EVERY `|| true` BELOW IS LOAD-BEARING, NOT DEFENSIVE NOISE. Under `set -e` a# command substitution whose command fails ABORTS THE SCRIPT; `grep -c` exits 1# on zero matches and so does `rg`. Without them, the very inputs these guards# exist to describe kill the gate at the assignment and no guard ever speaks --# exit 1 with no message, which is indistinguishable from the gate not running,# the exact confusion this file's header says the estate has been fooled by# twice. The derivation case was found by sabotage; the summary case was found# by adversarial review, and on that input this instrumentation had been# strictly WORSE than the hardcoded literal it replaced, which did print a# message and a log tail.# THE COMPLETENESS CHECK COMES FIRST, and deliberately so. The anchor is# column-0 `(test "` forms; a test INDENTED inside another form is still# collected by the runner and invisible to it. Indenting ALL of them trips the# floor below, which then says "the DERIVATION is broken" -- true, but the least# specific true thing available. Indenting ONE trips neither the floor nor# anything else, and surfaces as "declares 16 but collected 17": the gate# accusing a healthy suite for a defect in its own anchor, which is a narrower# instance of exactly what this file was changed to stop doing. So ask about# completeness before asking about the count, and name the real defect.indented_tests=$(grep -cE '^[[:space:]]+\(test "' test/test-passive-parse.sgl || true)test "$indented_tests" -eq 0 || { echo "test/test-passive-parse.sgl has $indented_tests INDENTED (test \"...\" forms;" >&2 echo "the column-0 derivation cannot see them, so the DERIVATION is incomplete" >&2 grep -nE '^[[:space:]]+\(test "' test/test-passive-parse.sgl >&2; exit 1; }expected_tests=$(grep -cE '^\(test "' test/test-passive-parse.sgl || true)test "$expected_tests" -ge 1 || { echo "derived 0 tests from test/test-passive-parse.sgl; the DERIVATION is broken, not the suite" >&2 exit 1; }# >>> ARM1_SUMMARY_ASSERTIONS BEGIN# test/sabotage-sd-p4-counts.sh LEG 2b slices these exact lines out of THIS file# and runs them against synthetic summaries under the same `set -euo pipefail`.# That is deliberate: a retyped copy would agree with this block by# construction. Keep the block self-contained -- it may read only# `$suite_log.clean` and `$expected_tests`.reported=$(rg -o 'Tests:[[:space:]]+[0-9]+ passed' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)collected=$(rg -o '\([0-9]+ total\)' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)test -n "$reported" -a -n "$collected" || { echo "passive suite printed no summary line" >&2 tail -40 "$suite_log.clean" >&2; exit 1; }# TWO assertions, not one. A single derived count catches neither case cleanly:# every test the FILE declares must have been COLLECTED -- which catches a test# that silently stopped running -- and every test collected must have PASSED,# which catches a failure the summary would otherwise bury.test "$collected" = "$expected_tests" || { echo "test/test-passive-parse.sgl declares $expected_tests tests but the runner collected $collected" >&2 tail -40 "$suite_log.clean" >&2; exit 1; }test "$reported" = "$collected" || { echo "passive suite reported $reported passed of $collected collected" >&2 tail -40 "$suite_log.clean" >&2; exit 1; }# <<< ARM1_SUMMARY_ASSERTIONS ENDrg -q 'All tests passed' "$suite_log.clean" || { echo "passive suite did not report all tests passing" >&2; tail -40 "$suite_log.clean" >&2; exit 1; }# The suite asserts this floor itself; reproducing it here is defence in depthtest -n "$checked" || { echo "suite printed no node-count denominator" >&2; tail -40 "$suite_log" >&2; exit 1; }test "$checked" -ge 120 || { echo "span walk covered only $checked nodes" >&2; exit 1; }pass 1 "passive suite 17/17, spans verified at $checked nodes"pass 1 "passive suite $reported passed / $collected collected / $expected_tests declared, spans verified at $checked nodes"# ---------------------------------------------------------------- ARM 02# No-execution witness, WITH its positive control in the same arm.test/sabotage-sd-p4-counts.shadded
#!/usr/bin/env bash# Sabotage driver for gate-sd-p4.sh ARM 01's DERIVED test count.## ARM 01 used to assert a hardcoded `Tests: 17 passed (17 total)`. It now derives# the declared count from test/test-passive-parse.sgl and makes TWO assertions:# declared == collected, and collected == passed. A derived count never shown to# DISCRIMINATE is a literal with extra steps, so this drives a red for each of# them, plus one for the derivation itself.## LEG 1 product layer. A `(test "` form is planted at column 0 INSIDE a# function that is never called, so the derivation counts it and the# runner never collects it -- the shape of "a test silently stopped# running", which is what assertion one exists for.# LEG 2 product layer. A real toplevel test is planted that FAILS. It goes# red, but through the gate's pre-existing exit-status check rather# than assertion two, because the runner exits non-zero. Asserted on# that message, and reported as what it is rather than dressed up.# LEG 2b assertion layer. The gate's summary assertions are SLICED OUT OF THE# GATE FILE by its sentinel comments and run against synthetic# summaries under the same `set -euo pipefail`. Slicing rather than# retyping is the point: a retyped copy agrees with the gate by# construction, and the shell options differ, which is how the first# version of this leg certified semantics the gate did not have.# Includes an ANSI-coloured summary, because the real path reaches# these assertions only through the gate's colour strip.# LEG 3 assertion layer. The derivation's anchor is defeated while the suite# still passes -- the product is untouched -- and the gate must blame# the derivation rather than accuse the suite.# LEG 4 assertion layer. ONE form is indented, which the floor cannot see: the# derivation drops by one while the runner still collects them all, so# without the completeness check the gate accuses a healthy suite.## Attribution anchors on output the PASSING path cannot produce: the gate prints# `SD_P4_GATE_01` only when arm 1 passes, so EVERY leg requires its specific# error text AND the absence of that marker. A bare non-zero exit proves# nothing; 126 and 127 produce one too.## COST: the legs are cheap (each dies inside arm 1), but the POSITIVE CONTROL at# the end runs the gate to completion, including arm 4's book rebuild. Budget# roughly fifteen minutes for the run as a whole.## The suite is restored from a copy and verified BY HASH under a trap that fires# on abort as well as exit. A sibling of this script has no trap, and an abort# between the damage and the repair left that corruption in the worktree.## EVERY `|| true` here is load-bearing for the same reason it is in the gate:# under `set -e` a command substitution whose command fails aborts the script,# and `grep -c`/`rg` exit 1 on zero matches. Without them a plant that failed to# take would kill this driver at the assignment, and its SETUP-FAILED message --# the one that exists to say the leg is vacuous -- would never print. Three of# them were missing in the first version of this file, found by adversarial# review rather than by running it, because the plants all happened to work.set -euo pipefailrepo_dir="$(cd "$(dirname "$0")/.." && pwd)"cd "$repo_dir"suite=test/test-passive-parse.sglgate=test/gate-sd-p4.shcommand -v rg >/dev/null || { echo "SETUP-FAILED: rg is required" >&2; exit 2; }test -f "$suite" || { echo "SETUP-FAILED: $suite is missing" >&2; exit 2; }test -x "$gate" || { echo "SETUP-FAILED: $gate is missing or not executable" >&2; exit 2; }work=$(mktemp -d "${TMPDIR:-/tmp}/sd-p4-counts-sabotage.XXXXXX")pristine="$work/suite.pristine"cp "$suite" "$pristine"base_sha=$(sha256sum "$suite" | awk '{print $1}')echo "baseline $suite sha256=$base_sha"restore() { cp "$pristine" "$suite" local now; now=$(sha256sum "$suite" | awk '{print $1}') if [ "$now" = "$base_sha" ]; then echo "RESTORED $suite (sha256 matches baseline)" else echo "RESTORE FAILED: $suite is $now, baseline was $base_sha" >&2 fi}# Restore FIRST, then clear scratch. Never the other way round: $pristine lives# in $work.cleanup() { restore; rm -rf "$work"; }trap cleanup EXIT INT TERMdeclared_now() { grep -cE '^\(test "' "$suite" || true; }base_declared=$(declared_now)test "$base_declared" -ge 1 || { echo "SETUP-FAILED: the pristine suite derives $base_declared tests; nothing to sabotage" >&2 exit 2; }echo "baseline derivation: $base_declared declared tests"echo# Runs the gate and reports arm 1's verdict.expect_arm1_red() { local name="$1" expect="$2" log="$work/$1.log" rc=0 "$gate" >"$log" 2>&1 || rc=$? echo "--- $name: derivation now reads $(declared_now); gate exit=$rc" if [ "$rc" -eq 0 ]; then echo " NOT RED: the gate passed. $name did not discriminate." >&2; return 1; fi if rg -q 'SD_P4_GATE_01' "$log"; then echo " MIS-ATTRIBUTED: arm 1 printed its pass marker, so the gate died later." >&2 tail -5 "$log" >&2; return 1; fi if rg -qF "$expect" "$log"; then echo " RED, attributed to arm 1, and SD_P4_GATE_01 absent:" rg -NF "$expect" "$log" | head -2 | sed 's/^/ /' || true else echo " RED but with the WRONG message. Expected: $expect" >&2 tail -12 "$log" >&2; return 1; fi}# ---------------------------------------------------------------------- LEG 1echo "=== LEG 1 (product): declared > collected -- a test that stopped running ==="restorecat >>"$suite" <<'PLANT';; --- sabotage-sd-p4-counts LEG 1: declared at column 0, never collected ---(define (sd-p4-counts-sabotage-never-called)(test "sd-p4 counts sabotage -- declared, never collected" (assert-true #t)))PLANTplanted=$(declared_now)test "$planted" -eq $(( base_declared + 1 )) || { echo "SETUP-FAILED: the plant did not move the derivation ($base_declared -> $planted)" >&2 exit 2; }echo "plant verified: derivation moved $base_declared -> $planted"expect_arm1_red LEG1 "declares $planted tests but the runner collected $base_declared"echo# ---------------------------------------------------------------------- LEG 2echo "=== LEG 2 (product): a collected test FAILS ==="restorecat >>"$suite" <<'PLANT';; --- sabotage-sd-p4-counts LEG 2: collected and failing ---(test "sd-p4 counts sabotage -- collected and failing" (assert-true #f))PLANTleg2_declared=$(declared_now)test "$leg2_declared" -eq $(( base_declared + 1 )) || { echo "SETUP-FAILED: the LEG 2 plant did not reach the suite" >&2; exit 2; }expect_arm1_red LEG2 "passive suite exited non-zero"echo " NOTE: the runner exits non-zero on a failing test, so the gate's"echo " pre-existing exit-status check fires before assertion two is reached."echo " Assertion two therefore guards a runner that reports a failure while"echo " exiting clean. LEG 2b exercises it on exactly that input."echo# --------------------------------------------------------------------- LEG 2becho "=== LEG 2b (assertion layer): the gate's OWN summary assertions, sliced ==="restorearm1="$work/arm1-assertions.sh"{ echo 'set -euo pipefail' sed -n '/^# >>> ARM1_SUMMARY_ASSERTIONS BEGIN$/,/^# <<< ARM1_SUMMARY_ASSERTIONS END$/p' "$gate" echo 'echo "green ($reported/$collected/$expected_tests)"'} >"$arm1"# The slice must actually contain the assertions, or this leg silently tests an# empty script and passes.for needle in 'reported=' 'collected=' 'test "$collected" = "$expected_tests"' 'test "$reported" = "$collected"'; do grep -qF -- "$needle" "$arm1" || { echo "SETUP-FAILED: the sentinel slice from $gate is missing: $needle" >&2 echo " (did the ARM1_SUMMARY_ASSERTIONS markers move?)" >&2; exit 2; }doneecho "sliced $(grep -cvE '^\s*#|^\s*$' "$arm1") code lines out of $gate between its sentinels"# Synthetic summaries, ANSI-coloured and then put through the GATE'S OWN strip,# because that is the only way the real path reaches these assertions.strip() { sed -e 's/\x1b\[[0-9;]*m//g' "$1" >"$2"; }n="$base_declared"; m=$(( base_declared - 1 ))printf ' \033[32mTests:\033[0m %d passed, 1 failed \033[2m(%d total)\033[0m\n' "$m" "$n" >"$work/buried.raw"printf ' \033[32mTests:\033[0m %d passed \033[2m(%d total)\033[0m\n' "$n" "$n" >"$work/healthy.raw"printf ' \033[2mno summary here at all\033[0m\n' >"$work/nosummary.raw"for f in buried healthy nosummary; do strip "$work/$f.raw" "$work/$f.clean"; donegrep -q $'\033' "$work/buried.raw" || { echo "SETUP-FAILED: the coloured fixture carries no ANSI" >&2; exit 2; }grep -q $'\033' "$work/buried.clean" && { echo "SETUP-FAILED: the strip left ANSI behind" >&2; exit 2; }run_arm1() { # $1=clean-log $2=expected_tests -> the sliced block's WHOLE output # NOT `tail -1`. Each failing branch in the gate prints its message and then # dumps `tail -40` of the log, so the last line is log content and the message # is buried above it. Matching on the last line reported LEG 2b as failing when # the assertion had in fact fired correctly -- the leg accused a working gate. suite_log="${1%.clean}" expected_tests="$2" bash "$arm1" 2>&1 || true}saw() { printf '%s' "$1" | grep -qF -- "$2"; }buried=$(run_arm1 "$work/buried.clean" "$n")healthy=$(run_arm1 "$work/healthy.clean" "$n")nosummary=$(run_arm1 "$work/nosummary.clean" "$n")saw "$buried" "reported $m passed of $n collected" && \ echo " coloured buried-failure summary -> fired: reported $m passed of $n collected" || { echo " LEG 2b FAILED: assertion two did not fire on a buried failure. It said:" >&2 printf '%s\n' "$buried" | head -5 >&2; exit 1; }saw "$healthy" "green ($n/$n/$n)" && \ echo " coloured healthy summary -> stood down: green ($n/$n/$n)" || { echo " LEG 2b POSITIVE CONTROL FAILED: the assertions fired on a healthy summary:" >&2 printf '%s\n' "$healthy" | head -5 >&2; exit 1; }saw "$nosummary" "printed no summary line" && \ echo " no summary at all -> fired: printed no summary line" || { echo " LEG 2b FAILED: a missing summary did not produce the no-summary message." >&2 echo " That is the guard that dies silently without its \`|| true\`. It said:" >&2 printf '%s\n' "$nosummary" | head -5 >&2; exit 1; }echo " the gate's own assertions fire on a buried failure and on a missing summary,"echo " and stand down on a healthy one."echo# ---------------------------------------------------------------------- LEG 3echo "=== LEG 3 (assertion layer): the DERIVATION itself is broken ==="restore# INDENT every `(test "` by one space. The suite still parses and still passes --# the PRODUCT is untouched -- but the derivation's anchor stops matching. The# first version of this leg commented the forms out with `;;`, which orphaned# their closing parens and broke the suite's LOAD; the gate's exit-status check# fired first and the driver correctly reported WRONG-MESSAGE rather than a red.sed -i 's|^(test "| (test "|' "$suite"zero=$(declared_now)test "$zero" -eq 0 || { echo "SETUP-FAILED: derivation still yields $zero, not 0" >&2; exit 2; }still=$(grep -cE '^ \(test "' "$suite" || true)test "$still" -eq "$base_declared" || { echo "SETUP-FAILED: indenting lost tests ($base_declared -> $still); that is a PRODUCT break," >&2 echo " which would make this an assertion-layer leg in name only" >&2; exit 2; }echo "plant verified: derivation yields 0 while the suite still declares $still tests"# The indent guard fires before the floor, and names the real defect.expect_arm1_red LEG3 "INDENTED (test"echo# ---------------------------------------------------------------------- LEG 4echo "=== LEG 4 (assertion layer): a PARTIAL derivation miss -- one test indented ==="restore# The case the floor cannot see. Indent exactly ONE form: the derivation drops to# N-1 while the runner still collects N, so without the completeness check the# gate reports "declares 16 tests but the runner collected 17" -- accusing a# suite that is perfectly healthy for a defect in the gate's own anchor. That is# the same lie the hardcoded literal told, one size smaller, and it is why the# completeness check runs before the count.sed -i '0,/^(test "/s|^(test "| (test "|' "$suite"one_off=$(declared_now)test "$one_off" -eq $(( base_declared - 1 )) || { echo "SETUP-FAILED: expected the derivation to drop by exactly one ($base_declared -> $one_off)" >&2 exit 2; }indented=$(grep -cE '^[[:space:]]+\(test "' "$suite" || true)test "$indented" -eq 1 || { echo "SETUP-FAILED: expected exactly 1 indented form, found $indented" >&2; exit 2; }echo "plant verified: derivation $base_declared -> $one_off with 1 form indented; the suite still declares $base_declared"expect_arm1_red LEG4 "has 1 INDENTED"echo# --------------------------------------------------------- POSITIVE CONTROLecho "=== POSITIVE CONTROL: arm 1 must go GREEN again on the restored suite ==="echo " (this one runs the gate to completion; arm 4 rebuilds the book)"restorectl="$work/control.log"; ctl_rc=0"$gate" >"$ctl" 2>&1 || ctl_rc=$?if rg -q 'SD_P4_GATE_01' "$ctl"; then rg -N 'SD_P4_GATE_0' "$ctl" | sed 's/^/ /' if [ "$ctl_rc" -ne 0 ]; then echo " arm 1 GREEN; the gate exited $ctl_rc in a LATER arm, which does not affect" echo " the arm-1 verdicts above. Run the gate on its own for a full green." fielse echo "POSITIVE CONTROL FAILED: arm 1 did not pass on the restored suite (exit $ctl_rc)" >&2 tail -20 "$ctl" >&2; exit 1fiechoecho "SD_P4_COUNTS_SABOTAGE_COMPLETE"