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/cortex/blob/main/tests/pin/run.sh # cortex aien-dev/cortex 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 `cortex / tests / pin / run.sh` 92 lines ยท 5405 bytes Raw Blame History 1 #!/bin/sh 2 # tests/pin/run.sh : the one-pin gate. PIN is the only place the compiler pin is written; 3 # tools/omc.sh, build.sh's SHA256SUMS line, the gate labels and CI read it, and build/pincheck 4 # (tools/pincheck.om, compiled by build.sh) refuses a tracked file that restates it. 5 # sh tests/pin/run.sh (after sh build.sh) 6 # Cases: the tree passes (rc 0); controls in a scratch directory with a copy of PIN: a file that 7 # restates the revision prefix and one that restates the omc sha256 are each refused (rc 1), a 8 # file under evidence/ that names the pin is not judged (rc 0), a malformed PIN is refused (rc 2); 9 # and tools/omc.sh refuses an OMC whose sha256 differs from PIN (rc 1). A second scratch directory 10 # has a fixture PIN whose revision and sha256 both start with 8 digits, so these hold at any real pin: 11 # the all-digit 8-character prefixes, 12- and 16-character prefixes, an upper-case prefix and both 12 # full values are each refused (rc 1); dates, counts and 8-digit near misses of the prefixes pass 13 # (rc 0). Five mutants of tools/pincheck.om (a word must hold a letter again, prefixes shorter than 9 14 # ignored, only the first character compared against the revision or against the sha256, no A-F 15 # folding) are compiled with the pinned omc and each must get at least one fixture case wrong. 16 # Exit 0 only when every case gives its expected result. 17 set -u 18 R=$(cd "$(dirname "$0")/../.." && pwd) 19 W=${WORK:-$R/build/pin-work} 20 P=$R/build/pincheck 21 [ -x "$P" ] || { echo "pin: build first (sh build.sh)" >&2; exit 2; } 22 rm -rf "$W" && mkdir -p "$W" || exit 2 23 pass=0 fail=0 24 ok() { echo "PASS $*"; pass=$((pass + 1)); } 25 bad() { echo "FAIL $*"; fail=$((fail + 1)); } 26 want() { # want NAME RC DIR FILES... 27 n=$1 w=$2 d=$3; shift 3 28 out=$(cd "$d" && printf '%s\n' "$@" | "$P" 2>&1); rc=$? 29 if [ $rc -eq "$w" ]; then ok "$n (rc $rc): $(echo "$out" | tail -n 1)"; else bad "$n: rc $rc, want $w: $out"; fi 30 } 31 want tree 0 "$R" $(cd "$R" && git ls-files) 32 rev=$(awk '$1 == "omega-mv" { print $2 }' "$R/PIN") 33 sha=$(awk '$1 == "omc-sha256" { print $2 }' "$R/PIN") 34 mkdir -p "$W/c/evidence" 35 cp "$R/PIN" "$W/c/PIN" 36 printf 'built with omega-mv %s\n' "$(echo "$rev" | cut -c1-8)" > "$W/c/rev.md" 37 printf 'omc sha256 %s (copied)\n' "$sha" > "$W/c/sha.md" 38 printf 'this run used omc %s\n' "$sha" > "$W/c/evidence/run.log" 39 printf 'no pin here: `91b3c932` is an older revision\n' > "$W/c/old.md" 40 want control-rev 1 "$W/c" rev.md 41 want control-sha 1 "$W/c" sha.md 42 want evidence-not-judged 0 "$W/c" evidence/run.log 43 want other-hash-not-judged 0 "$W/c" old.md 44 mkdir -p "$W/m" 45 printf 'omega-mv %s\n' "$(echo "$rev" | cut -c1-8)" > "$W/m/PIN" 46 want malformed-pin 2 "$W/m" PIN 47 # fixture values built from short pieces, so this file names no 7-character word of them 48 d8=$((2718 * 10000 + 2818)) 49 s8=$((3141 * 10000 + 5926)) 50 drev=$d8$(printf %s 0a1b 2c3d 4e5f 6a7b 8c9d 0e1f 2a3b 4c5d) 51 dsha=$s8$(printf %s 5e6f 7a8b 9c0d 1e2f 3a4b 5c6d 7e8f 9a0b 1c2d 3e4f 5a6b 7c8d 9e0f 1a2b) 52 mkdir -p "$W/d" 53 printf 'omega-mv %s\nomc-sha256 %s\n' "$drev" "$dsha" > "$W/d/PIN" 54 printf 'built with omega-mv %s\n' "$d8" > "$W/d/r8.md" 55 printf 'omc %s (sha256 prefix)\n' "$s8" > "$W/d/s8.md" 56 printf 'rev %s\n' "$(echo "$drev" | cut -c1-12)" > "$W/d/r12.md" 57 printf 'omc %s\n' "$(echo "$dsha" | cut -c1-16)" > "$W/d/s16.md" 58 printf 'omega-mv %s\n' "$drev" > "$W/d/rfull.md" 59 printf 'omc-sha256 %s\n' "$dsha" > "$W/d/sfull.md" 60 printf 'REV %s\n' "$(echo "$drev" | cut -c1-12 | tr a-f A-F)" > "$W/d/upper.md" 61 printf 'landed %s, %s rows; %s and %s are not the pin\n' $((2026 * 10000 + 1111)) $((1000 * 10000)) $((d8 + 1)) $((s8 + 1)) > "$W/d/numbers.md" 62 cases="r8:1 s8:1 r12:1 s16:1 rfull:1 sfull:1 upper:1 numbers:0" 63 for c in $cases; do want "fixture-${c%:*}" "${c#*:}" "$W/d" "${c%:*}.md"; done 64 wrong() { # wrong BIN: the fixture cases BIN gets wrong 65 for c in $cases; do 66 (cd "$W/d" && echo "${c%:*}.md" | "$1" > /dev/null 2>&1); rc=$? 67 [ $rc -eq "${c#*:}" ] || printf '%s ' "${c%:*}" 68 done 69 } 70 OMC=$(sh "$R/tools/omc.sh") || exit 2 71 mutant() { # mutant NAME SED-ARGS...: compile tools/pincheck.om edited by sed; it must be caught 72 n=$1; shift 73 sed "$@" "$R/tools/pincheck.om" > "$W/$n.om" 74 if cmp -s "$R/tools/pincheck.om" "$W/$n.om"; then bad "mutant $n: the edit did not apply"; return; fi 75 { echo om2; cat "$W/$n.om"; } | "$OMC" > "$W/$n" 2> "$W/$n.err" 76 if [ $? -ne 0 ] || [ -s "$W/$n.err" ]; then bad "mutant $n does not compile: $(cat "$W/$n.err")"; return; fi 77 chmod +x "$W/$n" 78 got=$(wrong "$W/$n") 79 if [ -n "$got" ]; then ok "mutant $n caught by: $got"; else bad "mutant $n passes every fixture case"; fi 80 } 81 mutant m-letter -e 's/^if eq get st q_hex 1$/if and eq get st q_hex 1 hasletter/' \ 82 -e '/^fn endword to void$/i fn hasletter to bool\nfor i ulong 64\nif ge i get st q_len\nbreak\nend\nif gt get tok i 57\nret true\nend\nend\nret false\nend' 83 mutant m-floor -e 's/^if lt n 7$/if lt n 9/' 84 mutant m-revfirst -e 's/^if ne get tok i get rev i$/if ne get tok 0 get rev 0/' 85 mutant m-shafirst -e 's/^if ne get tok i get sha i$/if ne get tok 0 get sha 0/' 86 mutant m-nofold -e 's/^d = add c 32$/d = c/' 87 printf 'not a compiler\n' > "$W/fake-omc" 88 if OMC=$W/fake-omc sh "$R/tools/omc.sh" > /dev/null 2>&1; then bad "omc.sh accepted a binary whose sha256 is not the one in PIN" 89 else ok "omc.sh refuses a binary whose sha256 is not the one in PIN"; fi 90 rm -rf "$W" 91 echo "pin: pass=$pass fail=$fail" 92 [ $fail -eq 0 ] && [ $pass -eq 20 ]