AtlatestRepositorysigil-doc

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

1#!/usr/bin/env bash
2# SD-P2 print-toolchain arms. Run under: guix shell typst poppler qpdf -- bash test/gate-sd-p2-print.sh
3#
4# TWO INDEPENDENT REASONS FOR THE PDF TO CHANGE ON THIS BRANCH, and they are
5# checked separately rather than letting one clean run stand in for the pair:
6#
7# 1. the D13 rename changes the admonition's default label, so the book PDF
8# MUST differ from the pre-rename output and MUST now read "aside";
9# 2. the video work adds a check on the constructed Typst destination, which
10# for every valid source is a pass-through, so the emitted source for
11# existing video content MUST be byte-identical.
13# One expectation is "this changed", the other is "this did not change". A
14# single diff cannot demonstrate both, and a gate that only asserted "the PDF
15# still builds" would be blind to either going wrong.
16set -euo pipefail
18repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
19cd "$repo_dir"
20sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
21sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"
22export SIGIL_REDIRECTS="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"
23gate_dir="$(mktemp -d "$repo_dir/build/sd-p2-print.XXXXXX")"
24export XDG_CACHE_HOME="$gate_dir/cache"
26for tool in typst pdftotext rg git; do
27 command -v "$tool" >/dev/null \
28 || { echo "gate-sd-p2-print: $tool is missing; run under guix shell typst poppler qpdf" >&2; exit 1; }
29done
30typst --version | tee "$gate_dir/toolchain.txt"
31echo SD_P2_PRINT_00_TOOLCHAIN
33# ---------------------------------------------------------------------------
34# Arm P1 - the rename reached the typeset page, not merely the source tree.
35# The renderers derive this label from the kind symbol, so nothing in the
36# renderer diff proves the output moved; only the artifact does.
37# ---------------------------------------------------------------------------
38"$sigil" -L src -L book tools/build-practical-sigil-print.sgl "$gate_dir/book.typ"
39typst compile --root "$repo_dir" --creation-timestamp 0 --pdf-standard a-2b --jobs 1 \
40 "$gate_dir/book.typ" "$gate_dir/book.pdf"
41pdftotext -layout "$gate_dir/book.pdf" "$gate_dir/book.txt"
42# Positive control first: the admonition block must actually be on the page, or
43# the absence assertion below would pass on a document that simply lost it.
44rg -q 'Keep the first version direct' "$gate_dir/book.txt" \
45 || { echo "gate-sd-p2-print: the admonition body is missing from the PDF; the check below would be vacuous" >&2; exit 1; }
46# Whole-word matching is precise here because neither word occurs in the book's
47# prose: `rg -w` over book/practical-sigil/*.sgd finds them only on the two
48# admonition delimiter lines. So a hit is the label and nothing else.
49rg -qw aside "$gate_dir/book.txt" \
50 || { echo "gate-sd-p2-print: the renamed label does not appear in the typeset output" >&2; exit 1; }
51if rg -nw note "$gate_dir/book.txt"; then
52 echo "gate-sd-p2-print: the old label is still on the typeset page, at the lines above" >&2; exit 1
53fi
54echo SD_P2_PRINT_01_RENAME_REACHED_THE_PAGE
56# ---------------------------------------------------------------------------
57# Arm P2 - the video destination check is a pass-through for valid sources.
58# Emitted source for the shipped video shapes must be EXACTLY these bytes; if
59# the check ever starts rewriting or dropping a destination, this goes red.
60# ---------------------------------------------------------------------------
61"$sigil" -L "$sigil_sxml_root/src" -L src -L test test test/test-video-destination.sgl --report \
62 | tee "$gate_dir/video.txt"
63rg -q '5 passed' "$gate_dir/video.txt"
64echo SD_P2_PRINT_02_VIDEO_DESTINATIONS_UNCHANGED_FOR_VALID_SOURCES
66# ---------------------------------------------------------------------------
67# Arm P3 - the reviewed print gates still pass end to end.
68# ---------------------------------------------------------------------------
69bash test/gate-d6.sh >"$gate_dir/d6.txt" 2>&1
70rg -q D6_GATE_GREEN "$gate_dir/d6.txt"
71bash test/gate-d6-customization.sh >"$gate_dir/d6c.txt" 2>&1
72rg -q D6_CUSTOMIZATION_GATE_GREEN "$gate_dir/d6c.txt"
73bash test/gate-glossary.sh >"$gate_dir/glossary.txt" 2>&1
74rg -q GLOSSARY_GATE_GREEN "$gate_dir/glossary.txt"
75bash test/gate-semantic-structures.sh >"$gate_dir/structures.txt" 2>&1
76rg -q SEMANTIC_STRUCTURES_GATE_GREEN "$gate_dir/structures.txt"
77echo SD_P2_PRINT_03_D6_CUSTOMIZATION_GLOSSARY_STRUCTURES_GREEN
79printf 'SD_P2_PRINT_GATE_GREEN artifacts=%s\n' "$gate_dir"