AtlatestRepositorysigil-doc

sigil-doc / tree / testsabotage-sd-p7.sh

1#!/usr/bin/env bash
2# SD-P7 sabotage driver.
3#
4# A gate that cannot demonstrate it fails is not a gate. Each leg plants a real
5# defect, runs the arm that should catch it, and REQUIRES a red. A leg that does
6# not go red ABORTS the driver: "the gate does not catch this" is a finding.
7#
8# FOUR THINGS THIS DRIVER DOES DELIBERATELY, each because the estate has been
9# bitten by its absence:
11# 1. RESTORATION IS UNCONDITIONAL. `trap restore EXIT INT TERM`, not a step
12# that must be reached. SD-P1's leg 8 tripped `set -u` between a forge and
13# its restore and left a corrupted artifact in the worktree.
14# 2. EVERY RESTORE IS VERIFIED BY SHA256 against a copy taken before anything
15# was touched -- never by the exit code of `cp`, which reports success on a
16# wipe.
17# 3. EVERY ANCHOR IS A WHOLE LINE, MATCHED LITERALLY AND REQUIRED TO BE
18# UNIQUE. A leg whose anchor has moved aborts instead of quietly becoming a
19# no-op and reporting a green.
20# 4. A RED IS ASSERTED ON THE NAMED ARM, not on exit status and not merely on
21# "something failed". A compile error fails everything and means something
22# entirely different, so every arm-based leg also requires that OTHER arms
23# still pass -- i.e. that the suite genuinely ran.
25# FABLE'S S-b HAS NO TARGET IN THIS IMPLEMENTATION, and that is a finding rather
26# than an omission. S-b asks for a leg that applies the section-child predicate
27# only at the OUTERMOST section and passes deeper children through unexamined,
28# so that the depth arm reddens while the single-level arm stays green.
30# THERE IS NO SUCH CODE PATH. `@section` builds INSIDE-OUT: the innermost
31# section is constructed first, and each section validates its own children at
32# its own construction. Nothing ever walks a finished tree deciding which levels
33# to check, so there is no traversal to shorten. The depth property is
34# STRUCTURAL, a consequence of construction order, not algorithmic.
36# Measured rather than argued: a leg planting "skip the check when this child
37# list contains a section" left BOTH the depth arm and the single-level arm
38# green, because the inner section's own child list contains no section and is
39# checked normally on the way up.
41# The depth arm is nonetheless LIVE -- legs 2, 6 and 7 all redden it -- so it is
42# not vacuous, it is simply not independent of the single-level arm. Leg 2 now
43# asserts that explicitly, so the claim is gated rather than narrated.
45# TWO LEGS THIS DRIVER NO LONGER HAS, AND WHY -- here rather than buried in a
46# helper comment, because this is where someone auditing the SABOTAGE SET will
47# look, and an absent leg is exactly the thing a reader cannot see.
49# LEG 18 (Fable's S-b) was written, run, and DELETED. See the S-b note above:
50# it has no target. Before that was understood it also died in an instructive
51# way: its replacement text spanned TWO LINES, and `awk -v` cannot carry an
52# embedded newline, so the driver exited 1 with no leg log and no named
53# failure -- the one failure mode this whole file is built to not have. That
54# is why `replace_line` now refuses a multi-line replacement by name.
56# LEG 13's SIGNATURE was rewritten. It quoted the gate's prose, the gate's
57# wording changed when arm 3 grew a second name set, and the leg then could
58# not recognise its own success. It now keys on `author-fourth-name`, the
59# value the leg itself plants, which cannot drift.
61# LAYERS. Legs marked [product] break the shipped code; leg 10 is [assertion]
62# and breaks an expected value in the suite. They answer different questions: an
63# assertion-layer red proves the harness notices when the harness changes; a
64# product-layer red proves the suite executes the loaded product rather than a
65# mirror of itself.
66set -euo pipefail
67repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
68cd "$repo_dir"
69mkdir -p "$repo_dir/build"
70sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
71export SIGIL_REDIRECTS="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"
72work=$(mktemp -d "$repo_dir/build/sd-p7-sabotage.XXXXXX")
73export XDG_CACHE_HOME="$work/cache"
75for tool in sha256sum grep awk sed diff find; do
76 command -v "$tool" >/dev/null || { echo "$tool is required by this driver" >&2; exit 1; }
77done
78test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }
80TARGETS=(
81 src/sigil/doc/model.sgl
82 src/sigil/doc/private/author-runtime.sgl
83 src/sigil/doc/private/parser.sgl
84 src/sigil/doc/render/plain.sgl
85 test/sd-p7/folio/model.sgl
86 test/test-section-profile.sgl
88mkdir -p "$work/pristine"
89for f in "${TARGETS[@]}"; do
90 mkdir -p "$work/pristine/$(dirname "$f")"
91 cp "$f" "$work/pristine/$f"
92done
94restore() {
95 local rc=$? bad=0 want have
96 for f in "${TARGETS[@]}"; do
97 cp "$work/pristine/$f" "$f"
98 want=$(sha256sum < "$work/pristine/$f" | cut -d' ' -f1)
99 have=$(sha256sum < "$f" | cut -d' ' -f1)
100 if [ "$want" != "$have" ]; then
101 echo "RESTORE FAILED BY CONTENT for $f (want $want, have $have)" >&2
102 bad=1
103 fi
104 done
105 if [ "$bad" != 0 ]; then
106 echo "SD_P7_SABOTAGE_RESTORE_FAILED -- the worktree is NOT clean, fix by hand" >&2
107 exit 90
108 fi
109 echo "SD_P7_SABOTAGE_RESTORED (${#TARGETS[@]} targets verified by sha256)"
110 exit "$rc"
112trap restore EXIT INT TERM
114reset_tree() { for f in "${TARGETS[@]}"; do cp "$work/pristine/$f" "$f"; done; }
116# Replace one whole line, matched literally, required to occur exactly once.
117replace_line() {
118 local file="$1" from="$2" to="$3" label="$4" n
119 # `awk -v` cannot carry an embedded newline, so a multi-line replacement dies
120 # as an opaque exit 1 rather than as a named failure. Measured: leg 18 did
121 # exactly that. Refuse it here, where the message can say why.
122 case "$to" in *"
123"*) echo "LEG REPLACEMENT IS MULTI-LINE, which replace_line cannot apply: $label" >&2; exit 91 ;; esac
124 n=$(grep -Fxc -- "$from" "$file" || true)
125 if [ "$n" != "1" ]; then
126 echo "LEG ANCHOR NOT UNIQUE ($n occurrences): $label" >&2
127 echo " in $file: $from" >&2
128 exit 91
129 fi
130 awk -v from="$from" -v to="$to" '{ if ($0 == from) print to; else print }' "$file" > "$work/edit.tmp"
131 cp "$work/edit.tmp" "$file"
132 grep -Fxq -- "$to" "$file" || { echo "LEG EDIT DID NOT LAND: $label" >&2; exit 91; }
135append_line() { printf '%s\n' "$2" >> "$1"; }
137run_suite() {
138 local log="$1"
139 "$sigil" -L src -L test -L book test test/test-section-profile.sgl > "$log" 2>&1 || true
140 sed -i 's/\x1b\[[0-9;]*m//g' "$log"
143# ARM lines only. The runner also prints a `✓ All tests passed!` banner, which
144# is not an arm; it is subtracted by name rather than by assuming it is there.
145# A CONSTRUCTION-TIME REFUSAL CANNOT BE OBSERVED THROUGH THE TEST RUNNER.
147# Measured, and it cost a run: when a profile refuses at construction the module
148# holding it fails to LOAD, and `sigil test` reports
150# test-section-profile LOAD ERROR:
151# ERROR load failed test/test-section-profile.sgl
153# with the message EMPTY. The red is real and its reason is discarded, so a leg
154# asserting on the refusal text sees nothing and a leg asserting only on "load
155# failed" cannot tell a correct refusal from any compile error whatsoever --
156# which is the difference between a check and a shrug.
158# So these legs import the module DIRECTLY and read the process's own output,
159# where the message survives. This is the better instrument regardless: it
160# observes the refusal rather than a runner's summary of it.
161run_import_probe() {
162 local module="$1" log="$2"
163 "$sigil" -L src -L test eval "(begin (import $module) (display \"PROBE_LOADED_WITHOUT_REFUSAL\") (newline))" \
164 > "$log" 2>&1 || true
165 sed -i 's/\x1b\[[0-9;]*m//g' "$log"
168# A refusal-shaped red: the signature must be present AND the module must not
169# have loaded. Without the second half a module that loaded fine while some
170# unrelated text matched would pass.
171expect_refusal() {
172 local n="$1" layer="$2" label="$3" signature="$4" log="$5"
173 if grep -qF -- "PROBE_LOADED_WITHOUT_REFUSAL" "$log"; then
174 printf 'SD_P7_SABOTAGE_%02d [%s] DID NOT GO RED - the module loaded, so nothing was refused: %s\n' \
175 "$n" "$layer" "$label" >&2
176 tail -20 "$log" >&2
177 exit 92
178 fi
179 if grep -qF -- "$signature" "$log"; then
180 printf 'SD_P7_SABOTAGE_%02d [%s] RED %s\n refused at construction: %s\n' \
181 "$n" "$layer" "$label" "$signature"
182 else
183 printf 'SD_P7_SABOTAGE_%02d [%s] DID NOT GO RED WITH THE RIGHT REASON: %s\n' \
184 "$n" "$layer" "$label" >&2
185 echo "--- expected signature: $signature" >&2
186 tail -20 "$log" >&2
187 exit 92
188 fi
191passing_arms() {
192 local ticks banner
193 # Leading whitespace is REQUIRED in the anchor: the runner indents arm lines
194 # four spaces and the banner two, so `^✓ ` returns a confident zero.
195 ticks=$(grep -cE '^[[:space:]]*✓ ' "$1" || true)
196 banner=$(grep -cE '^[[:space:]]*✓ All tests passed' "$1" || true)
197 echo $((ticks - banner))
200# Signature-based red: the log must contain a string only the planted defect can
201# produce. Used where the defect prevents the suite from loading at all, which
202# is the correct outcome for a construction-time refusal.
203expect_signature() {
204 local n="$1" layer="$2" label="$3" signature="$4" log="$5"
205 if grep -qF -- "$signature" "$log"; then
206 printf 'SD_P7_SABOTAGE_%02d [%s] RED %s\n signature: %s\n' \
207 "$n" "$layer" "$label" "$signature"
208 else
209 printf 'SD_P7_SABOTAGE_%02d [%s] DID NOT GO RED - the gate does not catch this: %s\n' \
210 "$n" "$layer" "$label" >&2
211 echo "--- expected signature: $signature" >&2
212 tail -40 "$log" >&2
213 exit 92
214 fi
217# Arm-based red: the NAMED arm must stop passing, AND other arms must still
218# pass. Without the second half a compile error satisfies the first half, and a
219# compile error is not evidence that the arm checks anything.
220expect_arm() {
221 local n="$1" layer="$2" label="$3" arm="$4" log="$5" now
222 now=$(passing_arms "$log")
223 if grep -Fq -- "✓ $arm" "$log"; then
224 printf 'SD_P7_SABOTAGE_%02d [%s] DID NOT GO RED - the arm still passes: %s\n' \
225 "$n" "$layer" "$label" >&2
226 echo "--- arm: $arm" >&2
227 tail -40 "$log" >&2
228 exit 92
229 fi
230 if [ "$now" -lt 1 ]; then
231 printf 'SD_P7_SABOTAGE_%02d [%s] INCONCLUSIVE - NO arm passed, so the suite did not run: %s\n' \
232 "$n" "$layer" "$label" >&2
233 tail -40 "$log" >&2
234 exit 92
235 fi
236 printf 'SD_P7_SABOTAGE_%02d [%s] RED %s\n arm "%s" no longer passes; %s of %s arms still do\n' \
237 "$n" "$layer" "$label" "$arm" "$now" "$BASELINE_ARMS"
240# ---------------------------------------------------------------- BASELINE
241# GREEN FIRST, and its arm count recorded. Without this a leg's red is equally
242# consistent with the suite having been broken before the driver started.
243base_log="$work/leg00-baseline.log"
244run_suite "$base_log"
245grep -qE 'Tests: +[0-9]+ passed' "$base_log" \
246 || { tail -40 "$base_log"; echo "baseline reported no summary" >&2; exit 93; }
247if grep -qE '[0-9]+ failed' "$base_log"; then
248 tail -40 "$base_log"; echo "baseline is not green -- sabotage would prove nothing" >&2; exit 93
249fi
250BASELINE_ARMS=$(passing_arms "$base_log")
251test "$BASELINE_ARMS" -gt 0 || { echo "baseline passed zero arms" >&2; exit 93; }
252echo "SD_P7_SABOTAGE_00 baseline suite GREEN, ${BASELINE_ARMS} arms"
254E2E="a folio-shaped profile builds a @section holding @task children, end to end"
255REFUSAL="a structural container is refused as a section child, and a work item is not"
256LAUNDER="a manuscript cannot launder a structural container through a section"
257NARROW="a profile may widen the section child set but never narrow it"
258VACUOUS="the constructor refuses the values that would make its own checks vacuous"
259FLOOR="a profile's predicates must be able to say no"
260DEPTH="the section-child predicate applies at every depth, not only the outermost"
261UNDESCRIBED="a profile without a describer emits today's wording, unlocated"
262DEFAULT="sigil/doc's own profile is today's policy, and its seam is unchanged"
263AMBIENT="the ambient profile is restored, including when the thunk raises"
265# Leg 17's anchor. `document->plain` returning the empty string is caught by
266# `test/test-model.sgl:5` -- `(> (string-length (document->plain …)) 500)` -- and
267# by nothing in arms 1-3, which is what makes it a test OF ARM 4 rather than a
268# test of whichever arm happens to fire first.
269PLAIN_ANCHOR_FROM=' (define (document->plain root) (render root))))'
270PLAIN_ANCHOR_TO=' (define (document->plain root) "")))'
272WIDE_CHILD=" (or (block-node? x) (folio-work-item? x) (folio-relational-node? x) (folio-structural-container? x)))"
273REAL_CHILD=" (or (block-node? x) (folio-work-item? x) (folio-relational-node? x)))"
275# ---------------------------------------------------------------- LEG 01
276# THE §6a ROW'S NAMED SABOTAGE, in the shape the MECHANISM catches: the folio
277# profile's section-child predicate is widened to admit structural containers
278# while its declaration still refuses them. The PROFILE must fail to construct,
279# which happens when `(sd-p7 folio model)` loads -- so the suite cannot even
280# start, and the signature is what makes that a refusal rather than a crash.
281reset_tree
282replace_line test/sd-p7/folio/model.sgl "$REAL_CHILD" "$WIDE_CHILD" "leg 1: widen folio-section-child?"
283log="$work/leg01.log"; run_import_probe "(sd-p7 folio model)" "$log"
284expect_refusal 1 product "predicate widened, declaration intact" \
285 "admits a witness the profile declares refused" "$log"
287# ---------------------------------------------------------------- LEG 02
288# THE SAME WIDENING WITH THE DECLARATION DELETED TOO. This is the shape a real
289# future widening would take, and leg 1 does not cover it: with the declaration
290# gone the profile constructs happily and only the ARMS can catch it. Leg 1
291# proves the mechanism works; leg 2 proves the arms are load-bearing without it.
292reset_tree
293replace_line test/sd-p7/folio/model.sgl "$REAL_CHILD" "$WIDE_CHILD" "leg 2: widen folio-section-child?"
294# THE REPLACEMENT WITNESS MUST STILL BE REFUSED BY THE WIDENED PREDICATE, or
295# the profile fails to construct and this leg tests the MECHANISM again instead
296# of the arms. Measured: the first spelling used a `related` node, which the
297# widened predicate ADMITS, so the profile refused at construction, the suite
298# could not load, and the driver correctly reported INCONCLUSIVE rather than
299# accepting a red for the wrong reason. A `text` node is in folio's vocabulary
300# and outside the widened child set, which is exactly what is needed.
301replace_line test/sd-p7/folio/model.sgl \
302 " (list (make-milestone \"m-witness\" \"a refused container\" '() witness-location)" \
303 " (list (make-text \"a refused inline node\" witness-location)" \
304 "leg 2: replace the refused milestone witness"
305replace_line test/sd-p7/folio/model.sgl \
306 " (make-phase \"p-witness\" \"a refused container\" '() witness-location)))" \
307 " ))" \
308 "leg 2: drop the refused phase witness"
309log="$work/leg02.log"; run_suite "$log"
310expect_arm 2 product "widened AND declaration deleted -> the arms catch it" "$REFUSAL" "$log"
311expect_arm 2 product "widened AND declaration deleted -> the manuscript arm too" "$LAUNDER" "$log"
312# THE DEPTH ARM IS LIVE, gated here rather than asserted in prose. It cannot be
313# reddened INDEPENDENTLY of the single-level arm -- see the note on Fable's S-b in
314# this file's header -- so its ability to fail is demonstrated where it can be.
315expect_arm 2 product "widened AND declaration deleted -> the depth arm too" "$DEPTH" "$log"
316# CAUTION 1 (Fable): the two assertions above are satisfied by an ERROR STRING
317# GOING MISSING, which a fixture failing to evaluate for an unrelated reason
318# also produces. That is a red for the wrong cause, and a marker proving the arm
319# RAN rather than that it CHECKED.
321# So this leg additionally demands POSITIVE EVIDENCE OF ACCEPTANCE: with the
322# predicate widened, the laundering manuscript must BUILD and the resulting tree
323# must actually contain a milestone inside a section inside a task. Note it
324# asserts the SHAPE, never the describer's wording -- keying on text I had just
325# made configurable would rebuild the same defect one layer over.
326accept_log="$work/leg02-acceptance.log"
327"$sigil" -L src -L test eval '(begin
328 (import (sigil doc) (sd-p7 folio model))
329 (load "test/fixtures/sd-p7-folio-laundering.sgd")
330 (let* ((doc (eval (quote document)))
331 (task (let scan ((xs (note-children doc)))
332 (cond ((null? xs) #f) ((task? (car xs)) (car xs)) (else (scan (cdr xs))))))
333 (section (and task (let scan ((xs (task-children task)))
334 (cond ((null? xs) #f) ((section? (car xs)) (car xs))
335 (else (scan (cdr xs)))))))
336 (smuggled (and section (let scan ((xs (section-children section)))
337 (cond ((null? xs) #f) ((milestone? (car xs)) (car xs))
338 (else (scan (cdr xs))))))))
339 (if smuggled
340 (begin (display "LAUNDERED: milestone ") (display (milestone-id smuggled))
341 (display " inside section ") (display (section-id section))
342 (display " inside task ") (display (task-id task)) (newline))
343 (begin (display "NOT-LAUNDERED") (newline)))))' > "$accept_log" 2>&1 || true
344sed -i 's/\x1b\[[0-9;]*m//g' "$accept_log"
345if grep -q "^LAUNDERED: milestone m-smuggled inside section smuggling inside task t-wrapper$" "$accept_log"; then
346 printf 'SD_P7_SABOTAGE_02 [product] RED %s\n positive evidence: %s\n' \
347 "the widened predicate genuinely ACCEPTS the laundered tree" \
348 "$(grep '^LAUNDERED:' "$accept_log")"
349else
350 echo "SD_P7_SABOTAGE_02 INCONCLUSIVE - the manuscript did not build a laundered tree, so the arms' red is not attributable to acceptance" >&2
351 tail -20 "$accept_log" >&2
352 exit 92
353fi
355# ---------------------------------------------------------------- LEG 03
356# ANTI-NARROWING REMOVED. Its input is neutered rather than its scoring, so the
357# check still runs and simply has nothing to check -- the exact shape of a
358# vacuous guard.
359reset_tree
360replace_line src/sigil/doc/model.sgl \
361 " (core-block-witnesses)" \
362 " '()" \
363 "leg 3: neuter the anti-narrowing witness set"
364log="$work/leg03.log"; run_suite "$log"
365expect_arm 3 product "anti-narrowing check neutered" "$NARROW" "$log"
367# ---------------------------------------------------------------- LEG 04
368# THE ANTI-VACUITY GUARD REMOVED. Without it a profile may declare a bare
369# symbol refused and pass the refusal check for free.
370reset_tree
371replace_line src/sigil/doc/model.sgl \
372 " (append admitted refused)" \
373 " '()" \
374 "leg 4: neuter the vocabulary check on declared witnesses"
375log="$work/leg04.log"; run_suite "$log"
376expect_arm 4 product "anti-vacuity guard neutered" "$VACUOUS" "$log"
378# ---------------------------------------------------------------- LEG 05
379# `make-section-with-profile` IGNORES THE PROFILE. Gate 3 of the three.
380reset_tree
381replace_line src/sigil/doc/model.sgl \
382 " (make-section-checked (content-profile-record-section-child-predicate profile)" \
383 " (make-section-checked block-node?" \
384 "leg 5: make-section-with-profile ignores its profile"
385log="$work/leg05.log"; run_suite "$log"
386expect_arm 5 product "section constructor ignores the profile" "$E2E" "$log"
388# ---------------------------------------------------------------- LEG 06
389# `author-normalize` REVERTS TO THE CLOSED ENUMERATION. Gate 1 of the three, and
390# the one a manuscript hits FIRST -- measured, and the reason this phase is not
391# confined to `make-section`.
392reset_tree
393replace_line src/sigil/doc/private/author-runtime.sgl \
394 " ((author-node? value) value)" \
395 " ((document-node? value) value)" \
396 "leg 6: author-normalize back to document-node?"
397log="$work/leg06.log"; run_suite "$log"
398expect_arm 6 product "author-normalize back to the closed enumeration" "$E2E" "$log"
400# ---------------------------------------------------------------- LEG 07
401# `author-flatten` REVERTS. Gate 2 of the three, and the leg that justifies the
402# AMBIENT design: `author-flatten` is called lexically from inside
403# `(sigil doc author)`, so no prelude rebinding could ever have reached it.
404reset_tree
405replace_line src/sigil/doc/private/author-runtime.sgl \
406 " ((author-node? (car xs)) (walk (cdr xs) (cons (car xs) out)))" \
407 " ((document-node? (car xs)) (walk (cdr xs) (cons (car xs) out)))" \
408 "leg 7: author-flatten back to document-node?"
409log="$work/leg07.log"; run_suite "$log"
410expect_arm 7 product "author-flatten back to the closed enumeration" "$E2E" "$log"
412# ---------------------------------------------------------------- LEG 08
413# `with-content-profile` LOSES ITS `dynamic-wind`. Restoration becomes a step
414# that must be reached, so a manuscript that raises leaves a delegating
415# language's profile installed for whatever runs next.
416# The restore moves INTO the thunk, so a normal return still restores and a
417# RAISE does not -- which is precisely "a recovery that only runs on the happy
418# path", and precisely what the arm's raising case exists to catch. A leg that
419# simply deleted the restore would redden the arm's easy half as well and prove
420# less.
421reset_tree
422replace_line src/sigil/doc/private/author-runtime.sgl \
423 " (dynamic-wind swap! thunk swap!)))))" \
424 " (let ((r (begin (swap!) (thunk)))) (swap!) r)))))" \
425 "leg 8: restore only on the happy path"
426log="$work/leg08.log"; run_suite "$log"
427expect_arm 8 product "ambient profile restored only on the happy path" "$AMBIENT" "$log"
429# ---------------------------------------------------------------- LEG 09
430# THE FOUR-ARGUMENT `make-section` IS SILENTLY WIDENED. `#lang sigil/doc` and
431# every direct caller would start accepting children they have always refused.
432reset_tree
433replace_line src/sigil/doc/model.sgl \
434 " (make-section-checked block-node? #f id title children loc))" \
435 " (make-section-checked (lambda (x) #t) #f id title children loc))" \
436 "leg 9: make-section admits anything"
437log="$work/leg09.log"; run_suite "$log"
438expect_arm 9 product "make-section silently widened" "$DEFAULT" "$log"
440# ---------------------------------------------------------------- LEG 12
441# THE MECHANISM PROTECTS `sigil/doc`'s OWN PROFILE TOO, not only folio's. Widen
442# the DEFAULT profile's section-child predicate and its own declared refused
443# witnesses -- a `text` and a `list-item` -- make it refuse to construct.
444# `document-node?`, not `(lambda (x) #t)`. The floor on refusal runs BEFORE the
445# declaration check, so a totally permissive predicate fails at the floor with a
446# different message and this leg would then be testing the floor -- which leg 14
447# already covers. Widening to `document-node?` is also the realistic mistake: it
448# passes the floor and the anti-narrowing check and is caught only by the
449# profile's own declaration, which is the property this leg exists to pin.
450reset_tree
451replace_line src/sigil/doc/model.sgl \
452 " (make-content-profile \"sigil/doc\" document-node? block-node?" \
453 " (make-content-profile \"sigil/doc\" document-node? document-node?" \
454 "leg 12: widen the default profile's section-child predicate"
455log="$work/leg12.log"; run_import_probe "(sigil doc)" "$log"
456expect_refusal 12 product "default profile widened past its own declaration" \
457 "admits a witness the profile declares refused" "$log"
459# ---------------------------------------------------------------- LEG 10
460# ASSERTION LAYER, deliberately: one expected task id in the suite is perturbed.
461# This proves the end-to-end arm's assertions are live rather than decorative --
462# a different question from every leg above, all of which broke the product.
463reset_tree
464replace_line test/test-section-profile.sgl \
465 " (assert-equal \"t-predicate\" (task-id (cadr children)))" \
466 " (assert-equal \"t-perturbed\" (task-id (cadr children)))" \
467 "leg 10: perturb an expected task id"
468log="$work/leg10.log"; run_suite "$log"
469expect_arm 10 assertion "an expected task id perturbed" "$E2E" "$log"
471# ---------------------------------------------------------------- LEG 14
472# THE FLOOR ON REFUSAL, neutered at its input. Without it, `(lambda (x) #t)`
473# satisfies the vocabulary guard for free and a profile can declare a junk
474# predicate instead of a junk witness. Adversarial review found this hole; this
475# leg is what stops it being reopened.
476reset_tree
477replace_line src/sigil/doc/model.sgl \
478 " (let ((non-nodes (non-node-witnesses)))" \
479 " (let ((non-nodes '()))" \
480 "leg 14: neuter the floor on refusal"
481log="$work/leg14.log"; run_suite "$log"
482expect_arm 14 product "floor on refusal neutered" "$FLOOR" "$log"
484# ---------------------------------------------------------------- LEG 15
485# THE `admitted` CHECK, which nothing covered until review asked. Every profile
486# in the tree satisfies it trivially, so its deletion was invisible.
487reset_tree
488replace_line src/sigil/doc/model.sgl \
489 " admitted" \
490 " '()" \
491 "leg 15: neuter the admitted-witness check"
492log="$work/leg15.log"; run_suite "$log"
493expect_arm 15 product "admitted-witness check neutered" "$VACUOUS" "$log"
495# ---------------------------------------------------------------- LEG 16
496# THE CORE-BLOCK FLOOR ON `refused`, which closes the identity-discrimination
497# route past the sampled anti-narrowing check.
498reset_tree
499replace_line src/sigil/doc/model.sgl \
500 " (profile-require-none who \"core block floor\" block-node?" \
501 " (profile-require-none who \"core block floor\" (lambda (x) #f)" \
502 "leg 16: neuter the core-block floor on refused witnesses"
503log="$work/leg16.log"; run_suite "$log"
504expect_arm 16 product "core-block floor on refused witnesses neutered" "$FLOOR" "$log"
506# ---------------------------------------------------------------- LEG 19
507# THE DESCRIBER MUST NOT REACH THE DEFAULT PATH. Make `make-section` pass the
508# default profile's describer instead of `#f` -- the "why build the message
509# twice" tidy-up. Under this design the describer is the ONLY thing that can add
510# a location, so the leak shows up as a location appearing where there was none.
511reset_tree
512replace_line src/sigil/doc/model.sgl \
513 " (make-section-checked block-node? #f id title children loc))" \
514 " (make-section-checked block-node? (lambda (node) \"located: child belongs to the wrong semantic category\") id title children loc))" \
515 "leg 19: a describer reaches the default path"
516log="$work/leg19.log"; run_suite "$log"
517expect_arm 19 product "describer leaked into the default path" "$UNDESCRIBED" "$log"
519# ---------------------------------------------------------------- LEG 11
520# CAN GATE ARM 2 -- THE CONSTRUCTION DIFFERENTIAL -- FAIL AT ALL?
522# Every leg above reddens the SUITE. Arm 2 exists precisely to cover what the
523# suite does not, so nothing above it establishes that arm 2 can fire, and an
524# equality check that cannot fail is the most convincing vacuous gate there is.
526# The planted defect is therefore chosen to be INVISIBLE TO THE SUITE and
527# visible to the differential: `code-block-language` returns `#f` instead of the
528# stored language. `test/test-section-profile.sgl` never touches a code block,
529# so arm 1 stays green and the gate REACHES arm 2 -- which compares 32 recorded
530# `(language "...")` fields across the baseline's 22 manuscripts.
531reset_tree
532replace_line src/sigil/doc/model.sgl \
533 " (define code-block? code-block-record?) (define (code-block-language x) (copy-string-or-false (code-block-record-language x))) (define (code-block-content x) (string-copy (code-block-record-content x))) (define (code-block-location x) (safe-location (code-block-record-location x)))" \
534 " (define code-block? code-block-record?) (define (code-block-language x) #f) (define (code-block-content x) (string-copy (code-block-record-content x))) (define (code-block-location x) (safe-location (code-block-record-location x)))" \
535 "leg 11: code-block-language drops the stored language"
536if bash test/gate-sd-p7.sh > "$work/leg11.log" 2>&1; then
537 echo "SD_P7_SABOTAGE_11 [product] DID NOT GO RED - the construction differential accepted a changed document" >&2
538 tail -30 "$work/leg11.log" >&2
539 exit 92
540fi
541# The gate must have got PAST arm 1. If it died at arm 1 this leg proves the
542# SUITE caught the defect and says nothing whatever about arm 2, which is the
543# only question it was asked.
544grep -q '^SD_P7_GATE_01 ' "$work/leg11.log" \
545 || { echo "SD_P7_SABOTAGE_11 INCONCLUSIVE - the gate died before reaching arm 2" >&2; tail -30 "$work/leg11.log" >&2; exit 92; }
546expect_signature 11 product "a document field changed, invisible to the suite" \
547 "arm 02: constructed documents changed" "$work/leg11.log"
549# ---------------------------------------------------------------- LEG 13
550# CAN GATE ARM 3 FAIL AT ALL? The arm derives the set of runtime names the
551# parser emits and compares it against the documented set. Add a fourth
552# emission site and the arm must refuse.
553reset_tree
554append_line src/sigil/doc/private/parser.sgl " ;; (list 'author-fourth-name)"
555if bash test/gate-sd-p7.sh > "$work/leg13.log" 2>&1; then
556 echo "SD_P7_SABOTAGE_13 [product] DID NOT GO RED - gate arm 3 accepted a fourth emitted name" >&2
557 tail -30 "$work/leg13.log" >&2
558 exit 92
559fi
560# THE SIGNATURE IS THE LEG'S OWN PLANTED VALUE, not a quotation of the gate's
561# prose. The first spelling expected "emitted runtime names have moved" and the
562# arm now says "emitted AUTHOR-RUNTIME names have moved" -- I rewrote the arm to
563# pin two name sets and left the leg quoting the old wording. The gate failed
564# exactly as intended and the leg could not recognise its own success: taxonomy
565# shape 10, in the driver that exists to catch shape 10.
567# `author-fourth-name` is what THIS leg appends, so the check cannot drift when
568# the arm's wording changes again. The `arm 03` half is asserted separately so a
569# failure at some other arm cannot satisfy it.
570grep -q "SD_P7_GATE_FAILED: arm 03:" "$work/leg13.log" \
571 || { echo "SD_P7_SABOTAGE_13 DID NOT GO RED AT ARM 03" >&2; tail -20 "$work/leg13.log" >&2; exit 92; }
572expect_signature 13 product "a fourth runtime name added to the parser" \
573 "author-fourth-name" "$work/leg13.log"
575# ---------------------------------------------------------------- LEG 17
576# CAN GATE ARM 4 -- THE FULL-SUITE REGRESSION -- FAIL AT ALL?
578# The coverage table has to have a row for every arm. Arm 4 was observed red for
579# real during this phase (a load-path error made four suites fail to load), but
580# that was an ENVIRONMENT change, not a planted product defect, so it does not
581# establish that arm 4 catches a regression in the code.
583# The defect must be invisible to arms 1-3, or the gate dies earlier and this
584# leg certifies an arm it never reached: a renderer change is invisible to the
585# phase suite (which renders nothing), to the construction differential (which
586# compares `document->datum`, not rendered text), and to the name derivation.
587reset_tree
588replace_line src/sigil/doc/render/plain.sgl \
589 "$PLAIN_ANCHOR_FROM" "$PLAIN_ANCHOR_TO" "leg 17: break the plain renderer"
590if bash test/gate-sd-p7.sh > "$work/leg17.log" 2>&1; then
591 echo "SD_P7_SABOTAGE_17 [product] DID NOT GO RED - the full-suite regression accepted a broken renderer" >&2
592 tail -30 "$work/leg17.log" >&2
593 exit 92
594fi
595for marker in SD_P7_GATE_01 SD_P7_GATE_02 SD_P7_GATE_03; do
596 grep -q "^$marker " "$work/leg17.log" \
597 || { echo "SD_P7_SABOTAGE_17 INCONCLUSIVE - the gate died before arm 4 (missing $marker)" >&2
598 tail -30 "$work/leg17.log" >&2; exit 92; }
599done
600expect_signature 17 product "a renderer defect, invisible to arms 1-3" \
601 "arm 04: a test failed" "$work/leg17.log"
603reset_tree
604# The count is DERIVED from the legs this file actually runs, not restated: a
605# driver that says "12 legs" while running 11 is the stale-constant shape.
606legs=$(grep -cE '^expect_(arm|signature) [0-9]+' "$0")
607echo "SD_P7_SABOTAGE_COMPLETE ${legs} red assertions, all satisfied at their named arm"