test: act on the adversarial review, and retire+replace gate-sd-p7 arm 02
The review (read-only over 0b7c5ca..HEAD) found six live defects. All are fixed here, and running the fixes found three more in the fixes themselves.
RETIRED test/gate-sd-p7.sh arm 02 and REPLACED it. It is the same class as the gate-sd-p3 arms retired earlier -- a differential pinned to an endpoint this phase moves -- and it was missed the first time. Characterised by measurement before the notice was written: the exclusion set, the record count (22 -> 27) and the baseline's ABSOLUTE byte positions each retire it independently. With the location numbers normalised away, 19 of 22 manuscripts are structurally identical and the 3 that differ are D8 itself -- two kind flips and sd-p1-article-root going from a raise to a real document. The property is intact and the arm cannot say so.
Its replacement is gate-sd-p8 arm 06, both sides in one run, asserting on STRUCTURE rather than positions -- deliberately, since this retirement is the demonstration of why a baseline pinned to offsets is a trap. The weakening is named in the arm: it cannot see a pure location regression, and arm 05 plus the root-profile suite cover that.
Arm 05 now asserts only_after and the skipped SETS. A ten-line content rewrite of sd-p1-article-root.sgd had been passing as "the base tree could not lower it". The first skipped check compared COUNTS and reddened falsely -- a count cannot tell "a manuscript regressed" from "a manuscript was added to be refused", so it compares names, in both directions, deriving the added set from git.
Arm 05's root-only rewrite is bounded to at most two generated heads, so a manuscript that changed its root AND a nested command of the same name is reported UNEXPECTED rather than "nothing else moved".
Arm 03's UNCHECKED class is reachable now; it was defaulted and overwritten on every branch, so "0 unclassified" was vacuous. The class that exists is "a language this arm does not know", which is not the same as a manuscript being wrong.
The dump's make-srcloc predicate guards on the manuscript's own name -- its comment had claimed a check the code did not make -- and an unrecognised binding suffix is reported rather than crashing the emitter.
sabotage LEG 06 is distinguishable from LEG 05: both reddened with the same sentence, so either would have scored the other's success.
The gate transcript now lists uncommitted paths. It printed head: while measuring the working tree.
Also: src/sigil/doc/reader.sgl said the base language admits "exactly one @chapter" and that its diagnostics are reproduced "byte for byte" -- true when SD-P1 wrote them, falsified by D8 two weeks later. And the "nineteen manuscripts" figure in four places is 17; the counts now reconcile to the census's independently derived 32.
src/sigil/doc/reader.sgl | 30 +++++++++----
test/gate-portability.sh | 10 +++++
test/gate-sd-p3.sh | 19 ++++----
test/gate-sd-p7.sh | 138 ++++++++++++++++++++++++---------------------------------
test/gate-sd-p8.sh | 397 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
test/sabotage-sd-p8.sh | 24 +++++++++-
test/sd-p8-lowering-dump.sgl | 38 ++++++++++++----
test/test-passive-parse.sgl | 11 +++--
8 files changed, 511 insertions(+), 156 deletions(-)src/sigil/doc/reader.sglmodified
;;; surface a DELEGATING language profile builds on.;;;;;; SD-P1 (review finding B2): the root container is a profile parameter rather;;; than a constant in the parser. `#lang sigil/doc` uses `sigil-doc-profile`,;;; which is exactly the historical policy -- exactly one `@chapter` -- spelled;;; as a value. A language such as `#lang folio/doc`, whose roots are `@note`;;; and `@project`, constructs its own profile and delegates the whole grammar;;; and every location to this module. It must never fork the parser.;;; than a constant in the parser.;;;;;; SD-P8 then used that parameter on `sigil/doc` itself, executing ruling D8;;; (2026-08-22): `#lang sigil/doc` admits exactly one `@article` -- the generic;;; standalone document -- and `@chapter` moved to the sibling genre language;;; `#lang sigil/doc/book` in `(sigil doc book reader)`. So the base profile is;;; NO LONGER the historical policy spelled as a value, and its two root-policy;;; diagnostics are deliberately no longer byte-identical to the pre-SD-P1;;; strings: they are DERIVED from the profile and followed its root set when it;;; moved, with no edit to the formatter.;;;;;; (The two sentences those two paragraphs replace were TRUE when SD-P1 wrote;;; them and were falsified by a ruling two weeks later that did not touch this;;; file. Prose beside code goes stale silently and no gate covers it.);;;;;; A language such as `#lang folio/doc`, whose roots are `@note` and;;; `@project`, constructs its own profile and delegates the whole grammar and;;; every location to this module. It must never fork the parser.;;;;;; The profile constructors are re-exported here rather than left in;;; `(sigil doc private parser)` so that a delegating reader depends only on a (let ((entry (assq key context))) (if entry (cdr entry) (error "sigil/doc reader: incomplete language context")))) ;; `#lang sigil/doc`. Behaviour is unchanged by SD-P1: the profile it passes ;; reproduces the previous hardcoded policy, including both diagnostics ;; byte for byte. ;; `#lang sigil/doc`. SD-P1 made the root container a parameter without ;; changing behaviour; SD-P8 then changed the behaviour deliberately, by ;; changing only the profile this passes. The form sequence emitted below is ;; unchanged by both. (define (read-language-source source context) (read-language-source-with-profile sigil-doc-profile source context))test/gate-portability.shmodified
exit 1fi# SD-P8 added `test/gate-sd-p8.sh`, which resolves sigil-sxml and the dev# compiler exactly as these do. Adding it here rather than leaving it to the# absolute-path sweep alone is the population check this file exists to be: a# new gate that took a sibling path unconfigurably would pass the regex above# and still be unportable.rg -q 'SIGIL_SXML_ROOT' test/gate-sd-p8.shrg -q 'SIGIL_D1_COMPILER' test/gate-sd-p8.shrg -q 'SIGIL_D1_COMPILER' test/sabotage-sd-p8.shrg -q 'SIGIL_SXML_ROOT' test/sabotage-sd-p8.shfor gate in test/gate-d4a.sh test/gate-d6.sh test/gate-d6-customization.sh \ test/gate-semantic-structures.sh test/gate-glossary.sh; do rg -q 'SIGIL_SXML_ROOT' "$gate"test/gate-sd-p3.shmodified
## WHY IT IS GONE. Ruling D8 (David, 2026-08-22) moves `@chapter` out of# `#lang sigil/doc` into `#lang sigil/doc/book`, which edits the `#lang` line of# nineteen manuscripts. All 16 of this arm's corpus are among them. A header# 17 manuscripts (plus 3 more whose ROOT command changed with the header left# alone, and 1 rewritten outright). All 16 of this arm's corpus are among the 17.# A header# line growing from 16 bytes to 21 moves every byte offset in the manuscript by# 5, so every one of those hashes changes -- measured before the migration was# written, by editing one fixture and re-running the dump:# BECAUSE it is ruled and recorded -- laundering is hiding a red, not retiring a# differential whose endpoints have moved.## SUCCESSOR, and it is strictly stronger: `test/gate-sd-p8.sh` arm 3. It# SUCCESSOR, and it is strictly stronger: `test/gate-sd-p8.sh` arm 5. It# generates BOTH sides in one run -- a detached worktree at SD-P8's own base and# the working tree -- so it has no committed baseline to go stale, and it# refuses with "baseline superseded" if HEAD stops descending from that base. It# compares 21 manuscripts rather than 16, on a DERIVED population rather than an# compares 22 manuscripts rather than 16 (21 of them in the intersection with the# base tree), on a DERIVED population rather than an# inherited list, and its claim is not "the hashes match" but "the only thing# that changed is the root symbol, and for the nineteen header-only manuscripts# that changed is the root symbol, and for the 17 header-only manuscripts# not even that" -- a hash equality tells you two numbers differ and nothing# about why.## STANDING PATTERN, restated for whoever changes lowering next: ship your own# before/after differential scoped to your own base, embed the base SHA in the# arm, and make a superseded base fail with "baseline superseded -- see ruling"# rather than with a bare diff. `test/gate-sd-p8.sh` arm 3 is a worked example.pass 3 "RETIRED 2026-08-22 at SD-P8 under Fable's 2026-08-11 ruling; superseded by test/gate-sd-p8.sh arm 3 (see comment)"# rather than with a bare diff. `test/gate-sd-p8.sh` arm 5 is a worked example.pass 3 "RETIRED 2026-08-22 at SD-P8 under Fable's 2026-08-11 ruling; superseded by test/gate-sd-p8.sh arm 5 (see comment)"# ---------------------------------------------------------------- ARM 04# RETIRED 2026-08-22, same disposition and same reasoning as arm 3 above, of# structurally by `test/test-prose-runs.sgl` (arm 1 of this gate, whose count is# derived from that suite) and by arm 2's node-by-node equality between the bare# and wrapped spellings, neither of which depends on a pre-SD-P3 hash table.# `test/gate-sd-p8.sh` arm 3 additionally shows that the D8 migration moved# `test/gate-sd-p8.sh` arm 5 additionally shows that the D8 migration moved# NOTHING in the lowering of the manuscripts SD-P3 cared about, header aside,# which is the closest standing equivalent of what this arm certified.pass 4 "RETIRED 2026-08-22 at SD-P8 with arm 3, whose changed-set was its only input; property covered by arm 1, arm 2 and test/gate-sd-p8.sh arm 3 (see comment)"pass 4 "RETIRED 2026-08-22 at SD-P8 with arm 3, whose changed-set was its only input; property covered by arm 1, arm 2 and test/gate-sd-p8.sh arm 5 (see comment)"# ---------------------------------------------------------------- ARM 05# Regression: the suites that own the frozen behaviour, with their countstest/gate-sd-p7.shmodified
pass 1 "section-profile suite ${suite_total}/${suite_total}, ${sections_built} sections built through a profile, ${witnesses} core witnesses = ${disjuncts} block-node? disjuncts"# ---------------------------------------------------------------- ARM 02# DEFAULT BEHAVIOUR UNCHANGED, MEASURED. Every manuscript in the tree is built# and its canonical document -- every field AND every node's full source# location -- compared against the pre-change baseline. "The suites still pass"# only covers the properties someone thought to assert; this is an equality.before=test/transcripts/sd-p7/construction-before.txtafter="$gate_dir/construction-after.txt"# The baseline must carry its own provenance, so a superseded one fails as# "baseline superseded" rather than as a bare diff.grep -q '^SD_P7_CONSTRUCTION_DUMP v1$' "$before" \ || die "arm 02: the baseline carries no provenance marker"base_sha=$(grep '^base-sha: ' "$before" | sed 's/^base-sha: //')git cat-file -e "$base_sha^{commit}" 2>/dev/null \ || die "arm 02: baseline names commit $base_sha, which is not in this repository"git merge-base --is-ancestor "$base_sha" HEAD \ || die "arm 02: baseline base $base_sha is not an ancestor of HEAD -- baseline superseded, regenerate and say so"bash test/sd-p7-construction-dump.sh "$after" >/dev/null 2>&1 \ || die "arm 02: could not produce an AFTER dump"# Compare the RECORDS only. Headers legitimately differ (different base sha,# different dirty-path count) and so does the completion line, which now reports# the exclusion the baseline predates. The documents must not differ.before_body="$gate_dir/before.body"; after_body="$gate_dir/after.body"sed -n '/^=== /,$p' "$before" | grep -v '^SD_P7_CONSTRUCTION_DUMP_COMPLETE' > "$before_body"sed -n '/^=== /,$p' "$after" | grep -v '^SD_P7_CONSTRUCTION_DUMP_COMPLETE' > "$after_body"# ...and the completion markers are asserted separately rather than dropped, so# a truncated run cannot pass by having had its marker filtered away.grep -q '^SD_P7_CONSTRUCTION_DUMP_COMPLETE ' "$before" || die "arm 02: baseline has no completion marker"grep -q '^SD_P7_CONSTRUCTION_DUMP_COMPLETE ' "$after" || die "arm 02: AFTER has no completion marker"# A diff of two empty files compares equal (taxonomy shape 4). Assert the# compared artifact is non-trivial, against a denominator READ FROM THE AFTER# ARTIFACT'S OWN HEADER rather than recomputed here or imagined.# Field position, not "the first number on the line": these header lines carry# prose that contains digits (`SD-P7`, `*.sgd`), and a number extractor over# prose is a coin flip that happens to be right today.compared=$(grep '^compared: ' "$after" | awk '{print $2}')found=$(grep '^population: ' "$after" | awk '{print $2}')excluded=$(grep '^excluded: ' "$after" | awk '{print $2}')test -n "$compared" || die "arm 02: AFTER header reports no compared count"test "$((compared + excluded))" = "$found" \ || die "arm 02: AFTER partition does not account for its population ($compared + $excluded != $found)"# THE EXCLUSION IS BOUNDED BY THE COMMIT, NOT BY A NAME PREFIX.# RETIRED 2026-08-23 BY THE LEADER, AT SD-P8, UNDER FABLE'S RULING OF# 2026-08-11. This arm has NOT silently disappeared and its red has NOT been# hidden -- read this before concluding anything.## The first version of this check compared the dump's excluded count against# `find test/fixtures -name 'sd-p7-*.sgd' | wc -l` -- which is the SAME# PREDICATE RESTATED. Add another `sd-p7-*.sgd` later and both sides grow# together, the gate stays green, and the manuscript silently leaves the# differential. A tautology cannot bound anything.# WHAT IT DID. It regenerated `test/sd-p7-construction-dump.sh` and required the# CONSTRUCTED document of every manuscript in the tree -- `document->string`,# which carries every field and every node's full source location -- to be# byte-identical to `test/transcripts/sd-p7/construction-before.txt`. That is a# strong statement, and a genuinely different one from a lowering differential:# SD-P7 changed CONSTRUCTION (`make-section` and the author runtime's node# admission) and touched lowering not at all, so a lowering differential would# have been byte-identical under a completely broken SD-P7.## The real bound is: an excluded manuscript must be one THIS BRANCH ADDED since# the baseline's base. That set cannot grow by naming convention.added_manuscripts="$gate_dir/added-manuscripts"git diff --name-only --diff-filter=A "$base_sha" HEAD -- 'book/*.sgd' 'test/*.sgd' \ | sort > "$added_manuscripts"excluded_paths="$gate_dir/excluded-paths"grep '^excluded-path: ' "$after" | sed 's/^excluded-path: //' | sort > "$excluded_paths"test "$excluded" -ge 1 || die "arm 02: the exclusion matched nothing, so it is not describing what it claims"test "$excluded" = "$(wc -l < "$excluded_paths")" \ || die "arm 02: the dump's excluded COUNT and its excluded PATHS disagree"diff -u "$added_manuscripts" "$excluded_paths" > "$gate_dir/exclusion.diff" \ || { cat "$gate_dir/exclusion.diff" die "arm 02: the exclusion set is not exactly the manuscripts this branch added since $base_sha"; }while read -r p; do test -f "$p" || die "arm 02: excluded path $p does not exist"done < "$excluded_paths"before_records=$(grep -c '^=== ' "$before_body")after_records=$(grep -c '^=== ' "$after_body")test "$before_records" -gt 0 || die "arm 02: the baseline body holds no records"test "$after_records" = "$compared" \ || die "arm 02: AFTER wrote $after_records records for $compared compared manuscripts"test "$after_records" = "$before_records" \ || die "arm 02: AFTER covered $after_records manuscripts, baseline covered $before_records"before_bytes=$(wc -c < "$before_body")test "$before_bytes" -gt 10000 \ || die "arm 02: baseline body is only $before_bytes bytes -- too small to be the real dump"diff -u "$before_body" "$after_body" > "$gate_dir/construction.diff" \ || { head -40 "$gate_dir/construction.diff"; die "arm 02: constructed documents changed"; }pass 2 "constructed documents identical across $after_records manuscripts ($before_bytes bytes compared; $excluded added by this phase excluded and exercised by the suite instead; baseline $base_sha)"# WHY IT IS GONE. Ruling D8 moves `@chapter` out of `#lang sigil/doc`, and this# arm is pinned to its endpoint in THREE independent ways, each of which alone# retires it. Measured, not argued -- `test/sd-p7-construction-dump.sh` was run# against this tree and compared to the committed baseline:## 1. THE EXCLUSION SET is `git diff --diff-filter=A <base> HEAD` compared for# EXACT equality against the dump's excluded paths. SD-P8 adds five# fixtures, so this dies first, before any document is compared.# 2. THE RECORD COUNT: the baseline header says `population: 22 manuscripts`;# this tree has 32 `.sgd` files and the dump compares 27.# 3. THE EMBEDDED POSITIONS. The baseline is full of ABSOLUTE byte offsets --# `("book/practical-sigil/01-useful-first-script.sgd" 78 4 1 2143)` -- and# a `#lang` line growing from 16 to 21 bytes shifts every one of them by 5# on all 17 header-migrated manuscripts.## WHAT THE MEASUREMENT ACTUALLY SHOWS, which is the part that matters for# whether anything is being hidden. Of the 22 manuscripts common to both sides,# once the location NUMBERS are normalised away:## 19 of 22 structurally IDENTICAL# 3 of 22 structurally different, and all three are D8 itself:# sd-p3-bare-prose.sgd (kind chapter) -> (kind article)# sd-p3-wrapped.sgd (kind chapter) -> (kind article)# sd-p1-article-root.sgd RAISED ... -> a real document, because D8 is# exactly what makes `@article` legal in the base# language; this is the phase's headline effect# showing up in the construction dump## So the property this arm protects is INTACT, and the arm cannot say so because# its baseline is pinned to offsets. That is endpoint drift, not a defect, and# it is the same disposition as `test/gate-sd-p3.sh` arms 3 and 4.## REGENERATING THE BASELINE IS THE WRONG ANSWER, for the same reason it was# wrong there: `construction-before.txt` is a PRE-SD-P7 endpoint. Regenerating# it against today's tree destroys the transition it certifies and leaves a# differential comparing the present to the present.## SUCCESSOR: `test/gate-sd-p8.sh` arm 06, which generates BOTH sides in one run# (a detached worktree at SD-P8's own base, and the working tree) and asserts on# STRUCTURE rather than on absolute byte positions -- deliberately, because this# retirement is the demonstration of why a baseline pinned to offsets is a trap.## EVIDENCE PRESERVED: `test/transcripts/sd-p7/construction-before.txt` stays in# the tree unmodified, and the `test -f` preconditions still assert it is# present. It is SD-P7's reviewed evidence.pass 2 "RETIRED 2026-08-23 at SD-P8 under Fable's 2026-08-11 ruling; superseded by test/gate-sd-p8.sh arm 06, which asserts on structure rather than offsets (see comment)"# ---------------------------------------------------------------- ARM 03# THE DELEGATING-LANGUAGE CONTRACT. A profile is installed by binding thetest/gate-sd-p8.shmodified
# here. The exceptions are stated where they occur and are FLOORS, not# restatements of a value.## ARM 3 IS A DIFFERENTIAL AND IS SCOPED TO ITS OWN BASE. It generates BOTH sides# ARM 5 IS A DIFFERENTIAL AND IS SCOPED TO ITS OWN BASE. It generates BOTH sides# in one run -- a detached worktree at $base_sha, and this working tree -- so it# has no committed baseline to go stale, and it fails with "baseline superseded"# rather than a bare diff if its base is no longer an ancestor of HEAD. It is# PROVENANCE. This differential's meaning is bound to this commit: it is the# tree D8 was executed against. If HEAD ever stops descending from it, the arm# says so in those words instead of printing a diff nobody can interpret.# THE BASE IS PINNED AND IS DELIBERATELY NOT `master`. `0b7c5ca` is the tree D8# was executed against; master moved past it on 2026-08-23 while this branch was# in flight. This differential certifies the D8 TRANSITION, not "everything since# last Tuesday", and re-pointing it at a moving master would reintroduce exactly# the endpoint drift that retired `gate-sd-p3.sh` arms 3-4 and `gate-sd-p7.sh`# arm 2. The is-ancestor check below is what keeps it honest: it still holds# after a rebase onto a later master, and refuses with "baseline superseded" if# it ever stops.base_sha="${SD_P8_BASE_SHA:-0b7c5ca}"sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"echo " compiler: $sigil"echo " redirects: $redirects"echo " base_sha: $base_sha"# THE TREE STATE, NOT JUST THE COMMIT. This gate measures the WORKING TREE, and# printing only `head:` would name a commit it is not testing -- a differential# whose transcript is one `git stash` away from describing a different tree than# it measured. `test/sd-p7-construction-dump.sh` already does this properly and# it is where the shape is borrowed from. Uncommitted paths are LISTED, not# counted, because "3 modified paths" tells a later reader nothing about whether# the modification was in the product or in the gate.echo " head: $(git rev-parse HEAD)"echo " tree: $(git status --porcelain | wc -l) uncommitted path(s)"git status --porcelain | sed 's/^/ tree-dirty: /'sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"test -d "$sxml_root/src" || die "sigil-sxml source not found at $sxml_root/src" || { cat "$kind_log" >&2; die "arm 02: article is no longer constructible -- folio's publication lowering depends on it"; }rg -q '^SD_P8_KIND chapter :: "chapter"$' "$kind_log" \ || { cat "$kind_log" >&2; die "arm 02: chapter is no longer constructible"; }# THE POPULATION, not the diff. Every `make-document` call site in shipped source# and in the test tree, classified; any that names `'book` is a finding.# THE POPULATION, NOT THE DIFF -- and it needs an exception class, which the# first version of this sweep did not have.## WHAT WENT WRONG, because it is the interesting part. The sweep was# "every `(make-document` site in the tree; any naming `'book` is a finding",# and it fired on `test/test-root-profile.sgl`, where two sites construct# `'book` DELIBERATELY inside `assert-error` to prove the kind is refused. The# sweep could not tell a violation from the test that guards against# violations, so it was red on a healthy tree. It was never seen green: the# sabotage suite reached this arm before any full gate run did, on a leg aimed# at something else entirely.## The repair is not to exclude `test/`, which would gut the sweep. It is to# CLASSIFY every site and print one row each, so the output length is the# denominator and an unclassified site fails loudly:## * in `src/`, `tools/` or `book/` -- shipped or product code -- a `'book`# site is a violation, full stop;# * in `test/` it is legitimate ONLY as a refusal test, which means the site# sits inside an `assert-error` or a captured-message form;# * anything else is UNCLASSIFIED and fails, because "I could not tell" and# "it is fine" must not print the same way.## And at least one NEGATIVE-TEST site is REQUIRED. Without one, nothing in the# tree exercises the refusal at a call site and this arm would be asserting an# absence with no positive control -- which passes for free.sites="$gate_dir/make-document-sites.txt"{ rg -n --no-heading "\(make-document " src test tools book || true; } >"$sites"site_count=$(wc -l <"$sites")test "$site_count" -ge 1 || die "arm 02: found no make-document call sites at all; the sweep examined nothing"book_sites=$( { rg -c "\(make-document '?book" "$sites" || true; } )test "${book_sites:-0}" -eq 0 \ || { rg -n "\(make-document '?book" "$sites" >&2; die "arm 02: a call site still constructs the dropped kind"; }pass 2 "kind book refused by name with 2 positive controls; $site_count make-document sites swept, 0 construct it"# A FLOOR, labelled: this is not a restatement of the current count, it is the# level below which the sweep has plainly lost its population.test "$site_count" -ge 20 \ || die "arm 02: the sweep found only $site_count make-document sites; it is not examining the tree"book_ledger="$gate_dir/book-kind-sites.txt": >"$book_ledger"violations=0; negative_tests=0; unclassified=0while IFS= read -r hit; do test -n "$hit" || continue path="${hit%%:*}" rest="${hit#*:}" lineno="${rest%%:*}" case "$path" in src/*|tools/*|book/*) violations=$((violations + 1)) printf 'VIOLATION %s:%s (product code must not construct the dropped kind)\n' \ "$path" "$lineno" >>"$book_ledger" ;; test/*) # The site's own line plus one either side: a refusal test wraps the # construction in a form that CAPTURES the raise. window=$(sed -n "$((lineno > 1 ? lineno - 1 : 1)),$((lineno + 1))p" "$path") if printf '%s' "$window" | rg -q 'assert-error|message \(lambda'; then negative_tests=$((negative_tests + 1)) printf 'NEGATIVE-TEST %s:%s (constructs it to prove it is refused)\n' \ "$path" "$lineno" >>"$book_ledger" else unclassified=$((unclassified + 1)) printf 'UNCLASSIFIED %s:%s (names the dropped kind and is not guarded by a refusal assertion)\n' \ "$path" "$lineno" >>"$book_ledger" fi ;; *) unclassified=$((unclassified + 1)) printf 'UNCLASSIFIED %s:%s (outside every classified directory)\n' \ "$path" "$lineno" >>"$book_ledger" ;; esacdone < <( { rg -n --no-heading "\(make-document '?book" src test tools book || true; } )cat "$book_ledger"book_rows=$(wc -l <"$book_ledger")book_hits=$( { rg -c "\(make-document '?book" "$sites" || true; } )test "$book_rows" -eq "${book_hits:-0}" \ || die "arm 02: found ${book_hits:-0} sites naming the dropped kind but classified $book_rows of them"test "$violations" -eq 0 \ || { rg '^VIOLATION' "$book_ledger" >&2; die "arm 02: $violations product call sites still construct the dropped kind"; }test "$unclassified" -eq 0 \ || { rg '^UNCLASSIFIED' "$book_ledger" >&2; die "arm 02: $unclassified sites name the dropped kind and could not be classified"; }test "$negative_tests" -ge 1 \ || die "arm 02: no test constructs the dropped kind to prove it is refused, so this sweep's absence claim has no positive control"pass 2 "kind book refused by name with 2 positive controls; $site_count make-document sites swept, ${book_hits:-0} name the dropped kind and all $negative_tests are refusal tests, 0 in product code"# ---------------------------------------------------------------- ARM 03# (ARM 05 below carries the differential; arms 2 and 3 are the cheap ones and# this arm prints one row per manuscript so the output length is the second one.census="$gate_dir/census.txt": >"$census"total=0; base_lang=0; book_lang=0; other_lang=0; negative=0; bad=0total=0; base_lang=0; book_lang=0; other_lang=0; negative=0; bad=0; unknown_lang=0while IFS= read -r m; do total=$((total + 1)) lang=$(head -1 "$m" | sed -n 's|^#lang \(.*\)$|\1|p') root=$( { rg -o -m1 '^@[a-z][a-z-]*' "$m" || echo "@NONE"; } | head -1) # THREE CLASSES, AND `UNCHECKED` HAS TO BE REACHABLE OR THE PASS LINE LIES. # # The first version defaulted `verdict=UNCHECKED` and then overwrote it on # EVERY branch -- the inner catch-all made everything either OK or ILLEGAL -- # so "0 unclassified" was vacuously true. A guard against a state the code # makes unreachable is not a denominator, it is decoration. # # The class that genuinely exists is: a language THIS GATE DOES NOT KNOW. # That is different from a manuscript being wrong, and conflating the two is # the actual risk here -- a `#lang folio/doc` fixture added later would be # reported ILLEGAL, which is false, or would need this arm silently widened. # So an unknown language is UNCHECKED and FAILS, which forces whoever adds a # language to say what its legal roots are. verdict=UNCHECKED case "$m" in */sd-p8-base-*|*/sd-p8-book-article-root.sgd|*/sd-p8-book-two-chapters.sgd) verdict=NEGATIVE-FIXTURE; negative=$((negative + 1)) ;; *) case "$lang::$root" in "sigil/doc::@article") verdict=OK; base_lang=$((base_lang + 1)) ;; "sigil/doc/book::@chapter") verdict=OK; book_lang=$((book_lang + 1)) ;; "sigil/doc::@note") verdict=OK-EXPLICIT-PROFILE; other_lang=$((other_lang + 1)) ;; "sd-p7/folio::@note") verdict=OK-OTHER-LANGUAGE; other_lang=$((other_lang + 1)) ;; *) verdict=ILLEGAL; bad=$((bad + 1)) ;; case "$lang" in "sigil/doc"|"sigil/doc/book"|"sd-p7/folio") case "$lang::$root" in "sigil/doc::@article") verdict=OK; base_lang=$((base_lang + 1)) ;; "sigil/doc/book::@chapter") verdict=OK; book_lang=$((book_lang + 1)) ;; "sigil/doc::@note") verdict=OK-EXPLICIT-PROFILE; other_lang=$((other_lang + 1)) ;; "sd-p7/folio::@note") verdict=OK-OTHER-LANGUAGE; other_lang=$((other_lang + 1)) ;; *) verdict=ILLEGAL; bad=$((bad + 1)) ;; esac ;; *) verdict=UNCHECKED; unknown_lang=$((unknown_lang + 1)) ;; esac ;; esac printf '%-22s %-16s %-9s %s\n' "$verdict" "$lang" "$root" "$m" >>"$census"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"; }# 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.# The `unknown language` class, counted from the rows and cross-checked against# the loop's own counter -- two independently produced numbers, because a loop# cannot audit itself.unchecked=$( { rg -c '^UNCHECKED' "$census" || true; } )test "${unchecked:-0}" -eq "$unknown_lang" \ || die "arm 03: $unknown_lang unknown-language manuscripts counted but ${unchecked:-0} rows printed"test "${unchecked:-0}" -eq 0 \ || { rg '^UNCHECKED' "$census" >&2; die "arm 03: ${unchecked} manuscripts were not classified at all"; } || { rg '^UNCHECKED' "$census" >&2 die "arm 03: ${unchecked} manuscripts declare a language this arm does not know, so it cannot say whether their root is legal; widen the arm deliberately or fix the manuscript"; }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"pass 3 "census $total manuscripts, 0 illegal, 0 of an unknown language :: $base_lang base, $book_lang book, $other_lang other-language, $negative negative fixtures"# ---------------------------------------------------------------- ARM 04# END TO END through the real `#lang` path: the two REQUIRED GREENS and the four## The claim: across the whole manuscript corpus, the ONLY manuscripts whose# lowering changed are the ones whose ROOT COMMAND this phase changed, and for# each of those the change is EXACTLY the root symbol. The nineteen manuscripts# each of those the change is EXACTLY the root symbol. The 17 manuscripts# that took a header edit alone lower identically.## What makes that assertable is `test/sd-p8-lowering-dump.sgl`, which emits every # 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. # THE SUBSTITUTION MUST BE UNAMBIGUOUS BEFORE IT IS TRUSTED, and it must be # BOUNDED. 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. Three conditions: # # * after the change the old spelling must be gone entirely, and before it # the new spelling must not have existed -- so the mapping is a bijection # on this pair of sections; # * the rewrite must change SOMETHING, or the comparison below is between # the two sections unmodified and a genuine root-only change would read as # UNEXPECTED for the wrong reason; # * and it must change AT MOST as many occurrences as a root can account # for. A `/g` substitution over the whole section would also rewrite a # NESTED generated `chapter` head, so a manuscript that changed its root # AND some other command of the same name would report "nothing else # moved". The root appears twice in a lowered manuscript -- once in the # generated command head and once in the `author-flatten` command-name # argument -- so more than two is a second construct, not the root. if [ "$( { rg -cF "]] $new>" "$b" || true; } )" != "" ] \ || [ "$( { rg -cF "]] $old>" "$f" || true; } )" != "" ]; then unexpected=$((unexpected + 1)) "$name" "$root_b" "$root_a" >>"$ledger" continue fi occurrences=$( { rg -oF "]] $old>" "$b" || true; } | wc -l) if [ "$occurrences" -lt 1 ] || [ "$occurrences" -gt 2 ]; then unexpected=$((unexpected + 1)) printf 'UNEXPECTED %-40s root=%s -> %s, but %s generated `%s` heads is not a root alone; refusing to rewrite\n' \ "$name" "$root_b" "$root_a" "$occurrences" "$old" >>"$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 || die "arm 05: the dump lowered $after_compared manuscripts but the ledger holds $compared"echo " denominator: after found $after_found, lowered $after_compared; before lowered $before_compared; ledger rows $((compared + only_before))"# `only_after` and `skipped` ARE ASSERTED, and the first version of this arm did# not assert either. A count nobody asserts on is a count nobody is checking:# `test/fixtures/sd-p1-article-root.sgd` had its whole body rewritten by this# phase (+10 -9) and passed through this ledger as `AFTER-ONLY ... the base tree# could not lower it`, which is TRUE and says nothing about its content. The# after-only class is legitimate but it is not free: each member must be named# in advance, so a manuscript joining it is a decision rather than an accident.## Both expected members are here for a REASON, not merely listed:# sd-p1-article-root.sgd root `@article`; the base profile at the base SHA# was `(chapter)` and refused it. D8 is exactly the# change that makes it lowerable, so its appearance# here is the phase's headline effect, not a gap.# sd-p8-book-chapter-root.sgd added by this phase; no base-side counterpart# can exist.expected_after_only="$gate_dir/expected-after-only"printf 'sd-p1-article-root.sgd\nsd-p8-book-chapter-root.sgd\n' | sort >"$expected_after_only"actual_after_only="$gate_dir/actual-after-only"{ rg '^AFTER-ONLY' "$ledger" || true; } | awk '{print $2}' | sort >"$actual_after_only"diff -u "$expected_after_only" "$actual_after_only" >"$gate_dir/after-only.diff" \ || { cat "$gate_dir/after-only.diff" >&2 die "arm 05: the set of manuscripts only the current tree can lower is not the set this phase intends"; }test "$only_after" -eq "$(wc -l <"$expected_after_only")" \ || die "arm 05: $only_after after-only rows for $(wc -l <"$expected_after_only") expected names"# A CONTENT REWRITE OF AN AFTER-ONLY MANUSCRIPT IS STILL A CHANGE, and the# differential structurally cannot see it (there is no before-side section to# compare). Saying so is the honest disposition; hiding it behind a passing# ledger row is not. The suite is what covers these: `test/test-root-profile.sgl`# evaluates `sd-p1-article-root.sgd` through the shipped base profile and asserts# its kind and title, and `test/sd-p8-language-probe.sgl` loads# `sd-p8-book-chapter-root.sgd` through the real `#lang` path.echo " after-only: $only_after manuscripts, named in advance; their CONTENT is not covered by this differential and is covered by the suite and the language probe instead"# THE SKIPPED SETS, COMPARED BY NAME. The first version of this check compared# COUNTS and required `after <= before`, which was simply wrong: this phase adds# four manuscripts that are DELIBERATELY unlowerable (the negative fixtures the# language probe drives), so the after side legitimately skips more. The gate# caught it loudly on its first run with "something stopped being lowerable",# which was false -- a count cannot tell "a manuscript regressed" from "a# manuscript was added to be refused". Only the names can.## Two directions, both asserted:# * a manuscript the base tree could LOWER must not have become skippable --# that is the regression this check exists for;# * a manuscript newly skipped must be one this phase ADDED, which is derived# from git rather than listed here.skipped_names() { rg -o '^--- SKIPPED \S+' "$1" | awk '{print $3}' | sort; }skipped_names "$after_dump" >"$gate_dir/skipped-after"skipped_names "$before_dump" >"$gate_dir/skipped-before"comm -13 "$gate_dir/skipped-before" "$gate_dir/skipped-after" >"$gate_dir/newly-skipped"comm -23 "$gate_dir/skipped-before" "$gate_dir/skipped-after" >"$gate_dir/no-longer-skipped"git diff --name-only --diff-filter=A "$base_sha" HEAD -- '*.sgd' \ | sed 's|.*/||' | sort >"$gate_dir/added-manuscripts"while read -r n; do test -n "$n" || continue grep -Fxq -- "$n" "$gate_dir/added-manuscripts" \ || { echo "newly skipped: $n" >&2 die "arm 05: $n is skipped by this tree and was not skipped by the base tree, and this phase did not add it -- it stopped being lowerable"; }done <"$gate_dir/newly-skipped"# The other direction is a GAIN, not a fault, but it must still be named: a# manuscript that stopped being skipped is one D8 made lowerable, and it has to# be in the after-only set the arm already pins.while read -r n; do test -n "$n" || continue grep -Fxq -- "$n" "$expected_after_only" \ || { echo "no longer skipped: $n" >&2 die "arm 05: $n became lowerable and is not in this arm's expected after-only set"; }done <"$gate_dir/no-longer-skipped"echo " skipped: after $(wc -l <"$gate_dir/skipped-after"), before $(wc -l <"$gate_dir/skipped-before"); $(wc -l <"$gate_dir/newly-skipped") newly skipped (all added by this phase), $(wc -l <"$gate_dir/no-longer-skipped") newly lowerable"# A FLOOR, deliberately, not a restatement: adding a manuscript must not# desynchronise this, and a corpus that collapsed must not read as a pass.test "$identical" -ge 15 \pass 5 "differential vs $base_sha: $identical identical, $expected_change root-only, $only_after newly lowerable, 0 unexpected, over $compared lowered of $after_found found"# ---------------------------------------------------------------- ARM 06# THE CONSTRUCTION DIFFERENTIAL, replacing `test/gate-sd-p7.sh` arm 02.## Arm 5 above compares LOWERING -- emitted syntax. This compares the CONSTRUCTED# document, which is a different property and the one SD-P7 owns: a lowering# differential is byte-identical under a completely broken content profile. When# arm 02 of gate-sd-p7 was retired (its baseline is pinned to absolute byte# offsets that a `#lang` edit shifts), that property lost its standing check, and# retiring without replacing loses a property.## THE ONE DESIGN DECISION, and it is the lesson of the retirement it replaces:# THIS ARM ASSERTS ON STRUCTURE, NOT ON POSITIONS. `document->string` embeds# every node's `(file pos line col span)`. Comparing those verbatim is precisely# what made the old baseline unmaintainable, so every location TUPLE belonging# to a manuscript is normalised to the marker `L` before comparison. What# remains is the document's shape and every non-positional field: kinds, titles,# authors, ids, text, the tree.## That is deliberately weaker than the arm it replaces, and the weakening is# named rather than glossed: THIS ARM CANNOT SEE A PURE LOCATION REGRESSION.# Locations are covered instead by arm 5 (which asserts them header-relative,# so it sees any shift that is not the header's) and by# `test/test-root-profile.sgl`, whose location assertions recompute every# expected byte offset, line and column independently.before_c="$gate_dir/construction-before.txt"after_c="$gate_dir/construction-after.txt"setsid -w bash test/sd-p7-construction-dump.sh "$after_c" >"$gate_dir/construction-after.log" 2>&1 \ || { tail -20 "$gate_dir/construction-after.log" >&2; die "arm 06: the construction dump failed on this tree"; }( cd "$base_tree" \ && cp "$repo_dir/test/sd-p7-construction-dump.sh" test/ \ && SIGIL_D1_REDIRECTS="$gate_dir/base-redirects.sgl" \ SIGIL_D1_COMPILER="$sigil" \ setsid -w bash test/sd-p7-construction-dump.sh "$before_c" ) \ >"$gate_dir/construction-before.log" 2>&1 \ || { tail -20 "$gate_dir/construction-before.log" >&2; die "arm 06: the construction dump failed on the base tree"; }for side in "$before_c" "$after_c"; do rg -q 'SD_P7_CONSTRUCTION_DUMP_COMPLETE' "$side" \ || { tail -10 "$side" >&2; die "arm 06: a construction dump printed no completion marker"; }done# The location normaliser, and the marker line excluded for the reason SD-P3's# gate learned the hard way: it names the corpus size, so leaving it in ties the# LAST manuscript's record to how many manuscripts were dumped.split_construction() { # $1 = dump, $2 = out dir mkdir -p "$2" grep -v '^SD_P7_CONSTRUCTION_DUMP_COMPLETE' "$1" \ | sed -E 's/("[^"]*\.sgd") [0-9]+ [0-9]+ [0-9]+ [0-9]+/\1 L/g' \ | awk -v o="$2" '/^=== /{n=$2; gsub("/","_",n)} n!=""{print > (o "/" n)}'}split_construction "$before_c" "$gate_dir/con-before"split_construction "$after_c" "$gate_dir/con-after"# THE NORMALISER MUST BE SHOWN TO HAVE FIRED. A `sed` that matched nothing would# make this a verbatim comparison wearing a normaliser's name -- and it would# then fail for exactly the reason the retired arm did, with a message about# structure.## CHECK THE NORMALISED OUTPUT, NOT THE RAW DUMP. The first version of this guard# grepped `$after_c`, which is the dump BEFORE `split_construction` runs sed over# it, so the marker could never appear there and the guard reddened on a healthy# tree. Caught by the guard itself on its first run, which is the only reason a# check aimed at one file rather than another is visible at all.normalised=$( { rg -c ' L\)' "$gate_dir"/con-after/* || true; } | awk -F: '{n+=$NF} END{print n+0}')test "${normalised:-0}" -ge 1 \ || die "arm 06: the location normaliser matched nothing in the split records; it is not normalising, so this comparison is not the one described"con_ledger="$gate_dir/construction-ledger.txt": >"$con_ledger"con_same=0; con_diff=0; con_after_only=0; con_before_only=0for f in "$gate_dir/con-before"/*; do name="${f##*/}" a="$gate_dir/con-after/$name" if [ ! -f "$a" ]; then con_before_only=$((con_before_only + 1)) printf 'BEFORE-ONLY %s (this tree no longer constructs it)\n' "$name" >>"$con_ledger" elif cmp -s "$f" "$a"; then con_same=$((con_same + 1)) printf 'IDENTICAL %s\n' "$name" >>"$con_ledger" else con_diff=$((con_diff + 1)) printf 'DIFFERS %s\n' "$name" >>"$con_ledger" fidonefor f in "$gate_dir/con-after"/*; do name="${f##*/}" test -f "$gate_dir/con-before/$name" || { con_after_only=$((con_after_only + 1)) printf 'AFTER-ONLY %s (added by this phase)\n' "$name" >>"$con_ledger"; }donecat "$con_ledger"# THE EXPECTED DIFFERENCES, NAMED. Anything else is a finding. All three are D8# itself: two manuscripts whose root command changed, so their document KIND# changed with it, and one that the base tree could not construct at all because# its `@article` root was illegal there -- which is the whole point of the phase.expected_con="$gate_dir/expected-construction-diffs"printf 'test_fixtures_sd-p1-article-root.sgd\ntest_fixtures_sd-p3-bare-prose.sgd\ntest_fixtures_sd-p3-wrapped.sgd\n' | sort >"$expected_con"{ rg '^DIFFERS' "$con_ledger" || true; } | awk '{print $2}' | sort >"$gate_dir/actual-construction-diffs"diff -u "$expected_con" "$gate_dir/actual-construction-diffs" >"$gate_dir/construction.diff" \ || { cat "$gate_dir/construction.diff" >&2 die "arm 06: the constructed documents that changed are not the ones this phase intends"; }# And the two kind flips are asserted BY NAME, so "it differs" cannot stand in# for "it differs in the way D8 predicts".for m in sd-p3-bare-prose sd-p3-wrapped; do rg -q '\(document \(kind chapter\)' "$gate_dir/con-before/test_fixtures_$m.sgd" \ || die "arm 06: $m was not a chapter at the base, so the kind-flip claim is not about what changed" rg -q '\(document \(kind article\)' "$gate_dir/con-after/test_fixtures_$m.sgd" \ || die "arm 06: $m is not an article now"donerg -q 'RAISED' "$gate_dir/con-before/test_fixtures_sd-p1-article-root.sgd" \ || die "arm 06: the base tree DID construct sd-p1-article-root.sgd, so D8 is not what made it constructible"rg -q '\(document \(kind article\)' "$gate_dir/con-after/test_fixtures_sd-p1-article-root.sgd" \ || die "arm 06: sd-p1-article-root.sgd still does not construct"test "$con_before_only" -eq 0 \ || { rg '^BEFORE-ONLY' "$con_ledger" >&2; die "arm 06: this tree stopped constructing a manuscript the base tree built"; }# A FLOOR, labelled: not a restatement of the current count.test "$con_same" -ge 15 \ || die "arm 06: only $con_same constructed documents are unchanged; the migration moved more than D8 intends"pass 6 "construction differential vs $base_sha: $con_same identical, $con_diff changed and all named, $con_after_only added, 0 lost; locations normalised (see comment: this arm cannot see a pure location regression, arm 5 and the suite cover that)"# ---------------------------------------------------------------- ARM 07# REGRESSION. The full suite with the FULL load path -- four entries, because a# short path degrades into "failed to load", which the runner reports WITHOUT# failing the process. The file count is its own assertion for that reason.# the gate with this UNSET and requires the GREEN marker, so no leg can be# satisfied by a run that skipped anything.if [ -n "${SD_P8_SKIP_REGRESSION:-}" ]; then printf 'SD_P8_GATE_06 SKIPPED (SD_P8_SKIP_REGRESSION is set)\n' echo "SD_P8_GATE_PARTIAL arms 1-5 only; the regression arm did not run" printf 'SD_P8_GATE_07 SKIPPED (SD_P8_SKIP_REGRESSION is set)\n' echo "SD_P8_GATE_PARTIAL arms 1-6 only; the regression arm did not run" exit 0firegression_log="$gate_dir/regression.log" >"$regression_log" 2>&1 || regression_status=$?sed -i 's/\x1b\[[0-9;]*m//g' "$regression_log"grep -qE 'Tests: +[0-9]+ passed' "$regression_log" \ || { tail -40 "$regression_log" >&2; die "arm 06: could not read a suite summary -- the run may not have executed anything"; } || { tail -40 "$regression_log" >&2; die "arm 07: could not read a suite summary -- the run may not have executed anything"; }files_line=$(grep -oE 'Files: +[0-9]+ of [0-9]+ run' "$regression_log" | tail -1 || true)test -n "$files_line" || { tail -40 "$regression_log" >&2; die "arm 06: the runner reported no file count"; }test -n "$files_line" || { tail -40 "$regression_log" >&2; die "arm 07: the runner reported no file count"; }files_run=$(echo "$files_line" | grep -oE '[0-9]+' | head -1)files_found=$(echo "$files_line" | grep -oE '[0-9]+' | tail -1)test "$files_run" = "$files_found" || die "arm 06: only $files_run of $files_found test files ran"test "$files_run" = "$files_found" || die "arm 07: only $files_run of $files_found test files ran"if grep -qE '[0-9]+ failed' "$regression_log"; then grep -nE '✗|failed' "$regression_log" | head -30 >&2 die "arm 06: a test failed" die "arm 07: a test failed"fitest "$regression_status" = "0" \ || { tail -40 "$regression_log" >&2; die "arm 06: the runner exited $regression_status with no failing test reported"; } || { tail -40 "$regression_log" >&2; die "arm 07: the runner exited $regression_status with no failing test reported"; }Showing the first 500 of 521 diff lines for this file. This diff is INCOMPLETE; read the file or clone the repository for the rest.
test/sabotage-sd-p8.shmodified
'(and #f (pair? value)'run_gate "$work/leg06.log" && die "LEG 06: the gate passed with the position normalization disabled"leg_red 06 "$work/leg06.log" "manuscripts changed for a reason this phase did not intend"# CORROBORATION, and it is not optional here. LEG 05 and LEG 06 both redden arm# 5 with the SAME sentence, so on that string alone the two legs cannot be told# apart by their own evidence -- either one would score the other's success.# They must be distinguished by WHICH manuscripts move:## LEG 05 changes one manuscript's prose -> exactly minimal.sgd is UNEXPECTED# LEG 06 disables the normalization -> every HEADER-MIGRATED manuscript# is UNEXPECTED, because their# embedded make-srcloc positions are# absolute again## So this leg requires a WALL, not a row: at least ten unexpected manuscripts,# and minimal.sgd among them for a reason opposite to leg 5's.unexpected_rows=$( { rg -c '^UNEXPECTED' "$work/leg06.log" || echo 0; } )test "${unexpected_rows:-0}" -ge 10 \ || { rg '^UNEXPECTED|^IDENTICAL' "$work/leg06.log" >&2 die "LEG 06: disabling the normalization produced only ${unexpected_rows:-0} unexpected manuscripts; a header-shift leak should move every migrated one, so this red is probably not the one this leg is about"; }rg -qF 'UNEXPECTED minimal.sgd' "$work/leg06.log" \ || die "LEG 06: the wall of unexpected manuscripts does not include minimal.sgd"printf 'SD_P8_SABOTAGE_06 CORROBORATED %s manuscripts unexpected, not the single row leg 5 produces\n' "$unexpected_rows"restore_all || die "restore failed; the worktree is still sabotaged"# ---------------------------------------------------------------- LEG 07 || { 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; dofor n in 01 02 03 04 05 06 07; do 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_09 GREEN the restored tree passes all six arms\n'printf 'SD_P8_SABOTAGE_09 GREEN the restored tree passes all seven arms\n'echo "SD_P8_SABOTAGE_COMPLETE 8 reds (6 product, 1 instrument, 1 coverage) and 1 positive control"test/sd-p8-lowering-dump.sglmodified
;;;;;; SD-P3's dump is the AFTER half of a differential whose BEFORE half is a;;; committed table of sha256s taken from a pre-SD-P3 tree. D8 migrates the;;; `#lang` line of nineteen manuscripts, which moves every byte offset in each;;; `#lang` line of 17 manuscripts, which moves every byte offset in each;;; of them by the header's length delta, so every one of those hashes changes.;;; The BEFORE half stores hashes and not sections, so no normalization can be;;; applied to it retroactively -- the differential cannot be rescued, only(define (syntax-datum-of value) (if (syntax? value) (syntax-datum value) value));; THE GUARD IS THE MANUSCRIPT'S OWN NAME, not merely "not the generated;; marker". An earlier version accepted any six-element `make-srcloc` call whose;; second element was any string, while its comment claimed a check the code did;; not make: an author writing `(make-srcloc "anything.sgd" 1 1 100 5)` inside a;; top-level `@(...)` would have had element 4 silently rewritten, hiding a real;; change to that literal. Nothing in the corpus does that today -- which is;; exactly the condition under which an over-broad predicate goes unnoticed.(define current-manuscript "")(define (generated-srcloc-call? value) (and (pair? value) (eq? (syntax-datum-of (car value)) 'make-srcloc) (= (length value) 6) (let ((file (syntax-datum-of (cadr value)))) (and (string? file) (not (string=? file "<sigil/doc-generated>")))))) (and (string? file) (string=? file current-manuscript)))))(define expression-binding-prefix "#%sigil/doc-expression:")(define (expression-binding? name) ;; same reason as the other two, and it is worth knowing on its own: a ;; manuscript's generated binding names are NOT stable under an edit to its ;; `#lang` line. ;; ;; A SUFFIX THAT IS NOT A NUMBER IS REPORTED, NOT SUBTRACTED. `string->number` ;; returns `#f` on a name this code did not expect, and `(- #f header-end)` ;; would raise from inside the emitter -- killing the dump and surfacing in ;; the gate as "the dump printed no completion marker", a red about a missing ;; marker for what is actually an unrecognised binding name. Emitting the ;; symbol verbatim instead makes it a DIFFERENCE the differential reports ;; against the other side, which is the correct place for a surprise. ((and (symbol? value) (expression-binding? (symbol->string value))) (display "#%sigil/doc-expression:rel:") (display (- (string->number (substring (symbol->string value) (string-length expression-binding-prefix) (string-length (symbol->string value)))) header-end))) (let* ((name (symbol->string value)) (suffix (substring name (string-length expression-binding-prefix) (string-length name))) (offset (string->number suffix))) (if (and offset (integer? offset)) (begin (display "#%sigil/doc-expression:rel:") (display (- offset header-end))) (begin (display "#%sigil/doc-expression:UNRECOGNISED-SUFFIX:") (display suffix))))) (else (write value))));; ----------------------------------------------------------------- profiles (id (language-header-id header)) (profile (profile-for id))) (set! header-end (language-header-end header)) (set! current-manuscript name) ;; The MANIFEST line carries everything that legitimately differs between ;; the two trees -- the language id, the header length, the root command -- ;; and is deliberately OUTSIDE the compared section. Putting it inside wouldtest/test-passive-parse.sglmodified
(tree-node-text child)) (assert-true (not (string=? slice (tree-node-text child)))))))(test "the passive tree does not enforce the single-chapter root policy" ;; "exactly one @chapter" is a LOWERING rule, not a fact about the grammar. ;; folio roots are @note/@project and must be inspectable before SD-P1 ;; parameterizes the root container.(test "the passive tree does not enforce the single-root policy" ;; A root policy is a LOWERING rule, not a fact about the grammar. It was ;; "exactly one @chapter" when this arm was written and is "exactly one ;; @article" since ruling D8 (SD-P8) -- and the point is that the passive path ;; is indifferent to BOTH. The manuscript below declares `#lang sigil/doc` and ;; two @note roots, which no sigil/doc profile has ever admitted, and the ;; passive tree reports it regardless. (let* ((source "#lang sigil/doc\n@note[\"topics/x\"]{@p{body}}\n@note[\"topics/y\"]{@p{body}}\n") (tree (inspect-document-source source "roots.sgd" 16)) (commands (let loop ((xs (document-tree-roots tree)) (out '()))