AtlatestRepositorysigil-doc

sigil-doc / tree / testsd-p7-construction-dump.sh

1#!/usr/bin/env bash
2# 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-P7
7# changes CONSTRUCTION -- `make-section` and the author runtime's node
8# admission -- and lowering is not touched at all. A lowering differential would
9# 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 used
11# on. What has to be compared here is the built DOCUMENT.
13# `document->string` is `(format "~s" (document->datum root))`, and
14# `document->datum` carries every field AND every node's full source location
15# (file, byte position, line, column, span). So an equality over this output is
16# a strong statement about semantic content and locations together, rather than
17# the weaker "the suites did not complain".
19# A manuscript that RAISES is recorded by its message, not skipped. Several
20# fixtures in this tree are deliberately malformed or deliberately rooted
21# outside `sigil-doc-profile`; "raises exactly this message" is part of the
22# behaviour that must not change, and skipping them would quietly shrink the
23# population (taxonomy shape 14).
25# POPULATION IS DERIVED, NOT LISTED. `find book test -name '*.sgd'` is the
26# population; the script prints its size and refuses to run on an empty one, so
27# a mistyped path cannot produce an empty dump that compares equal to another
28# empty dump (taxonomy shape 4).
30# ONE EXCLUSION, AND IT IS STATED RATHER THAN SILENT. The manuscripts this phase
31# ADDED (`test/fixtures/sd-p7-*.sgd`) cannot appear in a differential whose whole
32# purpose is "the behaviour that existed before is unchanged": they did not exist
33# when the baseline was taken, so there is nothing to compare them against, and
34# including them would make every AFTER run differ from every baseline for a
35# reason that is not a behaviour change.
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 differential
39# answers a different question from the suite, and the exclusion is exactly the
40# set of manuscripts about which it has no question to answer.
42# The script prints FOUND, EXCLUDED (by name) and COMPARED, so the denominator
43# and the gap are both in the artifact. An exclusion whose count is not reported
44# is a sample wearing a population's clothes.
45set -euo pipefail
46repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
47cd "$repo_dir"
49out="${1:?usage: sd-p7-construction-dump.sh <output-file>}"
50sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
51test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }
52for tool in find sort git; do
53 command -v "$tool" >/dev/null || { echo "$tool is required by this dump" >&2; exit 1; }
54done
56mkdir -p "$repo_dir/build"
57cache_dir=$(mktemp -d "$repo_dir/build/sd-p7-dump-cache.XXXXXX")
58trap 'rm -rf "$cache_dir"' EXIT INT TERM
59export XDG_CACHE_HOME="$cache_dir"
60export SIGIL_REDIRECTS="${SIGIL_D1_REDIRECTS:-$repo_dir/dev-redirects.sgl}"
62# Population, derived from the tree, then partitioned.
63mapfile -t found < <(find book test -name '*.sgd' | sort)
64manuscripts=(); excluded=()
65for path in "${found[@]}"; do
66 case "$path" in
67 test/fixtures/sd-p7-*) excluded+=("$path") ;;
68 *) manuscripts+=("$path") ;;
69 esac
70done
71count=${#manuscripts[@]}
72found_count=${#found[@]}
73excluded_count=${#excluded[@]}
74test "$count" -gt 0 || { echo "manuscript population is empty -- refusing to write a dump" >&2; exit 1; }
75test "$((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 as
79# "baseline superseded", never as a bare diff. Per the differential-gate pattern
80# in topics/folio-doc-phase-queue-2026-08-10.
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 leaves
85 # src-cleanliness unprovable from the artifact alone, which is the only
86 # 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"; done
95 echo "compared: $count manuscripts"
96 echo "cache: isolated (fresh XDG_CACHE_HOME per run; cold for the first manuscript, warm after)"
97} > "$out"
99for path in "${manuscripts[@]}"; do
100 echo "=== $path" >> "$out"
101 # One process per manuscript. Manuscripts define top-level author commands
102 # (`article`, `callout`, ...) and every one of them binds `document`, so
103 # loading several into one module would let an earlier manuscript's bindings
104 # answer for a later one's.
105 "$sigil" -L src -L test eval "(begin
106 (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"
110done
112echo "SD_P7_CONSTRUCTION_DUMP_COMPLETE $count of $found_count manuscripts ($excluded_count excluded)" >> "$out"
113echo "SD_P7_CONSTRUCTION_DUMP_COMPLETE $count of $found_count manuscripts ($excluded_count excluded) -> $out"