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/tools/candidate/parity/run.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 / tools / candidate / parity / run.sh` 109 lines ยท 6101 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # tools/candidate/parity/run.sh: the byte-for-byte parity oracle of the candidate checkers. 3 # usage: run.sh [record|record-extensions] 4 # Every directory under cases/candidate and cases/pins is one case: m.toml (plus amendments or a 5 # files/ tree), `mode` (sha | shawords | emptysha | gh | files: how the checker reaches commits and 6 # lock files, all offline stubs under mktemp) and an optional `args` file (one argument per line, 7 # default m.toml). A case runs with its directory as the working directory; stdout and stderr are 8 # captured in order through one pipe and the exit code is appended as "rc=N"; in gh mode the fake 9 # gh's argv log follows. The expected files were recorded from the bash scripts this corpus 10 # froze (scripts/check_candidate.sh and scripts/check_candidate_pins.sh at `1dd84d1`) with the 11 # word `record`; without it the outputs are compared and any difference is printed. A case with a 12 # `limit` file is a named, documented difference (README "Limits"): it is shown, not counted as a 13 # failure, and reported if it ever becomes identical. 14 # Six candidate cases also assert the exact kernel-repository rename against the frozen oracle; 15 # unlike a limit, any other byte difference (or the old repository name) fails. 16 # A case with an `extension` file tests behaviour added after the bash was deleted (-mv sources and 17 # in-tree contracts, DRA-46): its expected file comes from `record-extensions` (the .om, reviewed by 18 # hand), it is counted on its own "extensions:" line and any difference fails; `record` skips it. 19 set -u 20 here="$(cd "$(dirname "$0")" && pwd)" 21 cand="$1"; pins="$2"; mode="${3:-compare}" 22 cand="$(cd "$(dirname "$cand")" && pwd)/$(basename "$cand")" 23 pins="$(cd "$(dirname "$pins")" && pwd)/$(basename "$pins")" 24 tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT 25 mkdir -p "$tmp/bin" 26 cat > "$tmp/stub" <<'S' 27 #!/usr/bin/env bash 28 [ "$2" != "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" ] 29 S 30 cat > "$tmp/stubw" <<'S' 31 #!/usr/bin/env bash 32 [ "$1" = "--flag" ] || exit 9 33 [ "$3" != "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" ] 34 S 35 cat > "$tmp/stubf" <<'S' 36 #!/usr/bin/env bash 37 cat "$PARITY_FILES/$1/$2/$3" 2>/dev/null || { echo "{\"message\":\"No commit found for the ref $2\"}"; exit 1; } 38 S 39 cat > "$tmp/stubfw" <<'S' 40 #!/usr/bin/env bash 41 [ "$1" = "--flag" ] || exit 9 42 cat "$PARITY_FILES/$2/$3/$4" 2>/dev/null || { echo "{\"message\":\"No commit found for the ref $3\"}"; exit 1; } 43 S 44 cat > "$tmp/bin/gh" <<'S' 45 #!/usr/bin/env bash 46 echo "$*" >> "$GH_STUB_LOG" 47 [ "$1" = "api" ] || exit 2 48 sha="${2##*/}" 49 if [ "$sha" = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" ]; then echo "gh: Not Found (HTTP 404)" >&2; exit 1; fi 50 echo "$sha" 51 S 52 chmod +x "$tmp/stub" "$tmp/stubw" "$tmp/stubf" "$tmp/stubfw" "$tmp/bin/gh" 53 same=0; diff=0; limits=0; renames=0; xsame=0; xdiff=0 54 one() { # one 55 local g="$1" bin="$2" d="$3" name; name="$(basename "$d")" 56 local m; m="$(cat "$d/mode")" 57 local args=(m.toml); [ -f "$d/args" ] && mapfile -t args < "$d/args" 58 : > "$tmp/gh.log" 59 ( cd "$d" && unset CAND_SHA_CHECK CAND_FILE_AT 60 case "$m" in 61 sha) export CAND_SHA_CHECK="$tmp/stub" ;; 62 shawords) export CAND_SHA_CHECK="$tmp/stubw --flag" ;; 63 emptysha) export CAND_SHA_CHECK="" PATH="$tmp/bin:$PATH" GH_STUB_LOG="$tmp/gh.log" ;; 64 gh) export PATH="$tmp/bin:$PATH" GH_STUB_LOG="$tmp/gh.log" ;; 65 files) export CAND_FILE_AT="$tmp/stubf" PARITY_FILES="$d/files" ;; 66 fileswords) export CAND_FILE_AT="$tmp/stubfw --flag" PARITY_FILES="$d/files" ;; 67 esac 68 "$bin" "${args[@]}" 2>&1; echo "rc=$?" 69 if [ -s "$tmp/gh.log" ]; then echo "-- gh calls --"; cat "$tmp/gh.log"; fi 70 ) | sed "s|$bin||g" > "$tmp/out" 71 local exp="$here/expected/$g/$name.out" 72 if [ -f "$d/extension" ]; then 73 # An extension case (README "Extension cases"): behaviour the bash never had, so its expected 74 # file was recorded from the .om (record-extensions) and reviewed by hand. Counted apart from the 75 # frozen oracle; `record` (the bash oracle) never touches it. 76 if [ "$mode" = record ]; then return; fi 77 if [ "$mode" = record-extensions ]; then mkdir -p "$here/expected/$g"; cp "$tmp/out" "$exp"; xsame=$((xsame+1)); return; fi 78 if cmp -s "$tmp/out" "$exp"; then xsame=$((xsame+1)) 79 else xdiff=$((xdiff+1)); echo "DIFF (extension): $g/$name"; diff "$exp" "$tmp/out" | sed 's/^/ /'; fi 80 return 81 fi 82 if [ "$mode" = record ]; then mkdir -p "$here/expected/$g"; cp "$tmp/out" "$exp"; same=$((same+1)); return; fi 83 case "$g/$name" in 84 candidate/gh-404-contract|candidate/gh-404|candidate/gh-good|candidate/gh-live-cand0|candidate/nonexistent-sha|candidate/sha-check-unset-empty) 85 # Transform only complete API/diagnostic lines, never manifest keys or arbitrary text. 86 sed -E \ 87 -e 's|^(api repos/aien-dev/)aienos(/commits/[0-9a-f]{40} -q \.sha)$|\1aienux\2|' \ 88 -e 's|^(FAIL: commit [0-9a-f]{40} not found in aien-dev/)aienos$|\1aienux|' \ 89 "$exp" > "$tmp/renamed" 90 if ! cmp -s "$exp" "$tmp/renamed" && cmp -s "$tmp/out" "$tmp/renamed"; then 91 renames=$((renames+1)); echo "RENAME (exact delta): $g/$name" 92 else 93 diff=$((diff+1)); echo "DIFF (required exact naming delta): $g/$name" 94 diff "$tmp/renamed" "$tmp/out" | sed 's/^/ /' 95 fi 96 return ;; 97 esac 98 if cmp -s "$tmp/out" "$exp"; then 99 if [ -f "$d/limit" ]; then echo "LIMIT CLOSED (now identical, drop the limit file): $g/$name"; fi 100 same=$((same+1)) 101 elif [ -f "$d/limit" ]; then 102 limits=$((limits+1)); echo "LIMIT (named, expected to differ): $g/$name: $(cat "$d/limit")"; diff "$exp" "$tmp/out" | sed 's/^/ /' 103 else diff=$((diff+1)); echo "DIFF: $g/$name"; diff "$exp" "$tmp/out" | sed 's/^/ /'; fi 104 } 105 for d in "$here"/cases/candidate/*/; do one candidate "$cand" "${d%/}"; done 106 for d in "$here"/cases/pins/*/; do one pins "$pins" "${d%/}"; done 107 echo "parity: $same identical, $renames exact naming deltas, $limits named limits, $diff different" 108 echo "extensions: $xsame identical, $xdiff different" 109 [ "$diff" -eq 0 ] && [ "$xdiff" -eq 0 ]