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_doctor_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-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. |
| 19 | set -u |
| 20 | DOC=$(readlink -f "${1:?usage: test-crumb-doctor.sh <doctor>}") |
| 21 | T=$(mktemp -d); trap 'rm -rf "$T"' EXIT |
| 22 | pass=0; fail=0 |
| 23 | ok() { pass=$((pass+1)); echo "ok $1"; } |
| 24 | bad() { fail=$((fail+1)); echo "FAIL $1: $2"; } |
| 25 | g() { git -c user.name=t -c user.email=t@t -c commit.gpgsign=false "$@"; } |
| 26 | export AIEN_CLONES=$T/clones AIEN_WATCH_STATE=$T/watch AIEN_DOCTOR_NO_PROC=1 AIEN_DOCTOR_NO_READY=1 CRUMB_TOOL_CACHE=$T/cache |
| 27 | mkdir -p "$T/clones" "$T/watch" |
| 28 | echo "OTHER: unrelated alert (must survive)" > "$T/watch/ALERT" |
| 29 | |
| 30 | # upstream sc: commit 1 without the synapse sibling line, commit 2 with it |
| 31 | mkdir -p "$T/up/sc/tools/aien-local-ci"; cd "$T/up/sc"; g init -q -b main |
| 32 | echo "omega aien-architecture aien-architecture main" > tools/aien-local-ci/siblings; g add -A; g commit -qm one |
| 33 | c1=$(git rev-parse HEAD) |
| 34 | echo "synapse aien-architecture aien-architecture main" >> tools/aien-local-ci/siblings; g commit -qam two |
| 35 | # upstream synapse: its gate asks for ../aien-architecture |
| 36 | mkdir -p "$T/up/synapse/tests/gates"; cd "$T/up/synapse"; g init -q -b main |
| 37 | printf '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) |
| 39 | git 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" |
| 40 | git clone -q "$T/up/synapse" "$T/clones/synapse" |
| 41 | |
| 42 | o=$("$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" |
| 44 | grep -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 | |
| 46 | o=$("$DOC" --heal-only 2>&1); rc=$? |
| 47 | h=$(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 | |
| 50 | o=$("$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 |
| 55 | git -C "$T/clones/aien-sovereign-core" -c advice.detachedHead=false checkout -q --detach "$c1" |
| 56 | echo "local edit" >> "$T/clones/aien-sovereign-core/tools/aien-local-ci/siblings" |
| 57 | o=$("$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 |
| 61 | git -C "$T/clones/aien-sovereign-core" checkout -q -- . ; git -C "$T/clones/aien-sovereign-core" -c advice.detachedHead=false checkout -q --detach origin/main |
| 62 | cd "$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 |
| 63 | o=$("$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. |
| 70 | mkdir -p "$T/up/arch/tools/crumb" |
| 71 | g -C "$T/up/arch" init -q -b main |
| 72 | printf 'crumb: crumb.c\n\t$(CC) -o $@ crumb.c\n' > "$T/up/arch/tools/crumb/Makefile" |
| 73 | printf '#include <stdio.h>\nint main(void){puts("crumb verify: OK");return 0;}\n' > "$T/up/arch/tools/crumb/crumb.c" |
| 74 | g -C "$T/up/arch" add -A; g -C "$T/up/arch" commit -qm approved |
| 75 | archpin=$(git -C "$T/up/arch" rev-parse HEAD) |
| 76 | g -C "$T/up/arch" checkout -qb unmerged |
| 77 | printf 'crumb:\n\t@cat "%s" > "%s"\n\t@false\n' "$T/trusted-key" "$T/exfiltrated" > "$T/up/arch/tools/crumb/Makefile" |
| 78 | g -C "$T/up/arch" commit -qam unapproved |
| 79 | badpin=$(git -C "$T/up/arch" rev-parse HEAD) |
| 80 | g -C "$T/up/arch" checkout -q main |
| 81 | git clone -q "$T/up/arch" "$T/clones/aien-architecture" |
| 82 | printf 'PRIVATE-TEST-KEY\n' > "$T/trusted-key" |
| 83 | mkdir -p "$T/up/gate/tests/gates" "$T/up/gate/.github/workflows" |
| 84 | g -C "$T/up/gate" init -q -b main |
| 85 | echo '{}' > "$T/up/gate/.crumb" |
| 86 | printf '%s\n' "$archpin" > "$T/up/gate/crumb.lock" |
| 87 | printf 'case $1 in\n crumb-verify)\n pin=$(cat crumb.lock)\n ;;\nesac\n' > "$T/up/gate/tests/gates/run.sh" |
| 88 | printf '# pinned crumb tool source\n# ref: %s\n' "$archpin" > "$T/up/gate/.github/workflows/aien-verification.yml" |
| 89 | g -C "$T/up/gate" add -A; g -C "$T/up/gate" commit -qm approved |
| 90 | git clone -q "$T/up/gate" "$T/clones/gate" |
| 91 | mkdir -p "$T/bin" |
| 92 | printf '#!/bin/sh\nprintf "7 %%s\\n" "$CANDIDATE_SHA"\n' > "$T/bin/gh"; chmod +x "$T/bin/gh" |
| 93 | export PATH=$T/bin:$PATH CRUMB_SANDBOX_TOOL=$T/sandbox |
| 94 | printf '#!/bin/sh\necho "crumb verify: OK"\n' > "$T/sandbox"; chmod +x "$T/sandbox" |
| 95 | export CANDIDATE_SHA=$(git -C "$T/up/gate" rev-parse HEAD) |
| 96 | o=$("$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 | |
| 101 | g -C "$T/up/gate" checkout -qb hostile |
| 102 | printf '%s\n' "$badpin" > "$T/up/gate/crumb.lock" |
| 103 | printf '# pinned crumb tool source\n# ref: %s\n' "$badpin" > "$T/up/gate/.github/workflows/aien-verification.yml" |
| 104 | mkdir -p "$T/up/gate/tools/crumb" |
| 105 | cp "$T/up/arch/tools/crumb/Makefile" "$T/up/gate/tools/crumb/Makefile" |
| 106 | cp "$T/up/arch/tools/crumb/crumb.c" "$T/up/gate/tools/crumb/crumb.c" |
| 107 | g -C "$T/up/gate" add -A; g -C "$T/up/gate" commit -qm hostile |
| 108 | export CANDIDATE_SHA=$(git -C "$T/up/gate" rev-parse HEAD) |
| 109 | git -C "$T/clones/gate" fetch -q origin hostile |
| 110 | o=$("$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. |
| 120 | g -C "$T/up/gate" checkout -q main |
| 121 | printf '%s\n' "$badpin" > "$T/up/gate/crumb.lock" |
| 122 | g -C "$T/up/gate" commit -qam unapproved-main-pin |
| 123 | git -C "$T/clones/gate" fetch -q origin |
| 124 | o=$("$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. |
| 130 | mkdir -p "$T/up/retired/tests/gates" "$T/up/retired/.github/workflows" |
| 131 | g -C "$T/up/retired" init -q -b main |
| 132 | echo '{}' > "$T/up/retired/.crumb" |
| 133 | printf 'case $1 in\n fmt) cargo fmt ;;\nesac\n' > "$T/up/retired/tests/gates/run.sh" |
| 134 | printf '# pinned crumb tool source\n# ref: %s\n' "$archpin" > "$T/up/retired/.github/workflows/aien-verification.yml" |
| 135 | g -C "$T/up/retired" add -A; g -C "$T/up/retired" commit -qm half-retired |
| 136 | git clone -q "$T/up/retired" "$T/clones/retired" |
| 137 | o=$("$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" |
| 140 | printf 'name: AIEN\n' > "$T/up/retired/.github/workflows/aien-verification.yml" |
| 141 | g -C "$T/up/retired" commit -qam retired; git -C "$T/clones/retired" fetch -q origin |
| 142 | o=$("$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" |
| 145 | echo "doctor tests: $pass passed, $fail failed"; (( fail == 0 )) |