Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-architecture-mv/blob/main/scripts/pipeline-proofs/13-determinism.sh # aien-architecture-mv Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-architecture-mv / scripts / pipeline-proofs / 13-determinism.sh` 52 lines ยท 2987 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # 13: two compiles of the same tree produce byte-identical .crumb files. 3 # Two clones at the same commit have every generated block stripped, then each is compiled from nothing. 4 # Under a frozen clock (faketime; the RFC-0003 D3 stamps are the only time-dependent bytes) the files must be 5 # byte-identical; under the real clock, one second apart, the files minus the compiled_at stamp must be identical. 6 here="$(cd "$(dirname "$0")" && pwd)"; . "$here/lib.sh" 7 proof_begin 13 "determinism: same tree, two compiles, identical .crumb bytes" "${1:-}" 8 9 strip_generated() { # strip_generated : remove extensions.generated from every tracked .crumb 10 local c 11 for c in $(git -C "$1" ls-files '*.crumb' '**/.crumb'); do 12 jq 'del(.extensions.generated)' "$1/$c" > "$1/$c.tmp" && mv "$1/$c.tmp" "$1/$c" 13 done 14 } 15 compare() { # compare -> prints identical/total 16 local id=0 n=0 c 17 for c in $(git -C "$1" ls-files '*.crumb' '**/.crumb'); do 18 n=$((n+1)) 19 if [ "$3" = raw ]; then cmp -s "$1/$c" "$2/$c" && id=$((id+1)) 20 else [ "$(jq -S "$3" "$1/$c")" = "$(jq -S "$3" "$2/$c")" ] && id=$((id+1)); fi 21 done 22 echo "$id/$n" 23 } 24 all_of() { echo "${1#*/}/${1#*/}"; } # "k/n" -> "n/n" 25 26 FROZEN='@2026-10-11 00:00:00 i0' 27 if command -v faketime >/dev/null 2>&1; then 28 clone_repo "$TMP/a"; clone_repo "$TMP/b"; strip_generated "$TMP/a"; strip_generated "$TMP/b" 29 check_eq "both clones at the same commit" "$(git -C "$TMP/a" rev-parse HEAD)" "$(git -C "$TMP/b" rev-parse HEAD)" 30 cd "$TMP/a" || exit 1 31 measure compile_a_from_nothing_frozen faketime -f "$FROZEN" $CRUMB compile . 32 note "$(echo "$OUT" | tail -1)" 33 RW=$(echo "$OUT" | tail -1 | sed -n 's/.*crumbs, \([0-9]*\) rewritten.*/\1/p'); num "rewritten_from_nothing=$RW" 34 check_eq "every crumb was regenerated" "$RW" "$(crumb_dirs . | wc -l)" 35 cd "$TMP/b" || exit 1 36 measure compile_b_from_nothing_frozen faketime -f "$FROZEN" $CRUMB compile . 37 cd "$TMP" || exit 1 38 R=$(compare "$TMP/a" "$TMP/b" raw); num "byte_identical_frozen_clock=$R" 39 check_eq "every .crumb byte-identical under a frozen clock" "$R" "$(all_of "$R")" 40 else 41 note "faketime not installed: frozen-clock comparison NOT_RUN"; FAILS=$((FAILS+1)) 42 fi 43 44 clone_repo "$TMP/c"; clone_repo "$TMP/d"; strip_generated "$TMP/c"; strip_generated "$TMP/d" 45 ( cd "$TMP/c" && $CRUMB compile . >/dev/null ); sleep 1.1; ( cd "$TMP/d" && $CRUMB compile . >/dev/null ) 46 R2=$(compare "$TMP/c" "$TMP/d" 'del(.extensions.generated.compiled_at)'); num "identical_minus_compiled_at_real_clock=$R2" 47 check_eq "real clock, one second apart: identical apart from the compiled_at stamp" "$R2" "$(all_of "$R2")" 48 R3=$(compare "$TMP/c" "$TMP/d" '.extensions.generated.digest'); num "identical_digests_real_clock=$R3" 49 check_eq "every Merkle digest identical" "$R3" "$(all_of "$R3")" 50 R4=$(compare "$TMP/c" "$TMP/d" raw); num "raw_identical_real_clock=$R4" 51 note "raw files under the real clock differ only in compiled_at (informational)" 52 proof_end