interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / scripts / pipeline-proofs / 14-fixed-point.sh

28 lines · 2112 bytes Raw Blame History
1#!/usr/bin/env bash
2# 14: fixed point. A second compile changes nothing: "0 rewritten", `git status --porcelain` empty,
3# and every .crumb byte-for-byte as before. Checked at HEAD (crumbs already CURRENT) and from nothing.
4here="$(cd "$(dirname "$0")" && pwd)"; . "$here/lib.sh"
5proof_begin 14 "fixed point: the second compile rewrites nothing" "${1:-}"
6clone_repo "$TMP/a"; cd "$TMP/a" || exit 1
7rewritten() { echo "$1" | tail -1 | sed -n 's/.*crumbs, \([0-9]*\) rewritten.*/\1/p'; }
8crumb_sum() { git ls-files '*.crumb' '**/.crumb' | sort | xargs cat | sha256sum | cut -c1-16; }
9
10# (a) at HEAD: the committed crumbs are already what compile would write
11measure compile_at_head $CRUMB compile .; note "$(echo "$OUT" | tail -1)"
12check_eq "compile at HEAD rewrites 0" "$(rewritten "$OUT")" 0
13check_eq "git status --porcelain is empty after compile at HEAD" "$(git status --porcelain | wc -l)" 0
14
15# (b) from nothing: strip, compile once (n rewritten), compile again (0 rewritten, bytes unchanged)
16for c in $(git ls-files '*.crumb' '**/.crumb'); do jq 'del(.extensions.generated)' "$c" > "$c.tmp" && mv "$c.tmp" "$c"; done
17measure compile_1_from_nothing $CRUMB compile .; N1=$(rewritten "$OUT"); num "first_compile_rewritten=$N1"
18check_eq "first compile regenerated every crumb" "$N1" "$(crumb_dirs . | wc -l)"
19S1=$(crumb_sum); P1=$(git status --porcelain | sort | sha256sum | cut -c1-16)
20measure compile_2 $CRUMB compile .; N2=$(rewritten "$OUT"); num "second_compile_rewritten=$N2"
21check_eq "second compile rewrites 0" "$N2" 0
22check_eq "second compile leaves every .crumb byte-identical" "$(crumb_sum)" "$S1"
23check_eq "second compile leaves git status unchanged" "$(git status --porcelain | sort | sha256sum | cut -c1-16)" "$P1"
24git add -A && git commit -q -m "crumb compile (proof 14)"
25measure compile_3_after_commit $CRUMB compile .; check_eq "compile after committing rewrites 0" "$(rewritten "$OUT")" 0
26check_eq "git status --porcelain empty after the crumb commit + compile" "$(git status --porcelain | wc -l)" 0
27measure verify $CRUMB verify .; check "verify OK at the fixed point" [ "$RC" -eq 0 ]
28proof_end