AtlatestRepositorysigil-doc

sigil-doc / tree / testsd-p1-before-transcript.sh

1#!/usr/bin/env bash
2# Regenerate `test/transcripts/sd-p1/classification-before.txt` -- the measured
3# behaviour of `@text{}`/`@expr{}` under the PRE-SD-P1 parser.
4#
5# This exists as a script rather than as a command someone once ran because the
6# transcript is an INPUT to `test/gate-sd-p1.sh` arm 2, and a reviewer must be
7# able to re-derive it rather than trust it.
8#
9# THE TRAP IT EXISTS TO AVOID: `sigil -L <other>/src` invoked from THIS package's
10# root does NOT shadow this package's own `src/`. Driving a "before" run that way
11# silently measures the CURRENT parser and produces a transcript that looks
12# perfect and means nothing. The pristine tree is therefore extracted as a
13# STANDALONE PACKAGE and run from its own root, and this script emits the
14# marker `PRE_SD_P1_CONTROL_UNBOUND` only after positively confirming that the
15# tree it ran cannot resolve a binding that exists solely in the new parser.
16set -euo pipefail
17repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
18cd "$repo_dir"
19sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
20base="${SD_P1_BASE:-c41979c}"
21out="test/transcripts/sd-p1/classification-before.txt"
23test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }
24git rev-parse --verify "$base^{commit}" >/dev/null 2>&1 || {
25 echo "base commit $base is not resolvable" >&2; exit 1; }
27pre="$repo_dir/build/sd-p1-pre"
28rm -rf "$pre"; mkdir -p "$pre" "$(dirname "$out")"
29# `book` and `test/fixtures` come along because the lowering dump names
30# manuscripts by repo-relative path and must read the pre-SD-P1 copies of them.
31git archive "$base" src package.sgl book test/fixtures | tar -x -C "$pre"
32cp test/sd-p1-classification-probe.sgl "$pre/probe.sgl"
33cp test/sd-p1-lowering-dump.sgl "$pre/dump.sgl"
35# `dev-redirects.sgl` is SIBLING-RELATIVE, so a package living under build/
36# cannot use it. Write an absolute-path equivalent.
37sibling="$(cd "$repo_dir/.." && pwd)"
38cat >"$pre/abs-redirects.sgl" <<EOF
39(redirects
40 repos: (list
41 (for-repo url: "codeberg:sigil/sigil"
42 use: (from-path dir: "$sibling/sigil"))
43 (for-repo url: "codeberg:sigil/sigil-sxml"
44 use: (from-path dir: "$sibling/sigil-sxml"))))
45EOF
47cache=$(mktemp -d "$repo_dir/build/sd-p1-before-cache.XXXXXX")
48control_log="$cache/control.log"
50# THE INSTRUMENT CHECK, before any measurement is believed.
51set +e
52( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \
53 "$sigil" -L src eval '(begin (import (sigil doc private parser)) (display sigil-doc-profile))' ) \
54 >"$control_log" 2>&1
55set -e
56if ! grep -q "unbound variable 'sigil-doc-profile'" "$control_log"; then
57 echo "POSITIVE CONTROL FAILED: the tree under test resolved sigil-doc-profile," >&2
58 echo "so it is NOT the pre-SD-P1 parser. Refusing to write a before transcript." >&2
59 cat "$control_log" >&2
60 exit 1
61fi
63probe_log="$cache/probe.log"
64( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \
65 "$sigil" -L src eval -f probe.sgl ) >"$probe_log" 2>&1
66# DERIVE the expected case count from the probe source rather than repeating
67# it here. A hardcoded count went stale the moment a case was added, and this
68# guard then failed a run whose probe had actually worked perfectly.
69cases=$(grep -c '^(report "' test/sd-p1-classification-probe.sgl)
70test "$cases" -ge 1 || { echo "could not count the probe's cases" >&2; exit 1; }
71grep -q "SD_P1_CLASSIFICATION_PROBE_COMPLETE $cases cases" "$probe_log" || {
72 echo "the pre-SD-P1 probe did not run all $cases cases" >&2; cat "$probe_log" >&2; exit 1; }
74dump_log="$cache/lowering.log"
75( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \
76 "$sigil" -L src eval -f dump.sgl ) >"$dump_log" 2>&1
77grep -q 'SD_P1_LOWERING_DUMP_COMPLETE 10 manuscripts' "$dump_log" || {
78 echo "the pre-SD-P1 lowering dump did not cover all 10 manuscripts" >&2
79 tail -20 "$dump_log" >&2; exit 1; }
80cp "$dump_log" test/transcripts/sd-p1/lowering-before.txt
81echo "wrote test/transcripts/sd-p1/lowering-before.txt ($(wc -l <"$dump_log") lines)"
84 echo "# Measured behaviour of @text{}/@expr{} under the PRE-SD-P1 parser."
85 echo "# Regenerate with test/sd-p1-before-transcript.sh"
86 echo "#"
87 echo "# base commit: $base"
88 echo "# parser blob: $(git rev-parse "$base:src/sigil/doc/private/parser.sgl")"
89 echo "# compiler: $("$sigil" --version 2>&1 | sed -e 's/\x1b\[[0-9;]*m//g')"
90 echo "#"
91 echo "# POSITIVE CONTROL -- the tree measured below could not resolve a binding"
92 echo "# that exists only in the post-SD-P1 parser, so it really is the old one:"
93 sed -e 's/^/# /' "$control_log"
94 echo "PRE_SD_P1_CONTROL_UNBOUND"
95 cat "$probe_log"
96} >"$out"
98echo "wrote $out"