AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
set -euo pipefail3
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"4
cd "$repo_dir"5
mkdir -p "$repo_dir/build"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
cache_dir=$(mktemp -d "$repo_dir/build/d2-cache.XXXXXX")9
export SIGIL_REDIRECTS="$redirects"11
mkdir -p "$cache_dir/real"12
# Subject-existence pins: `if rg` reads a missing file (exit 2) the same as a13
# clean one (exit 1); a renamed semantic core would disarm this sweep silently.14
test -f src/sigil/doc/model.sgl15
test -f src/sigil/doc/traversal.sgl16
if rg -n -i '(html|sxml|css|typst|latex|slate|class=|tag:)' src/sigil/doc/model.sgl src/sigil/doc/traversal.sgl; then17
echo "backend vocabulary leaked into semantic core" >&2; exit 118
fi19
future="$(find src -type f | rg '/(slate|pdf)\.sgl$' || true)"20
test -z "$future"21
test "$(find src -type f | rg '/html\.sgl$' | wc -l)" -eq 122
test "$(find src -type f | rg '/typst\.sgl$' | wc -l)" -eq 123
export XDG_CACHE_HOME="$cache_dir/real"25
# Compile the package and run the focused contract first. The real-language26
# controls below then exercise the public #lang path against those exact bytes.27
setsid -w "$sigil" -L src -L test test test/test-reader.sgl --report29
observed=$(setsid -w "$sigil" -L src -L test eval '(begin (import (sigil doc)) (load "test/fixtures/practical-sigil-chapter.sgd") (display (document-title (eval (quote document)))) (display "|") (display (eval (quote tip-calls))) (display "|") (display (document->plain (eval (quote document)))))')30
case "$observed" in31
*"A Useful First Script|2|"*"macro-expanded phrase"*"computed inline expression"*"Computed Section 2"*) ;;32
*) echo "D2 authoring positive control failed" >&2; exit 1 ;;33
esac34
reader_sgb=$(find "$cache_dir/real" -path '*/sigil/doc/reader.sgb' -print -quit)35
test -n "$reader_sgb"36
# POSITIVE CONTROLS FOR THE ABSENCE ASSERTION BELOW -- RUN FIRST, DELIBERATELY.37
# Until they pass, the assertion they guard means nothing, so they do not run38
# after it.39
#40
# `test "$before" = "$after"` below claims that loading the manuscript through41
# the public #lang path did NOT recompile the reader. That is an assertion that42
# NOTHING happened, and it is satisfied for free by anything that stops the43
# `eval` from running at all.44
#45
# It was reachable, not hypothetical. Until 2026-08-22 that line was a bare46
# `setsid`, which forks and returns 0 at once whenever the setsid process is a47
# process-group leader -- which is what bash makes it at an interactive prompt,48
# and by hand at a prompt is the only way anything in this repo is run.49
#50
# WHAT WAS MEASURED, STATED PRECISELY SO NOBODY READS IT AS "THIS GATE IS RED":51
# the measurement was of this ARM'S SHAPE -- stat, run a child that rewrites the52
# artifact, stat again -- with a synthetic 3-second child, under `bash -i` on a53
# pty. The bare form reported GREEN for an artifact the child demonstrably HAD54
# rewritten; `-w` reported RED. It says the shape can produce a false green. It55
# says nothing about whether the real manuscript recompiles the real reader, and56
# the assertion below is expected to hold.57
#58
# `-w` closes the race. These two controls close the other half, and they assert59
# DIFFERENT things:60
#61
# (a) A REBUILD LANDS AT THIS EXACT PATH. Without it, a recompile that wrote62
# somewhere else would leave `before = after` true while the very thing the63
# arm rules out had happened.64
# (b) THE `stat` PROBE SEES A REWRITE IN PLACE. That is the actual failure mode65
# -- an existing artifact overwritten, not a deleted one recreated -- and66
# (a) alone cannot show it, because a file that was removed and recreated67
# changes its stat triple by construction the moment it exists again.68
#69
# Both work in a THROWAWAY COPY of the cache, so the working tree is untouched70
# and no restore step has to be reached. The copy is removed afterwards: it is71
# under `build/` and therefore invisible to git, which is not the same as free.72
control_cache="$cache_dir/control"73
cp -a "$cache_dir/real" "$control_cache"74
control_sgb=$(find "$control_cache" -path '*/sigil/doc/reader.sgb' -print -quit)75
test -n "$control_sgb" || { echo "positive control: no reader.sgb in the copied cache" >&2; exit 1; }77
# (b) first, because it needs no compiler and a failure here invalidates (a) too.78
inplace_before=$(stat -c '%y:%s:%i' "$control_sgb")79
printf '\0' >>"$control_sgb"80
inplace_after=$(stat -c '%y:%s:%i' "$control_sgb")81
test "$inplace_before" != "$inplace_after" || {82
echo "POSITIVE CONTROL (b) FAILED: the stat probe cannot see an in-place rewrite." >&283
echo " before: $inplace_before" >&284
echo " after: $inplace_after" >&285
echo " The 'before = after' assertion below therefore proves nothing." >&2; exit 1; }87
# (a) now: delete the compiled reader from the copy and re-run the same88
# manuscript against that cache. It must be written back to the same path.89
rm -f "$control_sgb"90
XDG_CACHE_HOME="$control_cache" setsid -w "$sigil" -L src -L test \91
eval -f test/fixtures/practical-sigil-chapter.sgd >"$cache_dir/control.log" 2>&1 || {92
echo "positive control (a): the forced-recompile run failed" >&293
tail -30 "$cache_dir/control.log" >&2; exit 1; }94
test -f "$control_sgb" || {95
echo "POSITIVE CONTROL (a) FAILED: a recompile did not land at the path this arm watches." >&296
echo " expected: $control_sgb" >&297
echo " A rebuild could therefore happen without moving 'before'/'after' at all." >&2; exit 1; }98
rm -rf "$control_cache"99
echo "D2 cache-reuse probe armed: in-place rewrite visible to stat ($inplace_before -> $inplace_after); a rebuild lands at the watched path"101
# THE ASSERTION ITSELF, now that both halves of the probe have been shown to fire.102
before=$(stat -c '%y:%s:%i' "$reader_sgb")103
setsid -w "$sigil" -L src -L test eval -f test/fixtures/practical-sigil-chapter.sgd104
after=$(stat -c '%y:%s:%i' "$reader_sgb")105
test "$before" = "$after"107
echo "D2_REAL_LANGUAGE_GREEN"