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/interplane-mv/blob/main/adapters/aien/scripts/test-live-daemon.sh # interplane-mv INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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. 25 set -euo pipefail 26 27 here="$(cd "$(dirname "$0")" && pwd)" 28 adapter="$(cd "$here/.." && pwd)" 29 repo="$(cd "$adapter/../.." && pwd)" 30 die() { 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" 35 command -v jq >/dev/null || die "jq is required" 36 model_dir="${AIEN_LEDGER_MODEL_DIR:-$HOME/.cache/huggingface/hub/models--unsloth--Llama-3.2-1B-Instruct/snapshots/`5a8abab4a5d6f164389b1079fb721cfab8d7126c`}" 37 for f in model.safetensors tokenizer.json config.json; do 38 [ -f "$model_dir/$f" ] || die "model dir lacks $f: $model_dir" 39 done 40 if command -v quietlock >/dev/null && ! quietlock check >/dev/null 2>&1; then 41 die "quiet flag is held (quietlock check): no long run now" 42 fi 43 mkdir -p "$OUT" 44 OUT="$(cd "$OUT" && pwd)" 45 [ ! -e "$OUT/rows" ] || die "$OUT/rows exists: use a fresh OUT (a sealed run is never overwritten)" 46 started="$(date -u +%FT%TZ)" 47 required="row1_ x1_ x2_ x3_ x4_" 48 rows="${LIVE_ROWS:-}" 49 if [ -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 53 fi 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. 57 skip_slice=""; [ -n "$rows" ] || skip_slice="--skip slice1_" 58 log="$OUT/live.log" 59 set +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 62 test_rc=$? 63 set -e 64 [ "$test_rc" -eq 0 ] || { tail -5 "$log" >&2; die "live tests exited $test_rc (log $log)"; } 65 passed="$(grep -c '^test .* \.\.\. ok$' "$log" || true)" 66 failed="$(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" 69 for r in $required; do 70 grep -q "^test .*${r}.* \.\.\. ok$" "$log" || die "required test $r did not run and pass" 71 done 72 tests_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. 75 bundle="$OUT/rows/row1/bundle" 76 [ -f "$bundle/COMPANION.json" ] || die "row 1 exported no bundle: $bundle/COMPANION.json" 77 verify() { (cd "$repo/provenance" && cargo run -q --locked --release -- verify "$1" 2>&1 || true) | tail -1; } 78 want_incomplete="PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn" 79 verdict="$(verify "$bundle")" 80 case "$verdict" in 81 "$want_incomplete") ;; 82 *) die "unexpected verdict on the live bundle: $verdict";; 83 esac 84 85 # 3. Tamper checks on hard-linked copies (a changed file is written fresh, never in place). 86 neg="$OUT/negative" 87 mkdir -p "$neg" 88 fork() { rm -rf "$neg/$1"; cp -al "$bundle" "$neg/$1"; } 89 restamp() { # 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 } 95 rewrite() { # 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 } 102 expect() { # 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" 108 fork control 109 [ "$(verify "$neg/control")" = "$verdict" ] || die "negative control: an untouched copy no longer verifies" 110 echo "control $verdict" >>"$neg/verdicts.txt" 111 # (a) the proposal content in the trace changes; the manifest still names the old digest. 112 fork content_bytes 113 rewrite "$neg/content_bytes" interplane_trace 's/Friday/Monday/' 114 expect content_bytes "$neg/content_bytes" digest_mismatch 115 # (b) same change, manifest restamped to hide it: the grant's content digest still disagrees. 116 fork content_restamped 117 rewrite "$neg/content_restamped" interplane_trace 's/Friday/Monday/' 118 restamp "$neg/content_restamped" interplane_trace 119 expect 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. 121 fork ack_bytes 122 rewrite "$neg/ack_bytes" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/' 123 expect ack_bytes "$neg/ack_bytes" digest_mismatch 124 # (d) same change, restamped: the daemon-written ack must say DONE. 125 fork ack_restamped 126 rewrite "$neg/ack_restamped" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/' 127 restamp "$neg/ack_restamped" ledger_ack 128 expect ack_restamped "$neg/ack_restamped" binding_mismatch 129 # (e) a retained file is truncated (partial write). 130 fork truncated 131 p="$(jq -r .records.ledger_intent.path "$neg/truncated/COMPANION.json")" 132 head -c 20 "$neg/truncated/$p" >"$neg/truncated/$p.new"; rm "$neg/truncated/$p"; mv "$neg/truncated/$p.new" "$neg/truncated/$p" 133 expect truncated "$neg/truncated" size_mismatch 134 135 # 4. Receipt. 136 finished="$(date -u +%FT%TZ)" 137 omega="${OMEGA_LOCK_REV:-}" 138 if [ -z "$omega" ] && [ -n "${AIEN_OMEGA_COMPOSE_DIR:-}" ]; then 139 omega="$(git -C "$AIEN_OMEGA_COMPOSE_DIR" rev-parse HEAD 2>/dev/null || true)" 140 fi 141 dirty=false; [ -z "$(git -C "$repo" status --porcelain -- adapters provenance 2>/dev/null)" ] || dirty=true 142 jq -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. 163 if [ "${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)" 165 fi 166 echo "GATE PASS: $passed live tests, verdict: $verdict; receipt $OUT/receipt.json"