AtlatestRepositorysigil-doc

sigil-doc / tree / testgate-sd-p2-backend-refusal.sh

1#!/usr/bin/env bash
2# 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 the
5# only thing refusing? It cannot be asked through the public API, because
6# make-url-link refuses a hostile target before any renderer sees it - which is
7# the design working. So the probe runs against a scratch copy of the tree whose
8# CORE check has been neutered. Only that input is neutered; the probe's own
9# scoring and its benign positive control are untouched.
10set -euo pipefail
12repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
13cd "$repo_dir"
14mkdir -p "$repo_dir/build"
15sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"
16sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"
17work="${SD_P2_BACKEND_WORK:-$(mktemp -d "$repo_dir/build/sd-p2-backend.XXXXXX")}"
18mkdir -p "$work"
20for tool in rg sed cmp sha256sum; do
21 command -v "$tool" >/dev/null || { echo "gate-sd-p2-backend-refusal: missing $tool" >&2; exit 1; }
22done
23test -x "$sigil" || { echo "gate-sd-p2-backend-refusal: $sigil is not executable" >&2; exit 1; }
25scratch="$work/neutered"
26mkdir -p "$scratch"
27# Hash the real file so the leak check below compares CONTENT. Comparing
28# against git status instead answers a different question: it fires on any
29# ordinary uncommitted edit and says nothing about what the sed touched.
30core_before="$(sha256sum src/sigil/doc/model.sgl | cut -d' ' -f1)"
31cp -r src "$scratch/src"
32cp -r test "$scratch/test"
33# The probe must run with the scratch tree as its OWN package root. Run it from
34# the repo root and the local package.sgl resolves (sigil doc *) to the real src
35# no matter what -L says, silently turning this arm back into a core test - which
36# is exactly how it failed the first time it was written, and why the probe
37# asserts its own instrument before scoring anything.
38cp package.sgl "$scratch/package.sgl"
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"
46sed -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 core
50# again while claiming to test the backends.
51rg -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; }
53if cmp -s src/sigil/doc/model.sgl "$scratch/src/sigil/doc/model.sgl"; then
54 echo "gate-sd-p2-backend-refusal: neutered copy is identical to the real one" >&2; exit 1
55fi
57( 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"
61rg -q PROBE_00_CORE_NEUTERED_AS_INTENDED "$work/backend-refusal.txt"
62rg -q PROBE_01_POSITIVE_CONTROL_BENIGN_TARGET_RENDERS "$work/backend-refusal.txt"
63rg -q PROBE_02_BOTH_BACKENDS_REFUSED_EVERY_HOSTILE_TARGET "$work/backend-refusal.txt"
65core_after="$(sha256sum src/sigil/doc/model.sgl | cut -d' ' -f1)"
66test "$core_before" = "$core_after" \
67 || { echo "gate-sd-p2-backend-refusal: neutering leaked into the real tree" >&2; exit 1; }
69echo SD_P2_03_EACH_BACKEND_REFUSES_WITHOUT_THE_CORE_GATE