AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# SD-P7 -- canonical dump of CONSTRUCTED documents for every manuscript in the tree.3
#4
# WHY THIS EXISTS AND WHY IT IS NOT `sd-p1-lowering-dump.sgl`.5
#6
# SD-P1 changed LOWERING, so its differential compares emitted syntax. SD-P77
# changes CONSTRUCTION -- `make-section` and the author runtime's node8
# admission -- and lowering is not touched at all. A lowering differential would9
# therefore be byte-identical under a completely broken version of this phase,10
# which is the definition of a check that cannot fail on the input it is used11
# on. What has to be compared here is the built DOCUMENT.12
#13
# `document->string` is `(format "~s" (document->datum root))`, and14
# `document->datum` carries every field AND every node's full source location15
# (file, byte position, line, column, span). So an equality over this output is16
# a strong statement about semantic content and locations together, rather than17
# the weaker "the suites did not complain".18
#19
# A manuscript that RAISES is recorded by its message, not skipped. Several20
# fixtures in this tree are deliberately malformed or deliberately rooted21
# outside `sigil-doc-profile`; "raises exactly this message" is part of the22
# behaviour that must not change, and skipping them would quietly shrink the23
# population (taxonomy shape 14).24
#25
# POPULATION IS DERIVED, NOT LISTED. `find book test -name '*.sgd'` is the26
# population; the script prints its size and refuses to run on an empty one, so27
# a mistyped path cannot produce an empty dump that compares equal to another28
# empty dump (taxonomy shape 4).29
#30
# ONE EXCLUSION, AND IT IS STATED RATHER THAN SILENT. The manuscripts this phase31
# ADDED (`test/fixtures/sd-p7-*.sgd`) cannot appear in a differential whose whole32
# purpose is "the behaviour that existed before is unchanged": they did not exist33
# when the baseline was taken, so there is nothing to compare them against, and34
# including them would make every AFTER run differ from every baseline for a35
# reason that is not a behaviour change.36
#37
# They are not untested. They are the subject of `test/test-section-profile.sgl`,38
# which loads both end to end through the real `#lang` path. The differential39
# answers a different question from the suite, and the exclusion is exactly the40
# set of manuscripts about which it has no question to answer.41
#42
# The script prints FOUND, EXCLUDED (by name) and COMPARED, so the denominator43
# and the gap are both in the artifact. An exclusion whose count is not reported44
# is a sample wearing a population's clothes.45
set -euo pipefail46
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"47
cd "$repo_dir"49
out="${1:?usage: sd-p7-construction-dump.sh <output-file>}"50
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"51
test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }52
for tool in find sort git; do53
command -v "$tool" >/dev/null || { echo "$tool is required by this dump" >&2; exit 1; }54
done56
mkdir -p "$repo_dir/build"57
cache_dir=$(mktemp -d "$repo_dir/build/sd-p7-dump-cache.XXXXXX")58
trap 'rm -rf "$cache_dir"' EXIT INT TERM59
export XDG_CACHE_HOME="$cache_dir"60
export SIGIL_REDIRECTS="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"62
# Population, derived from the tree, then partitioned.63
mapfile -t found < <(find book test -name '*.sgd' | sort)64
manuscripts=(); excluded=()65
for path in "${found[@]}"; do66
case "$path" in67
test/fixtures/sd-p7-*) excluded+=("$path") ;;68
*) manuscripts+=("$path") ;;69
esac70
done71
count=${#manuscripts[@]}72
found_count=${#found[@]}73
excluded_count=${#excluded[@]}74
test "$count" -gt 0 || { echo "manuscript population is empty -- refusing to write a dump" >&2; exit 1; }75
test "$((count + excluded_count))" = "$found_count" \76
|| { echo "partition lost manuscripts: $count + $excluded_count != $found_count" >&2; exit 1; }78
# PROVENANCE, embedded in the artifact itself so a superseded baseline fails as79
# "baseline superseded", never as a bare diff. Per the differential-gate pattern80
# in topics/folio-doc-phase-queue-2026-08-10.81
{82
echo "SD_P7_CONSTRUCTION_DUMP v1"83
echo "base-sha: $(git rev-parse HEAD)"84
# SCOPED TO src, and the paths NAMED. A whole-tree count leaves85
# src-cleanliness unprovable from the artifact alone, which is the only86
# cleanliness this differential depends on.87
echo "src-state: $(git status --porcelain -- src | wc -l) modified paths under src/"88
git status --porcelain -- src | sed "s/^/src-dirty: /"89
echo "tree-state: $(git status --porcelain | wc -l) modified paths overall"90
git status --porcelain | sed "s/^/tree-dirty: /"91
echo "compiler: $("$sigil" --version 2>&1 | tail -1)"92
echo "population: $found_count found by: find book test -name '*.sgd' | sort"93
echo "excluded: $excluded_count (added by SD-P7; absent from the baseline, so there is nothing to compare them against -- they are exercised by test/test-section-profile.sgl instead)"94
for path in ${excluded[@]+"${excluded[@]}"}; do echo "excluded-path: $path"; done95
echo "compared: $count manuscripts"96
echo "cache: isolated (fresh XDG_CACHE_HOME per run; cold for the first manuscript, warm after)"97
} > "$out"99
for path in "${manuscripts[@]}"; do100
echo "=== $path" >> "$out"101
# One process per manuscript. Manuscripts define top-level author commands102
# (`article`, `callout`, ...) and every one of them binds `document`, so103
# loading several into one module would let an earlier manuscript's bindings104
# answer for a later one's.105
"$sigil" -L src -L test eval "(begin106
(import (sigil doc))107
(display (guard (e (else (string-append \"RAISED: \" (exception-message e))))108
(begin (load \"$path\") (document->string (eval (quote document))))))109
(newline))" >> "$out" 2>&1 || echo "DUMP_PROCESS_EXIT_NONZERO" >> "$out"110
done112
echo "SD_P7_CONSTRUCTION_DUMP_COMPLETE $count of $found_count manuscripts ($excluded_count excluded)" >> "$out"113
echo "SD_P7_CONSTRUCTION_DUMP_COMPLETE $count of $found_count manuscripts ($excluded_count excluded) -> $out"