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-local-ci / tests / crumb_shim_test.sh

104 lines · 5709 bytes Raw Blame History
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.
18set -u
19SHIM=$(readlink -f "${1:?usage: test-crumb-shim.sh <shim>}")
20T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
21pass=0; fail=0
22ok() { pass=$((pass+1)); echo "ok $1"; }
23bad() { fail=$((fail+1)); echo "FAIL $1: $2"; }
24g() { git -c user.name=t -c user.email=t@t -c commit.gpgsign=false "$@"; }
25printf '#!/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.
29mkdir -p "$T/up-arch/tools/crumb"; g -C "$T/up-arch" init -q -b main
30mk() {
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}
34mk 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)
35mk 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)
36g -C "$T/up-arch" checkout -qb hostile
37printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-make-ran" > "$T/up-arch/tools/crumb/Makefile"
38g -C "$T/up-arch" commit -qam hostile; C=$(git -C "$T/up-arch" rev-parse HEAD)
39g -C "$T/up-arch" checkout -q main
40git clone -q "$T/up-arch" "$T/arch"
41export CRUMB_SANDBOX_TOOL=$T/sandbox CRUMB_TOOL_CACHE=$T/cache CRUMB_ARCH_CLONE=$T/arch
42
43repo() { # 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}
52repo locked "$A"
53repo lockedB " ${B^^} "
54repo plain
55repo badlock invalid
56repo nopin "$C"
57mkdir -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.
60printf '%s\n' "$C" > "$T/locked/crumb.lock"
61mkdir -p "$T/plain/tools/crumb"
62cp "$T/up-arch/tools/crumb/Makefile" "$T/plain/tools/crumb/Makefile"
63printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-plain-ran" > "$T/plain/tools/crumb/Makefile"
64cp "$T/up-arch/tools/crumb/crumb.c" "$T/plain/tools/crumb/crumb.c"
65printf 'crumb:\n\t@touch "%s"\n\t@false\n' "$T/hostile-arch-ran" > "$T/arch/tools/crumb/Makefile"
66mkdir -p "$T/arch/sub"
67
68out() { (cd "$1" && shift && "$SHIM" "$@" 2>&1); }
69expect() { # 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}
74expect "candidate lock ignored, trusted main pin used" "PIN-A verify ." "$T/locked" verify .
75expect "approved ancestor pin B" "PIN-B verify ." "$T/lockedB" verify .
76expect "nested candidate uses trusted main" "PIN-A verify ." "$T/locked/sub/dir" verify .
77expect "path argument chooses target main" "PIN-A verify $T/locked" "$T/plain" verify "$T/locked"
78expect "file argument chooses target main" "PIN-A context" "$T/notgit" context "$T/locked/.crumb"
79expect "candidate source without trusted main tool uses sandbox" "SANDBOX verify ." "$T/plain" verify .
80expect "outside git uses sandbox" "SANDBOX verify ." "$T/notgit" verify .
81expect "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
85r=$(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"
87r=$(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.
93git -C "$T/locked" update-ref -d refs/remotes/origin/main
94r=$(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.
98printf '#!/bin/sh\necho out; echo err >&2; exit 5\n' > "$T/sandbox"
99o=$(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"
101w=$(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
104echo "shim tests: $pass passed, $fail failed"; (( fail == 0 ))