interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / adapters / aien / scripts / test-live-daemon.sh

166 lines · 9612 bytes Raw Blame History
1#!/usr/bin/env bash
2# Live verified-run gate for the INTERPLANE AIEN adapter.
3#
4# Runs the adapter's live-daemon tests (they are #[ignore]d: they start a real `aien-cli daemon`,
5# ~6.5 min each on the CPU reference backend), then feeds the bundle row 1 exported to the offline
6# provenance verifier and checks the verdict, then tampers with copies of the bundle and requires
7# the verifier to refuse each with a named code. It cannot pass vacuously: zero tests run, a
8# missing required row, a failed test, a missing bundle or an unexpected verdict all fail it.
9#
10# Inputs (environment):
11# AIEN_BIN native aien-cli binary (required)
12# AIEN_LEDGER_MODEL_DIR dir with model.safetensors, tokenizer.json, config.json
13# (default: the unsloth Llama-3.2-1B-Instruct snapshot in the HF cache)
14# OUT output dir (required; rows/ live.log receipt.json are written here)
15# Optional:
16# LIVE_ROWS space-separated test-name filters (default: every live test). Row 1 and
17# the four attack tests (x1_ x2_ x3_ x4_) are ALWAYS required to have run.
18# SOVEREIGN_CORE_REV revision the binary was built from; the daemon does not print it, so it is
19# recorded as caller-asserted (default UNVERIFIED)
20# OMEGA_LOCK_REV omega revision of the linked compose library; default: git rev-parse of
21# $AIEN_OMEGA_COMPOSE_DIR when set, else UNVERIFIED
22# SKIP_SLICE 1: do not run the fix-the-test slice gate (scripts/test-fix-the-test.sh) at the end
23# CARGO_TARGET_DIR build dir
24# Exit 0 only when every check passed. No process is killed here; the daemons are the tests' own.
25set -euo pipefail
26
27here="$(cd "$(dirname "$0")" && pwd)"
28adapter="$(cd "$here/.." && pwd)"
29repo="$(cd "$adapter/../.." && pwd)"
30die() { echo "GATE FAIL: $*" >&2; exit 1; }
31
32: "${AIEN_BIN:?AIEN_BIN must name the native aien-cli binary}"
33: "${OUT:?OUT must name the output directory}"
34[ -x "$AIEN_BIN" ] || die "AIEN_BIN not executable: $AIEN_BIN"
35command -v jq >/dev/null || die "jq is required"
36model_dir="${AIEN_LEDGER_MODEL_DIR:-$HOME/.cache/huggingface/hub/models--unsloth--Llama-3.2-1B-Instruct/snapshots/5a8abab4a5d6f164389b1079fb721cfab8d7126c}"
37for f in model.safetensors tokenizer.json config.json; do
38 [ -f "$model_dir/$f" ] || die "model dir lacks $f: $model_dir"
39done
40if command -v quietlock >/dev/null && ! quietlock check >/dev/null 2>&1; then
41 die "quiet flag is held (quietlock check): no long run now"
42fi
43mkdir -p "$OUT"
44OUT="$(cd "$OUT" && pwd)"
45[ ! -e "$OUT/rows" ] || die "$OUT/rows exists: use a fresh OUT (a sealed run is never overwritten)"
46started="$(date -u +%FT%TZ)"
47required="row1_ x1_ x2_ x3_ x4_"
48rows="${LIVE_ROWS:-}"
49if [ -n "$rows" ]; then
50 for r in $required; do
51 case " $rows " in *" $r "*) ;; *) die "LIVE_ROWS must include $r (required rows: $required)";; esac
52 done
53fi
54
55# 1. The live tests.
56# The fix-the-test slice row has its own gate (step 5); with no LIVE_ROWS filter it is skipped here.
57skip_slice=""; [ -n "$rows" ] || skip_slice="--skip slice1_"
58log="$OUT/live.log"
59set +e
60(cd "$adapter" && AIEN_BIN="$AIEN_BIN" AIEN_LEDGER_MODEL_DIR="$model_dir" LEDGER_OUT="$OUT/rows" \
61 cargo test --locked --test compose_ledger --test compose_ledger_attacks -- --ignored --test-threads=1 $skip_slice $rows) >"$log" 2>&1
62test_rc=$?
63set -e
64[ "$test_rc" -eq 0 ] || { tail -5 "$log" >&2; die "live tests exited $test_rc (log $log)"; }
65passed="$(grep -c '^test .* \.\.\. ok$' "$log" || true)"
66failed="$(grep -c '^test .* \.\.\. FAILED$' "$log" || true)"
67[ "$passed" -ge 1 ] || die "zero live tests ran (vacuous pass refused)"
68[ "$failed" -eq 0 ] || die "$failed live tests failed"
69for r in $required; do
70 grep -q "^test .*${r}.* \.\.\. ok$" "$log" || die "required test $r did not run and pass"
71done
72tests_json="$(grep '^test .* \.\.\. ok$' "$log" | sed 's/^test \(.*\) \.\.\. ok$/\1/' | jq -R . | jq -s .)"
73
74# 2. The verifier on the freshly exported row-1 bundle.
75bundle="$OUT/rows/row1/bundle"
76[ -f "$bundle/COMPANION.json" ] || die "row 1 exported no bundle: $bundle/COMPANION.json"
77verify() { (cd "$repo/provenance" && cargo run -q --locked --release -- verify "$1" 2>&1 || true) | tail -1; }
78want_incomplete="PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn"
79verdict="$(verify "$bundle")"
80case "$verdict" in
81 "$want_incomplete") ;;
82 *) die "unexpected verdict on the live bundle: $verdict";;
83esac
84
85# 3. Tamper checks on hard-linked copies (a changed file is written fresh, never in place).
86neg="$OUT/negative"
87mkdir -p "$neg"
88fork() { rm -rf "$neg/$1"; cp -al "$bundle" "$neg/$1"; }
89restamp() { # bundle record-name: set the manifest's sha256 and size to the file as it is now
90 local d="$1" n="$2" p; p="$(jq -r ".records.$n.path" "$d/COMPANION.json")"
91 jq --arg n "$n" --arg s "$(sha256sum "$d/$p" | cut -d' ' -f1)" --argjson b "$(wc -c <"$d/$p")" \
92 '.records[$n].sha256=$s | .records[$n].bytes=$b' "$d/COMPANION.json" >"$d/COMPANION.tmp"
93 mv "$d/COMPANION.tmp" "$d/COMPANION.json"
94}
95rewrite() { # bundle record-name sed-expression: same-length byte edit, written as a fresh file
96 local d="$1" n="$2" p; p="$(jq -r ".records.$n.path" "$d/COMPANION.json")"
97 sed "$3" "$d/$p" >"$d/$p.new"
98 cmp -s "$d/$p" "$d/$p.new" && die "tamper edit changed nothing in $p"
99 [ "$(wc -c <"$d/$p")" -eq "$(wc -c <"$d/$p.new")" ] || die "tamper edit changed the size of $p"
100 rm "$d/$p"; mv "$d/$p.new" "$d/$p"
101}
102expect() { # name bundle code
103 local v; v="$(verify "$2")"
104 case "$v" in "FAIL $3:"*) echo "negative $1: $v";; *) die "negative $1: wanted FAIL $3, got: $v";; esac
105 echo "$1 $v" >>"$neg/verdicts.txt"
106}
107: >"$neg/verdicts.txt"
108fork control
109[ "$(verify "$neg/control")" = "$verdict" ] || die "negative control: an untouched copy no longer verifies"
110echo "control $verdict" >>"$neg/verdicts.txt"
111# (a) the proposal content in the trace changes; the manifest still names the old digest.
112fork content_bytes
113rewrite "$neg/content_bytes" interplane_trace 's/Friday/Monday/'
114expect content_bytes "$neg/content_bytes" digest_mismatch
115# (b) same change, manifest restamped to hide it: the grant's content digest still disagrees.
116fork content_restamped
117rewrite "$neg/content_restamped" interplane_trace 's/Friday/Monday/'
118restamp "$neg/content_restamped" interplane_trace
119expect content_restamped "$neg/content_restamped" binding_mismatch
120# (c) the ack record's state changes (same-length byte edit); the manifest still names the old digest.
121fork ack_bytes
122rewrite "$neg/ack_bytes" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/'
123expect ack_bytes "$neg/ack_bytes" digest_mismatch
124# (d) same change, restamped: the daemon-written ack must say DONE.
125fork ack_restamped
126rewrite "$neg/ack_restamped" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/'
127restamp "$neg/ack_restamped" ledger_ack
128expect ack_restamped "$neg/ack_restamped" binding_mismatch
129# (e) a retained file is truncated (partial write).
130fork truncated
131p="$(jq -r .records.ledger_intent.path "$neg/truncated/COMPANION.json")"
132head -c 20 "$neg/truncated/$p" >"$neg/truncated/$p.new"; rm "$neg/truncated/$p"; mv "$neg/truncated/$p.new" "$neg/truncated/$p"
133expect truncated "$neg/truncated" size_mismatch
134
135# 4. Receipt.
136finished="$(date -u +%FT%TZ)"
137omega="${OMEGA_LOCK_REV:-}"
138if [ -z "$omega" ] && [ -n "${AIEN_OMEGA_COMPOSE_DIR:-}" ]; then
139 omega="$(git -C "$AIEN_OMEGA_COMPOSE_DIR" rev-parse HEAD 2>/dev/null || true)"
140fi
141dirty=false; [ -z "$(git -C "$repo" status --porcelain -- adapters provenance 2>/dev/null)" ] || dirty=true
142jq -n \
143 --arg adapter_commit "$(git -C "$repo" rev-parse HEAD)" --argjson adapter_dirty "$dirty" \
144 --arg bin_sha "$(sha256sum "$AIEN_BIN" | cut -d' ' -f1)" \
145 --arg sc_rev "${SOVEREIGN_CORE_REV:-UNVERIFIED}" \
146 --arg sc_rev_basis "$([ -n "${SOVEREIGN_CORE_REV:-}" ] && echo 'caller-asserted: the daemon does not print its revision' || echo 'the daemon does not print its revision')" \
147 --arg omega "${omega:-UNVERIFIED}" --arg verdict "$verdict" \
148 --arg companion_sha "$(sha256sum "$bundle/COMPANION.json" | cut -d' ' -f1)" \
149 --argjson tests "$tests_json" --argjson passed "$passed" \
150 --arg started "$started" --arg finished "$finished" \
151 --arg negatives "$(cat "$neg/verdicts.txt")" \
152 '{kind: "interplane-aien-live-gate-receipt", adapter_commit: $adapter_commit, adapter_dirty: $adapter_dirty,
153 sovereign_core_bin_sha256: $bin_sha, sovereign_core_rev: $sc_rev, sovereign_core_rev_basis: $sc_rev_basis,
154 omega_lock: $omega, backend: "CPU reference (as printed in the daemon log)",
155 verdict: $verdict, bundle_companion_sha256: $companion_sha,
156 tests: {passed: $passed, names: $tests}, negative_checks: ($negatives | split("\n") | map(select(length>0))),
157 started: $started, finished: $finished,
158 limits: ["records are unsigned exports; the verifier cannot tell an export from a hand-written file",
159 "desk MAC for ComposeAuthorize stays default-off (not changed here)",
160 "native compose library linking is not reported by the daemon",
161 "the model turn is scripted: proposal authorship is not claimed"]}' >"$OUT/receipt.json"
162# 5. The fix-the-test slice (scripts/test-fix-the-test.sh): its own live row, bundle verdict, tamper checks and receipt.
163if [ "${SKIP_SLICE:-0}" != "1" ]; then
164 OUT="$OUT/slice" "$here/test-fix-the-test.sh" || die "fix-the-test slice gate failed (set SKIP_SLICE=1 to run without it)"
165fi
166echo "GATE PASS: $passed live tests, verdict: $verdict; receipt $OUT/receipt.json"