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 / 20-rebase-crumb-local.sh
| 1 | #!/usr/bin/env bash |
| 2 | # 20: scripts/rebase-crumb.sh keeps source changes and resolves a .crumb-only conflict with main's copy, with no |
| 3 | # GitHub and no crumb tool (crumb compile/verify retired 2026-11-07, DRA-97). A local bare repository stands in for |
| 4 | # origin (the script requires an aien-dev URL; url.insteadOf redirects it to the bare repo). Branch feat changes a |
| 5 | # leaf file, then hand-edits the root .crumb in a separate commit (an old-style crumb commit); main then moves with |
| 6 | # a change in another subtree and its own root .crumb edit, so the root .crumb conflicts in .crumb only. |
| 7 | # Expected: exit 0, feat's source change kept, main's change present, every .crumb equal to main's copy, no |
| 8 | # "crumb compile" commit added, last commit is feat's source commit, pushed. CRUMB and a `crumb` on PATH are stubs |
| 9 | # that record any call and exit 99; the proof checks they were never called. |
| 10 | here="$(cd "$(dirname "$0")" && pwd)"; . "$here/lib.sh" |
| 11 | proof_begin 20 "rebase-crumb.sh on a local bare origin keeps source, takes main's crumbs, runs no crumb tool" "${1:-}" |
| 12 | RB=${REBASE_CRUMB:-$here/../rebase-crumb.sh}; [ -x "$RB" ] || { echo "rebase-crumb.sh not found at $RB" >&2; exit 2; } |
| 13 | FAKEURL="https://github.com/aien-dev/proof-repo" |
| 14 | clone_repo "$TMP/seed"; git -C "$TMP/seed" checkout -q -B main |
| 15 | git clone -q --bare "$TMP/seed" "$TMP/origin.git" |
| 16 | git clone -q "$TMP/origin.git" "$TMP/w"; W=$TMP/w |
| 17 | git clone -q "$TMP/origin.git" "$TMP/other"; O=$TMP/other |
| 18 | for r in "$W" "$O"; do git -C "$r" config user.name proof; git -C "$r" config user.email proof@example.invalid; done |
| 19 | |
| 20 | L1=$(leaf_crumb_dir "$W") || { echo "no leaf crumb dir" >&2; exit 1; } |
| 21 | F1=$(tracked_file_in "$W" "$L1") |
| 22 | # a second subtree sharing only the root with L1 |
| 23 | L2=""; for d in $(crumb_dirs "$W" | grep -v '^\.$' | awk -F/ '{print NF" "$0}' | sort -rn | cut -d' ' -f2); do |
| 24 | case "$L1/" in "$d"/*) continue ;; esac; case "$d/" in "$L1"/*) continue ;; esac |
| 25 | F2=$(tracked_file_in "$W" "$d"); [ -n "$F2" ] || continue; L2=$d; break |
| 26 | done |
| 27 | [ -n "$L2" ] || { F2=README.md; L2=.; } |
| 28 | num "feat_file=$F1"; num "main_file=$F2" |
| 29 | |
| 30 | mkdir -p "$TMP/bin" |
| 31 | printf '#!/usr/bin/env bash\necho "$*" >> "%s/crumb-called"\nexit 99\n' "$TMP" > "$TMP/bin/crumb" |
| 32 | chmod +x "$TMP/bin/crumb"; export PATH="$TMP/bin:$PATH" CRUMB="$TMP/bin/crumb" |
| 33 | |
| 34 | # feat: source change, then a hand-edited root .crumb as a separate last commit, pushed |
| 35 | git -C "$W" checkout -q -b feat |
| 36 | printf '\n# proof 20 FEAT MARKER\n' >> "$W/$F1"; git -C "$W" commit -qam "feat: change $F1" |
| 37 | printf '\n# proof 20 feat crumb\n' >> "$W/.crumb"; git -C "$W" commit -qam "crumb compile" |
| 38 | git -C "$W" push -q origin feat |
| 39 | git -C "$W" remote set-url origin "$FAKEURL"; git -C "$W" config "url.$TMP/origin.git.insteadOf" "$FAKEURL" |
| 40 | git -C "$W" checkout -q main |
| 41 | |
| 42 | # main moves: change in another subtree plus its own root .crumb edit, pushed |
| 43 | printf '\n# proof 20 MAIN MARKER\n' >> "$O/$F2"; git -C "$O" commit -qam "main: change $F2" |
| 44 | printf '\n# proof 20 main crumb\n' >> "$O/.crumb"; git -C "$O" commit -qam "crumb edit (main)" |
| 45 | git -C "$O" push -q origin main |
| 46 | MAINSHA=$(git -C "$O" rev-parse HEAD) |
| 47 | check "root .crumb differs between feat and new main (a crumb conflict exists)" sh -c "! git -C '$O' diff --quiet origin/feat origin/main -- .crumb" |
| 48 | |
| 49 | measure rebase_crumb "$RB" "$W" feat |
| 50 | note "$(echo "$OUT" | tail -1 | cut -c1-120)" |
| 51 | check_eq "rebase-crumb.sh exits 0" "$RC" 0 |
| 52 | check "retired crumb notice printed" grep -qF "crumb: retired (DRA-97)" <<<"$OUT" |
| 53 | check "feat's source change survived" grep -q 'proof 20 FEAT MARKER' "$W/$F1" |
| 54 | check "main's change is present" grep -q 'proof 20 MAIN MARKER' "$W/$F2" |
| 55 | check_eq "feat now sits on the new main" "$(git -C "$W" merge-base HEAD origin/main)" "$MAINSHA" |
| 56 | check "every .crumb equals main's copy" git -C "$W" diff --quiet origin/main HEAD -- '*.crumb' '**/.crumb' |
| 57 | check "root .crumb is main's copy, not feat's" sh -c "grep -q 'proof 20 main crumb' '$W/.crumb' && ! grep -q 'proof 20 feat crumb' '$W/.crumb'" |
| 58 | check_eq "no crumb compile commit after the rebase" "$(git -C "$W" log --format=%s origin/main..HEAD | grep -c '^crumb compile' || true)" 0 |
| 59 | check_eq "last commit is feat's source commit" "$(git -C "$W" log -1 --format=%s)" "feat: change $F1" |
| 60 | check_eq "pushed: origin/feat == local feat" "$(git -C "$TMP/origin.git" rev-parse refs/heads/feat)" "$(git -C "$W" rev-parse HEAD)" |
| 61 | check_eq "working tree clean" "$(git -C "$W" status --porcelain | wc -l)" 0 |
| 62 | check "the crumb tool was never called" test ! -e "$TMP/crumb-called" |
| 63 | num "commits_on_main=$(git -C "$W" rev-list --count origin/main..HEAD)" |
| 64 | proof_end |