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/omega-mv/blob/main/tests/synapse/corpus_guard.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / synapse / corpus_guard.sh` 58 lines ยท 2589 bytes Raw Blame History 1 #!/bin/sh 2 # corpus_guard.sh: the J1 driver refuses a corpus it must not trust, with a typed line. 3 # corpus_guard.sh DRIVER UNIT CORPUS CASE_OFFSET WORKDIR 4 # CASE_OFFSET is the "case section at byte N" the driver printed for the real corpus. Each guard 5 # edits a copy and expects one "corpus refused: CODE" line and exit 3: 6 # G1 trailer byte flipped -> CORPUS_FINGERPRINT 7 # G2 label byte changed, trailer recomputed -> CORPUS_PIN (parity alone would still pass) 8 # G3 first case position set to 0xFFFFFFF0 -> CORPUS_RANGE (pin overridden to reach the check) 9 # G4 first case base index set to 0xFFFF -> CORPUS_RANGE (pin overridden) 10 # POSIX sh, dd, head, sha256sum, xxd. 11 set -u 12 drv=${1:?driver} unit=${2:?unit} corpus=${3:?corpus} off=${4:?case offset} dir=${5:?workdir} 13 mkdir -p "$dir" 14 fails=0 15 16 poke() { # file offset octal-escaped-bytes 17 printf "$3" | dd of="$1" bs=1 seek="$2" conv=notrunc status=none 18 } 19 reseal() { # recompute the SHA-256 trailer of a copy; prints the new whole-file hash (the pin form) 20 n=$(($(wc -c < "$1") - 32)) 21 h=$(head -c "$n" "$1" | sha256sum | cut -c1-64) 22 printf '%s' "$h" | xxd -r -p | dd of="$1" bs=1 seek="$n" conv=notrunc status=none 23 sha256sum "$1" | cut -c1-64 24 } 25 expect() { # name code file [pin override] 26 name=$1 code=$2 file=$3 ov=${4:-} 27 SYN_CORPUS_PIN_OVERRIDE=$ov "$drv" "$unit" "$file" 0 > "$dir/$name.out" 2>&1 28 rc=$? 29 line=$(grep '^corpus refused: ' "$dir/$name.out" | head -1) 30 case "$rc:$line" in 31 "3:corpus refused: $code:"*) echo "$name: OK exit 3, $line" ;; 32 *) echo "$name: WRONG exit $rc, want $code; got: $(grep -v '^FAIL' "$dir/$name.out" | tail -2 | tr '\n' ' ')"; fails=$((fails + 1)) ;; 33 esac 34 } 35 36 n=$(wc -c < "$corpus") 37 cp "$corpus" "$dir/g1.bin" 38 last=$(tail -c 1 "$dir/g1.bin" | xxd -p) 39 if [ "$last" = 00 ]; then poke "$dir/g1.bin" $((n - 1)) '\001'; else poke "$dir/g1.bin" $((n - 1)) '\000'; fi 40 expect G1 CORPUS_FINGERPRINT "$dir/g1.bin" 41 42 cp "$corpus" "$dir/g2.bin" 43 lab=$(grep -obUa 'fixture record 0' "$dir/g2.bin" | head -1 | cut -d: -f1) 44 poke "$dir/g2.bin" "$lab" 'F' 45 reseal "$dir/g2.bin" > /dev/null 46 expect G2 CORPUS_PIN "$dir/g2.bin" 47 48 cp "$corpus" "$dir/g3.bin" 49 poke "$dir/g3.bin" $((off + 3)) '\360\377\377\377' 50 h3=$(reseal "$dir/g3.bin") 51 expect G3 CORPUS_RANGE "$dir/g3.bin" "$h3" 52 53 cp "$corpus" "$dir/g4.bin" 54 poke "$dir/g4.bin" "$off" '\377\377' 55 h4=$(reseal "$dir/g4.bin") 56 expect G4 CORPUS_RANGE "$dir/g4.bin" "$h4" 57 58 if [ "$fails" -eq 0 ]; then echo "corpus guard: PASS (4 of 4 refused with the expected code)"; else echo "corpus guard: FAIL ($fails wrong)"; exit 1; fi