interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / tools / aien-verify / tests / run.sh

213 lines · 15129 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# aien-verify tests: sha256 vectors, both committed fixtures, four mutation tests on copies.
18# Usage: tests/run.sh (set TMPDIR to a scratch folder; fixtures are never written to)
19set -u
20here=$(cd "$(dirname "$0")/.." && pwd)
21repo=$(cd "$here/../.." && pwd)
22runs=$repo/docs/campaigns/whole-system-e2e/runs
23FA=$runs/RUN-1-dry-20261010T133749Z
24FB=$runs/RUN-1-dry-20261010T134202Z
25# contract digest of aien-architecture main 3c584a49 (passed on the command line, as the verifier requires)
26CS=8ba653848287bc77db253466f6d3ff37c70a42be55601ad47eb1f838a41d20f0
27work=$(mktemp -d)
28trap 'rm -rf "$work"' EXIT
29bin=$work/aien-verify
30pass=0; fail=0
31ok() { pass=$((pass + 1)); echo "ok $1"; }
32bad() { fail=$((fail + 1)); echo "FAIL $1"; }
33check() { # name, command...
34 n=$1; shift
35 if "$@" >/dev/null 2>&1; then ok "$n"; else bad "$n"; fi
36}
37tree_sum() { (cd "$1" && find . -type f | LC_ALL=C sort | xargs sha256sum | sha256sum | cut -d' ' -f1); }
38
39before=$(tree_sum "$runs")
40"$here/build.sh" "$bin" >/dev/null 2>&1 || { echo "build failed"; exit 1; }
41rustc --edition 2021 --test "$here/src/main.rs" -o "$work/unit" 2>/dev/null && check "unit tests (sha256 vectors incl. empty and abc)" "$work/unit"
42check "binary selftest (sha256 vectors)" "$bin" --selftest
43
44rows_of() { grep -E '^(E[1-6]|CTRL-E[1-6]) ' ; }
45expect() { # name, run dir, expected rows (here-doc via $3)
46 out=$("$bin" "$2" --contract-sha256 $CS 2>/dev/null)
47 got=$(printf '%s\n' "$out" | rows_of)
48 if [ "$got" = "$3" ]; then ok "$1 rows"; else bad "$1 rows"; printf 'got:\n%s\n' "$got"; fi
49}
50expect "fixture A" "$FA" "E1 NOT_RUN
51E2 NOT_RUN
52E3 FAIL
53E4 NOT_RUN
54E5 NOT_RUN
55E6 PASS
56CTRL-E1 NOT_RUN
57CTRL-E2 NOT_RUN
58CTRL-E3 NOT_RUN
59CTRL-E4 NOT_RUN
60CTRL-E5 NOT_RUN
61CTRL-E6 NOT_RUN"
62expect "fixture B" "$FB" "E1 NOT_RUN
63E2 NOT_RUN
64E3 FAIL
65E4 FAIL
66E5 NOT_RUN
67E6 PASS
68CTRL-E1 NOT_RUN
69CTRL-E2 NOT_RUN
70CTRL-E3 NOT_RUN
71CTRL-E4 NOT_RUN
72CTRL-E5 NOT_RUN
73CTRL-E6 NOT_RUN"
74
75vid() { "$bin" "$1" --contract-sha256 $CS 2>/dev/null | sed -n 's/^verdict_id //p'; }
76A1=$(vid "$FA"); A2=$(vid "$FA"); B1=$(vid "$FB"); B2=$(vid "$FB")
77[ -n "$A1" ] && [ "$A1" = "$A2" ] && ok "fixture A verdict_id stable ($A1)" || bad "fixture A verdict_id stable"
78[ -n "$B1" ] && [ "$B1" = "$B2" ] && ok "fixture B verdict_id stable ($B1)" || bad "fixture B verdict_id stable"
79[ "$A1" = 728ae9152ef546ab4ccf1b7619fd22d21acb2914870197ac58e8843f9afaaf77 ] && ok "fixture A verdict_id pinned" || bad "fixture A verdict_id pinned"
80[ "$B1" = d7d57162ac318ec05f2d97ad9530d9d3a571275409b040f65ccd0e391f6c9615 ] && ok "fixture B verdict_id pinned" || bad "fixture B verdict_id pinned"
81for F in "$FA" "$FB"; do
82 "$bin" "$F" --contract-sha256 $CS 2>/dev/null | grep -q '^chain_unbroken true$' && ok "$(basename $F) chain unbroken" || bad "$(basename $F) chain unbroken"
83 "$bin" "$F" --contract-sha256 $CS >/dev/null 2>&1; [ $? -eq 1 ] && ok "$(basename $F) exit 1 (FAIL rows)" || bad "$(basename $F) exit 1"
84done
85"$bin" "$FB" --contract-sha256 $CS --objective-id 093e66ec92a6b428b49a0aa2a75678e9fdb155f423e1e7c71c5ae9fef11a60b1 2>/dev/null | grep -q '^chain_unbroken true$' && ok "objective id argument accepted" || bad "objective id argument accepted"
86"$bin" "$FB" --contract-sha256 $CS --objective-id 00000000000000000000000000000000000000000000000000000000000000aa 2>/dev/null | grep -q 'OBJECTIVE_ID' && ok "wrong objective id named" || bad "wrong objective id named"
87"$bin" "$FB" >/dev/null 2>&1; [ $? -eq 2 ] && ok "missing --contract-sha256 refused" || bad "missing --contract-sha256 refused"
88
89# E5 with a peer: equal base id passes, unequal fails; both machines then print one final id
90PASSID=$("$bin" "$FB" --contract-sha256 $CS --peer-verdict-id "$B1" 2>/dev/null | sed -n 's/^verdict_id //p')
91"$bin" "$FB" --contract-sha256 $CS --peer-verdict-id "$B1" 2>/dev/null | grep -q '^E5 PASS$' && ok "E5 PASS with matching peer base id" || bad "E5 PASS with matching peer base id"
92[ "$PASSID" != "$B1" ] && ok "E5 PASS changes the final id ($PASSID)" || bad "E5 changes final id"
93"$bin" "$FB" --contract-sha256 $CS --peer-verdict-id "$A1" 2>/dev/null | grep -q '^E5 FAIL$' && ok "E5 FAIL with differing peer id" || bad "E5 FAIL with differing peer id"
94
95# --write writes both files into a copy, never into the fixture
96cp -r "$FB" "$work/w" && "$bin" "$work/w" --contract-sha256 $CS --write >/dev/null 2>&1
97[ -s "$work/w/VERIFIER_VERDICT.txt" ] && [ -s "$work/w/VERIFIER_RECEIPT.json" ] && ok "--write wrote verdict and receipt" || bad "--write wrote verdict and receipt"
98grep -q '"chain_unbroken": true' "$work/w/VERIFIER_RECEIPT.json" && grep -q '"verifier_sha256": "' "$work/w/VERIFIER_RECEIPT.json" && ok "receipt carries chain_unbroken and verifier_sha256" || bad "receipt fields"
99"$bin" "$work/w" --contract-sha256 $CS 2>/dev/null | grep -q '^chain_unbroken true$' && ok "re-verify after --write still unbroken" || bad "re-verify after --write"
100
101mutant() { rm -rf "$work/m"; cp -r "$1" "$work/m"; }
102detect() { # name, expected reason text, expected row line or empty
103 out=$("$bin" "$work/m" --contract-sha256 $CS 2>/dev/null); rc=$?
104 if [ $rc -ne 0 ] && printf '%s\n' "$out" | grep -q -- "$2"; then ok "$1 detected ($2)"; else bad "$1 detected ($2)"; printf '%s\n' "$out" | grep '^# ' | head -5; fi
105 if [ -n "${3:-}" ]; then printf '%s\n' "$out" | grep -q -- "$3" && ok "$1 row: $3" || bad "$1 row: $3"; fi
106}
107# M1: one byte changed in an output file
108mutant "$FB"; printf 'X' | dd of="$work/m/artifacts/E3m-report.md" bs=1 seek=3 conv=notrunc 2>/dev/null
109detect "M1 one byte changed in an output file" MANIFEST_DIGEST "# (supplementary) E3m FAIL: DIGEST_MISMATCH"
110# M2: one chain link broken
111mutant "$FB"; sed -i 's/"prev_receipt_sha256": "[0-9a-f]*"/"prev_receipt_sha256": "1111111111111111111111111111111111111111111111111111111111111111"/' "$work/m/chain/006-E3m.json"
112detect "M2 chain link broken" LINK_BROKEN
113# M3: one file dropped from SHA256SUMS
114mutant "$FB"; grep -v 'artifacts/E3m-report.md' "$work/m/chain/SHA256SUMS" >"$work/ms" && cp "$work/ms" "$work/m/chain/SHA256SUMS"
115detect "M3 file dropped from SHA256SUMS" MANIFEST_UNLISTED
116# M4a: a status edited FAIL to PASS, links and manifest NOT repaired
117mutant "$FB"; sed -i 's/"status": "FAIL"/"status": "PASS"/' "$work/m/chain/005-E3.json"
118detect "M4a receipt status FAIL->PASS, unrepaired" LINK_BROKEN
119# M4b: same edit with every link and manifest line repaired, so only the false status word remains
120mutant "$FB"; sed -i 's/"status": "FAIL"/"status": "PASS"/' "$work/m/chain/005-E3.json"
121prev=0000000000000000000000000000000000000000000000000000000000000000
122for f in $(ls "$work/m/chain"/0*.json | LC_ALL=C sort); do
123 sed -i "s/\"prev_receipt_sha256\": \"[0-9a-f]*\"/\"prev_receipt_sha256\": \"$prev\"/" "$f"
124 prev=$(sha256sum "$f" | cut -d' ' -f1)
125done
126: >"$work/newsums"
127while read -r h p; do
128 if [ -f "$work/m/$p" ]; then printf '%s %s\n' "$(sha256sum "$work/m/$p" | cut -d' ' -f1)" "$p" >>"$work/newsums"; else printf '%s %s\n' "$h" "$p" >>"$work/newsums"; fi
129done <"$work/m/chain/SHA256SUMS"
130cp "$work/newsums" "$work/m/chain/SHA256SUMS"
131out=$("$bin" "$work/m" --contract-sha256 $CS 2>/dev/null)
132printf '%s\n' "$out" | grep -q '^chain_unbroken true$' && ok "M4b repaired chain is unbroken (only the lie remains)" || bad "M4b repaired chain unbroken"
133printf '%s\n' "$out" | grep -q '^E3 FAIL$' && ok "M4b E3 stays FAIL without the facts" || bad "M4b E3 stays FAIL"
134printf '%s\n' "$out" | grep -q 'status_disagreement: E3 receipt says PASS but the facts derive FAIL' && ok "M4b status_disagreement named" || bad "M4b status_disagreement named"
135# M5: a file added to the folder but not the manifest; M6: a link target removed (sequence gap)
136mutant "$FB"; echo extra >"$work/m/artifacts/extra.txt"
137detect "M5 unlisted extra file" MANIFEST_UNLISTED
138mutant "$FB"; rm "$work/m/chain/007-E4.json"
139detect "M6 receipt file dropped" SEQUENCE_GAP
140
141# CTRL-E5 (v1.3-ctrl-e5): judged from the receipt's facts. Built on a copy of fixture B with a receipt appended and the manifest rewritten.
142mkE5() { # dir, fields json (merged over a good receipt)
143 rm -rf "$1"; cp -r "$FB" "$1"; rm -f "$1/chain/SHA256SUMS"
144 last=$(ls "$1"/chain/0*.json | LC_ALL=C sort | tail -1); num=$(basename "$last" | cut -c1-3); next=$(printf '%03d' $((1$num - 999)))
145 jq --arg prev "$(sha256sum "$last" | cut -d' ' -f1)" --arg step CTRL-E5 --argjson f "$2" \
146 '{objective_id, run_id, step:$step, status:"PASS", prev_receipt_sha256:$prev, evidence:"test"} + $f' "$last" >"$1/chain/$next-CTRL-E5.json"
147 (cd "$1" && find . -type f ! -name SHA256SUMS ! -name VERIFIER_VERDICT.txt ! -name VERIFIER_RECEIPT.json -print0 | LC_ALL=C sort -z | xargs -0 sha256sum >chain/SHA256SUMS)
148}
149GOOD="{\"mutated_output_rejected\":true,\"mutated_chain_unbroken\":false,\"original_verdict_id\":\"$B1\",\"mutated_verdict_id\":\"1111111111111111111111111111111111111111111111111111111111111111\",\"verifier_reason\":\"# E3 FAIL: DIGEST_MISMATCH: x\"}"
150c5() { "$bin" "$1" --contract-sha256 $CS 2>/dev/null; }
151mkE5 "$work/e5a" "$GOOD"
152c5 "$work/e5a" | grep -q "^CTRL-E5 PASS$" && ok "CTRL-E5 PASS from a good receipt" || { bad "CTRL-E5 PASS from a good receipt"; c5 "$work/e5a" | grep "CTRL-E5"; }
153c5 "$work/e5a" | grep -q '^chain_unbroken true$' && ok "CTRL-E5 fixture chain unbroken" || bad "CTRL-E5 fixture chain unbroken"
154[ "$(c5 "$work/e5a" | sed -n 's/^verdict_id //p')" != "$B1" ] && ok "CTRL-E5 PASS changes the final id" || bad "CTRL-E5 PASS changes the final id"
155mkE5 "$work/e5b" "$(printf '%s' "$GOOD" | jq -c '.mutated_output_rejected=false')"
156c5 "$work/e5b" | grep -q '^CTRL-E5 FAIL$' && ok "CTRL-E5 FAIL when mutated_output_rejected is false" || bad "CTRL-E5 FAIL when rejected false"
157mkE5 "$work/e5c" "$(printf '%s' "$GOOD" | jq -c '.original_verdict_id="2222222222222222222222222222222222222222222222222222222222222222"')"
158c5 "$work/e5c" | grep -q '^CTRL-E5 FAIL$' && ok "CTRL-E5 FAIL when original_verdict_id is not the derived pre id" || bad "CTRL-E5 FAIL on wrong original id"
159mkE5 "$work/e5d" "$(printf '%s' "$GOOD" | jq -c '.mutated_verdict_id=.original_verdict_id')"
160c5 "$work/e5d" | grep -q '^CTRL-E5 FAIL$' && ok "CTRL-E5 FAIL when the verdict id did not change" || bad "CTRL-E5 FAIL on unchanged id"
161mkE5 "$work/e5e" "$(printf '%s' "$GOOD" | jq -c '.mutated_chain_unbroken=true')"
162c5 "$work/e5e" | grep -q '^CTRL-E5 FAIL$' && ok "CTRL-E5 FAIL when the mutated chain stayed unbroken" || bad "CTRL-E5 FAIL on unbroken mutated chain"
163mkE5 "$work/e5f" "{}"
164c5 "$work/e5f" | grep -q '^CTRL-E5 NOT_RUN$' && ok "CTRL-E5 NOT_RUN when the receipt lacks facts" || bad "CTRL-E5 NOT_RUN without facts"
165c5 "$FB" | grep -q '^CTRL-E5 NOT_RUN$' && ok "CTRL-E5 NOT_RUN when no receipt" || bad "CTRL-E5 NOT_RUN absent"
166
167# regression: the recorded RUN-1 (no facts-bearing CTRL-E5 receipt) still verifies to its recorded ids
168R1=$runs/RUN-1-20261010T154724Z
169if [ -d "$R1" ]; then
170 C9=9e3d5f4e23d65ac17be8f2f4ca48355f0aaa486f67ff5a8a8044dcdd646d34e8
171 out=$("$bin" "$R1" --contract-sha256 $C9 --peer-verdict-id a50fccb63363ef9224a19bd8bf4f249754abf5d88667ba0fd6ce93dfb8d63d80 2>/dev/null)
172 printf '%s\n' "$out" | grep -q '^verdict_id 437467db4149b013738578c10ef68b7168dfb95feae8dea882de17a6118fc5fd$' && ok "RUN-1 verdict_id unchanged with the Spark base id as peer" || bad "RUN-1 verdict_id unchanged"
173 printf '%s\n' "$out" | grep -q '^base_verdict_id a50fccb63363ef9224a19bd8bf4f249754abf5d88667ba0fd6ce93dfb8d63d80$' && ok "RUN-1 base_verdict_id unchanged" || bad "RUN-1 base_verdict_id unchanged"
174fi
175
176
177# VERIFIER-v1.1-e3m (sc#423): E3m D4 follows the receipt's d4_rule; recorded GB10 folders keep their verdict ids
178C9=9e3d5f4e23d65ac17be8f2f4ca48355f0aaa486f67ff5a8a8044dcdd646d34e8
179R2=$runs/RUN-2-GB10-20261011T030554Z
180R3=$runs/RUN-3-GB10-20261011T045450Z
181g9() { "$bin" "$1" --contract-sha256 $C9 2>/dev/null; }
182if [ -d "$R2" ]; then
183 out=$(g9 "$R2")
184 printf '%s\n' "$out" | grep -q '^verdict_id af9e744cc3187400e00599159999f357f53c1df867556f62c8f71a552662800c$' && ok "RUN-2-GB10 verdict_id unchanged" || bad "RUN-2-GB10 verdict_id unchanged"
185 printf '%s\n' "$out" | grep -q '^# (supplementary) E3m FAIL: .*D4 required name(s) missing: \["windmill"\]' && ok "RUN-2-GB10 E3m FAIL (no d4_rule: exact rule)" || bad "RUN-2-GB10 E3m exact rule"
186fi
187if [ -d "$R3" ]; then
188 out=$(g9 "$R3")
189 printf '%s\n' "$out" | grep -q '^verdict_id 9ca9b7af6f9255fc7247acae33492768252d5f2017b40c29c159e04fbca833d5$' && ok "RUN-3-GB10 verdict_id unchanged" || bad "RUN-3-GB10 verdict_id unchanged"
190 printf '%s\n' "$out" | grep -q '^# (supplementary) E3m PASS' && ok "RUN-3-GB10 E3m PASS under its d4_rule" || bad "RUN-3-GB10 E3m PASS under its d4_rule"
191 printf '%s\n' "$out" | grep -q 'status_disagreement: E3m' && bad "RUN-3-GB10 E3m disagreement gone" || ok "RUN-3-GB10 E3m disagreement gone"
192 printf '%s\n' "$out" | grep -q 'status_disagreement: CTRL-E4 receipt says PASS but the facts derive NOT_RUN' && ok "RUN-3-GB10 CTRL-E4 disagreement kept" || bad "RUN-3-GB10 CTRL-E4 disagreement kept"
193 relink() { # repair every link and manifest line of $work/m after an edit, so only the edited fact differs
194 p=0000000000000000000000000000000000000000000000000000000000000000
195 for f in $(ls "$work/m/chain"/0*.json | LC_ALL=C sort); do
196 sed -i "s/\"prev_receipt_sha256\": \"[0-9a-f]*\"/\"prev_receipt_sha256\": \"$p\"/" "$f"; p=$(sha256sum "$f" | cut -d' ' -f1)
197 done
198 : >"$work/newsums"
199 while read -r h q; do
200 if [ -f "$work/m/$q" ]; then printf '%s %s\n' "$(sha256sum "$work/m/$q" | cut -d' ' -f1)" "$q" >>"$work/newsums"; else printf '%s %s\n' "$h" "$q" >>"$work/newsums"; fi
201 done <"$work/m/chain/SHA256SUMS"
202 cp "$work/newsums" "$work/m/chain/SHA256SUMS"
203 }
204 mutant "$R3"; jq -c 'del(.d4_rule)' "$work/m/chain/007-E3m.json" >"$work/e" && cp "$work/e" "$work/m/chain/007-E3m.json"; relink
205 out=$(g9 "$work/m")
206 printf '%s\n' "$out" | grep -q '^chain_unbroken true$' && printf '%s\n' "$out" | grep -q '^# (supplementary) E3m FAIL: .*windmill' && ok "RUN-3 copy without d4_rule: exact rule, E3m FAIL" || bad "RUN-3 copy without d4_rule"
207 mutant "$R3"; jq -c '.d4_rule="case-insensitive substring"' "$work/m/chain/007-E3m.json" >"$work/e" && cp "$work/e" "$work/m/chain/007-E3m.json"; relink
208 g9 "$work/m" | grep -q '^# (supplementary) E3m NOT_RUN: unknown d4_rule' && ok "RUN-3 copy with an unknown d4_rule: E3m NOT_RUN" || bad "RUN-3 copy unknown d4_rule"
209fi
210after=$(tree_sum "$runs")
211[ "$before" = "$after" ] && ok "fixtures untouched" || bad "fixtures untouched"
212echo "passed $pass, failed $fail"
213[ $fail -eq 0 ]