aien-protocols-mv
Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem
Brought by drakestapleton
aien-protocols-mv / specs / aienet / jobpath / check-harness.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Deterministic fault injection for the parity/mutant runners, not kernel parity. |
| 3 | set -euo pipefail |
| 4 | here=$(cd "$(dirname "$0")" && pwd) |
| 5 | scratch=$(mktemp -d) |
| 6 | trap 'rm -rf "$scratch"' EXIT |
| 7 | mkdir -p "$scratch/specs/aienet/jobpath" "$scratch/tools" "$scratch/target/debug/examples" |
| 8 | cp "$here/parity.sh" "$here/mutants.sh" "$scratch/specs/aienet/jobpath/" |
| 9 | cat > "$scratch/tools/cargo" <<'EOF' |
| 10 | #!/bin/sh |
| 11 | exit "${FIXTURE_CARGO_RC:-0}" |
| 12 | EOF |
| 13 | cat > "$scratch/target/debug/examples/an0_digest" <<'EOF' |
| 14 | #!/bin/bash |
| 15 | case ${FIXTURE_ORACLE:-valid} in |
| 16 | empty) exit 0 ;; |
| 17 | fail) exit 101 ;; |
| 18 | invalid) echo 'not hex'; exit 0 ;; |
| 19 | esac |
| 20 | printf '010001000100010000000000000000 %064d\n' 0 |
| 21 | case ${FIXTURE_ORACLE:-valid} in |
| 22 | extra) echo extra ;; |
| 23 | esac |
| 24 | EOF |
| 25 | cat > "$scratch/recompute" <<'EOF' |
| 26 | #!/bin/bash |
| 27 | hex=$(xxd -p -c 256) |
| 28 | case "$hex" in |
| 29 | 020001000100010000000000000001) exit 3 ;; |
| 30 | 010000000100010000000000000001|010101000100010000000000000001) exit 4 ;; |
| 31 | 0100010001000100000000000000) exit 2 ;; |
| 32 | esac |
| 33 | case ${FIXTURE_RECOMPUTE:-valid} in |
| 34 | empty) exit 0 ;; |
| 35 | fail) exit 1 ;; |
| 36 | invalid) echo bad; exit 0 ;; |
| 37 | mismatch) printf '%064d\n' 1; exit 0 ;; |
| 38 | esac |
| 39 | printf '%064d\n' 0 |
| 40 | EOF |
| 41 | chmod +x "$scratch/tools/cargo" "$scratch/recompute" "$scratch/target/debug/examples/an0_digest" |
| 42 | export CARGO_TARGET_DIR=$scratch/target |
| 43 | export PATH=$scratch/tools:$PATH |
| 44 | parity=$scratch/specs/aienet/jobpath/parity.sh |
| 45 | expect() { |
| 46 | local name=$1 want=$2 rc |
| 47 | shift 2 |
| 48 | if "$@" >"$scratch/$name.log" 2>&1; then rc=0; else rc=$?; fi |
| 49 | if [ "$rc" != "$want" ]; then |
| 50 | cat "$scratch/$name.log" |
| 51 | echo "FAIL $name expected=$want observed=$rc"; exit 1 |
| 52 | fi |
| 53 | echo "PASS $name exit=$rc" |
| 54 | } |
| 55 | expect fixture-baseline 0 bash "$parity" "$scratch/recompute" |
| 56 | expect cargo-failure 2 env FIXTURE_CARGO_RC=101 bash "$parity" "$scratch/recompute" |
| 57 | if grep -q '^MATCH' "$scratch/cargo-failure.log"; then echo 'FAIL cargo-failure matched stale output'; exit 1; fi |
| 58 | for mode in empty fail invalid extra; do |
| 59 | expect "oracle-$mode" 2 env FIXTURE_ORACLE=$mode bash "$parity" "$scratch/recompute" |
| 60 | done |
| 61 | for mode in empty fail invalid; do |
| 62 | expect "recompute-$mode" 2 env FIXTURE_RECOMPUTE=$mode bash "$parity" "$scratch/recompute" |
| 63 | done |
| 64 | expect digest-mismatch 1 env FIXTURE_RECOMPUTE=mismatch bash "$parity" "$scratch/recompute" |
| 65 | expect missing-recompute 2 bash "$parity" "$scratch/absent" |
| 66 | expect missing-omc 2 env -u OMEGA_OMC -u OMEGA_MV bash "$scratch/specs/aienet/jobpath/mutants.sh" |
| 67 | grep -q '^OM-MUTANTS NOT_RUN:' "$scratch/missing-omc.log" |
| 68 | # Hide a prerequisite without relying on what the host has installed. |
| 69 | mkdir "$scratch/limited" |
| 70 | ln -s "$(command -v dirname)" "$scratch/limited/dirname" |
| 71 | expect missing-cargo 2 env PATH="$scratch/limited" /bin/bash "$parity" "$scratch/recompute" |
| 72 | ln -s "$scratch/tools/cargo" "$scratch/limited/cargo" |
| 73 | expect missing-xxd 2 env PATH="$scratch/limited" /bin/bash "$parity" "$scratch/recompute" |
| 74 | echo 'HARNESS PASS' |