AtlatestRepositorysigil-doc

sigil-doc / tree / testsd-p7-pristine-control.sh

1#!/usr/bin/env bash
2# SD-P7 pristine control: run the FULL suite against the tree as it was before
3# this phase, with the identical command and environment, so any failure can be
4# attributed rather than argued about.
5#
6# TWO TRAPS THIS AVOIDS, both recorded by SD-P1:
7#
8# 1. `sigil -L <dir>` DOES NOT SHADOW THE PACKAGE'S OWN `src/`. Extracting an
9# old tree somewhere and adding it to the load path from THIS package root
10# runs the CURRENT code and produces a "before" transcript measured against
11# the after. The extracted tree is therefore run FROM ITS OWN package root.
12# 2. `dev-redirects.sgl` is sibling-relative, so a detached package needs an
13# ABSOLUTE-path redirects file written for it.
15# And the positive control that makes the result mean anything: the pristine
16# tree must NOT be able to resolve a binding only this phase's code has. If
17# `make-content-profile` is bound in there, the extraction did not work and the
18# run is measuring the wrong tree.
19set -euo pipefail
20repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
21cd "$repo_dir"
22sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
23sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"
24base_sha="${1:-$(grep '^base-sha: ' test/transcripts/sd-p7/construction-before.txt | sed 's/^base-sha: //')}"
26test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }
27git cat-file -e "$base_sha^{commit}" || { echo "no such commit: $base_sha" >&2; exit 1; }
29work=$(mktemp -d /tmp/sd-p7-pristine.XXXXXX)
30trap 'echo "pristine tree left at $work for inspection"' EXIT
31git archive "$base_sha" | tar -x -C "$work"
32test -f "$work/package.sgl" || { echo "extraction produced no package root" >&2; exit 1; }
34cat > "$work/absolute-redirects.sgl" <<EOF
35(redirects
36 repos: (list
37 (for-repo url: "codeberg:sigil/sigil"
38 use: (from-path dir: "$(cd "$repo_dir/../sigil" && pwd)"))
39 (for-repo url: "codeberg:sigil/sigil-sxml"
40 use: (from-path dir: "$(cd "$sigil_sxml_root" && pwd)"))))
41EOF
43export SIGIL_REDIRECTS="$work/absolute-redirects.sgl"
44export XDG_CACHE_HOME="$work/cache"
45mkdir -p "$XDG_CACHE_HOME"
47echo "=== PRISTINE CONTROL: base $base_sha, extracted to $work"
48cd "$work"
50# POSITIVE CONTROL ON THE EXTRACTION ITSELF, before any result is believed.
51control=$("$sigil" -L src eval '(begin (import (sigil doc)) (display make-content-profile))' 2>&1 || true)
52case "$control" in
53 *"unbound"*|*"not exported"*|*"no binding"*)
54 echo "PRISTINE_CONTROL_OK: the extracted tree does not know make-content-profile" ;;
55 *)
56 echo "PRISTINE_CONTROL_FAILED: the extracted tree resolved make-content-profile" >&2
57 echo " -> this run is measuring the CURRENT code, not the pristine tree" >&2
58 echo " -> $control" >&2
59 exit 1 ;;
60esac
62status=0
63"$sigil" -L "$sigil_sxml_root/src" -L src -L test -L book test 2>&1 \
64 | sed 's/\x1b\[[0-9;]*m//g' || status=$?
65echo "PRISTINE_CONTROL_COMPLETE status=$status"