aien-protocols-mv
Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem
Brought by drakestapleton
aien-protocols-mv / specs / latent-payload / run-native.sh
| 1 | #!/bin/sh |
| 2 | # LTP0 native conformance runner: shell glue around the unchanged |
| 3 | # omega-mv om2 conductor. It adds no protocol logic. |
| 4 | # |
| 5 | # Usage: sh specs/latent-payload/run-native.sh OMEGA_SRC |
| 6 | # OMEGA_SRC an omega-mv checkout; the suite runs on the omc it commits |
| 7 | # (named by its seed/out/omc.sha256). The original receipts' |
| 8 | # revision stays recorded in sources.json. |
| 9 | # The OMEGA_SRC environment variable is used when no argument |
| 10 | # is given. |
| 11 | # |
| 12 | # The conductor reads its SHA-256 constant fixtures from the fixed relative |
| 13 | # path seed/qualification/om2/fixtures/, and host.cases names its sources |
| 14 | # relative to this repository root. The runner therefore works from the |
| 15 | # repository root (found from its own location, not the caller's cwd), |
| 16 | # links build/nl3-omega and a temporary root `seed` to OMEGA_SRC, and removes |
| 17 | # the `seed` link again on exit. Every missing input is named before the |
| 18 | # conductor runs. |
| 19 | # |
| 20 | # Exit: the conductor's status (0 PASS, 1 FAIL, 3 INVALID, ...), or 2 when |
| 21 | # a prerequisite is missing or a path would be overwritten. |
| 22 | |
| 23 | cases=specs/latent-payload/host.cases |
| 24 | scratch=build/nl3-run |
| 25 | |
| 26 | die() { |
| 27 | printf 'run-native: %s\n' "$1" >&2 |
| 28 | exit 2 |
| 29 | } |
| 30 | |
| 31 | src=${1:-${OMEGA_SRC:-}} |
| 32 | [ -n "$src" ] || die 'usage: run-native.sh OMEGA_SRC (or set OMEGA_SRC)' |
| 33 | [ -d "$src" ] || die "OMEGA_SRC is not a directory: $src" |
| 34 | src=$(cd "$src" && pwd -P) || die "cannot resolve OMEGA_SRC: $src" |
| 35 | |
| 36 | here=$(dirname "$0") |
| 37 | root=$(cd "$here/../.." && pwd -P) || die "cannot resolve repository root from $0" |
| 38 | cd "$root" || die "cannot enter repository root $root" |
| 39 | [ -f "$cases" ] || die "missing $root/$cases" |
| 40 | |
| 41 | for rel in seed/out/omc \ |
| 42 | seed/qualification/om2/gate.om \ |
| 43 | seed/qualification/om2/fixtures/sha256-k.dec \ |
| 44 | seed/qualification/om2/fixtures/sha256-iv.dec \ |
| 45 | om/tls/sha2.om; do |
| 46 | [ -f "$src/$rel" ] || die "missing $src/$rel (OMEGA_SRC must be an omega-mv checkout)" |
| 47 | done |
| 48 | |
| 49 | # The compiler is the one OMEGA_SRC itself commits: its seed/out/omc.sha256 names it, the |
| 50 | # binary must match, and the run prints both so the log records which compiler ran. |
| 51 | [ -f "$src/seed/out/omc.sha256" ] || die "missing $src/seed/out/omc.sha256" |
| 52 | # The shell builtin read takes the first field, so no helper found on PATH decides the pin. |
| 53 | pin= |
| 54 | read -r pin _rest < "$src/seed/out/omc.sha256" || [ -n "$pin" ] || die "cannot read $src/seed/out/omc.sha256" |
| 55 | [ ${#pin} -eq 64 ] || die "$src/seed/out/omc.sha256 does not hold a sha256: $pin" |
| 56 | got=$(sha256sum "$src/seed/out/omc") || die "cannot hash $src/seed/out/omc" |
| 57 | got=${got%% *} |
| 58 | [ "$got" = "$pin" ] || die "$src/seed/out/omc sha256 $got, but its seed/out/omc.sha256 says $pin" |
| 59 | # The revision printed is the compiler's revision only when the checkout commits these exact |
| 60 | # bytes: a pair edited in the work tree is refused, not labelled with the commit it is not. |
| 61 | rev=unknown |
| 62 | if rev=$(git -C "$src" rev-parse --verify -q HEAD 2>/dev/null); then |
| 63 | for rel in seed/out/omc seed/out/omc.sha256; do |
| 64 | want=$(git -C "$src" rev-parse -q --verify "HEAD:$rel") || die "$src HEAD does not commit $rel" |
| 65 | have=$(git -C "$src" hash-object "$src/$rel") || die "cannot hash $src/$rel" |
| 66 | [ "$want" = "$have" ] || die "$src/$rel differs from what $src HEAD ($rev) commits; use a clean checkout" |
| 67 | done |
| 68 | else |
| 69 | rev="unknown (not a git checkout)" |
| 70 | fi |
| 71 | printf 'run-native: omc sha256 %s (OMEGA_SRC %s)\n' "$pin" "$rev" |
| 72 | |
| 73 | # Link targets: reuse a link that already points at OMEGA_SRC, refuse anything else. |
| 74 | link() { |
| 75 | if [ -L "$2" ]; then |
| 76 | [ "$(cd "$2" && pwd -P)" = "$1" ] || die "$root/$2 links elsewhere; remove it or pass that tree" |
| 77 | return 1 |
| 78 | fi |
| 79 | [ ! -e "$2" ] || die "$root/$2 exists and is not a link to $1" |
| 80 | ln -s "$1" "$2" || die "cannot create link $root/$2" |
| 81 | } |
| 82 | |
| 83 | [ ! -e "$scratch" ] || die "scratch $root/$scratch exists; remove it first" |
| 84 | mkdir -p build || die "cannot create $root/build" |
| 85 | link "$src" build/nl3-omega |
| 86 | if link "$src/seed" seed; then |
| 87 | trap 'rm -f "$root/seed"' EXIT |
| 88 | trap 'exit 130' INT TERM |
| 89 | fi |
| 90 | |
| 91 | if build/nl3-omega/seed/out/omc < build/nl3-omega/seed/qualification/om2/gate.om > build/nl3-gate; then |
| 92 | chmod +x build/nl3-gate || die "cannot chmod $root/build/nl3-gate" |
| 93 | else |
| 94 | rc=$? |
| 95 | printf 'run-native: conductor compile failed, rc=%s\n' "$rc" >&2 |
| 96 | exit "$rc" |
| 97 | fi |
| 98 | |
| 99 | build/nl3-gate build/nl3-omega/seed/out/omc "$pin" "$cases" "$scratch" |