interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / aienet / jobpath / check-harness.sh

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