aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / scripts / pipeline-proofs / 19-pr-gate-refuses-stale.sh
| 1 | #!/usr/bin/env bash |
| 2 | # 19: since the crumb retirement (2026-11-07, DRA-97) stale, missing or mixed crumbs no longer block admission. |
| 3 | # The real scripts/pr-gate.sh (with a fake `gh` that answers from fixtures: open PR, CLEAN, no required contexts) |
| 4 | # is run with --worktree on a clone whose PR branch (a) changed source without recompiling (formerly STALE), |
| 5 | # (b) deleted a .crumb (formerly MISSING), (c) changed source only, with no crumb commit, (d) changed source and |
| 6 | # a .crumb in one last commit (formerly refused by rule 2). Every case must exit 0 with |
| 7 | # "GATE crumb: SKIP retired". The crumb tool is never needed: CRUMB and a `crumb` on PATH are stubs that record |
| 8 | # any call and exit 99, and the proof checks they were never called. No network. |
| 9 | here="$(cd "$(dirname "$0")" && pwd)"; . "$here/lib.sh" |
| 10 | proof_begin 19 "pr-gate.sh no longer refuses stale, missing or mixed crumbs (retired, DRA-97)" "${1:-}" |
| 11 | GATE=${PR_GATE:-$here/../pr-gate.sh}; [ -x "$GATE" ] || { echo "pr-gate.sh not found at $GATE" >&2; exit 2; } |
| 12 | export SLEEP_SECS=0 |
| 13 | clone_repo "$TMP/seed"; git -C "$TMP/seed" checkout -q -B main |
| 14 | git clone -q --bare "$TMP/seed" "$TMP/origin.git" |
| 15 | git clone -q "$TMP/origin.git" "$TMP/w"; W=$TMP/w |
| 16 | git -C "$W" config user.name proof; git -C "$W" config user.email proof@example.invalid |
| 17 | FX="$TMP/fx"; mkdir -p "$FX" "$TMP/bin"; export FX |
| 18 | cat > "$TMP/bin/gh" <<'S' |
| 19 | #!/usr/bin/env bash |
| 20 | d="$FX/$CASE" |
| 21 | case "$1 $2" in |
| 22 | "pr view") cat "$d/pr.json" ;; |
| 23 | "pr list") echo '[]' ;; |
| 24 | api\ repos/*) echo '[]' ;; |
| 25 | *) echo "fake gh: unhandled: $*" >&2; exit 2 ;; |
| 26 | esac |
| 27 | S |
| 28 | printf '#!/usr/bin/env bash\necho "$*" >> "%s/crumb-called"\nexit 99\n' "$TMP" > "$TMP/bin/crumb" |
| 29 | chmod +x "$TMP/bin/gh" "$TMP/bin/crumb"; export PATH="$TMP/bin:$PATH" CRUMB="$TMP/bin/crumb" |
| 30 | fx() { # fx <case> <branch> <sha> |
| 31 | mkdir -p "$FX/$1" |
| 32 | printf '{"number":1,"state":"OPEN","isDraft":false,"baseRefName":"main","headRefName":"%s","headRefOid":"%s","mergeable":"MERGEABLE","mergeStateStatus":"CLEAN","reviewDecision":"","statusCheckRollup":[]}\n' "$2" "$3" > "$FX/$1/pr.json" |
| 33 | } |
| 34 | L=$(leaf_crumb_dir "$W") || { echo "no leaf crumb dir" >&2; exit 1; } |
| 35 | F=$(tracked_file_in "$W" "$L") |
| 36 | MAIN=main |
| 37 | branch() { git -C "$W" checkout -q -b "$1" "origin/$MAIN"; } |
| 38 | push() { git -C "$W" push -q origin "$1"; git -C "$W" rev-parse HEAD; } |
| 39 | admitted() { # admitted <label> : last gate run exited 0 with the retired SKIP and no crumb FAIL |
| 40 | check_eq "$1: pr-gate exits 0 (dry run)" "$RC" 0 |
| 41 | check "$1: GATE crumb: SKIP retired" grep -qF 'GATE crumb: SKIP retired 2026-11-07 (DRA-97); .crumb files are history' <<<"$OUT" |
| 42 | check "$1: no GATE crumb: FAIL" bash -c '! grep -q "^GATE crumb: FAIL" <<<"$1"' _ "$OUT" |
| 43 | } |
| 44 | |
| 45 | # (a) formerly stale: source change committed without recompiling |
| 46 | branch stale; printf '\n# proof 19 stale\n' >> "$W/$F"; git -C "$W" commit -qam "source change, no crumb compile" |
| 47 | SHA=$(push stale); fx stale stale "$SHA" |
| 48 | export CASE=stale; measure gate_stale "$GATE" proof-repo 1 --worktree "$W" --dry-run |
| 49 | admitted "stale tree" |
| 50 | note "$(grep '^GATE crumb' <<<"$OUT" | cut -c1-110)" |
| 51 | |
| 52 | # (b) formerly missing: a .crumb deleted (immediate child of a crumbed parent, and a deep one if present) |
| 53 | IMM=""; DEEP="" |
| 54 | for d in $(crumb_dirs "$W" | grep -v '^\.$'); do |
| 55 | p=${d%/*}; [ "$p" = "$d" ] && p=. |
| 56 | if [ -f "$W/$p/.crumb" ]; then [ -n "$IMM" ] || IMM=$d; else [ -n "$DEEP" ] || DEEP=$d; fi |
| 57 | done |
| 58 | num "immediate_child_crumb=$IMM"; num "deep_crumb_without_crumbed_parent=${DEEP:-none}" |
| 59 | branch missing-immediate; git -C "$W" rm -q "$IMM/.crumb"; git -C "$W" commit -qm "delete $IMM/.crumb" |
| 60 | SHA=$(push missing-immediate); fx missing missing-immediate "$SHA" |
| 61 | export CASE=missing; measure gate_missing_immediate "$GATE" proof-repo 1 --worktree "$W" --dry-run |
| 62 | admitted "missing immediate-child crumb" |
| 63 | if [ -n "$DEEP" ]; then |
| 64 | branch missing-deep; git -C "$W" rm -q "$DEEP/.crumb"; git -C "$W" commit -qm "delete $DEEP/.crumb" |
| 65 | SHA=$(push missing-deep); fx deep missing-deep "$SHA" |
| 66 | export CASE=deep; measure gate_missing_deep "$GATE" proof-repo 1 --worktree "$W" --dry-run |
| 67 | admitted "missing deep crumb" |
| 68 | else |
| 69 | note "no deep crumb without a crumbed parent in this repository; (b2) not applicable" |
| 70 | fi |
| 71 | |
| 72 | # (c) source change only, no crumb commit: the final SHA is the source commit |
| 73 | branch ok; printf '\n# proof 19 ok\n' >> "$W/$F"; git -C "$W" commit -qam "source change" |
| 74 | SHA=$(push ok); fx ok ok "$SHA" |
| 75 | export CASE=ok; measure gate_ok "$GATE" proof-repo 1 --worktree "$W" --dry-run |
| 76 | admitted "source-only head" |
| 77 | note "$(grep '^GATE crumb' <<<"$OUT" | cut -c1-110)" |
| 78 | |
| 79 | # (d) formerly refused: source and a .crumb changed in the same last commit |
| 80 | branch mixed; printf '\n# proof 19 mixed\n' >> "$W/$F"; printf '\n' >> "$W/$L/.crumb" |
| 81 | git -C "$W" add -A; git -C "$W" commit -qm "source + crumb together" |
| 82 | SHA=$(push mixed); fx mixed mixed "$SHA" |
| 83 | export CASE=mixed; measure gate_mixed "$GATE" proof-repo 1 --worktree "$W" --dry-run |
| 84 | admitted "mixed last commit" |
| 85 | check "mixed last commit: not refused by rule 2" bash -c '! grep -q "crumb commit must be separate and last" <<<"$1"' _ "$OUT" |
| 86 | |
| 87 | check "the crumb tool was never called" test ! -e "$TMP/crumb-called" |
| 88 | proof_end |