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/synapse/blob/main/scripts/crumb-parity.sh # synapse A component of the AienOS ecosystem. 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 `synapse / scripts / crumb-parity.sh` 114 lines ยท 4296 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Parity check between synapse-crumb and the reference crumb.c (ADR 0004). 3 # 4 # Builds tools/crumb/crumb.c from aien-architecture at the pinned commit with `cc` only, 5 # copies the fixture tree (crates/synapse-crumb/tests/fixtures/tree, where `dot.crumb` 6 # stands for `.crumb` so this repository's own crumb tooling never reads the fixtures) 7 # into a throwaway Git repository, runs `validate`, `sniff`, and `explain`, and compares 8 # the normalised output with the golden files the Rust parity tests read. 9 # 10 # Usage: scripts/crumb-parity.sh [--update] 11 # --update rewrite the golden files instead of comparing. 12 # Env: AIEN_ARCHITECTURE_REPO path to an aien-architecture clone 13 # (default: $HOME/workspace/aien-architecture). 14 # 15 # Dependencies: bash, git, cc, sha256sum, diff, coreutils. No jq, no Python. 16 set -euo pipefail 17 18 PIN_COMMIT=`29780e56c9e6b9111d884e0d4b146737228c19f6` 19 PIN_SOURCE_SHA256=`ef0f6566fb838917a750eb898f66596b76aa15a53d7d61bedac03c4c963ee147` 20 TARGETS=(. d1 d1/nested d1/nested/deeper d2 d3 badjson gap gap/inner unknown 21 bom scalar latin1 nuljunk dupkey surrogate) 22 23 here=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) 24 fixtures="$here/crates/synapse-crumb/tests/fixtures/tree" 25 golden="$here/crates/synapse-crumb/tests/golden" 26 arch="${AIEN_ARCHITECTURE_REPO:-$HOME/workspace/aien-architecture}" 27 update=0 28 case "${1:-}" in 29 --update) update=1 ;; 30 "") ;; 31 *) echo "usage: $0 [--update]" >&2; exit 2 ;; 32 esac 33 34 work=$(mktemp -d) 35 trap 'rm -rf "$work"' EXIT 36 37 # 1. Pinned source and build. 38 git -C "$arch" cat-file -e "$PIN_COMMIT^{commit}" \ 39 || { echo "FAIL: $arch lacks commit $PIN_COMMIT (git fetch it first)" >&2; exit 1; } 40 git -C "$arch" show "$PIN_COMMIT:tools/crumb/crumb.c" > "$work/crumb.c" 41 src_sha=$(sha256sum "$work/crumb.c" | cut -d' ' -f1) 42 if [ "$src_sha" != "$PIN_SOURCE_SHA256" ]; then 43 echo "FAIL: crumb.c sha256 $src_sha != pinned $PIN_SOURCE_SHA256" >&2; exit 1 44 fi 45 cc -O2 -o "$work/crumb" "$work/crumb.c" 46 bin_sha=$(sha256sum "$work/crumb" | cut -d' ' -f1) 47 cc_ver=$(cc --version | head -n1) 48 echo "crumb.c $PIN_COMMIT sha256 $src_sha" 49 echo "binary sha256 $bin_sha ($cc_ver)" 50 51 # 2. Fixture tree in a throwaway Git repository (bounds explain's upward walk at its root). 52 mkdir -p "$work/tree" 53 root=$(cd "$work/tree" && pwd -P) 54 while IFS= read -r -d '' f; do 55 rel=${f#"$fixtures"/} 56 dest="$root/$rel" 57 [ "$(basename "$rel")" = dot.crumb ] && dest="$(dirname "$dest")/.crumb" 58 mkdir -p "$(dirname "$dest")" 59 cp "$f" "$dest" 60 done < <(find "$fixtures" -type f -print0) 61 git -C "$root" init -q 62 export CRUMB_COORD_ROOT="$work/coord" 63 mkdir -p "$CRUMB_COORD_ROOT" 64 65 norm() { sed "s#$root##g"; } 66 out="$work/out" 67 mkdir -p "$out" 68 69 # 3. validate: whole tree. Exit 1 is expected (the fixtures include invalid crumbs). 70 set +e 71 "$work/crumb" validate "$root" > "$out/validate.raw" 72 validate_rc=$? 73 set -e 74 { norm < "$out/validate.raw"; echo "exit $validate_rc"; } > "$out/validate.txt" 75 76 # 4. sniff: keep the directory's own .crumb lines (coordination state is not compared). 77 : > "$out/sniff.txt" 78 for t in "${TARGETS[@]}"; do 79 echo "### sniff $t" >> "$out/sniff.txt" 80 "$work/crumb" sniff parity "$root/$t" 2>/dev/null \ 81 | sed '/^shared coordination:/,$d' | norm >> "$out/sniff.txt" 82 done 83 84 # 5. explain: keep NEAREST CRUMB and INHERITED INVARIANTS. 85 : > "$out/explain.txt" 86 for t in "${TARGETS[@]}"; do 87 echo "### explain $t" >> "$out/explain.txt" 88 "$work/crumb" explain "$root/$t" 2>/dev/null \ 89 | sed -n '/^== NEAREST CRUMB ==$/,/^== SHARED COORDINATION ==$/p' \ 90 | sed '$d' | norm >> "$out/explain.txt" 91 done 92 93 printf 'commit %s\ncrumb.c sha256 %s\n' "$PIN_COMMIT" "$PIN_SOURCE_SHA256" > "$out/PIN" 94 95 if [ "$update" = 1 ]; then 96 mkdir -p "$golden" 97 cp "$out/validate.txt" "$out/sniff.txt" "$out/explain.txt" "$out/PIN" "$golden/" 98 # Build record: informational, differs by compiler, never compared. 99 printf 'binary sha256 %s\ncompiler %s\n' "$bin_sha" "$cc_ver" > "$golden/BUILD.txt" 100 echo "UPDATED golden files in $golden" 101 exit 0 102 fi 103 104 status=0 105 for f in PIN validate.txt sniff.txt explain.txt; do 106 if diff -u "$golden/$f" "$out/$f"; then 107 echo "PASS $f" 108 else 109 echo "FAIL $f differs from golden" >&2 110 status=1 111 fi 112 done 113 [ "$status" = 0 ] && echo "PARITY OK: crumb.c output matches the golden files" 114 exit "$status"