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_doctor_test.sh

145 lines · 9430 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-doctor.sh <doctor>: the doctor goes RED on a stale trusted clone (the 2026-10-11..18 synapse
18# CRUMB-VERIFY "../aien-architecture is missing" cause), heals it, and raises/clears its aien-watch alert.
19set -u
20DOC=$(readlink -f "${1:?usage: test-crumb-doctor.sh <doctor>}")
21T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
22pass=0; fail=0
23ok() { pass=$((pass+1)); echo "ok $1"; }
24bad() { fail=$((fail+1)); echo "FAIL $1: $2"; }
25g() { git -c user.name=t -c user.email=t@t -c commit.gpgsign=false "$@"; }
26export AIEN_CLONES=$T/clones AIEN_WATCH_STATE=$T/watch AIEN_DOCTOR_NO_PROC=1 AIEN_DOCTOR_NO_READY=1 CRUMB_TOOL_CACHE=$T/cache
27mkdir -p "$T/clones" "$T/watch"
28echo "OTHER: unrelated alert (must survive)" > "$T/watch/ALERT"
29
30# upstream sc: commit 1 without the synapse sibling line, commit 2 with it
31mkdir -p "$T/up/sc/tools/aien-local-ci"; cd "$T/up/sc"; g init -q -b main
32echo "omega aien-architecture aien-architecture main" > tools/aien-local-ci/siblings; g add -A; g commit -qm one
33c1=$(git rev-parse HEAD)
34echo "synapse aien-architecture aien-architecture main" >> tools/aien-local-ci/siblings; g commit -qam two
35# upstream synapse: its gate asks for ../aien-architecture
36mkdir -p "$T/up/synapse/tests/gates"; cd "$T/up/synapse"; g init -q -b main
37printf 'case $1 in\n crumb-verify)\n need_sibling aien-architecture\n ;;\nesac\n' > tests/gates/run.sh; g add -A; g commit -qm s
38# trusted clones; sc work tree left on the OLD commit (what the Spark had)
39git clone -q "$T/up/sc" "$T/clones/aien-sovereign-core"; git -C "$T/clones/aien-sovereign-core" -c advice.detachedHead=false checkout -q --detach "$c1"
40git clone -q "$T/up/synapse" "$T/clones/synapse"
41
42o=$("$DOC" --no-prs --repos synapse --alert 2>&1); rc=$?
43(( rc == 1 )) && [[ $o == *"FAIL SIBMAP"*"missing synapse ../aien-architecture"* ]] && ok "stale trusted clone is RED (exit 1, names the missing sibling)" || bad "red" "rc=$rc $o"
44grep -q '^CRUMB-DRIFT: ' "$T/watch/ALERT" && grep -q '^OTHER: ' "$T/watch/ALERT" && ok "alert raised, other alerts kept" || bad "alert" "$(cat "$T/watch/ALERT")"
45
46o=$("$DOC" --heal-only 2>&1); rc=$?
47h=$(git -C "$T/clones/aien-sovereign-core" rev-parse HEAD); m=$(git -C "$T/clones/aien-sovereign-core" rev-parse origin/main)
48(( rc == 0 )) && [ "$h" = "$m" ] && ok "--heal-only moves the work tree to origin/main" || bad "heal" "rc=$rc head=$h main=$m $o"
49
50o=$("$DOC" --no-prs --repos synapse --alert 2>&1); rc=$?
51(( rc == 0 )) && [[ $o == *"PASS SIBMAP"* ]] && ok "after heal: GREEN" || bad "green" "rc=$rc $o"
52! grep -q '^CRUMB-DRIFT: ' "$T/watch/ALERT" && grep -q '^OTHER: ' "$T/watch/ALERT" && ok "alert cleared when green, other alerts kept" || bad "clear" "$(cat "$T/watch/ALERT")"
53
54# a dirty trusted clone is never moved (someone is using it): reported, not clobbered
55git -C "$T/clones/aien-sovereign-core" -c advice.detachedHead=false checkout -q --detach "$c1"
56echo "local edit" >> "$T/clones/aien-sovereign-core/tools/aien-local-ci/siblings"
57o=$("$DOC" --heal-only 2>&1); rc=$?
58(( rc == 1 )) && [[ $o == *"local changes"* ]] && grep -q "local edit" "$T/clones/aien-sovereign-core/tools/aien-local-ci/siblings" && ok "dirty work tree: refused, edit kept" || bad "dirty" "rc=$rc $o"
59
60# map on main missing a sibling a gate needs: RED even when the work tree is current
61git -C "$T/clones/aien-sovereign-core" checkout -q -- . ; git -C "$T/clones/aien-sovereign-core" -c advice.detachedHead=false checkout -q --detach origin/main
62cd "$T/up/synapse"; sed -i 's/need_sibling aien-architecture/need_sibling aien-architecture\n need_sibling omega/' tests/gates/run.sh; g commit -qam needs-omega; git -C "$T/clones/synapse" fetch -q
63o=$("$DOC" --no-prs --repos synapse 2>&1); rc=$?
64(( rc == 1 )) && [[ $o == *"synapse needs ../omega"* ]] && ok "gate needs a sibling the map lacks: RED" || bad "coverage" "rc=$rc $o"
65
66
67# Main pin/tool is approved; a fork-like PR changes the lock, hosted workflow
68# and Makefile to a key-reading recipe. The doctor may diff those bytes but
69# must never build the PR's source or execute its selected pin.
70mkdir -p "$T/up/arch/tools/crumb"
71g -C "$T/up/arch" init -q -b main
72printf 'crumb: crumb.c\n\t$(CC) -o $@ crumb.c\n' > "$T/up/arch/tools/crumb/Makefile"
73printf '#include <stdio.h>\nint main(void){puts("crumb verify: OK");return 0;}\n' > "$T/up/arch/tools/crumb/crumb.c"
74g -C "$T/up/arch" add -A; g -C "$T/up/arch" commit -qm approved
75archpin=$(git -C "$T/up/arch" rev-parse HEAD)
76g -C "$T/up/arch" checkout -qb unmerged
77printf 'crumb:\n\t@cat "%s" > "%s"\n\t@false\n' "$T/trusted-key" "$T/exfiltrated" > "$T/up/arch/tools/crumb/Makefile"
78g -C "$T/up/arch" commit -qam unapproved
79badpin=$(git -C "$T/up/arch" rev-parse HEAD)
80g -C "$T/up/arch" checkout -q main
81git clone -q "$T/up/arch" "$T/clones/aien-architecture"
82printf 'PRIVATE-TEST-KEY\n' > "$T/trusted-key"
83mkdir -p "$T/up/gate/tests/gates" "$T/up/gate/.github/workflows"
84g -C "$T/up/gate" init -q -b main
85echo '{}' > "$T/up/gate/.crumb"
86printf '%s\n' "$archpin" > "$T/up/gate/crumb.lock"
87printf 'case $1 in\n crumb-verify)\n pin=$(cat crumb.lock)\n ;;\nesac\n' > "$T/up/gate/tests/gates/run.sh"
88printf '# pinned crumb tool source\n# ref: %s\n' "$archpin" > "$T/up/gate/.github/workflows/aien-verification.yml"
89g -C "$T/up/gate" add -A; g -C "$T/up/gate" commit -qm approved
90git clone -q "$T/up/gate" "$T/clones/gate"
91mkdir -p "$T/bin"
92printf '#!/bin/sh\nprintf "7 %%s\\n" "$CANDIDATE_SHA"\n' > "$T/bin/gh"; chmod +x "$T/bin/gh"
93export PATH=$T/bin:$PATH CRUMB_SANDBOX_TOOL=$T/sandbox
94printf '#!/bin/sh\necho "crumb verify: OK"\n' > "$T/sandbox"; chmod +x "$T/sandbox"
95export CANDIDATE_SHA=$(git -C "$T/up/gate" rev-parse HEAD)
96o=$("$DOC" --repos gate 2>&1); rc=$?
97(( rc == 0 )) && [[ $o == *"PASS AGREE"*"trusted gate[crumb.lock"* ]] \
98 && [[ $o == *"INFO PROMOTE"*"metadata unchanged"* ]] \
99 && ok "approved main pin and unchanged candidate" || bad "approved main" "rc=$rc $o"
100
101g -C "$T/up/gate" checkout -qb hostile
102printf '%s\n' "$badpin" > "$T/up/gate/crumb.lock"
103printf '# pinned crumb tool source\n# ref: %s\n' "$badpin" > "$T/up/gate/.github/workflows/aien-verification.yml"
104mkdir -p "$T/up/gate/tools/crumb"
105cp "$T/up/arch/tools/crumb/Makefile" "$T/up/gate/tools/crumb/Makefile"
106cp "$T/up/arch/tools/crumb/crumb.c" "$T/up/gate/tools/crumb/crumb.c"
107g -C "$T/up/gate" add -A; g -C "$T/up/gate" commit -qm hostile
108export CANDIDATE_SHA=$(git -C "$T/up/gate" rev-parse HEAD)
109git -C "$T/clones/gate" fetch -q origin hostile
110o=$("$DOC" --repos gate --alert 2>&1); rc=$?
111(( rc == 1 )) && [[ $o == *"PASS AGREE"*"trusted gate[crumb.lock"* ]] \
112 && [[ $o == *"FAIL PROMOTE"*"operator promotion required"* ]] \
113 && [[ $o == *"crumb.lock"* ]] && [ ! -e "$T/exfiltrated" ] \
114 && grep -q '^CRUMB-DRIFT: ' "$T/watch/ALERT" \
115 && ok "candidate pin/Makefile demand promotion, key not read" \
116 || bad "hostile candidate" "rc=$rc sentinel=$(test -e "$T/exfiltrated" && echo PRESENT || echo absent) $o"
117
118# Negative control: even trusted main is refused if its pin is not in
119# architecture origin/main ancestry; the candidate source still never runs.
120g -C "$T/up/gate" checkout -q main
121printf '%s\n' "$badpin" > "$T/up/gate/crumb.lock"
122g -C "$T/up/gate" commit -qam unapproved-main-pin
123git -C "$T/clones/gate" fetch -q origin
124o=$("$DOC" --repos gate --no-prs 2>&1); rc=$?
125(( rc == 1 )) && [[ $o == *"trusted gate tool unavailable"* ]] && [ ! -e "$T/exfiltrated" ] \
126 && ok "unapproved main pin cannot build" || bad "unapproved main pin" "rc=$rc $o"
127
128# DRA-97: a main whose crumb gate and hosted crumb step are both retired passes AGREE
129# (its .crumb files stay as history); retiring only the gate step is still RED.
130mkdir -p "$T/up/retired/tests/gates" "$T/up/retired/.github/workflows"
131g -C "$T/up/retired" init -q -b main
132echo '{}' > "$T/up/retired/.crumb"
133printf 'case $1 in\n fmt) cargo fmt ;;\nesac\n' > "$T/up/retired/tests/gates/run.sh"
134printf '# pinned crumb tool source\n# ref: %s\n' "$archpin" > "$T/up/retired/.github/workflows/aien-verification.yml"
135g -C "$T/up/retired" add -A; g -C "$T/up/retired" commit -qm half-retired
136git clone -q "$T/up/retired" "$T/clones/retired"
137o=$("$DOC" --repos retired --no-prs 2>&1); rc=$?
138(( rc == 1 )) && [[ $o == *"FAIL AGREE"*"trusted gate tool unavailable (no crumb-verify step)"* ]] \
139 && ok "gate step retired, hosted crumb step still there: RED" || bad "half retired" "rc=$rc $o"
140printf 'name: AIEN\n' > "$T/up/retired/.github/workflows/aien-verification.yml"
141g -C "$T/up/retired" commit -qam retired; git -C "$T/clones/retired" fetch -q origin
142o=$("$DOC" --repos retired --no-prs 2>&1); rc=$?
143(( rc == 0 )) && [[ $o == *"PASS AGREE"*"crumb gate retired (DRA-97)"* ]] \
144 && ok "crumb gate and hosted step retired: GREEN" || bad "retired" "rc=$rc $o"
145echo "doctor tests: $pass passed, $fail failed"; (( fail == 0 ))