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
aien-sovereign-core-mv / tools / aien-local-ci / tests / crumb_shim_test.sh
| 1 | #!/usr/bin/env bash |
| 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 | # test-crumb-shim.sh <shim>: no network, candidate Makefiles/locks never execute. |
| 18 | set -u |
| 19 | SHIM=$(readlink -f "${1:?usage: test-crumb-shim.sh <shim>}") |
| 20 | T=$(mktemp -d); trap 'rm -rf "$T"' EXIT |
| 21 | pass=0; fail=0 |
| 22 | ok() { pass=$((pass+1)); echo "ok $1"; } |
| 23 | bad() { fail=$((fail+1)); echo "FAIL $1: $2"; } |
| 24 | g() { git -c user.name=t -c user.email=t@t -c commit.gpgsign=false "$@"; } |
| 25 | printf '#!/bin/sh\necho SANDBOX "$@"\n' > "$T/sandbox"; chmod +x "$T/sandbox" |
| 26 | |
| 27 | # Architecture main has two approved revisions. An unmerged commit carries a |
| 28 | # malicious Makefile: neither a candidate HEAD nor its lock can select it. |
| 29 | mkdir -p "$T/up-arch/tools/crumb"; g -C "$T/up-arch" init -q -b main |
| 30 | mk() { |
| 31 | printf 'crumb: crumb.c\n\t$(CC) -o $@ crumb.c\n' > "$T/up-arch/tools/crumb/Makefile" |
| 32 | printf '#include <stdio.h>\nint main(int c,char**v){printf("%s");for(int i=1;i<c;i++)printf(" %%s",v[i]);printf("\\n");return 0;}\n' "$1" > "$T/up-arch/tools/crumb/crumb.c" |
| 33 | } |
| 34 | mk PIN-A; g -C "$T/up-arch" add -A; g -C "$T/up-arch" commit -qm A; A=$(git -C "$T/up-arch" rev-parse HEAD) |
| 35 | mk PIN-B; g -C "$T/up-arch" add -A; g -C "$T/up-arch" commit -qm B; B=$(git -C "$T/up-arch" rev-parse HEAD) |
| 36 | g -C "$T/up-arch" checkout -qb hostile |
| 37 | printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-make-ran" > "$T/up-arch/tools/crumb/Makefile" |
| 38 | g -C "$T/up-arch" commit -qam hostile; C=$(git -C "$T/up-arch" rev-parse HEAD) |
| 39 | g -C "$T/up-arch" checkout -q main |
| 40 | git clone -q "$T/up-arch" "$T/arch" |
| 41 | export CRUMB_SANDBOX_TOOL=$T/sandbox CRUMB_TOOL_CACHE=$T/cache CRUMB_ARCH_CLONE=$T/arch |
| 42 | |
| 43 | repo() { # repo <name> [main lock] |
| 44 | local name=$1 |
| 45 | mkdir -p "$T/up-$name" |
| 46 | g -C "$T/up-$name" init -q -b main |
| 47 | echo '{}' > "$T/up-$name/.crumb" |
| 48 | [ $# = 1 ] || printf '%s\n' "$2" > "$T/up-$name/crumb.lock" |
| 49 | g -C "$T/up-$name" add -A; g -C "$T/up-$name" commit -qm main |
| 50 | git clone -q "$T/up-$name" "$T/$name" |
| 51 | } |
| 52 | repo locked "$A" |
| 53 | repo lockedB " ${B^^} " |
| 54 | repo plain |
| 55 | repo badlock invalid |
| 56 | repo nopin "$C" |
| 57 | mkdir -p "$T/locked/sub/dir" "$T/notgit" |
| 58 | # Candidate lock points to unmerged architecture code, and a generic repo |
| 59 | # with no lock pretends to own a tool. Neither source is executable authority. |
| 60 | printf '%s\n' "$C" > "$T/locked/crumb.lock" |
| 61 | mkdir -p "$T/plain/tools/crumb" |
| 62 | cp "$T/up-arch/tools/crumb/Makefile" "$T/plain/tools/crumb/Makefile" |
| 63 | printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-plain-ran" > "$T/plain/tools/crumb/Makefile" |
| 64 | cp "$T/up-arch/tools/crumb/crumb.c" "$T/plain/tools/crumb/crumb.c" |
| 65 | printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-arch-ran" > "$T/arch/tools/crumb/Makefile" |
| 66 | mkdir -p "$T/arch/sub" |
| 67 | |
| 68 | out() { (cd "$1" && shift && "$SHIM" "$@" 2>&1); } |
| 69 | expect() { # expect <name> <prefix> <dir> <args...> |
| 70 | local name=$1 want=$2 dir=$3 got; shift 3 |
| 71 | got=$(out "$dir" "$@") |
| 72 | [[ $got == "$want"* ]] && ok "$name" || bad "$name" "want '$want...', got '$got'" |
| 73 | } |
| 74 | expect "candidate lock ignored, trusted main pin used" "PIN-A verify ." "$T/locked" verify . |
| 75 | expect "approved ancestor pin B" "PIN-B verify ." "$T/lockedB" verify . |
| 76 | expect "nested candidate uses trusted main" "PIN-A verify ." "$T/locked/sub/dir" verify . |
| 77 | expect "path argument chooses target main" "PIN-A verify $T/locked" "$T/plain" verify "$T/locked" |
| 78 | expect "file argument chooses target main" "PIN-A context" "$T/notgit" context "$T/locked/.crumb" |
| 79 | expect "candidate source without trusted main tool uses sandbox" "SANDBOX verify ." "$T/plain" verify . |
| 80 | expect "outside git uses sandbox" "SANDBOX verify ." "$T/notgit" verify . |
| 81 | expect "architecture uses archived main not dirty Makefile" "PIN-B verify ." "$T/arch" verify . |
| 82 | [ ! -e "$T/hostile-make-ran" ] && [ ! -e "$T/hostile-plain-ran" ] && [ ! -e "$T/hostile-arch-ran" ] \ |
| 83 | && ok "candidate Makefiles never ran" || bad "candidate Makefile" "sentinel created" |
| 84 | |
| 85 | r=$(out "$T/badlock" verify .); rc=$? |
| 86 | (( rc == 97 )) && [[ $r == *"not one 40-hex"* ]] && ok "malformed main lock refuses" || bad "malformed main lock" "rc=$rc $r" |
| 87 | r=$(out "$T/nopin" verify .); rc=$? |
| 88 | (( rc == 97 )) && [[ $r == *"not in architecture origin/main ancestry"* ]] && [ ! -e "$T/hostile-make-ran" ] \ |
| 89 | && ok "unmerged main pin refuses before cache or build" || bad "unmerged main pin" "rc=$rc $r" |
| 90 | |
| 91 | # Negative control: main pin absent and architecture main missing its own |
| 92 | # source both refuse, never silently accept a candidate source. |
| 93 | git -C "$T/locked" update-ref -d refs/remotes/origin/main |
| 94 | r=$(out "$T/locked" verify .); rc=$? |
| 95 | (( rc == 97 )) && [[ $r == *"no trusted origin/main"* ]] && ok "missing main refuses" || bad "missing main" "rc=$rc $r" |
| 96 | |
| 97 | # Status pass-through applies only to a selected approved/sandbox tool. |
| 98 | printf '#!/bin/sh\necho out; echo err >&2; exit 5\n' > "$T/sandbox" |
| 99 | o=$(cd "$T/plain" && "$SHIM" verify . 2>/dev/null); rc=$? |
| 100 | (( rc == 5 )) && [ "$o" = out ] && ok "exit code and stdout pass through" || bad "pass-through" "rc=$rc out=$o" |
| 101 | w=$(cd "$T/lockedB" && CRUMB_SHIM_WHICH=1 "$SHIM" verify .) |
| 102 | [[ $w == "$T/cache/$B/crumb crumb.lock:$B $T/lockedB" ]] && ok "which reports main pin" || bad "which" "$w" |
| 103 | |
| 104 | echo "shim tests: $pass passed, $fail failed"; (( fail == 0 )) |