#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # selftest-inventory.sh — adversarial self-test for check.sh Phase 2c. # # WHAT PHASE 2c IS FOR. Phase 2b asks the kernel whether any AXIOM is declared # under Proofs/. It says nothing about the ~3000 other declarations. Phase 3 # pins the cones of the 31 named certificates. Between them sits everything # else: a helper lemma that quietly acquired an oracle in its cone, a # declaration added, removed or renamed, a compiler-generated auxiliary that # changed shape. Phase 2c pins that whole surface and diffs it both ways. # # Cases, each asserting a SPECIFIC diagnostic: # 0 positive control: the untouched tree passes # 1 an allowlist row deleted -> UNCLASSIFIED (in env, not allowlisted) # 2 an allowlist row invented -> STALE (allowlisted, not in env) # 3 a cone silently widened -> BOTH, because the record changed # 4 an axiom row appears -> AXIOM SURFACE DRIFT # 5 the count trailer disagrees -> INVENTORY TRUNCATED (no vacuous pass) # # It runs the SHIPPING inventory_gate.sh against a recorded observation, so no # Lean is needed and the whole thing takes a second. The observation itself is # produced by check.sh Phase 2c; this test attacks the gate that judges it. # ───────────────────────────────────────────────────────────────────────────── set -uo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" FAILURES=0 STASH="$(mktemp -d)" trap 'rm -rf "$STASH"' EXIT INT TERM ALLOW="$HERE/inventory-allowlist.txt" [ -s "$ALLOW" ] || { echo "FATAL: inventory-allowlist.txt missing or empty"; exit 1; } # The observation a green run would produce: the allowlist itself plus a # trailer. Deriving it from the allowlist is exactly right for this test — the # question is whether the GATE reacts correctly to differences, and each case # below introduces one. mkobs() { # mkobs [extra-line...] local out="$1"; shift grep '^INV|' "$ALLOW" > "$out" for l in "$@"; do printf '%s\n' "$l" >> "$out"; done LC_ALL=C sort -o "$out" "$out" echo "INV-COUNT|$(grep -c '^INV|' "$out")" >> "$out" } expect() { # expect