#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # selftest-auditonly.sh — adversarial self-test for check.sh --audit-only. # # --audit-only skips recompilation, which makes it the most dangerous thing in # this repository: if it ever accepted a tree whose sources had changed, a green # transcript would describe a corpus that is not on disk. Its whole safety rests # on refusing, so refusal is what this tests. # # Cases, each asserting a SPECIFIC diagnostic: # 0 no basis recorded -> REFUSING, may only follow a full run # 1 a proof source edited by one comment -> REFUSING, sources no longer match # 2 a proof source DELETED -> REFUSING (the basis lists it) # 3 a NEW proof source added -> ORPHAN, from the seam check, # which runs BEFORE the mode gate and catches it first # 4 an artifact deleted, sources intact -> MISSING ARTIFACT # 5 the basis file truncated -> REFUSING (mismatch, not a pass) # 6 mtimes touched but bytes unchanged -> PASSES, because bytes are the # test and mtimes are not: `touch` must neither grant nor deny permission # # Requires a prior full green run in this tree (that is what writes the basis). # No Lean runs here; the whole thing takes seconds. # ───────────────────────────────────────────────────────────────────────────── set -uo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" FAILURES=0 STASH="$(mktemp -d)" BASIS="$HERE/.audit-basis" VICTIM_SRC="Proofs/FeQ.lean" VICTIM_ART="Proofs/FeQ.olean" NEWSRC="$HERE/Proofs/ZZAuditOnlyProbe.lean" cleanup() { [ -f "$STASH/basis" ] && cp "$STASH/basis" "$BASIS" [ -f "$STASH/src" ] && cp "$STASH/src" "$HERE/$VICTIM_SRC" [ -f "$STASH/art" ] && cp "$STASH/art" "$HERE/$VICTIM_ART" rm -f "$NEWSRC" "${NEWSRC%.lean}.olean" rm -rf "$STASH" } trap cleanup EXIT INT TERM if [ ! -s "$BASIS" ]; then echo "FATAL: no basis in this tree. Run ./check.sh with no arguments first;" echo "this self-test exercises --audit-only, which requires one." exit 1 fi cp "$BASIS" "$STASH/basis" cp "$HERE/$VICTIM_SRC" "$STASH/src" cp "$HERE/$VICTIM_ART" "$STASH/art" expect() { # expect