test: harden the SD-P8 gate and rework two sabotage legs after running them
Running the sabotage suite found three things, all in the instruments.
LEG 02 predicted a red at the language arm and got one at arm 1. That is the expectation being wrong rather than the gate: arm 1 reads both profiles through the public modules, so it catches every PROFILE-LEVEL sabotage first. Recorded in the leg rather than quietly renumbered, and LEG 03 rewritten to reach past it -- it now sabotages the parser's multiplicity ENFORCEMENT while both profiles still say one, which separates "the profile is configured correctly" from "the parser obeys the profile". Only the second is what a required red is about.
New LEG 08 attacks the pinned literals from the DERIVATION side, by rewording the message formatter -- which is where a reword would actually come from. Arm 1 is blind to it and so is the differential; only the pins see it, and both languages' pins are required to.
Arm 5's root-only rewrite is now guarded. It substitutes the old root symbol for the new one and requires byte equality, and a substitution that could match anything else would MASK a difference. It refuses to rewrite unless the two spellings do not overlap, and dies if the rewrite matched nothing.
Also: arm 3's not checked assertion was a four-argument test ... -o ..., which is ambiguous in POSIX; it counts once and compares once now. And gate-sd-p3.sh's course_dir is dead since its arm 3 retired -- documented in place so that setting SD_P3_COURSE_DIR is not silently ignored.
test/gate-sd-p3.sh | 6 ++++++
test/gate-sd-p8.sh | 29 +++++++++++++++++++++++++++--
test/sabotage-sd-p8.sh | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
3 files changed, 128 insertions(+), 31 deletions(-)test/gate-sd-p3.shmodified
test -f test/transcripts/sd-p3/boundary-census-before.txt"$sigil" --version# DEAD SINCE THE ARM 3 RETIREMENT (2026-08-22), and kept only so that setting# `SD_P3_COURSE_DIR` is not silently ignored by a variable that no longer exists.# Arm 3 was the only reader; it widened the lowering corpus to the Guile course# conversion. Nothing else in this gate uses it, so setting the variable today# does nothing. Its successor, `test/gate-sd-p8.sh` arm 5, derives its corpus# from the repository rather than taking a directory.course_dir="${SD_P3_COURSE_DIR:-}"# `test-semantic-structures` reaches `(sigil doc render html)` and thereforetest/gate-sd-p8.shmodified
test "$rows" -eq "$total" || die "arm 03: examined $total manuscripts but printed $rows rows"test "$total" -ge 27 || die "arm 03: the census found only $total manuscripts; the population is wrong"test "$bad" -eq 0 || { rg '^ILLEGAL' "$census" >&2; die "arm 03: $bad manuscripts declare a language that does not admit their root"; }test "$( { rg -c '^UNCHECKED' "$census" || true; } )" = "" -o "$( { rg -c '^UNCHECKED' "$census" || echo 0; } )" -eq 0 \ || { rg '^UNCHECKED' "$census" >&2; die "arm 03: some manuscripts were not classified at all"; }# The `not checked` class, asserted explicitly rather than inferred from the# absence of complaint. A `test A -o B` compound with four-plus arguments is# ambiguous in POSIX and easy to get subtly wrong, so this counts once and# compares once.unchecked=$( { rg -c '^UNCHECKED' "$census" || true; } )test "${unchecked:-0}" -eq 0 \ || { rg '^UNCHECKED' "$census" >&2; die "arm 03: ${unchecked} manuscripts were not classified at all"; }test "$base_lang" -ge 1 || die "arm 03: no manuscript exercises the base language"test "$book_lang" -ge 15 || die "arm 03: only $book_lang manuscripts moved to the genre language"pass 3 "census $total manuscripts, 0 illegal, 0 unclassified :: $base_lang base, $book_lang book, $other_lang other-language, $negative negative fixtures" # section byte for byte -- a far stronger statement than "it changed, as # predicted", and the one that would catch a migration that also moved content. old="${root_b#@}"; new="${root_a#@}" # THE SUBSTITUTION MUST BE UNAMBIGUOUS BEFORE IT IS TRUSTED. A rewrite that # could match something other than the root symbol would MASK a real # difference, which is the one direction a differential must never fail in. # Two conditions make it unambiguous: after the change the old spelling must # be gone entirely, and before it the new spelling must not have existed. If # either fails, the manuscript is reported UNEXPECTED rather than rewritten -- # a refusal to judge, not a pass. if [ "$( { rg -cF "]] $new>" "$b" || true; } )" != "" ] \ || [ "$( { rg -cF "]] $old>" "$f" || true; } )" != "" ]; then unexpected=$((unexpected + 1)) printf 'UNEXPECTED %-40s root=%s -> %s, but the two spellings overlap; refusing to rewrite\n' \ "$name" "$root_b" "$root_a" >>"$ledger" continue fi sed "s/\]\] $old>/]] $new>/g" "$b" >"$gate_dir/rewritten-$name" # ...and the rewrite must actually have done something. A sed that matched # nothing would compare the base section to the after section unchanged, and # a manuscript whose only difference WAS the root would then read as # UNEXPECTED for the wrong reason. cmp -s "$b" "$gate_dir/rewritten-$name" \ && die "arm 05: the root rewrite for $name changed nothing, so its root symbol is not where this arm thinks it is" if cmp -s "$f" "$gate_dir/rewritten-$name"; then expected_change=$((expected_change + 1)) printf 'ROOT-ONLY %-40s root=%s -> %s, nothing else moved\n' "$name" "$root_b" "$root_a" >>"$ledger"test/sabotage-sd-p8.shmodified
pristine_hash() { cat "$work/pristine-$(echo "$1" | tr / _)"; }pristine_copy() { echo "$work/copy-$(echo "$1" | tr / _)"; }plant() { # $1 = file, $2 = pattern to replace, $3 = replacement local before after matches before=$(sha256sum "$1" | awk '{print $1}') test "$before" = "$(pristine_hash "$1")" || die "plant: $1 is not pristine" # UNIQUENESS FIRST. `sed` replaces the first match on every matching line and # says nothing about how many there were, so a pattern that drifted into # matching two sites would sabotage more than the leg describes -- and a leg # whose red cannot be attributed to one edit is not evidence. matches=$(grep -c -- "$2" "$1" || true) test "${matches:-0}" -eq 1 \ || die "plant: '$2' matches ${matches:-0} lines of $1; a sabotage must name exactly one site" sed -i "s|$2|$3|" "$1" after=$(sha256sum "$1" | awk '{print $1}') test "$before" != "$after" \ || die "plant: $1 did not change -- the sabotage never landed, so a red below would mean nothing"}# RETURNS non-zero rather than calling `die`. `die` ends in `exit`, and an# `exit` inside a function still ends the SHELL -- so an `if ! restore_all`# guard around a dying function can never take its own failure branch. That is# ---------------------------------------------------------------- LEG 02# PRODUCT. Give the genre language the BASE language's name.## The `sigil/doc/book:` prefix is the part of the genre's diagnostic that sends# an author to the right documentation, and it is derived from one string in one# place. This is the edit that would silently undo it.# The `sigil/doc/book:` prefix is what sends an author to the right# documentation, and it comes from one string in one place.## EXPECT THE RED AT ARM 01, NOT AT ARM 04. Arm 1 reads both profiles' name,# roots and multiplicity through the public modules, so it catches every# PROFILE-LEVEL sabotage before anything downstream runs. That layering was not# obvious until this leg was run: the first version of it predicted a red at arm# 4 and got one at arm 1, which is the expectation being wrong rather than the# gate. Recorded rather than quietly renumbered -- an arm that reddens somewhere# unpredicted is a finding either way# (topics/an-expectation-names-which-check-must-fail).echo "=== LEG 02 -- the genre profile reports the base language's name"plant "$BOOK" \ '(make-document-profile "sigil/doc/book" .(chapter) .one)' \ "(make-document-profile \"sigil/doc\" '(chapter) 'one)"run_gate "$work/leg02.log" && die "LEG 02: the gate passed with the genre language misnamed"leg_red 02 "$work/leg02.log" "arm 04: the genre language did not refuse @article naming sigil/doc/book"leg_red 02 "$work/leg02.log" "arm 01: the genre profile is not D8's"restore_all || die "restore failed; the worktree is still sabotaged"# ---------------------------------------------------------------- LEG 03# PRODUCT. Widen the genre's multiplicity.# PRODUCT, AND IT HAS TO REACH PAST ARM 01.## A REQUIRED RED becoming green is the failure mode a pass/fail count cannot# see: with `one-or-more`, the two-chapter manuscript is ACCEPTED and the gate# must say which case stopped being refused.echo "=== LEG 03 -- the genre accepts several chapters"plant "$BOOK" \ "'(chapter) 'one)" \ "'(chapter) 'one-or-more)"run_gate "$work/leg03.log" && die "LEG 03: the gate passed with the genre accepting two chapters"# The point is to make a REQUIRED RED go green -- the failure mode a pass/fail# count cannot see -- and to do it where arm 1 is blind. Widening the profile's# multiplicity would not work: arm 1 asserts `mult=one` for both languages and# would catch it first, exactly as leg 2 just showed. So this sabotages the# ENFORCEMENT instead, in `parse-document-parts-with-profile`, where `several?`# gates whether a second root is accepted. Both profiles still SAY `one`; the# parser stops meaning it.## That is a strictly better sabotage than the one it replaces: it separates# "the profile is configured correctly" from "the parser obeys the profile",# and only the second is what the required reds are about.echo "=== LEG 03 -- the parser stops enforcing multiplicity, while both profiles still say one"plant "$PARSER" \ '(or several? (null? root-nodes))' \ '(or #t (null? root-nodes))'run_gate "$work/leg03.log" && die "LEG 03: the gate passed with multiplicity unenforced"leg_red 03 "$work/leg03.log" "arm 04: not every case matched its expected verdict"rg -qF 'SD_P8_LANG book-refuses-two want=refuse got=accept MISMATCH' "$work/leg03.log" \ || die "LEG 03: the gate reddened, but not because the two-chapter manuscript was accepted"rg -qF 'want=refuse got=accept MISMATCH' "$work/leg03.log" \ || { rg -n 'SD_P8_LANG' "$work/leg03.log" >&2 die "LEG 03: the gate reddened, but no required-refusal case flipped to accept"; }restore_all || die "restore failed; the worktree is still sabotaged"# ---------------------------------------------------------------- LEG 04restore_all || die "restore failed; the worktree is still sabotaged"# ---------------------------------------------------------------- LEG 08# PRODUCT, AND IT IS THE ONE THE BRIEF ASKED FOR BY NAME.## SD-P8 rewrote pinned diagnostic literals. The risk the brief named is a# migration that updates a pin to match new output, leaving pin and product# moved together and neither tested against the other. Leg 1 attacks that from# the PROFILE side; this leg attacks it from the DERIVATION side, which is where# a reword would actually come from -- someone tidying the message formatter.## Arm 1 is blind to it (both profiles still report the right name, roots and# multiplicity) and so is arm 5 (the lowering of a legal manuscript does not# change). Only the pinned literals can see it, which is the whole point.echo "=== LEG 08 -- the derived misplaced-root message is reworded"plant "$PARSER" \ '": top-level author forms must precede "' \ '": top-level author forms must come before "'run_gate "$work/leg08.log" && die "LEG 08: the gate passed with a shipped diagnostic reworded"leg_red 08 "$work/leg08.log" "arm 04: the base language did not refuse @chapter with its own diagnostic"restore_all || die "restore failed; the worktree is still sabotaged"# ...and the SUITE's pins see it too, which is what makes them pins rather than# decoration. Run separately because the gate stops at its first failing arm.plant "$PARSER" \ '": top-level author forms must precede "' \ '": top-level author forms must come before "'run_suite "$work/leg08-suite.log" && die "LEG 08: the suite passed with a shipped diagnostic reworded"rg -qF "the base profile is D8's policy and D8's diagnostics, exactly" "$work/leg08-suite.log" \ || { tail -25 "$work/leg08-suite.log" >&2; die "LEG 08: the suite reddened somewhere other than the base pins"; }rg -qF "the book genre language is a sibling profile with its own diagnostics" "$work/leg08-suite.log" \ || { tail -25 "$work/leg08-suite.log" >&2; die "LEG 08: the GENRE language's pins did not see the reword"; }printf 'SD_P8_SABOTAGE_08 RED both languages pinned literals saw a reworded derivation\n'restore_all || die "restore failed; the worktree is still sabotaged"# ---------------------------------------------------------------- LEG 09# THE POSITIVE CONTROL, and it is not a formality.## Seven reds prove the gate can fire. They say nothing about whether it can# Eight reds prove the gate can fire. They say nothing about whether it can# STAND DOWN -- a gate wedged red by leg 1's restore having gone wrong would# score every leg above as a success. This is also what proves the tree came# back: `restore_all` checks hashes, and this checks behaviour.echo "=== LEG 08 -- the restored tree is green"echo "=== LEG 09 -- the restored tree is green"restore_all || die "restore failed; the worktree is still sabotaged"# THE FULL GATE, with SD_P8_SKIP_REGRESSION deliberately UNSET. Every leg above# ran with it set; if this control ran the same way, nothing here would ever have# executed the regression arm and "green" would be a claim about five arms# described as six.set +ebash test/gate-sd-p8.sh >"$work/leg08.log" 2>&1bash test/gate-sd-p8.sh >"$work/leg09.log" 2>&1control_rc=$?set -esed -i 's/\x1b\[[0-9;]*m//g' "$work/leg08.log"sed -i 's/\x1b\[[0-9;]*m//g' "$work/leg09.log"test "$control_rc" -eq 0 || { tail -40 "$work/leg08.log" >&2 die "LEG 08: the restored tree is NOT green; every red above is uninterpretable"; }rg -q '^SD_P8_GATE_GREEN$' "$work/leg08.log" \ || { tail -20 "$work/leg08.log" >&2; die "LEG 08: the gate exited 0 without printing its green marker"; }rg -q 'SD_P8_GATE_PARTIAL' "$work/leg08.log" \ && die "LEG 08: the control run skipped an arm; it does not establish a full green" tail -40 "$work/leg09.log" >&2 die "LEG 09: the restored tree is NOT green; every red above is uninterpretable"; }rg -q '^SD_P8_GATE_GREEN$' "$work/leg09.log" \ || { tail -20 "$work/leg09.log" >&2; die "LEG 09: the gate exited 0 without printing its green marker"; }rg -q 'SD_P8_GATE_PARTIAL' "$work/leg09.log" \ && die "LEG 09: the control run skipped an arm; it does not establish a full green"for n in 01 02 03 04 05 06; do rg -q "^SD_P8_GATE_$n " "$work/leg08.log" \ || die "LEG 08: arm $n printed no marker in the control run" rg -q "^SD_P8_GATE_$n " "$work/leg09.log" \ || die "LEG 09: arm $n printed no marker in the control run"doneprintf 'SD_P8_SABOTAGE_08 GREEN the restored tree passes all six arms\n'printf 'SD_P8_SABOTAGE_09 GREEN the restored tree passes all six arms\n'echo "SD_P8_SABOTAGE_COMPLETE 7 reds (5 product, 1 instrument, 1 coverage) and 1 positive control"echo "SD_P8_SABOTAGE_COMPLETE 8 reds (6 product, 1 instrument, 1 coverage) and 1 positive control"