AtlatestRepositorysigil-doc

sigil-doc / tree / testgate-d6-customization.sh

1#!/usr/bin/env bash
2set -euo pipefail
3
4repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
5cd "$repo_dir"
6sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
7redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"
8sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"
9typst_bin="${TYPST_BIN:-typst}"
10pdfinfo_bin="${PDFINFO_BIN:-pdfinfo}"
11pdftotext_bin="${PDFTOTEXT_BIN:-pdftotext}"
12pdftoppm_bin="${PDFTOPPM_BIN:-pdftoppm}"
13qpdf_bin="${QPDF_BIN:-qpdf}"
14convert_bin="${CONVERT_BIN:-convert}"
15sha256sum_bin="${SHA256SUM_BIN:-sha256sum}"
16mkdir -p "$repo_dir/build"
17gate_dir="$(mktemp -d "$repo_dir/build/d6-customization-gate.XXXXXX")"
18export XDG_CACHE_HOME="$gate_dir/cache"
19export SIGIL_REDIRECTS="$redirects"
20export SIGIL_D1_COMPILER="$sigil"
21export SIGIL_BYTECODE_BASE="${SIGIL_BYTECODE_BASE:-$(test/build-d3-bytecode-base.sh)}"
22export SOURCE_DATE_EPOCH=0
24for tool in "$typst_bin" "$pdfinfo_bin" "$pdftotext_bin" "$pdftoppm_bin" \
25 "$qpdf_bin" "$convert_bin" "$sha256sum_bin"; do
26 command -v "$tool" >/dev/null
27done
28"$typst_bin" --version | tee "$gate_dir/toolchain.txt"
29echo D6C_GATE_01_PINNED_TOOLCHAIN
31"$sigil" -L "$sigil_sxml_root/src" -L src test \
32 test/test-print.sgl test/test-print-customization.sgl --report \
33 | tee "$gate_dir/customization-tests.txt"
34rg -q '10 passed' "$gate_dir/customization-tests.txt"
35"$sigil" -L "$sigil_sxml_root/src" -L src -L book test test/test-book-config.sgl --report \
36 | tee "$gate_dir/book-config-tests.txt"
37rg -q '2 passed' "$gate_dir/book-config-tests.txt"
38echo D6C_GATE_02_OPTIONS_THEME_VALIDATION_AND_BOOK_CONFIG_12_12
40generate_default() {
41 local stem="$1"
42 "$sigil" -L src -L book tools/build-practical-sigil-print.sgl "$gate_dir/$stem.typ"
43 "$typst_bin" compile --root "$repo_dir" --creation-timestamp 0 --pdf-standard a-2b \
44 --jobs 1 "$gate_dir/$stem.typ" "$gate_dir/$stem.pdf"
46generate_default default-a
47generate_default default-b
48cmp "$gate_dir/default-a.typ" "$gate_dir/default-b.typ"
49cmp "$gate_dir/default-a.pdf" "$gate_dir/default-b.pdf"
50test "$("$sha256sum_bin" "$gate_dir/default-a.typ" | cut -d' ' -f1)" = \
51 831af06d88bb5d43fc6e5ea3ed64364eda37e585ee61a45d5d5c2098fcc43fae
52test "$("$sha256sum_bin" "$gate_dir/default-a.pdf" | cut -d' ' -f1)" = \
53 b1a48320da52a9a271cbf0250cbb84bb5d233fb459e7954464bbd9c113d4f17a
54# Digests updated 2026-08-10 for the D13 rename (note -> aside). The book's
55# admonition label is derived from the model kind, so renaming the kind changes
56# one line of emitted Typst and therefore both artifacts.
58# NOT updated on faith: the pre-rename tree (commit 99f80fa, url-link landed,
59# rename not yet) rebuilds to EXACTLY the previous 8b60e1ad... digest in this
60# environment, so the recorded expectation was valid and this environment
61# reproduces it bit for bit. Diffing that build against the current one yields
62# ONE changed line:
64# < ...inset: 10pt)[#strong[note]
65# > ...inset: 10pt)[#strong[aside]
67# Previous digests, kept so the change is auditable rather than silent:
68# typ 8b60e1ad81fddcbd459cb411b20a111548a9eeffcc22573f754ec1998c55d34d
69# pdf 0076e6d50830d10e231a7348304ea5f6730d5802408633d95b0ab7e63db4bf19
70echo D6C_GATE_03_DEFAULT_TYPST_AND_PDF_EXACT_D6_BYTES
72generate_alternate() {
73 local stem="$1"
74 "$sigil" -L src test/build-print-customization.sgl "$gate_dir/$stem.typ"
75 "$typst_bin" compile --root "$repo_dir" --creation-timestamp 0 --pdf-standard a-2b \
76 --jobs 1 "$gate_dir/$stem.typ" "$gate_dir/$stem.pdf"
78generate_alternate alternate-a
79generate_alternate alternate-b
80cmp "$gate_dir/alternate-a.typ" "$gate_dir/alternate-b.typ"
81cmp "$gate_dir/alternate-a.pdf" "$gate_dir/alternate-b.pdf"
82# `if cmp; then fail`, never a bare `! cmp` -- bash exempts `!`-inverted
83# commands from `set -e`, so the bare form could never fail: theming that
84# silently stopped applying would have passed (inert 2026-08-24).
85if cmp -s "$gate_dir/default-a.typ" "$gate_dir/alternate-a.typ"; then
86 echo 'D6C: alternate theme produced a .typ IDENTICAL to the default' >&2
87 exit 1
88fi
89if cmp -s "$gate_dir/default-a.pdf" "$gate_dir/alternate-a.pdf"; then
90 echo 'D6C: alternate theme produced a .pdf IDENTICAL to the default' >&2
91 exit 1
92fi
93"$qpdf_bin" --check "$gate_dir/alternate-a.pdf" >"$gate_dir/alternate-qpdf.txt" 2>&1
94"$pdfinfo_bin" "$gate_dir/alternate-a.pdf" >"$gate_dir/alternate-pdfinfo.txt"
95"$pdftotext_bin" -layout "$gate_dir/alternate-a.pdf" "$gate_dir/alternate.txt"
96rg -q '^Pages:[[:space:]]+5$' "$gate_dir/alternate-pdfinfo.txt"
97rg -q '^Page size:[[:space:]]+419\.528 x 595\.276 pts' "$gate_dir/alternate-pdfinfo.txt"
98rg -q '^Tagged:[[:space:]]+yes$' "$gate_dir/alternate-pdfinfo.txt"
99rg -q 'Chapter I Same Author' "$gate_dir/alternate.txt"
100rg -q 'I\.1\. A Themed Section' "$gate_dir/alternate.txt"
101rg -q 'Chapter II Guest Author' "$gate_dir/alternate.txt"
102rg -q 'Grace Hopper' "$gate_dir/alternate.txt"
103rg -q 'Copyable UTF-8: καλημέρα' "$gate_dir/alternate.txt"
104test "$(rg -o 'David Wilson' "$gate_dir/alternate.txt" | wc -l)" -eq 1
105"$pdftotext_bin" -f 4 -l 4 -layout "$gate_dir/alternate-a.pdf" "$gate_dir/alternate-page-4.txt"
106"$pdftotext_bin" -f 5 -l 5 -layout "$gate_dir/alternate-a.pdf" "$gate_dir/alternate-page-5.txt"
107rg -q 'Customization Pressure' "$gate_dir/alternate-page-4.txt"
108rg -q 'Chapter II Guest Author' "$gate_dir/alternate-page-5.txt"
109echo D6C_GATE_04_DISTINCT_A5_POLICY_AUTHORS_CONTENTS_ODD_START_HEADER_UTF8
111"$sigil" -L src test/build-print-customization.sgl \
112 "$gate_dir/chapter-header.typ" chapter-title
113"$typst_bin" compile --root "$repo_dir" --creation-timestamp 0 --pdf-standard a-2b \
114 --jobs 1 "$gate_dir/chapter-header.typ" "$gate_dir/chapter-header.pdf"
115"$pdftotext_bin" -f 4 -l 4 -layout "$gate_dir/chapter-header.pdf" \
116 "$gate_dir/chapter-header-page-4.txt"
117"$pdftotext_bin" -f 5 -l 5 -layout "$gate_dir/chapter-header.pdf" \
118 "$gate_dir/chapter-header-page-5.txt"
119rg -q 'Guest Author' "$gate_dir/chapter-header-page-4.txt"
120test "$(rg -o 'Guest Author' "$gate_dir/chapter-header-page-5.txt" | wc -l)" -ge 2
121echo D6C_GATE_05_CHAPTER_TITLE_RUNNING_HEADER_STATE
123"$pdftoppm_bin" -f 3 -l 3 -singlefile -png -r 160 "$gate_dir/alternate-a.pdf" \
124 "$gate_dir/alternate-page"
125"$convert_bin" "$gate_dir/alternate-page.png" -format %c histogram:info:- \
126 >"$gate_dir/alternate-histogram.txt"
127rg -qi '#58715F' "$gate_dir/alternate-histogram.txt"
128rg -qi '#A03C62' "$gate_dir/alternate-histogram.txt"
129rg -qi '#4E55A6' "$gate_dir/alternate-histogram.txt"
130rg -qi '#B05F18' "$gate_dir/alternate-histogram.txt"
131rg -qi '#EDF1F5' "$gate_dir/alternate-histogram.txt"
132echo D6C_GATE_06_CUSTOM_FONTS_COLORS_HIGHLIGHT_AND_COPYABLE_TEXT
134"$sigil" -L src -L book test/build-practical-sigil-compact.sgl \
135 "$gate_dir/practical-compact.typ"
136"$typst_bin" compile --root "$repo_dir" --creation-timestamp 0 --pdf-standard a-2b \
137 --jobs 1 "$gate_dir/practical-compact.typ" "$gate_dir/practical-compact.pdf"
138"$pdftotext_bin" -layout "$gate_dir/practical-compact.pdf" "$gate_dir/practical-compact.txt"
139rg -q 'Chapter I A Useful First Script' "$gate_dir/practical-compact.txt"
140rg -q 'Chapter II Change the Question' "$gate_dir/practical-compact.txt"
141echo D6C_GATE_07_CHECKED_IN_PRACTICAL_SIGIL_ALTERNATE_EDITION
143# Subject-existence pins: to `if rg`, a missing file (exit 2, empty output)
144# reads the same as a clean one, and an unmatched glob does too -- either would
145# disarm these sweeps silently.
146test -f src/sigil/doc/print.sgl
147if rg -n -i 'typst|paper|margin|font|color|\.typ' src/sigil/doc/print.sgl \
148 | rg -v '^[0-9]+:[[:space:]]*;'; then
149 echo 'D6 customization backend leakage into print policy' >&2
150 exit 1
151fi
152compgen -G 'book/practical-sigil/*.sgd' > /dev/null
153if rg -n 'typst-theme|print-options|make-typst-length' book/practical-sigil/*.sgd; then
154 echo 'D6 customization leaked build policy into manuscripts' >&2
155 exit 1
156fi
157echo D6C_GATE_08_BACKEND_FREE_POLICY_AND_PASSIVE_MANUSCRIPTS
159bash test/gate-d6.sh >"$gate_dir/d6-regression.txt"
160rg -q D6_GATE_GREEN "$gate_dir/d6-regression.txt"
161echo D6C_GATE_09_D0_D6_REGRESSIONS_GREEN
163printf 'D6_CUSTOMIZATION_GATE_GREEN artifacts=%s\n' "$gate_dir"