AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# SD-P1 gate: the root container as a reader/profile parameter (review B2).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 been7
# fooled by both.8
set -euo pipefail9
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"10
cd "$repo_dir"11
mkdir -p "$repo_dir/build"12
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"13
redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"14
gate_dir=$(mktemp -d "$repo_dir/build/sd-p1-gate.XXXXXX")15
export SIGIL_REDIRECTS="$redirects"16
export XDG_CACHE_HOME="$gate_dir/cache"18
pass() { printf 'SD_P1_GATE_%02d %s\n' "$1" "$2"; }20
# Every external tool this gate depends on must EXIST. An absent tool silently21
# degrades an assertion into a weaker one that cannot fail.22
for tool in rg git diff awk sed; do23
command -v "$tool" >/dev/null || { echo "$tool is required by this gate" >&2; exit 1; }24
done25
test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }26
test -f src/sigil/doc/private/parser.sgl27
test -f src/sigil/doc/reader.sgl28
test -f test/test-root-profile.sgl29
test -f test/fixtures/sd-p1-folio-roots.sgd30
test -f test/fixtures/sd-p1-article-root.sgd31
test -f test/transcripts/sd-p1/classification-before.txt32
"$sigil" --version34
# ---------------------------------------------------------------- ARM 0135
# The root-profile suite: exact locations for a fixture profile with a36
# different root set, the allowlist as a class in both directions,37
# multiplicity, the default profile's byte-identical diagnostics, article/book38
# reachability, constructor validation, aggregate ownership, the slot-count39
# classification, and the delegating reader's form sequence.40
suite_log="$gate_dir/root-profile-suite.log"41
# NOT `--report`: that flag captures the suite's stdout, and this arm asserts on42
# a denominator the suite PRINTS.43
if ! setsid -w "$sigil" -L src -L test test test/test-root-profile.sgl >"$suite_log" 2>&1; then44
echo "root-profile suite exited non-zero" >&2; tail -40 "$suite_log" >&2; exit 145
fi46
# Strip ANSI colour before matching, so the assertion depends on the runner's47
# words rather than on its escape sequences.48
sed -e 's/\x1b\[[0-9;]*m//g' "$suite_log" >"$suite_log.clean"49
# THE COUNT IS DERIVED FROM THE SUITE FILE, NOT WRITTEN IN.50
#51
# This line asserted a hardcoded `Tests: 11 passed (11 total)`. A TWELFTH test52
# was added to test/test-root-profile.sgl and the literal went stale, so this53
# gate has been RED ON MASTER against a suite that passes 12/12 -- the gate54
# lying about a healthy product. Confirmed 2026-08-22 by running a pristine copy55
# built from `git show HEAD:`: exit 1, "did not report 11 of 11 tests", with the56
# runner reporting `Tests: 12 passed (12 total)` and `All tests passed`.57
#58
# That is the same defect class as an assertion that cannot fail, pointing the59
# other way: a check that has stopped describing its subject. folio's60
# test/gate-f1a.sh states the rule in its own header and derives its count61
# exactly like this -- "Every count this gate checks is DERIVED FROM THE ARTIFACT62
# it describes, never written in as a literal. [...] That drift is the single63
# most common defect in this estate's gates." Adding a test must not require64
# editing a number here, and now it does not.65
#66
# NOTE FOR WHOEVER TOUCHES THE SIBLING: test/gate-sd-p4.sh hardcoded 17 in67
# exactly this way and was fixed the same way, so this pointer no longer names68
# an outstanding defect. It is kept because the DEFECT CLASS outlived both69
# instances: a count written in rather than derived goes stale silently and the70
# gate then accuses healthy product code. Before adding a count to any gate in71
# this directory, derive it from the artifact it describes.72
#73
# `|| true` is load-bearing. Under `set -e` a command substitution whose command74
# fails ABORTS THE SCRIPT, and `grep -c` exits 1 when it matches nothing, so75
# without it a broken derivation kills this gate at this line and the guard76
# below never speaks. Exit 1 with no message is indistinguishable from a gate77
# that never ran. Same fix, same reason, in test/gate-sd-p4.sh; found there by78
# sabotage rather than by reading either file.79
expected_tests=$(grep -cE '^\(test "' test/test-root-profile.sgl || true)80
test "$expected_tests" -ge 1 || {81
echo "derived 0 tests from test/test-root-profile.sgl; the DERIVATION is broken, not the suite" >&282
exit 1; }83
# `|| true` for the reason given above the derivation, and on the same class of84
# input: `rg` exits 1 when it matches nothing, `pipefail` propagates that out of85
# the substitution, and `set -e` would kill the gate on THIS line before the86
# guard below could say the suite printed no summary. Exit 1 with no message is87
# the least informative red available. Found by adversarial review of88
# test/gate-sd-p4.sh's equivalent block, not by running either gate.89
reported=$(rg -o 'Tests:[[:space:]]+[0-9]+ passed' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)90
collected=$(rg -o '\([0-9]+ total\)' "$suite_log.clean" | head -1 | grep -oE '[0-9]+' | head -1 || true)91
test -n "$reported" -a -n "$collected" || {92
echo "root-profile suite printed no summary line" >&293
tail -40 "$suite_log.clean" >&2; exit 1; }94
# Every test the FILE declares must have been collected, and every test collected95
# must have passed. The first catches a test that silently stopped running; the96
# second catches a failure the summary would otherwise bury.97
test "$collected" = "$expected_tests" || {98
echo "test/test-root-profile.sgl declares $expected_tests tests but the runner collected $collected" >&299
tail -40 "$suite_log.clean" >&2; exit 1; }100
test "$reported" = "$collected" || {101
echo "root-profile suite reported $reported passed of $collected collected" >&2102
tail -40 "$suite_log.clean" >&2; exit 1; }103
rg -q 'All tests passed' "$suite_log.clean" || {104
echo "root-profile suite did not report all tests passing" >&2105
tail -40 "$suite_log.clean" >&2; exit 1; }106
# The location denominator. Take field 2, not the first digit run: the marker's107
# own name contains digits.108
roots=$(rg -o 'SD_P1_ROOTS_CHECKED [0-9]+' "$suite_log.clean" | head -1 | awk '{print $2}' || true)109
test -n "$roots" || {110
echo "suite printed no root-count denominator" >&2; tail -40 "$suite_log.clean" >&2; exit 1; }111
test "$roots" -ge 2 || { echo "location walk covered only $roots roots" >&2; exit 1; }112
pass 1 "root-profile suite $reported/$expected_tests, locations verified at $roots roots"114
# ---------------------------------------------------------------- ARM 02115
# The classification change is CONFINED to the two colliding spellings.116
#117
# `test/transcripts/sd-p1/classification-before.txt` was produced by the118
# pre-SD-P1 parser running in its OWN package root. That detail is load-bearing:119
# `sigil -L <other>/src` invoked from THIS package root does NOT shadow this120
# package's `src/`, so a "before" run driven that way silently measures the121
# CURRENT parser. The BEFORE transcript therefore carries a positive control122
# proving the tree it came from could not resolve `sigil-doc-profile`, and this123
# arm refuses to compare against a transcript missing it.124
before="test/transcripts/sd-p1/classification-before.txt"125
rg -q 'PRE_SD_P1_CONTROL_UNBOUND' "$before" || {126
echo "the BEFORE transcript carries no pre-SD-P1 positive control; it cannot be trusted" >&2127
exit 1; }128
after_log="$gate_dir/classification-after.txt"129
setsid -w "$sigil" -L src -L test eval -f test/sd-p1-classification-probe.sgl >"$after_log" 2>&1130
# Derived, not hardcoded -- see test/sd-p1-before-transcript.sh for why.131
cases=$(rg -c '^\(report "' test/sd-p1-classification-probe.sgl || echo 0)132
test "$cases" -ge 1 || { echo "could not count the probe's cases" >&2; exit 1; }133
rg -q "SD_P1_CLASSIFICATION_PROBE_COMPLETE $cases cases" "$after_log" || {134
echo "the AFTER probe did not run all $cases cases" >&2; cat "$after_log" >&2; exit 1; }136
case_line() { rg -o "SD_P1_CASE $1 :: .*" "$2" | head -1; }137
changed=0138
for label in A-text-command-at-top-level B-expr-command-at-top-level \139
C-text-command-at-block-position D-expr-command-at-block-position \140
E-text-command-inline I-text-command-inside-inline-code; do141
b=$(case_line "$label" "$before"); a=$(case_line "$label" "$after_log")142
test -n "$b" -a -n "$a" || { echo "missing case $label in one transcript" >&2; exit 1; }143
if [ "$b" != "$a" ]; then changed=$((changed + 1)); fi144
done145
# At least one colliding spelling must have CHANGED, or this phase did nothing146
# to the classification and the arm is decorative.147
test "$changed" -ge 1 || {148
echo "no colliding spelling changed behaviour; the classification fix is inert" >&2149
diff "$before" "$after_log" >&2 || true; exit 1; }150
# ...and every POSITIVE CONTROL must be byte-identical, or the change was not151
# confined to the collision.152
for label in F-control-em-inline G-control-bare-prose-block \153
H-control-author-expression-at-top-level; do154
b=$(case_line "$label" "$before"); a=$(case_line "$label" "$after_log")155
test -n "$b" -a -n "$a" || { echo "missing control $label in one transcript" >&2; exit 1; }156
test "$b" = "$a" || {157
echo "CONTROL $label CHANGED -- the classification fix is not confined:" >&2158
echo " before: $b" >&2; echo " after: $a" >&2; exit 1; }159
done160
# Deliberately NOT copied into test/transcripts/: a reviewer re-executing this161
# gate must not have its worktree dirtied by doing so. The path is printed for162
# whoever is recording evidence.163
echo " classification-after: $after_log"164
pass 2 "classification change confined: $changed of 6 collision cases moved, 3 of 3 controls identical"166
# ---------------------------------------------------------------- ARM 03167
# RETIRED 2026-08-11 BY FABLE'S RULING, at SD-P3's merge, by the leader. Same168
# disposition and same reasoning as arm 5 below. This arm has NOT silently169
# disappeared and its red has NOT been hidden -- read this before concluding170
# anything.171
#172
# What it did: asserted that 21 named out-of-lane files were byte-unchanged173
# against SD-P1's base `c41979c`, so that a green elsewhere in this gate could174
# not be explained by something outside the parser lane having moved. It175
# carried its own positive control: `src/sigil/doc/private/parser.sgl` MUST176
# differ from the base, or the whole untouched-file probe was passing for free.177
# That control was well built and is the reason the arm was trustworthy while178
# its endpoints held.179
#180
# Why it is gone: it is a DIFFERENTIAL scoped to a transition that has181
# completed, not a standing invariant. Three of its 21 guarded files have since182
# moved for reasons the estate asked for, measured on master at `d38f30b`:183
#184
# src/sigil/doc/model.sgl +92 -6 (SD-P2, url-link)185
# src/sigil/doc/author.sgl +11 -4 (SD-P3, prose runs)186
# src/sigil/doc/render/html.sgl +34 (SD-P2)187
#188
# From those merges onward the arm reports RED for intended change. It was189
# already red on master itself before SD-P3 merged -- proven by the SD-P3190
# worker in a pristine worktree containing zero SD-P3 content191
# (`test/transcripts/sd-p3/merge/gate-sd-p1-arm3-red-on-master.txt`), which is192
# what established the red as SD-P2's and not SD-P3's. Attribution was settled193
# before retirement, deliberately: retiring a red you have not attributed is194
# how a real defect gets laundered.195
#196
# THE RULING (Fable, 2026-08-11): a differential gate's meaning is bound to the197
# two endpoints it compares. Standing gates assert invariants; differential198
# gates certify transitions, and a completed transition does not become a199
# standing invariant just because the check is still executable. A sweep of all200
# 21 harnesses in this tree found the class has exactly four members and no201
# fifth.202
#203
# WHAT IS LOST, stated plainly rather than waved off: no arm now asserts that a204
# future parser-lane change leaves the renderers and the passive suite alone.205
# That guarantee was always scoped to `c41979c` and cannot be rebased without206
# choosing new endpoints, which is a phase's job and not this file's. The207
# STANDING PATTERN for the next lowering-changing phase is the one recorded at208
# arm 5: ship your own before/after differential scoped to your own base, and209
# embed the baseline's provenance marker and intended base SHA in the arm, so a210
# superseded baseline fails with "baseline superseded -- see ruling" rather211
# than a bare diff.212
#213
# EVIDENCE PRESERVED: the transcripts under `test/transcripts/sd-p1/` stay in214
# the tree unmodified. Regenerating them from a later tree would destroy their215
# meaning rather than update it.216
pass 3 "RETIRED by Fable's ruling 2026-08-11; differential endpoints have moved (see comment)"218
# ---------------------------------------------------------------- ARM 04219
# A delegating language needs only the PUBLIC module. This runs in a fresh220
# process importing `(sigil doc reader)` and nothing else from sigil-doc, and221
# parses a folio-shaped manuscript through a profile it constructs itself.222
delegate_log="$gate_dir/delegation.log"223
cat >"$gate_dir/delegate-probe.sgl" <<'PROBE'224
(import (sigil core) (sigil fs) (sigil doc reader))225
(define profile (make-document-profile "folio/doc" '(note project) 'one-or-more))226
(define path "test/fixtures/sd-p1-folio-roots.sgd")227
(define parts (parse-document-parts-with-profile profile (read-file-string path) path 16))228
(display "SD_P1_DELEGATION roots=") (display (length (cadr parts)))229
(display " forms=") (display (length (car parts))) (newline)230
PROBE231
setsid -w "$sigil" -L src -L "$gate_dir" eval -f "$gate_dir/delegate-probe.sgl" >"$delegate_log" 2>&1 || {232
echo "delegation probe failed" >&2; cat "$delegate_log" >&2; exit 1; }233
rg -q 'SD_P1_DELEGATION roots=2 forms=0' "$delegate_log" || {234
echo "delegation probe did not deliver two roots from the public module" >&2235
cat "$delegate_log" >&2; exit 1; }236
pass 4 "a folio-shaped profile parses through (sigil doc reader) alone"238
# ---------------------------------------------------------------- ARM 05239
# RETIRED 2026-08-11 BY FABLE'S RULING. This arm has NOT silently disappeared240
# and its red has NOT been hidden -- read this before concluding anything.241
#242
# What it did: dumped the complete lowered form sequence for 10 real243
# manuscripts and required byte-equality with `test/transcripts/sd-p1/244
# lowering-before.txt`, a PRE-SD-P1 baseline. That certified a TRANSITION --245
# `c41979c` -> `acb9adf`, "SD-P1 changed nothing for default-profile246
# manuscripts" -- and the certification is complete: executed by the SD-P1247
# worker, then reproduced end to end by the reviewer with independently248
# regenerated artifacts on both sides (570,669 bytes compared).249
#250
# Why it is gone: SD-P3 (`feat/inline-commands-bare-prose`) INTENDS to change251
# the lowering of 2 of those 10 manuscripts, so from that commit onward this252
# arm reports RED for a change the estate asked for. Measured on that branch:253
# 8 of 10 identical, differing in exactly `minimal.sgd` and254
# `semantic-structures.sgd` -- the same two SD-P3's independent passive census255
# flags, so two unrelated instruments agree on the population.256
#257
# THE RULING (Fable, 2026-08-11, recorded in the SD-P1 row of258
# topics/sigil-doc-implementation-plan): a differential gate's meaning is bound259
# to the two endpoints it compares. Standing gates assert invariants;260
# differential gates certify transitions, and a completed transition does not261
# become a standing invariant just because the check is still executable.262
# Retiring it here is legitimate BECAUSE it is ruled and recorded -- laundering263
# is hiding a red, not retiring a differential whose endpoints have moved.264
#265
# SUCCESSOR, and it is strictly stronger: `test/gate-sd-p3.sh` arm 3 compares266
# 79 manuscripts (a DERIVED population, not an inherited list) against a267
# pre-SD-P3 baseline carrying three provenance controls, and cross-checks the268
# set of changed manuscripts against a second, independent instrument.269
#270
# EVIDENCE PRESERVED: `test/transcripts/sd-p1/lowering-before.txt` and271
# `lowering-after.txt` stay in the tree unmodified. They are SD-P1's reviewed272
# evidence and a regenerating them from a later tree would destroy their273
# meaning rather than update it.274
#275
# STANDING PATTERN for the next lowering-changing phase: ship your own276
# before/after differential scoped to your own base, and embed the baseline's277
# provenance marker and intended base SHA in the arm, so a superseded baseline278
# fails with "baseline superseded -- see ruling" rather than a bare diff.279
pass 5 "RETIRED by Fable's ruling 2026-08-11; superseded by gate-sd-p3.sh arm 3"281
# ---------------------------------------------------------------- ARM 06282
# Existing suites, unchanged in what they assert. gate-sd-p4.sh runs the passive283
# suite, the no-execution witness, the parser-state arms, and D0/D1/D2/D3.284
#285
# `SD_P1_SKIP_REGRESSION` exists for ONE caller: `test/sabotage-sd-p1.sh`, whose286
# leg 7 must re-run arm 2 and would otherwise pay the full ~30 minute287
# regression to do it. A skipped run CANNOT be mistaken for a full one -- it288
# prints a different final marker, and every consumer of this gate asserts on289
# `SD_P1_GATE_GREEN`.290
if [ "${SD_P1_SKIP_REGRESSION:-0}" = "1" ]; then291
echo "SD_P1_GATE_PARTIAL regression arm skipped by request"292
exit 0293
fi294
test/gate-sd-p4.sh295
pass 6 "SD-P4 + D0/D1/D2/D3 regression green"297
echo "SD_P1_GATE_GREEN"