AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
set -euo pipefail4
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"5
cd "$repo_dir"6
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"7
redirects="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"8
sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"9
typst_bin="${TYPST_BIN:-typst}"10
pdfinfo_bin="${PDFINFO_BIN:-pdfinfo}"11
pdftotext_bin="${PDFTOTEXT_BIN:-pdftotext}"12
pdftoppm_bin="${PDFTOPPM_BIN:-pdftoppm}"13
qpdf_bin="${QPDF_BIN:-qpdf}"14
convert_bin="${CONVERT_BIN:-convert}"15
sha256sum_bin="${SHA256SUM_BIN:-sha256sum}"16
mkdir -p "$repo_dir/build"17
gate_dir="$(mktemp -d "$repo_dir/build/d6-customization-gate.XXXXXX")"18
export XDG_CACHE_HOME="$gate_dir/cache"19
export SIGIL_REDIRECTS="$redirects"20
export SIGIL_D1_COMPILER="$sigil"21
export SIGIL_BYTECODE_BASE="${SIGIL_BYTECODE_BASE:-$(test/build-d3-bytecode-base.sh)}"22
export SOURCE_DATE_EPOCH=024
for tool in "$typst_bin" "$pdfinfo_bin" "$pdftotext_bin" "$pdftoppm_bin" \25
"$qpdf_bin" "$convert_bin" "$sha256sum_bin"; do26
command -v "$tool" >/dev/null27
done28
"$typst_bin" --version | tee "$gate_dir/toolchain.txt"29
echo D6C_GATE_01_PINNED_TOOLCHAIN31
"$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"34
rg -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"37
rg -q '2 passed' "$gate_dir/book-config-tests.txt"38
echo D6C_GATE_02_OPTIONS_THEME_VALIDATION_AND_BOOK_CONFIG_12_1240
generate_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"45
}46
generate_default default-a47
generate_default default-b48
cmp "$gate_dir/default-a.typ" "$gate_dir/default-b.typ"49
cmp "$gate_dir/default-a.pdf" "$gate_dir/default-b.pdf"50
test "$("$sha256sum_bin" "$gate_dir/default-a.typ" | cut -d' ' -f1)" = \51
831af06d88bb5d43fc6e5ea3ed64364eda37e585ee61a45d5d5c2098fcc43fae52
test "$("$sha256sum_bin" "$gate_dir/default-a.pdf" | cut -d' ' -f1)" = \53
b1a48320da52a9a271cbf0250cbb84bb5d233fb459e7954464bbd9c113d4f17a54
# Digests updated 2026-08-10 for the D13 rename (note -> aside). The book's55
# admonition label is derived from the model kind, so renaming the kind changes56
# one line of emitted Typst and therefore both artifacts.57
#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 this60
# environment, so the recorded expectation was valid and this environment61
# reproduces it bit for bit. Diffing that build against the current one yields62
# ONE changed line:63
#64
# < ...inset: 10pt)[#strong[note]65
# > ...inset: 10pt)[#strong[aside]66
#67
# Previous digests, kept so the change is auditable rather than silent:68
# typ 8b60e1ad81fddcbd459cb411b20a111548a9eeffcc22573f754ec1998c55d34d69
# pdf 0076e6d50830d10e231a7348304ea5f6730d5802408633d95b0ab7e63db4bf1970
echo D6C_GATE_03_DEFAULT_TYPST_AND_PDF_EXACT_D6_BYTES72
generate_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"77
}78
generate_alternate alternate-a79
generate_alternate alternate-b80
cmp "$gate_dir/alternate-a.typ" "$gate_dir/alternate-b.typ"81
cmp "$gate_dir/alternate-a.pdf" "$gate_dir/alternate-b.pdf"82
# `if cmp; then fail`, never a bare `! cmp` -- bash exempts `!`-inverted83
# commands from `set -e`, so the bare form could never fail: theming that84
# silently stopped applying would have passed (inert 2026-08-24).85
if cmp -s "$gate_dir/default-a.typ" "$gate_dir/alternate-a.typ"; then86
echo 'D6C: alternate theme produced a .typ IDENTICAL to the default' >&287
exit 188
fi89
if cmp -s "$gate_dir/default-a.pdf" "$gate_dir/alternate-a.pdf"; then90
echo 'D6C: alternate theme produced a .pdf IDENTICAL to the default' >&291
exit 192
fi93
"$qpdf_bin" --check "$gate_dir/alternate-a.pdf" >"$gate_dir/alternate-qpdf.txt" 2>&194
"$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"96
rg -q '^Pages:[[:space:]]+5$' "$gate_dir/alternate-pdfinfo.txt"97
rg -q '^Page size:[[:space:]]+419\.528 x 595\.276 pts' "$gate_dir/alternate-pdfinfo.txt"98
rg -q '^Tagged:[[:space:]]+yes$' "$gate_dir/alternate-pdfinfo.txt"99
rg -q 'Chapter I Same Author' "$gate_dir/alternate.txt"100
rg -q 'I\.1\. A Themed Section' "$gate_dir/alternate.txt"101
rg -q 'Chapter II Guest Author' "$gate_dir/alternate.txt"102
rg -q 'Grace Hopper' "$gate_dir/alternate.txt"103
rg -q 'Copyable UTF-8: καλημέρα' "$gate_dir/alternate.txt"104
test "$(rg -o 'David Wilson' "$gate_dir/alternate.txt" | wc -l)" -eq 1105
"$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"107
rg -q 'Customization Pressure' "$gate_dir/alternate-page-4.txt"108
rg -q 'Chapter II Guest Author' "$gate_dir/alternate-page-5.txt"109
echo D6C_GATE_04_DISTINCT_A5_POLICY_AUTHORS_CONTENTS_ODD_START_HEADER_UTF8111
"$sigil" -L src test/build-print-customization.sgl \112
"$gate_dir/chapter-header.typ" chapter-title113
"$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"119
rg -q 'Guest Author' "$gate_dir/chapter-header-page-4.txt"120
test "$(rg -o 'Guest Author' "$gate_dir/chapter-header-page-5.txt" | wc -l)" -ge 2121
echo D6C_GATE_05_CHAPTER_TITLE_RUNNING_HEADER_STATE123
"$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"127
rg -qi '#58715F' "$gate_dir/alternate-histogram.txt"128
rg -qi '#A03C62' "$gate_dir/alternate-histogram.txt"129
rg -qi '#4E55A6' "$gate_dir/alternate-histogram.txt"130
rg -qi '#B05F18' "$gate_dir/alternate-histogram.txt"131
rg -qi '#EDF1F5' "$gate_dir/alternate-histogram.txt"132
echo D6C_GATE_06_CUSTOM_FONTS_COLORS_HIGHLIGHT_AND_COPYABLE_TEXT134
"$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"139
rg -q 'Chapter I A Useful First Script' "$gate_dir/practical-compact.txt"140
rg -q 'Chapter II Change the Question' "$gate_dir/practical-compact.txt"141
echo D6C_GATE_07_CHECKED_IN_PRACTICAL_SIGIL_ALTERNATE_EDITION143
# 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 would145
# disarm these sweeps silently.146
test -f src/sigil/doc/print.sgl147
if rg -n -i 'typst|paper|margin|font|color|\.typ' src/sigil/doc/print.sgl \148
| rg -v '^[0-9]+:[[:space:]]*;'; then149
echo 'D6 customization backend leakage into print policy' >&2150
exit 1151
fi152
compgen -G 'book/practical-sigil/*.sgd' > /dev/null153
if rg -n 'typst-theme|print-options|make-typst-length' book/practical-sigil/*.sgd; then154
echo 'D6 customization leaked build policy into manuscripts' >&2155
exit 1156
fi157
echo D6C_GATE_08_BACKEND_FREE_POLICY_AND_PASSIVE_MANUSCRIPTS159
bash test/gate-d6.sh >"$gate_dir/d6-regression.txt"160
rg -q D6_GATE_GREEN "$gate_dir/d6-regression.txt"161
echo D6C_GATE_09_D0_D6_REGRESSIONS_GREEN163
printf 'D6_CUSTOMIZATION_GATE_GREEN artifacts=%s\n' "$gate_dir"