AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# SD-P8 gate: ruling D8 -- generic base language, genres as languages.3
#4
# Every arm prints its own marker and this script asserts on MARKERS, not on5
# exit status alone: a non-zero exit is equally consistent with a gate that6
# never ran (127 not-found, 126 not-executable), and this estate has been fooled7
# by both.8
#9
# Counts checked for EQUALITY are DERIVED from an artifact rather than written10
# here. The exceptions are stated where they occur and are FLOORS, not11
# restatements of a value.12
#13
# ARM 5 IS A DIFFERENTIAL AND IS SCOPED TO ITS OWN BASE. It generates BOTH sides14
# in one run -- a detached worktree at $base_sha, and this working tree -- so it15
# has no committed baseline to go stale, and it fails with "baseline superseded"16
# rather than a bare diff if its base is no longer an ancestor of HEAD. It is17
# the replacement `test/gate-sd-p3.sh` arms 3 and 4 name in their retirement18
# notices, built to the standing pattern Fable's 2026-08-11 ruling recorded for19
# the next lowering-changing phase.20
#21
#22
# A COINCIDENCE THIS PHASE LEANED ON, WRITTEN DOWN BECAUSE IT IS NOT DESIGN.23
# `@article` and `@chapter` are both 8 characters, and `article`/`chapter` both24
# 7. That is luck. It is what let the migration switch roots in25
# `test/test-reader.sgl`, `test/test-prose-runs.sgl` and26
# `test/sd-p1-classification-probe.sgl` with every location assertion, and the27
# three pinned positive controls in `test/gate-sd-p1.sh` arm 2, staying BYTE28
# IDENTICAL. Those controls are therefore LENGTH-SENSITIVE and nothing in them29
# says so: the next root rename, if it is not 8 characters, will redden that arm30
# for a reason that has nothing to do with what it checks. If you are here31
# because of that, this is your explanation.32
# THE ARMS ARE ORDERED CHEAPEST FIRST, deliberately. Arms 5 and 6 dominate the33
# runtime (a detached worktree plus two full lowering dumps, and the whole test34
# suite), and `set -e` stops at the first failure, so a sabotage leg aimed at an35
# early arm pays for none of that. That is not a convenience: a sabotage suite36
# nobody can afford to run is a sabotage suite nobody runs, and a gate that has37
# never been shown able to fail is a gate that has been shown to be quiet.38
set -euo pipefail39
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"40
cd "$repo_dir"41
mkdir -p "$repo_dir/build"43
# PROVENANCE. This differential's meaning is bound to this commit: it is the44
# tree D8 was executed against. If HEAD ever stops descending from it, the arm45
# says so in those words instead of printing a diff nobody can interpret.46
# THE BASE IS PINNED AND IS DELIBERATELY NOT `master`. `0b7c5ca` is the tree D847
# was executed against; master moved past it on 2026-08-23 while this branch was48
# in flight. This differential certifies the D8 TRANSITION, not "everything since49
# last Tuesday", and re-pointing it at a moving master would reintroduce exactly50
# the endpoint drift that retired `gate-sd-p3.sh` arms 3-4 and `gate-sd-p7.sh`51
# arm 2. The is-ancestor check below is what keeps it honest: it still holds52
# after a rebase onto a later master, and refuses with "baseline superseded" if53
# it ever stops.54
base_sha="${SD_P8_BASE_SHA:-0b7c5ca}"56
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"57
redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"58
gate_dir=$(mktemp -d "$repo_dir/build/sd-p8-gate.XXXXXX")59
export SIGIL_REDIRECTS="$redirects"60
export XDG_CACHE_HOME="$gate_dir/cache"62
# ZERO-PADDED OUTPUT, BASE-10 INPUT. `%02d` on a zero-padded argument is a trap:63
# bash reads `08` as octal, raises "invalid octal number", prints 00 and returns64
# NON-ZERO -- which under `set -e` killed the sabotage suite immediately after65
# leg 8 printed a mislabelled marker, so leg 9 (the positive control) never ran.66
# `10#` forces base 10, so the markers stay padded and a padded caller is safe.67
pass() { printf 'SD_P8_GATE_%02d %s\n' "$((10#$1))" "$2"; }68
die() { echo "$*" >&2; exit 1; }70
# An absent tool does not announce itself -- it impersonates a result. Every71
# external tool this gate leans on must EXIST before any of them is trusted.72
for tool in rg git awk sed sha256sum comm sort diff cmp setsid; do73
command -v "$tool" >/dev/null || die "$tool is required by this gate"74
done75
test -x "$sigil" || die "dev compiler not found at $sigil"76
test -f src/sigil/doc/private/parser.sgl77
test -f src/sigil/doc/book/reader.sgl || die "the D8 genre language is missing"78
test -f test/test-root-profile.sgl79
test -f test/sd-p8-lowering-dump.sgl80
test -f test/sd-p8-language-probe.sgl81
# The gate's INPUT SET, recorded rather than assumed: a caret-ranged dependency82
# is an unrecorded input, and so is an unnamed compiler.83
"$sigil" --version84
echo " compiler: $sigil"85
echo " redirects: $redirects"86
echo " base_sha: $base_sha"87
# THE TREE STATE, NOT JUST THE COMMIT. This gate measures the WORKING TREE, and88
# printing only `head:` would name a commit it is not testing -- a differential89
# whose transcript is one `git stash` away from describing a different tree than90
# it measured. `test/sd-p7-construction-dump.sh` already does this properly and91
# it is where the shape is borrowed from. Uncommitted paths are LISTED, not92
# counted, because "3 modified paths" tells a later reader nothing about whether93
# the modification was in the product or in the gate.94
echo " head: $(git rev-parse HEAD)"95
echo " tree: $(git status --porcelain | wc -l) uncommitted path(s)"96
git status --porcelain | sed 's/^/ tree-dirty: /'98
sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"99
test -d "$sxml_root/src" || die "sigil-sxml source not found at $sxml_root/src"101
# ---------------------------------------------------------------- ARM 01102
# The two languages are what D8 ruled, asked through the PUBLIC modules only.103
#104
# A delegating language must never need a private module, and the genre this105
# phase ships is the first proof of that inside this package rather than in a106
# test-only stand-in.107
probe_log="$gate_dir/profiles.log"108
cat >"$gate_dir/profile-probe.sgl" <<'PROBE'109
(import (sigil core) (sigil doc reader) (sigil doc book reader))110
(define (show label profile)111
(display label)112
(display " name=") (write (document-profile-name profile))113
(display " roots=") (write (document-profile-roots profile))114
(display " mult=") (write (document-profile-multiplicity profile))115
(newline))116
(show "SD_P8_PROFILE base" sigil-doc-profile)117
(show "SD_P8_PROFILE book" sigil-doc-book-profile)118
PROBE119
setsid -w "$sigil" -L src -L "$gate_dir" eval -f "$gate_dir/profile-probe.sgl" \120
>"$probe_log" 2>&1 || { cat "$probe_log" >&2; die "arm 01: the profile probe did not run"; }121
rg -q 'SD_P8_PROFILE base name="sigil/doc" roots=\(article\) mult=one' "$probe_log" \122
|| { cat "$probe_log" >&2; die "arm 01: the base profile is not D8's"; }123
rg -q 'SD_P8_PROFILE book name="sigil/doc/book" roots=\(chapter\) mult=one' "$probe_log" \124
|| { cat "$probe_log" >&2; die "arm 01: the genre profile is not D8's"; }125
pass 1 "both shipped profiles are D8's, reached through public modules alone"127
# ---------------------------------------------------------------- ARM 02128
# The dropped kind, checked as a CLASS rather than as a spelling.129
#130
# A refusal by name, a positive control that the two surviving kinds still131
# construct, and -- because a ruling that creates a rule must be checked against132
# the POPULATION and not only against the diff -- a sweep of every133
# `make-document` call site in the tree.134
kind_log="$gate_dir/kind.log"135
cat >"$gate_dir/kind-probe.sgl" <<'PROBE'136
(import (sigil core) (sigil syntax) (sigil doc))137
(define loc (make-srcloc "k.sgd" 1 1 0 1))138
(define (body) (list (make-paragraph (list (make-text "b" loc)) loc)))139
;; The VALUE on success, not a marker: `(guard ... (thunk) "NO-RAISE")` discards140
;; what the thunk returned and reports success identically for every kind, which141
;; would make the two positive controls below unable to tell article from page.142
(define (outcome thunk) (guard (exn (else (exception-message exn))) (thunk)))143
(define (try kind)144
(display "SD_P8_KIND ") (display kind) (display " :: ")145
(write (outcome (lambda () (symbol->string (document-kind (make-document kind "T" (list "A") (body) loc))))))146
(newline))147
(try 'article)148
(try 'chapter)149
(try 'book)150
(try 'page)151
PROBE152
setsid -w "$sigil" -L src -L "$gate_dir" eval -f "$gate_dir/kind-probe.sgl" \153
>"$kind_log" 2>&1 || { cat "$kind_log" >&2; die "arm 02: the kind probe did not run"; }154
rg -q '^SD_P8_KIND book :: "make-document: kind must be article or chapter"$' "$kind_log" \155
|| { cat "$kind_log" >&2; die "arm 02: make-document did not refuse the dropped kind by name"; }156
rg -q '^SD_P8_KIND page :: "make-document: kind must be article or chapter"$' "$kind_log" \157
|| { cat "$kind_log" >&2; die "arm 02: make-document did not refuse an unrelated kind, so the enum is not closed"; }158
# POSITIVE CONTROLS: a constructor that refused everything satisfies both above.159
rg -q '^SD_P8_KIND article :: "article"$' "$kind_log" \160
|| { cat "$kind_log" >&2; die "arm 02: article is no longer constructible -- folio's publication lowering depends on it"; }161
rg -q '^SD_P8_KIND chapter :: "chapter"$' "$kind_log" \162
|| { cat "$kind_log" >&2; die "arm 02: chapter is no longer constructible"; }163
# THE POPULATION, NOT THE DIFF -- and it needs an exception class, which the164
# first version of this sweep did not have.165
#166
# WHAT WENT WRONG, because it is the interesting part. The sweep was167
# "every `(make-document` site in the tree; any naming `'book` is a finding",168
# and it fired on `test/test-root-profile.sgl`, where two sites construct169
# `'book` DELIBERATELY inside `assert-error` to prove the kind is refused. The170
# sweep could not tell a violation from the test that guards against171
# violations, so it was red on a healthy tree. It was never seen green: the172
# sabotage suite reached this arm before any full gate run did, on a leg aimed173
# at something else entirely.174
#175
# The repair is not to exclude `test/`, which would gut the sweep. It is to176
# CLASSIFY every site and print one row each, so the output length is the177
# denominator and an unclassified site fails loudly:178
#179
# * in `src/`, `tools/` or `book/` -- shipped or product code -- a `'book`180
# site is a violation, full stop;181
# * in `test/` it is legitimate ONLY as a refusal test, which means the site182
# sits inside an `assert-error` or a captured-message form;183
# * anything else is UNCLASSIFIED and fails, because "I could not tell" and184
# "it is fine" must not print the same way.185
#186
# And at least one NEGATIVE-TEST site is REQUIRED. Without one, nothing in the187
# tree exercises the refusal at a call site and this arm would be asserting an188
# absence with no positive control -- which passes for free.189
sites="$gate_dir/make-document-sites.txt"190
{ rg -n --no-heading "\(make-document " src test tools book || true; } >"$sites"191
site_count=$(wc -l <"$sites")192
# A FLOOR, labelled: this is not a restatement of the current count, it is the193
# level below which the sweep has plainly lost its population.194
test "$site_count" -ge 20 \195
|| die "arm 02: the sweep found only $site_count make-document sites; it is not examining the tree"197
book_ledger="$gate_dir/book-kind-sites.txt"198
: >"$book_ledger"199
violations=0; negative_tests=0; unclassified=0200
while IFS= read -r hit; do201
test -n "$hit" || continue202
path="${hit%%:*}"203
rest="${hit#*:}"204
lineno="${rest%%:*}"205
case "$path" in206
src/*|tools/*|book/*)207
violations=$((violations + 1))208
printf 'VIOLATION %s:%s (product code must not construct the dropped kind)\n' \209
"$path" "$lineno" >>"$book_ledger" ;;210
test/*)211
# The site's own line plus one either side: a refusal test wraps the212
# construction in a form that CAPTURES the raise.213
window=$(sed -n "$((lineno > 1 ? lineno - 1 : 1)),$((lineno + 1))p" "$path")214
if printf '%s' "$window" | rg -q 'assert-error|message \(lambda'; then215
negative_tests=$((negative_tests + 1))216
printf 'NEGATIVE-TEST %s:%s (constructs it to prove it is refused)\n' \217
"$path" "$lineno" >>"$book_ledger"218
else219
unclassified=$((unclassified + 1))220
printf 'UNCLASSIFIED %s:%s (names the dropped kind and is not guarded by a refusal assertion)\n' \221
"$path" "$lineno" >>"$book_ledger"222
fi ;;223
*)224
unclassified=$((unclassified + 1))225
printf 'UNCLASSIFIED %s:%s (outside every classified directory)\n' \226
"$path" "$lineno" >>"$book_ledger" ;;227
esac228
done < <( { rg -n --no-heading "\(make-document '?book" src test tools book || true; } )229
cat "$book_ledger"230
book_rows=$(wc -l <"$book_ledger")231
book_hits=$( { rg -c "\(make-document '?book" "$sites" || true; } )232
test "$book_rows" -eq "${book_hits:-0}" \233
|| die "arm 02: found ${book_hits:-0} sites naming the dropped kind but classified $book_rows of them"234
test "$violations" -eq 0 \235
|| { rg '^VIOLATION' "$book_ledger" >&2; die "arm 02: $violations product call sites still construct the dropped kind"; }236
test "$unclassified" -eq 0 \237
|| { rg '^UNCLASSIFIED' "$book_ledger" >&2; die "arm 02: $unclassified sites name the dropped kind and could not be classified"; }238
test "$negative_tests" -ge 1 \239
|| die "arm 02: no test constructs the dropped kind to prove it is refused, so this sweep's absence claim has no positive control"240
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"242
# ---------------------------------------------------------------- ARM 03243
# (ARM 05 below carries the differential; arms 2 and 3 are the cheap ones and244
# run first -- see the ordering note in this file's header.)245
# THE CORPUS CENSUS, with its denominator and an explicit not-checked class.246
#247
# Every `.sgd` in the tree is classified by (declared language, root command) and248
# every one must land in a combination its own language admits. "No bad249
# manuscripts found" and "every manuscript was examined" are different claims;250
# this arm prints one row per manuscript so the output length is the second one.251
census="$gate_dir/census.txt"252
: >"$census"253
total=0; base_lang=0; book_lang=0; other_lang=0; negative=0; bad=0; unknown_lang=0254
while IFS= read -r m; do255
total=$((total + 1))256
lang=$(head -1 "$m" | sed -n 's|^#lang \(.*\)$|\1|p')257
root=$( { rg -o -m1 '^@[a-z][a-z-]*' "$m" || echo "@NONE"; } | head -1)258
# THREE CLASSES, AND `UNCHECKED` HAS TO BE REACHABLE OR THE PASS LINE LIES.259
#260
# The first version defaulted `verdict=UNCHECKED` and then overwrote it on261
# EVERY branch -- the inner catch-all made everything either OK or ILLEGAL --262
# so "0 unclassified" was vacuously true. A guard against a state the code263
# makes unreachable is not a denominator, it is decoration.264
#265
# The class that genuinely exists is: a language THIS GATE DOES NOT KNOW.266
# That is different from a manuscript being wrong, and conflating the two is267
# the actual risk here -- a `#lang folio/doc` fixture added later would be268
# reported ILLEGAL, which is false, or would need this arm silently widened.269
# So an unknown language is UNCHECKED and FAILS, which forces whoever adds a270
# language to say what its legal roots are.271
verdict=UNCHECKED272
case "$m" in273
*/sd-p8-base-*|*/sd-p8-book-article-root.sgd|*/sd-p8-book-two-chapters.sgd)274
verdict=NEGATIVE-FIXTURE; negative=$((negative + 1)) ;;275
*)276
case "$lang" in277
"sigil/doc"|"sigil/doc/book"|"sd-p7/folio")278
case "$lang::$root" in279
"sigil/doc::@article") verdict=OK; base_lang=$((base_lang + 1)) ;;280
"sigil/doc/book::@chapter") verdict=OK; book_lang=$((book_lang + 1)) ;;281
"sigil/doc::@note") verdict=OK-EXPLICIT-PROFILE; other_lang=$((other_lang + 1)) ;;282
"sd-p7/folio::@note") verdict=OK-OTHER-LANGUAGE; other_lang=$((other_lang + 1)) ;;283
*) verdict=ILLEGAL; bad=$((bad + 1)) ;;284
esac ;;285
*) verdict=UNCHECKED; unknown_lang=$((unknown_lang + 1)) ;;286
esac ;;287
esac288
printf '%-22s %-16s %-9s %s\n' "$verdict" "$lang" "$root" "$m" >>"$census"289
done < <(find book test -name '*.sgd' | sort)290
cat "$census"291
rows=$(wc -l <"$census")292
test "$rows" -eq "$total" || die "arm 03: examined $total manuscripts but printed $rows rows"293
test "$total" -ge 27 || die "arm 03: the census found only $total manuscripts; the population is wrong"294
test "$bad" -eq 0 || { rg '^ILLEGAL' "$census" >&2; die "arm 03: $bad manuscripts declare a language that does not admit their root"; }295
# The `unknown language` class, counted from the rows and cross-checked against296
# the loop's own counter -- two independently produced numbers, because a loop297
# cannot audit itself.298
unchecked=$( { rg -c '^UNCHECKED' "$census" || true; } )299
test "${unchecked:-0}" -eq "$unknown_lang" \300
|| die "arm 03: $unknown_lang unknown-language manuscripts counted but ${unchecked:-0} rows printed"301
test "${unchecked:-0}" -eq 0 \302
|| { rg '^UNCHECKED' "$census" >&2303
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"; }304
test "$base_lang" -ge 1 || die "arm 03: no manuscript exercises the base language"305
test "$book_lang" -ge 15 || die "arm 03: only $book_lang manuscripts moved to the genre language"306
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"308
# ---------------------------------------------------------------- ARM 04309
# END TO END through the real `#lang` path: the two REQUIRED GREENS and the four310
# REQUIRED REDS, each named, plus the reader-level diagnostic every refusal311
# carries. See the probe's header for why the diagnostic has to be re-derived at312
# the reader (the compiler's `#lang` loader drops it -- measured, pre-existing).313
lang_log="$gate_dir/language.log"314
setsid -w "$sigil" -L src -L test eval -f test/sd-p8-language-probe.sgl \315
>"$lang_log" 2>&1 || { cat "$lang_log" >&2; die "arm 04: the language probe did not run"; }316
# THE DENOMINATOR, derived from the probe's source and cross-checked against the317
# lines it printed. A probe whose cases were deleted still satisfies every318
# individual assertion below; only the count can see that.319
declared=$(rg -c '^ \(list "' test/sd-p8-language-probe.sgl)320
printed=$(rg -c '^SD_P8_LANG ' "$lang_log" || echo 0)321
test "$declared" -ge 6 || die "arm 04: the probe declares only $declared cases"322
test "$printed" -eq "$declared" \323
|| die "arm 04: the probe declares $declared cases but printed $printed"324
rg -q "SD_P8_LANGUAGE_PROBE_COMPLETE cases $declared matched $declared mismatched 0" "$lang_log" \325
|| { rg -n 'MISMATCH|SD_P8_LANGUAGE_PROBE_COMPLETE' "$lang_log" >&2326
die "arm 04: not every case matched its expected verdict"; }327
# Each REQUIRED RED by name, with the diagnostic that must accompany it. The328
# language NAME in each message is the load-bearing part: a genre language329
# reporting `sigil/doc:` would send an author to the wrong documentation.330
rg -q '^SD_P8_DIAG base-refuses-chapter :: "sigil/doc: top-level author forms must precede exactly one @article"$' "$lang_log" \331
|| die "arm 04: the base language did not refuse @chapter with its own diagnostic"332
rg -q '^SD_P8_DIAG base-refuses-two :: "sigil/doc: top-level author forms must precede exactly one @article"$' "$lang_log" \333
|| die "arm 04: the base language did not refuse a second @article"334
rg -q '^SD_P8_DIAG book-refuses-article :: "sigil/doc/book: top-level author forms must precede exactly one @chapter"$' "$lang_log" \335
|| die "arm 04: the genre language did not refuse @article naming sigil/doc/book"336
rg -q '^SD_P8_DIAG book-refuses-two :: "sigil/doc/book: top-level author forms must precede exactly one @chapter"$' "$lang_log" \337
|| die "arm 04: the genre language did not refuse a second @chapter naming sigil/doc/book"338
# THE POSITIVE CONTROLS. Four refusals are satisfied by a reader that refuses339
# everything; these two are not.340
rg -q '^SD_P8_LANG base-accepts-article want=accept got=accept MATCH kind-or-error="article"$' "$lang_log" \341
|| die "arm 04: #lang sigil/doc did not accept its own root"342
rg -q '^SD_P8_LANG book-accepts-chapter want=accept got=accept MATCH kind-or-error="chapter"$' "$lang_log" \343
|| die "arm 04: #lang sigil/doc/book did not accept its own root"344
rg -q '^SD_P8_DIAG base-accepts-article :: "NO-RAISE"$' "$lang_log" \345
|| die "arm 04: the base reader raised on the manuscript it must accept"346
rg -q '^SD_P8_DIAG book-accepts-chapter :: "NO-RAISE"$' "$lang_log" \347
|| die "arm 04: the genre reader raised on the manuscript it must accept"348
# THE `#lang`-LAYER MESSAGE, and why this is a two-branch assertion rather than349
# one.350
#351
# Until sigil 0.19.1 the compiler's language loader reported a reader's refusal352
# as `read-language-source failed for #lang <x>:` with NOTHING after the colon:353
# the error path read a buffer only C-raised errors populate, and readers are354
# written in Sigil. sigil commit 9a523988 ("fix(compiler): carry the reader's355
# own diagnostic into the #lang error") fixed it in v0.19.1. Measured 2026-08-22356
# against ONE tree with only the compiler varied:357
#358
# 0.19.0 (b99b8f2d): ... for #lang sigil/doc:359
# 0.19.1 (3d0668a0): ... for #lang sigil/doc: error: sigil/doc: top-level360
# author forms must precede exactly one @chapter361
#362
# This gate runs on the estate's PINNED dev compiler, which every other gate in363
# this repo shares, and moving it here alone would produce a measurement nobody364
# can compare against the others. So the expectation is chosen from the version365
# this gate already records -- and BOTH branches assert. A single "if it carries366
# text, the text must be right" would be vacuous on the older compiler, which is367
# precisely the shape that lets a gate pass for free.368
#369
# An unparseable version FAILS rather than falling through to the older branch:370
# taking the weaker expectation because a `sed` did not match is the same371
# vacuous green wearing a different hat.372
checked_layer=0373
version_line=$("$sigil" --version 2>&1 | sed 's/\x1b\[[0-9;]*m//g')374
compiler_version=$(printf '%s' "$version_line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)375
test -n "$compiler_version" \376
|| die "arm 04: could not parse a version out of '$version_line'; the #lang-layer expectation cannot be chosen, and guessing it would make this arm vacuous"377
as_number() { echo "$1" | awk -F. '{printf "%d%03d%03d", $1, $2, $3}'; }378
carries_floor=0.19.1379
if [ "$(as_number "$compiler_version")" -ge "$(as_number "$carries_floor")" ]; then380
lang_layer="carries"381
else382
lang_layer="empty"383
fi384
echo " #lang layer: compiler $compiler_version -> expecting the message to be '$lang_layer' (floor $carries_floor)"385
# One row per refusal case: language, and the diagnostic that language must386
# produce. The loop's length is the denominator -- a case dropped from it stops387
# being checked silently otherwise.388
while read -r case_name diag; do389
test -n "$case_name" || continue390
if [ "$lang_layer" = "carries" ]; then391
rg -q "^SD_P8_LANG $case_name .* kind-or-error=\".*: error: $diag\"\$" "$lang_log" \392
|| { rg -n "^SD_P8_LANG $case_name " "$lang_log" >&2393
die "arm 04: on sigil $compiler_version the #lang error must carry '$diag', and for $case_name it does not"; }394
else395
rg -q "^SD_P8_LANG $case_name .* kind-or-error=\"read-language-source failed for #lang [a-z/]+: \"\$" "$lang_log" \396
|| { rg -n "^SD_P8_LANG $case_name " "$lang_log" >&2397
die "arm 04: sigil $compiler_version predates $carries_floor, so the #lang error must be empty after the colon; for $case_name it is not -- re-read this block before changing anything, the expectation may simply be stale"; }398
fi399
checked_layer=$((checked_layer + 1))400
done <<'ROWS'401
base-refuses-chapter sigil/doc: top-level author forms must precede exactly one @article402
base-refuses-two sigil/doc: top-level author forms must precede exactly one @article403
book-refuses-article sigil/doc/book: top-level author forms must precede exactly one @chapter404
book-refuses-two sigil/doc/book: top-level author forms must precede exactly one @chapter405
ROWS406
test "${checked_layer:-0}" -eq 4 \407
|| die "arm 04: the #lang-layer loop checked ${checked_layer:-0} cases, not 4"408
pass 4 "$printed of $declared #lang cases matched: 4 required reds named by language and root, 2 required greens; #lang layer '$lang_layer' on sigil $compiler_version, $checked_layer of 4 checked"410
# ---------------------------------------------------------------- ARM 05411
# THE D8 DIFFERENTIAL. Both sides generated in one run.412
#413
# The claim: across the whole manuscript corpus, the ONLY manuscripts whose414
# lowering changed are the ones whose ROOT COMMAND this phase changed, and for415
# each of those the change is EXACTLY the root symbol. The 17 manuscripts416
# that took a header edit alone lower identically.417
#418
# What makes that assertable is `test/sd-p8-lowering-dump.sgl`, which emits every419
# manuscript position relative to that manuscript's own header end. Read its420
# header: the header delta reaches the lowered output in THREE places, and the421
# third (the generated binding name `#%sigil/doc-expression:<offset>`) is one422
# nobody would predict from reading the parser.423
git rev-parse --verify "$base_sha^{commit}" >/dev/null 2>&1 \424
|| die "arm 05: baseline superseded -- base $base_sha is not a commit in this repository; see the retirement notice in test/gate-sd-p3.sh"425
git merge-base --is-ancestor "$base_sha" HEAD \426
|| die "arm 05: baseline superseded -- HEAD no longer descends from $base_sha, so this differential compares nothing this branch is a delta from; re-scope it to the new base and record the ruling, as gate-sd-p1.sh arms 3 and 5 did"428
base_tree="$gate_dir/base-tree"429
cleanup() { git -C "$repo_dir" worktree remove --force "$base_tree" >/dev/null 2>&1 || true; }430
# Unconditional, not merely reached: an early exit between `worktree add` and the431
# end of this script would otherwise leave a stray worktree in a SHARED .git.432
trap cleanup EXIT INT TERM433
git worktree add --detach "$base_tree" "$base_sha" >/dev/null 2>&1 \434
|| die "arm 05: could not create a detached worktree at $base_sha"436
# THE SAME FILE ON BOTH SIDES. An instrument that differs between the two sides437
# of a differential measures itself. The base tree predates this script, so it is438
# copied in -- and its hash is asserted equal afterwards, because "I copied it"439
# and "the copy is the same file" are different claims.440
cp test/sd-p8-lowering-dump.sgl "$base_tree/test/"441
here_hash=$(sha256sum test/sd-p8-lowering-dump.sgl | awk '{print $1}')442
there_hash=$(sha256sum "$base_tree/test/sd-p8-lowering-dump.sgl" | awk '{print $1}')443
test "$here_hash" = "$there_hash" || die "arm 05: the two sides are not running the same dump script"445
# `dev-redirects.sgl` resolves `../sigil` relative to the package root and the446
# base worktree is not a sibling of that checkout, so an absolute one is written.447
sigil_repo="$(cd "$repo_dir/../sigil" && pwd)"448
sxml_repo="$(cd "$sxml_root" && pwd)"449
cat >"$gate_dir/base-redirects.sgl" <<EOF450
(redirects451
repos: (list452
(for-repo url: "codeberg:sigil/sigil"453
use: (from-path dir: "$sigil_repo"))454
(for-repo url: "codeberg:sigil/sigil-sxml"455
use: (from-path dir: "$sxml_repo"))))456
EOF458
after_dump="$gate_dir/after.txt"459
before_dump="$gate_dir/before.txt"460
setsid -w "$sigil" -L src -L test eval -f test/sd-p8-lowering-dump.sgl >"$after_dump" 2>&1 || true461
( cd "$base_tree" && SIGIL_REDIRECTS="$gate_dir/base-redirects.sgl" \462
XDG_CACHE_HOME="$gate_dir/base-cache" \463
setsid -w "$sigil" -L src -L test eval -f test/sd-p8-lowering-dump.sgl ) >"$before_dump" 2>&1 || true464
for side in after before; do465
f="$gate_dir/$side.txt"466
rg -q '^SD_P8_LOWERING_DUMP_COMPLETE ' "$f" \467
|| { tail -25 "$f" >&2; die "arm 05: the $side dump printed no completion marker"; }468
done470
# One directory of sections per side. The completion marker is EXCLUDED: it names471
# the corpus size, so leaving it in would tie the LAST manuscript's section to how472
# many manuscripts were dumped -- a difference with nothing to do with lowering.473
# The MANIFEST/SKIPPED lines are excluded too: they carry the language id, the474
# header length and the root command, which is exactly what legitimately differs.475
split() { # $1 = dump, $2 = out dir476
mkdir -p "$2"477
awk -v o="$2" '/^SD_P8_/{next} /^--- /{name="";next} /^=== /{name=$2} name!=""{print > (o "/" name)}' "$1"478
}479
split "$after_dump" "$gate_dir/sec-after"480
split "$before_dump" "$gate_dir/sec-before"482
# The SECOND, INDEPENDENT INSTRUMENT. The root command of each manuscript is read483
# as TEXT by the dump's own scanner and printed on the MANIFEST line, so the set484
# of manuscripts that MUST differ is derived without asking the lowering -- the485
# thing under test -- what it thinks a root was.486
manifest() { # $1 = dump -> "name root"487
rg -o '^--- MANIFEST \S+ lang=\S+ header=\d+ root=\S+' "$1" \488
| awk '{r=$NF; sub(/^root=/,"",r); print $3, r}' | sort489
}490
manifest "$after_dump" >"$gate_dir/roots-after"491
manifest "$before_dump" >"$gate_dir/roots-before"493
ledger="$gate_dir/ledger.txt"494
: >"$ledger"495
identical=0; expected_change=0; unexpected=0; only_after=0; only_before=0; compared=0496
# ONE LINE PER MANUSCRIPT, not one line per failure: the output length is the497
# denominator, and a manuscript that quietly stopped being examined is visible498
# without anyone counting.499
for f in "$gate_dir/sec-after"/*; do500
name="${f##*/}"501
compared=$((compared + 1))502
b="$gate_dir/sec-before/$name"503
root_a=$(awk -v n="$name" '$1==n{print $2}' "$gate_dir/roots-after")504
root_b=$(awk -v n="$name" '$1==n{print $2}' "$gate_dir/roots-before")505
if [ ! -f "$b" ]; then506
only_after=$((only_after + 1))507
printf 'AFTER-ONLY %-40s root=%s (the base tree could not lower it)\n' "$name" "$root_a" >>"$ledger"508
continue509
fi510
if cmp -s "$f" "$b"; then511
identical=$((identical + 1))512
printf 'IDENTICAL %-40s root=%s\n' "$name" "$root_a" >>"$ledger"513
test "$root_a" = "$root_b" \514
|| die "arm 05: $name lowers identically yet its root moved $root_b -> $root_a; the normalization is hiding a real difference"515
continue516
fi517
if [ "$root_a" = "$root_b" ]; then518
unexpected=$((unexpected + 1))519
printf 'UNEXPECTED %-40s root=%s unchanged, lowering differs\n' "$name" "$root_a" >>"$ledger"520
continue521
fi522
# A root-changed manuscript must differ by EXACTLY the root symbol. Substituting523
# the old symbol for the new one in the BEFORE section must reproduce the AFTER524
# section byte for byte -- a far stronger statement than "it changed, as525
# predicted", and the one that would catch a migration that also moved content.526
old="${root_b#@}"; new="${root_a#@}"527
# THE SUBSTITUTION MUST BE UNAMBIGUOUS BEFORE IT IS TRUSTED, and it must be528
# BOUNDED. A rewrite that could match something other than the root symbol529
# would MASK a real difference, which is the one direction a differential must530
# never fail in. Three conditions:531
#532
# * after the change the old spelling must be gone entirely, and before it533
# the new spelling must not have existed -- so the mapping is a bijection534
# on this pair of sections;535
# * the rewrite must change SOMETHING, or the comparison below is between536
# the two sections unmodified and a genuine root-only change would read as537
# UNEXPECTED for the wrong reason;538
# * and it must change AT MOST as many occurrences as a root can account539
# for. A `/g` substitution over the whole section would also rewrite a540
# NESTED generated `chapter` head, so a manuscript that changed its root541
# AND some other command of the same name would report "nothing else542
# moved". The root appears twice in a lowered manuscript -- once in the543
# generated command head and once in the `author-flatten` command-name544
# argument -- so more than two is a second construct, not the root.545
if [ "$( { rg -cF "]] $new>" "$b" || true; } )" != "" ] \546
|| [ "$( { rg -cF "]] $old>" "$f" || true; } )" != "" ]; then547
unexpected=$((unexpected + 1))548
printf 'UNEXPECTED %-40s root=%s -> %s, but the two spellings overlap; refusing to rewrite\n' \549
"$name" "$root_b" "$root_a" >>"$ledger"550
continue551
fi552
occurrences=$( { rg -oF "]] $old>" "$b" || true; } | wc -l)553
if [ "$occurrences" -lt 1 ] || [ "$occurrences" -gt 2 ]; then554
unexpected=$((unexpected + 1))555
printf 'UNEXPECTED %-40s root=%s -> %s, but %s generated `%s` heads is not a root alone; refusing to rewrite\n' \556
"$name" "$root_b" "$root_a" "$occurrences" "$old" >>"$ledger"557
continue558
fi559
sed "s/\]\] $old>/]] $new>/g" "$b" >"$gate_dir/rewritten-$name"560
cmp -s "$b" "$gate_dir/rewritten-$name" \561
&& die "arm 05: the root rewrite for $name changed nothing, so its root symbol is not where this arm thinks it is"562
if cmp -s "$f" "$gate_dir/rewritten-$name"; then563
expected_change=$((expected_change + 1))564
printf 'ROOT-ONLY %-40s root=%s -> %s, nothing else moved\n' "$name" "$root_b" "$root_a" >>"$ledger"565
else566
unexpected=$((unexpected + 1))567
printf 'UNEXPECTED %-40s root=%s -> %s, and MORE than the root moved\n' "$name" "$root_b" "$root_a" >>"$ledger"568
fi569
done570
for f in "$gate_dir/sec-before"/*; do571
name="${f##*/}"572
if [ ! -f "$gate_dir/sec-after/$name" ]; then573
only_before=$((only_before + 1))574
printf 'BEFORE-ONLY %-40s (this tree can no longer lower it)\n' "$name" >>"$ledger"575
fi576
done577
cat "$ledger"579
# THE DENOMINATOR, stated against the dumps' own totals rather than against the580
# ledger the loop just wrote -- a loop cannot audit itself.581
after_found=$(rg -o 'SD_P8_LOWERING_DUMP_COMPLETE found \d+' "$after_dump" | awk '{print $NF}')582
after_compared=$(rg -o 'compared \d+' "$after_dump" | awk '{print $NF}')583
before_compared=$(rg -o 'compared \d+' "$before_dump" | awk '{print $NF}')584
test "$compared" -eq "$after_compared" \585
|| die "arm 05: the dump lowered $after_compared manuscripts but the ledger holds $compared"586
echo " denominator: after found $after_found, lowered $after_compared; before lowered $before_compared; ledger rows $((compared + only_before))"588
# `only_after` and `skipped` ARE ASSERTED, and the first version of this arm did589
# not assert either. A count nobody asserts on is a count nobody is checking:590
# `test/fixtures/sd-p1-article-root.sgd` had its whole body rewritten by this591
# phase (+10 -9) and passed through this ledger as `AFTER-ONLY ... the base tree592
# could not lower it`, which is TRUE and says nothing about its content. The593
# after-only class is legitimate but it is not free: each member must be named594
# in advance, so a manuscript joining it is a decision rather than an accident.595
#596
# Both expected members are here for a REASON, not merely listed:597
# sd-p1-article-root.sgd root `@article`; the base profile at the base SHA598
# was `(chapter)` and refused it. D8 is exactly the599
# change that makes it lowerable, so its appearance600
# here is the phase's headline effect, not a gap.601
# sd-p8-book-chapter-root.sgd added by this phase; no base-side counterpart602
# can exist.603
expected_after_only="$gate_dir/expected-after-only"604
printf 'sd-p1-article-root.sgd\nsd-p8-book-chapter-root.sgd\n' | sort >"$expected_after_only"605
actual_after_only="$gate_dir/actual-after-only"606
{ rg '^AFTER-ONLY' "$ledger" || true; } | awk '{print $2}' | sort >"$actual_after_only"607
diff -u "$expected_after_only" "$actual_after_only" >"$gate_dir/after-only.diff" \608
|| { cat "$gate_dir/after-only.diff" >&2609
die "arm 05: the set of manuscripts only the current tree can lower is not the set this phase intends"; }610
test "$only_after" -eq "$(wc -l <"$expected_after_only")" \611
|| die "arm 05: $only_after after-only rows for $(wc -l <"$expected_after_only") expected names"612
# A CONTENT REWRITE OF AN AFTER-ONLY MANUSCRIPT IS STILL A CHANGE, and the613
# differential structurally cannot see it (there is no before-side section to614
# compare). Saying so is the honest disposition; hiding it behind a passing615
# ledger row is not. The suite is what covers these: `test/test-root-profile.sgl`616
# evaluates `sd-p1-article-root.sgd` through the shipped base profile and asserts617
# its kind and title, and `test/sd-p8-language-probe.sgl` loads618
# `sd-p8-book-chapter-root.sgd` through the real `#lang` path.619
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"620
# THE SKIPPED SETS, COMPARED BY NAME. The first version of this check compared621
# COUNTS and required `after <= before`, which was simply wrong: this phase adds622
# four manuscripts that are DELIBERATELY unlowerable (the negative fixtures the623
# language probe drives), so the after side legitimately skips more. The gate624
# caught it loudly on its first run with "something stopped being lowerable",625
# which was false -- a count cannot tell "a manuscript regressed" from "a626
# manuscript was added to be refused". Only the names can.627
#628
# Two directions, both asserted:629
# * a manuscript the base tree could LOWER must not have become skippable --630
# that is the regression this check exists for;631
# * a manuscript newly skipped must be one this phase ADDED, which is derived632
# from git rather than listed here.633
skipped_names() { rg -o '^--- SKIPPED \S+' "$1" | awk '{print $3}' | sort; }634
skipped_names "$after_dump" >"$gate_dir/skipped-after"635
skipped_names "$before_dump" >"$gate_dir/skipped-before"636
comm -13 "$gate_dir/skipped-before" "$gate_dir/skipped-after" >"$gate_dir/newly-skipped"637
comm -23 "$gate_dir/skipped-before" "$gate_dir/skipped-after" >"$gate_dir/no-longer-skipped"638
git diff --name-only --diff-filter=A "$base_sha" HEAD -- '*.sgd' \639
| sed 's|.*/||' | sort >"$gate_dir/added-manuscripts"640
while read -r n; do641
test -n "$n" || continue642
grep -Fxq -- "$n" "$gate_dir/added-manuscripts" \643
|| { echo "newly skipped: $n" >&2644
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"; }645
done <"$gate_dir/newly-skipped"646
# The other direction is a GAIN, not a fault, but it must still be named: a647
# manuscript that stopped being skipped is one D8 made lowerable, and it has to648
# be in the after-only set the arm already pins.649
while read -r n; do650
test -n "$n" || continue651
grep -Fxq -- "$n" "$expected_after_only" \652
|| { echo "no longer skipped: $n" >&2653
die "arm 05: $n became lowerable and is not in this arm's expected after-only set"; }654
done <"$gate_dir/no-longer-skipped"655
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"657
# A FLOOR, deliberately, not a restatement: adding a manuscript must not658
# desynchronise this, and a corpus that collapsed must not read as a pass.659
test "$identical" -ge 15 \660
|| die "arm 05: only $identical manuscripts lower identically; the migration moved more than the header"661
test "$expected_change" -ge 1 \662
|| die "arm 05: no manuscript changed its root, so the root-only comparison never ran and proves nothing"663
test "$unexpected" -eq 0 \664
|| { rg '^UNEXPECTED' "$ledger" >&2; die "arm 05: $unexpected manuscripts changed for a reason this phase did not intend"; }665
test "$only_before" -eq 0 \666
|| { rg '^BEFORE-ONLY' "$ledger" >&2; die "arm 05: this tree stopped being able to lower a manuscript the base tree could"; }667
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"669
# ---------------------------------------------------------------- ARM 06670
# THE CONSTRUCTION DIFFERENTIAL, replacing `test/gate-sd-p7.sh` arm 02.671
#672
# Arm 5 above compares LOWERING -- emitted syntax. This compares the CONSTRUCTED673
# document, which is a different property and the one SD-P7 owns: a lowering674
# differential is byte-identical under a completely broken content profile. When675
# arm 02 of gate-sd-p7 was retired (its baseline is pinned to absolute byte676
# offsets that a `#lang` edit shifts), that property lost its standing check, and677
# retiring without replacing loses a property.678
#679
# THE ONE DESIGN DECISION, and it is the lesson of the retirement it replaces:680
# THIS ARM ASSERTS ON STRUCTURE, NOT ON POSITIONS. `document->string` embeds681
# every node's `(file pos line col span)`. Comparing those verbatim is precisely682
# what made the old baseline unmaintainable, so every location TUPLE belonging683
# to a manuscript is normalised to the marker `L` before comparison. What684
# remains is the document's shape and every non-positional field: kinds, titles,685
# authors, ids, text, the tree.686
#687
# That is deliberately weaker than the arm it replaces, and the weakening is688
# named rather than glossed: THIS ARM CANNOT SEE A PURE LOCATION REGRESSION.689
# Locations are covered instead by arm 5 (which asserts them header-relative,690
# so it sees any shift that is not the header's) and by691
# `test/test-root-profile.sgl`, whose location assertions recompute every692
# expected byte offset, line and column independently.693
before_c="$gate_dir/construction-before.txt"694
after_c="$gate_dir/construction-after.txt"695
setsid -w bash test/sd-p7-construction-dump.sh "$after_c" >"$gate_dir/construction-after.log" 2>&1 \696
|| { tail -20 "$gate_dir/construction-after.log" >&2; die "arm 06: the construction dump failed on this tree"; }697
( cd "$base_tree" \698
&& cp "$repo_dir/test/sd-p7-construction-dump.sh" test/ \699
&& SIGIL_D1_REDIRECTS="$gate_dir/base-redirects.sgl" \700
SIGIL_D1_COMPILER="$sigil" \701
setsid -w bash test/sd-p7-construction-dump.sh "$before_c" ) \702
>"$gate_dir/construction-before.log" 2>&1 \703
|| { tail -20 "$gate_dir/construction-before.log" >&2; die "arm 06: the construction dump failed on the base tree"; }704
for side in "$before_c" "$after_c"; do705
rg -q 'SD_P7_CONSTRUCTION_DUMP_COMPLETE' "$side" \706
|| { tail -10 "$side" >&2; die "arm 06: a construction dump printed no completion marker"; }707
done709
# The location normaliser, and the marker line excluded for the reason SD-P3's710
# gate learned the hard way: it names the corpus size, so leaving it in ties the711
# LAST manuscript's record to how many manuscripts were dumped.712
split_construction() { # $1 = dump, $2 = out dir713
mkdir -p "$2"714
grep -v '^SD_P7_CONSTRUCTION_DUMP_COMPLETE' "$1" \715
| sed -E 's/("[^"]*\.sgd") [0-9]+ [0-9]+ [0-9]+ [0-9]+/\1 L/g' \716
| awk -v o="$2" '/^=== /{n=$2; gsub("/","_",n)} n!=""{print > (o "/" n)}'717
}718
split_construction "$before_c" "$gate_dir/con-before"719
split_construction "$after_c" "$gate_dir/con-after"721
# THE NORMALISER MUST BE SHOWN TO HAVE FIRED. A `sed` that matched nothing would722
# make this a verbatim comparison wearing a normaliser's name -- and it would723
# then fail for exactly the reason the retired arm did, with a message about724
# structure.725
#726
# CHECK THE NORMALISED OUTPUT, NOT THE RAW DUMP. The first version of this guard727
# grepped `$after_c`, which is the dump BEFORE `split_construction` runs sed over728
# it, so the marker could never appear there and the guard reddened on a healthy729
# tree. Caught by the guard itself on its first run, which is the only reason a730
# check aimed at one file rather than another is visible at all.731
normalised=$( { rg -c ' L\)' "$gate_dir"/con-after/* || true; } | awk -F: '{n+=$NF} END{print n+0}')732
test "${normalised:-0}" -ge 1 \733
|| die "arm 06: the location normaliser matched nothing in the split records; it is not normalising, so this comparison is not the one described"735
con_ledger="$gate_dir/construction-ledger.txt"736
: >"$con_ledger"737
con_same=0; con_diff=0; con_after_only=0; con_before_only=0738
for f in "$gate_dir/con-before"/*; do739
name="${f##*/}"740
a="$gate_dir/con-after/$name"741
if [ ! -f "$a" ]; then742
con_before_only=$((con_before_only + 1))743
printf 'BEFORE-ONLY %s (this tree no longer constructs it)\n' "$name" >>"$con_ledger"744
elif cmp -s "$f" "$a"; then745
con_same=$((con_same + 1))746
printf 'IDENTICAL %s\n' "$name" >>"$con_ledger"747
else748
con_diff=$((con_diff + 1))749
printf 'DIFFERS %s\n' "$name" >>"$con_ledger"750
fi751
done752
for f in "$gate_dir/con-after"/*; do753
name="${f##*/}"754
test -f "$gate_dir/con-before/$name" || {755
con_after_only=$((con_after_only + 1))756
printf 'AFTER-ONLY %s (added by this phase)\n' "$name" >>"$con_ledger"; }757
done758
cat "$con_ledger"760
# THE EXPECTED DIFFERENCES, NAMED. Anything else is a finding. All three are D8761
# itself: two manuscripts whose root command changed, so their document KIND762
# changed with it, and one that the base tree could not construct at all because763
# its `@article` root was illegal there -- which is the whole point of the phase.764
expected_con="$gate_dir/expected-construction-diffs"765
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"766
{ rg '^DIFFERS' "$con_ledger" || true; } | awk '{print $2}' | sort >"$gate_dir/actual-construction-diffs"767
diff -u "$expected_con" "$gate_dir/actual-construction-diffs" >"$gate_dir/construction.diff" \768
|| { cat "$gate_dir/construction.diff" >&2769
die "arm 06: the constructed documents that changed are not the ones this phase intends"; }770
# And the two kind flips are asserted BY NAME, so "it differs" cannot stand in771
# for "it differs in the way D8 predicts".772
for m in sd-p3-bare-prose sd-p3-wrapped; do773
rg -q '\(document \(kind chapter\)' "$gate_dir/con-before/test_fixtures_$m.sgd" \774
|| die "arm 06: $m was not a chapter at the base, so the kind-flip claim is not about what changed"775
rg -q '\(document \(kind article\)' "$gate_dir/con-after/test_fixtures_$m.sgd" \776
|| die "arm 06: $m is not an article now"777
done778
rg -q 'RAISED' "$gate_dir/con-before/test_fixtures_sd-p1-article-root.sgd" \779
|| die "arm 06: the base tree DID construct sd-p1-article-root.sgd, so D8 is not what made it constructible"780
rg -q '\(document \(kind article\)' "$gate_dir/con-after/test_fixtures_sd-p1-article-root.sgd" \781
|| die "arm 06: sd-p1-article-root.sgd still does not construct"782
test "$con_before_only" -eq 0 \783
|| { rg '^BEFORE-ONLY' "$con_ledger" >&2; die "arm 06: this tree stopped constructing a manuscript the base tree built"; }784
# A FLOOR, labelled: not a restatement of the current count.785
test "$con_same" -ge 15 \786
|| die "arm 06: only $con_same constructed documents are unchanged; the migration moved more than D8 intends"787
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)"789
# ---------------------------------------------------------------- ARM 07790
# REGRESSION. The full suite with the FULL load path -- four entries, because a791
# short path degrades into "failed to load", which the runner reports WITHOUT792
# failing the process. The file count is its own assertion for that reason.793
#794
# `SD_P8_SKIP_REGRESSION` EXISTS FOR ONE CALLER: `test/sabotage-sd-p8.sh`, whose795
# legs would otherwise pay for this suite seven times over to reach a red in an796
# earlier arm. A skipped arm must never read as a passing arm, so it prints797
# SKIPPED rather than a pass line, and the script ends at SD_P8_GATE_PARTIAL798
# instead of SD_P8_GATE_GREEN. The sabotage suite's own positive control runs799
# the gate with this UNSET and requires the GREEN marker, so no leg can be800
# satisfied by a run that skipped anything.801
if [ -n "${SD_P8_SKIP_REGRESSION:-}" ]; then802
printf 'SD_P8_GATE_07 SKIPPED (SD_P8_SKIP_REGRESSION is set)\n'803
echo "SD_P8_GATE_PARTIAL arms 1-6 only; the regression arm did not run"804
exit 0805
fi806
regression_log="$gate_dir/regression.log"807
regression_status=0808
setsid -w "$sigil" -L "$sxml_root/src" -L src -L test -L book test \809
>"$regression_log" 2>&1 || regression_status=$?810
sed -i 's/\x1b\[[0-9;]*m//g' "$regression_log"811
grep -qE 'Tests: +[0-9]+ passed' "$regression_log" \812
|| { tail -40 "$regression_log" >&2; die "arm 07: could not read a suite summary -- the run may not have executed anything"; }813
files_line=$(grep -oE 'Files: +[0-9]+ of [0-9]+ run' "$regression_log" | tail -1 || true)814
test -n "$files_line" || { tail -40 "$regression_log" >&2; die "arm 07: the runner reported no file count"; }815
files_run=$(echo "$files_line" | grep -oE '[0-9]+' | head -1)816
files_found=$(echo "$files_line" | grep -oE '[0-9]+' | tail -1)817
test "$files_run" = "$files_found" || die "arm 07: only $files_run of $files_found test files ran"818
if grep -qE '[0-9]+ failed' "$regression_log"; then819
grep -nE '✗|failed' "$regression_log" | head -30 >&2820
die "arm 07: a test failed"821
fi822
test "$regression_status" = "0" \823
|| { tail -40 "$regression_log" >&2; die "arm 07: the runner exited $regression_status with no failing test reported"; }824
# The root-profile suite's count DERIVED from its own source, and the two arms825
# this phase added named individually: a suite whose arms were deleted still826
# reports "all tests passed".827
expected_arms=$(rg -c '^\(test "' test/test-root-profile.sgl)828
rg -q "test-root-profile" "$regression_log" || die "arm 07: the root-profile suite did not run"829
rg -q "ok +$expected_arms passed +\./test/test-root-profile.sgl" "$regression_log" \830
|| { rg -n 'test-root-profile' "$regression_log" >&2831
die "arm 07: the root-profile suite did not report $expected_arms of its $expected_arms arms"; }832
rg -q 'the book genre language is a sibling profile with its own diagnostics' "$regression_log" \833
|| die "arm 07: the genre-language arm is not in the suite that ran"834
rg -q "the base profile is D8's policy and D8's diagnostics, exactly" "$regression_log" \835
|| die "arm 07: the base-profile arm is not in the suite that ran"836
summary=$(grep -E 'Tests: +[0-9]+ passed' "$regression_log" | tail -1 | tr -s ' ')837
pass 7 "full suite green with -L $sxml_root/src -L src -L test -L book :: $summary, $files_line, root-profile $expected_arms/$expected_arms"839
echo "SD_P8_GATE_GREEN"