AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# 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 is5
# NOT treated as evidence of anything: a missing binary (127) and a6
# 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 than9
# implied: the print-toolchain gates (gate-d6, gate-d6-customization,10
# gate-glossary, gate-semantic-structures) need Typst, Poppler and qpdf and are11
# run separately under `guix shell typst poppler qpdf --`. Their transcripts12
# live beside this gate's in test/transcripts/sd-p2/.13
set -euo pipefail15
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"16
cd "$repo_dir"17
mkdir -p "$repo_dir/build"18
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"19
redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"20
sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"21
gate_dir="$(mktemp -d "$repo_dir/build/sd-p2-gate.XXXXXX")"22
export XDG_CACHE_HOME="$gate_dir/cache"23
export SIGIL_REDIRECTS="$redirects"25
# Every external tool this gate depends on must exist. A missing tool degrades26
# a check to a weaker one silently; that is what this loop prevents.27
for tool in rg sed cmp wc git sha256sum; do28
command -v "$tool" >/dev/null || { echo "gate-sd-p2: missing required tool $tool" >&2; exit 1; }29
done30
test -x "$sigil" || { echo "gate-sd-p2: compiler $sigil is not executable" >&2; exit 1; }31
"$sigil" --version | tee "$gate_dir/compiler.txt"32
git -C "$repo_dir" rev-parse HEAD | tee "$gate_dir/head.txt"33
git -C "$repo_dir" status --short | tee "$gate_dir/tree.txt"34
echo SD_P2_00_BUILD_IDENTITY36
# ---------------------------------------------------------------------------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"41
rg -q '9 passed' "$gate_dir/url-link-tests.txt"42
echo SD_P2_01_NODE_MODEL_AUTHOR_AND_THREE_BACKENDS_9_944
# ---------------------------------------------------------------------------45
# Arm 2 - the sampled course targets are real, and the population is the one46
# claimed. Without this the fixture could drift into invented URLs and the47
# "the course links are representable" claim would rest on nothing.48
# ---------------------------------------------------------------------------49
links="test/fixtures/course-external-links.txt"50
test -s "$links"51
observed_links="$(wc -l <"$links" | tr -d ' ')"52
test "$observed_links" = "60" \53
|| { echo "gate-sd-p2: expected 60 course external links, found $observed_links" >&2; exit 1; }54
sampled=055
while IFS= read -r target; do56
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))59
done < <(rg -o -r '$1' -e '@url\["(https://[^"]+)"\]' test/fixtures/url-links.sgd \60
| rg '^https://(www\.gnu\.org|elpa\.nongnu\.org|www\.msys2\.org)')61
test "$sampled" = "4" \62
|| { echo "gate-sd-p2: expected 4 sampled course targets, checked $sampled" >&2; exit 1; }63
echo SD_P2_02_COURSE_TARGET_SAMPLE_IS_REAL_POPULATION_60_SAMPLED_465
# ---------------------------------------------------------------------------66
# Arm 3 - the per-backend policy is real, not decoration. Lives in its own67
# script so it can be sabotaged and re-run without a half-hour compile.68
# ---------------------------------------------------------------------------69
SD_P2_BACKEND_WORK="$gate_dir/backend" bash test/gate-sd-p2-backend-refusal.sh \70
| tee "$gate_dir/backend-refusal.txt"71
rg -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 absence75
# assertion that proves its searcher against a planted occurrence first.76
# ---------------------------------------------------------------------------77
bash test/gate-sd-p2-rename.sh | tee "$gate_dir/rename.txt"78
rg -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 no82
# 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 does85
# 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"89
rg -q '5 passed' "$gate_dir/video-tests.txt"90
echo SD_P2_05_VIDEO_DESTINATION_AND_INTERPOLATION_5_592
# ---------------------------------------------------------------------------93
# Arm 6 - nothing already reviewed regressed.94
# ---------------------------------------------------------------------------95
bash test/gate-d0.sh >"$gate_dir/d0.txt"96
bash test/gate-d1.sh >"$gate_dir/d1.txt"97
bash test/gate-d2.sh >"$gate_dir/d2.txt"98
bash test/gate-d3.sh >"$gate_dir/d3.txt"99
bash test/gate-d4a.sh >"$gate_dir/d4a.txt"100
rg -q D0_GATE_GREEN "$gate_dir/d0.txt"101
rg -q D1_GATE_GREEN "$gate_dir/d1.txt"102
rg -q D2_REAL_LANGUAGE_GREEN "$gate_dir/d2.txt"103
rg -q D3_GATE_GREEN "$gate_dir/d3.txt"104
rg -q D4A_GATE_GREEN "$gate_dir/d4a.txt"105
echo SD_P2_06_D0_TO_D4A_REGRESSIONS_GREEN107
printf 'SD_P2_GATE_GREEN artifacts=%s\n' "$gate_dir"