AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# SD-P2 arm 3, standalone so it can be sabotaged and re-run on its own.3
#4
# The question: is the per-backend link policy real, or is the semantic core the5
# only thing refusing? It cannot be asked through the public API, because6
# make-url-link refuses a hostile target before any renderer sees it - which is7
# the design working. So the probe runs against a scratch copy of the tree whose8
# CORE check has been neutered. Only that input is neutered; the probe's own9
# scoring and its benign positive control are untouched.10
set -euo pipefail12
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"13
cd "$repo_dir"14
mkdir -p "$repo_dir/build"15
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"16
sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"17
work="${SD_P2_BACKEND_WORK:-$(mktemp -d "$repo_dir/build/sd-p2-backend.XXXXXX")}"18
mkdir -p "$work"20
for tool in rg sed cmp sha256sum; do21
command -v "$tool" >/dev/null || { echo "gate-sd-p2-backend-refusal: missing $tool" >&2; exit 1; }22
done23
test -x "$sigil" || { echo "gate-sd-p2-backend-refusal: $sigil is not executable" >&2; exit 1; }25
scratch="$work/neutered"26
mkdir -p "$scratch"27
# Hash the real file so the leak check below compares CONTENT. Comparing28
# against git status instead answers a different question: it fires on any29
# ordinary uncommitted edit and says nothing about what the sed touched.30
core_before="$(sha256sum src/sigil/doc/model.sgl | cut -d' ' -f1)"31
cp -r src "$scratch/src"32
cp -r test "$scratch/test"33
# The probe must run with the scratch tree as its OWN package root. Run it from34
# the repo root and the local package.sgl resolves (sigil doc *) to the real src35
# no matter what -L says, silently turning this arm back into a core test - which36
# is exactly how it failed the first time it was written, and why the probe37
# asserts its own instrument before scoring anything.38
cp package.sgl "$scratch/package.sgl"39
{40
echo '(redirects'41
echo ' repos: (list'42
printf ' (for-repo url: "codeberg:sigil/sigil-sxml"\n use: (from-path dir: "%s"))))\n' \43
"$(cd "$sigil_sxml_root" && pwd)"44
} >"$scratch/dev-redirects.sgl"46
sed -i \47
's|^ (define (require-link-target who value allowed)$| (define (require-link-target who value allowed) value)\n (define (neutered-link-target-check who value allowed)|' \48
"$scratch/src/sigil/doc/model.sgl"49
# A sed that matched nothing exits 0. Without this the arm would test the core50
# again while claiming to test the backends.51
rg -q 'neutered-link-target-check' "$scratch/src/sigil/doc/model.sgl" \52
|| { echo "gate-sd-p2-backend-refusal: neutering did not apply; the arm would be vacuous" >&2; exit 1; }53
if cmp -s src/sigil/doc/model.sgl "$scratch/src/sigil/doc/model.sgl"; then54
echo "gate-sd-p2-backend-refusal: neutered copy is identical to the real one" >&2; exit 155
fi57
( cd "$scratch" \58
&& XDG_CACHE_HOME="$work/neutered-cache" SIGIL_REDIRECTS="$scratch/dev-redirects.sgl" \59
"$sigil" -L "$sigil_sxml_root/src" -L src -L test \60
eval -f test/probe-backend-link-refusal.sgl ) | tee "$work/backend-refusal.txt"61
rg -q PROBE_00_CORE_NEUTERED_AS_INTENDED "$work/backend-refusal.txt"62
rg -q PROBE_01_POSITIVE_CONTROL_BENIGN_TARGET_RENDERS "$work/backend-refusal.txt"63
rg -q PROBE_02_BOTH_BACKENDS_REFUSED_EVERY_HOSTILE_TARGET "$work/backend-refusal.txt"65
core_after="$(sha256sum src/sigil/doc/model.sgl | cut -d' ' -f1)"66
test "$core_before" = "$core_after" \67
|| { echo "gate-sd-p2-backend-refusal: neutering leaked into the real tree" >&2; exit 1; }69
echo SD_P2_03_EACH_BACKEND_REFUSES_WITHOUT_THE_CORE_GATE