AtlatestRepositorysigil-doc

sigil-doc / tree / testgate-sd-p2.sh

1#!/usr/bin/env bash
2# SD-P2 gate: the inline node for a link that leaves the publication.
3#
4# Every arm asserts a marker this script prints for itself. A non-zero exit is
5# NOT treated as evidence of anything: a missing binary (127) and a
6# non-executable script (126) both exit non-zero having run no assertion at all.
7#
8# WHAT THIS GATE DOES NOT COVER, stated so the omission is visible rather than
9# implied: the print-toolchain gates (gate-d6, gate-d6-customization,
10# gate-glossary, gate-semantic-structures) need Typst, Poppler and qpdf and are
11# run separately under `guix shell typst poppler qpdf --`. Their transcripts
12# live beside this gate's in test/transcripts/sd-p2/.
13set -euo pipefail
15repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
16cd "$repo_dir"
17mkdir -p "$repo_dir/build"
18sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
19redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"
20sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"
21gate_dir="$(mktemp -d "$repo_dir/build/sd-p2-gate.XXXXXX")"
22export XDG_CACHE_HOME="$gate_dir/cache"
23export SIGIL_REDIRECTS="$redirects"
25# Every external tool this gate depends on must exist. A missing tool degrades
26# a check to a weaker one silently; that is what this loop prevents.
27for tool in rg sed cmp wc git sha256sum; do
28 command -v "$tool" >/dev/null || { echo "gate-sd-p2: missing required tool $tool" >&2; exit 1; }
29done
30test -x "$sigil" || { echo "gate-sd-p2: compiler $sigil is not executable" >&2; exit 1; }
31"$sigil" --version | tee "$gate_dir/compiler.txt"
32git -C "$repo_dir" rev-parse HEAD | tee "$gate_dir/head.txt"
33git -C "$repo_dir" status --short | tee "$gate_dir/tree.txt"
34echo SD_P2_00_BUILD_IDENTITY
36# ---------------------------------------------------------------------------
37# Arm 1 - the node itself, through the real #lang reader, in all three backends.
38# ---------------------------------------------------------------------------
39"$sigil" -L "$sigil_sxml_root/src" -L src -L test test test/test-url-link.sgl --report \
40 | tee "$gate_dir/url-link-tests.txt"
41rg -q '9 passed' "$gate_dir/url-link-tests.txt"
42echo SD_P2_01_NODE_MODEL_AUTHOR_AND_THREE_BACKENDS_9_9
44# ---------------------------------------------------------------------------
45# Arm 2 - the sampled course targets are real, and the population is the one
46# claimed. Without this the fixture could drift into invented URLs and the
47# "the course links are representable" claim would rest on nothing.
48# ---------------------------------------------------------------------------
49links="test/fixtures/course-external-links.txt"
50test -s "$links"
51observed_links="$(wc -l <"$links" | tr -d ' ')"
52test "$observed_links" = "60" \
53 || { echo "gate-sd-p2: expected 60 course external links, found $observed_links" >&2; exit 1; }
54sampled=0
55while IFS= read -r target; do
56 rg -qF -- "$target" "$links" \
57 || { echo "gate-sd-p2: fixture target is not in the course corpus: $target" >&2; exit 1; }
58 sampled=$((sampled + 1))
59done < <(rg -o -r '$1' -e '@url\["(https://[^"]+)"\]' test/fixtures/url-links.sgd \
60 | rg '^https://(www\.gnu\.org|elpa\.nongnu\.org|www\.msys2\.org)')
61test "$sampled" = "4" \
62 || { echo "gate-sd-p2: expected 4 sampled course targets, checked $sampled" >&2; exit 1; }
63echo SD_P2_02_COURSE_TARGET_SAMPLE_IS_REAL_POPULATION_60_SAMPLED_4
65# ---------------------------------------------------------------------------
66# Arm 3 - the per-backend policy is real, not decoration. Lives in its own
67# script so it can be sabotaged and re-run without a half-hour compile.
68# ---------------------------------------------------------------------------
69SD_P2_BACKEND_WORK="$gate_dir/backend" bash test/gate-sd-p2-backend-refusal.sh \
70 | tee "$gate_dir/backend-refusal.txt"
71rg -q SD_P2_03_EACH_BACKEND_REFUSES_WITHOUT_THE_CORE_GATE "$gate_dir/backend-refusal.txt"
73# ---------------------------------------------------------------------------
74# Arm 4 - the D13 rename is complete. Also its own script, and an absence
75# assertion that proves its searcher against a planted occurrence first.
76# ---------------------------------------------------------------------------
77bash test/gate-sd-p2-rename.sh | tee "$gate_dir/rename.txt"
78rg -q SD_P2_04_RENAME_COMPLETE "$gate_dir/rename.txt"
80# ---------------------------------------------------------------------------
81# Arm 5 - a video destination is a link too, and used to be emitted with no
82# check at all. This corpus supplies ZERO natural positives (50 video nodes,
83# none refused), so the check has never been observed firing on real content;
84# its sabotage leg is what makes it distinguishable from a check that does
85# nothing, and the test carries its own benign control for the same reason.
86# ---------------------------------------------------------------------------
87"$sigil" -L "$sigil_sxml_root/src" -L src -L test test test/test-video-destination.sgl --report \
88 | tee "$gate_dir/video-tests.txt"
89rg -q '5 passed' "$gate_dir/video-tests.txt"
90echo SD_P2_05_VIDEO_DESTINATION_AND_INTERPOLATION_5_5
92# ---------------------------------------------------------------------------
93# Arm 6 - nothing already reviewed regressed.
94# ---------------------------------------------------------------------------
95bash test/gate-d0.sh >"$gate_dir/d0.txt"
96bash test/gate-d1.sh >"$gate_dir/d1.txt"
97bash test/gate-d2.sh >"$gate_dir/d2.txt"
98bash test/gate-d3.sh >"$gate_dir/d3.txt"
99bash test/gate-d4a.sh >"$gate_dir/d4a.txt"
100rg -q D0_GATE_GREEN "$gate_dir/d0.txt"
101rg -q D1_GATE_GREEN "$gate_dir/d1.txt"
102rg -q D2_REAL_LANGUAGE_GREEN "$gate_dir/d2.txt"
103rg -q D3_GATE_GREEN "$gate_dir/d3.txt"
104rg -q D4A_GATE_GREEN "$gate_dir/d4a.txt"
105echo SD_P2_06_D0_TO_D4A_REGRESSIONS_GREEN
107printf 'SD_P2_GATE_GREEN artifacts=%s\n' "$gate_dir"