Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/tools/aien-local-ci/tests/run.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / tools / aien-local-ci / tests / run.sh` 268 lines ยท 20239 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 # tests/run.sh: proves the C8 exec contract on this host. Run as the operator (uses sudo -n). Exit 1 on any FAIL. 18 set -uo pipefail 19 X=${AIEN_EXEC:-/usr/local/sbin/aien-run-exec} # AIEN_EXEC: test a candidate helper before install.sh installs it 20 RUN_HOME=/var/lib/aien-run 21 OP_HOME=${AIEN_OPERATOR_HOME:-$HOME} 22 pass=0; fail=0 23 ok() { pass=$((pass+1)); printf 'PASS %s\n' "$1"; } 24 bad() { fail=$((fail+1)); printf 'FAIL %s: %s\n' "$1" "$2"; } 25 run() { sudo -n "$X" "$@"; } # run [exec args]... -- cmd 26 here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 27 28 uid=$(id -u aien-run) 29 [[ -n $uid ]] || { echo "no aien-run user"; exit 1; } 30 31 # 1 runs as uid aien-run 32 out=$(run --cwd /tmp --timeout 10 --profile host -- id -u 2>&1) 33 [[ $out == "$uid" ]] && ok "runs as uid aien-run ($uid)" || bad "uid" "$out" 34 35 # 2 env cleared: planted secret absent, no SUDO_* leaks, only the allowed names 36 out=$(SECRET_PLANT=hunter2 run --cwd /tmp --timeout 10 --profile host -- sh -c 'echo "${SECRET_PLANT:-unset}"; env | cut -d= -f1 | grep -v -x -E "PATH|HOME|CARGO_HOME|RUSTUP_HOME|PWD|SHLVL|_|OLDPWD" | tr "\n" ","' 2>&1) 37 [[ $out == "unset" ]] && ok "env cleared (planted secret absent, no extra names)" || bad "env" "$out" 38 39 # 3 --env pass-through and refused names 40 out=$(run --cwd /tmp --timeout 10 --profile host --env FOO=bar -- sh -c 'echo $FOO' 2>&1) 41 [[ $out == bar ]] && ok "--env FOO=bar passes" || bad "--env" "$out" 42 run --cwd /tmp --timeout 10 --profile host --env LD_PRELOAD=x -- true >/dev/null 2>&1 && bad "--env LD_PRELOAD" "accepted" || ok "--env LD_PRELOAD refused" 43 44 # 4 no network for host profile 45 out=$(run --cwd /tmp --timeout 20 --profile host -- sh -c 'curl -s -m 3 https://github.com >/dev/null 2>&1; echo curl=$?; getent hosts github.com >/dev/null 2>&1; echo getent=$?; ip -o link | cut -d: -f2 | tr -d " " | tr "\n" ","' 2>&1) 46 out=$(tr "\n" " " <<<"$out"); [[ $out == *"curl="[1-9]* && $out == *"getent="[1-9]* && $out == *"lo,"* && $out != *"enP"* && $out != *"tailscale"* ]] && ok "host profile has no network ($out)" || bad "network" "$out" 47 48 # 4b loopback is up inside the namespace (a local server works), the host's own 127.0.0.1 services stay unreachable 49 out=$(run --cwd /tmp --timeout 20 --profile host -- bash -c 'ip -o link show lo | grep -q "state UNKNOWN\|,UP"; echo lo_up=$?; (exec 3<>/dev/tcp/127.0.0.1/9) 2>&1 | grep -o "refused\|unreachable" | head -1; (exec 3<>/dev/tcp/127.0.0.1/3443) 2>&1 | grep -o "refused\|unreachable" | head -1' 2>&1 | tr "\n" " ") 50 [[ $out == "lo_up=0 refused refused " ]] && ok "host profile loopback up, host 127.0.0.1:3443 not reachable ($out)" || bad "loopback" "$out" 51 52 # 5 timeout -> 124 53 t0=$(date +%s); run --cwd /tmp --timeout 1 --profile host -- sleep 30 >/dev/null 2>&1; rc=$?; t1=$(date +%s) 54 [[ $rc -eq 124 && $((t1-t0)) -lt 15 ]] && ok "timeout returns 124 in $((t1-t0))s" || bad "timeout" "rc=$rc after $((t1-t0))s" 55 56 # 6 exit code passthrough 57 run --cwd /tmp --timeout 10 --profile host -- sh -c 'exit 7' >/dev/null 2>&1; rc=$? 58 [[ $rc -eq 7 ]] && ok "exit code passthrough (7)" || bad "exit passthrough" "rc=$rc" 59 60 # 7 cwd honored 61 out=$(run --cwd "$RUN_HOME" --timeout 10 --profile host -- pwd 2>&1) 62 [[ $out == "$RUN_HOME" ]] && ok "cwd honored" || bad "cwd" "$out" 63 64 # 8 memory cap enforced (64M cap, allocate 300M in a shell variable) 65 out=$(run --cwd /tmp --timeout 60 --profile host --memory-max 64M -- sh -c 'x=$(head -c `300000000` /dev/zero | tr "\0" a); echo survived' 2>&1); rc=$? 66 [[ $rc -ne 0 && $out != *survived* ]] && ok "memory cap enforced (rc=$rc)" || bad "memory cap" "rc=$rc out=$out" 67 68 # 9 devices: host cannot open the GPU, gb10 can 69 out=$(run --cwd /tmp --timeout 10 --profile host -- sh -c 'exec 3<>/dev/nvidiactl' 2>&1); rc=$? 70 [[ $rc -ne 0 ]] && ok "host profile cannot open /dev/nvidiactl" || bad "host device policy" "opened nvidiactl" 71 out=$(run --cwd /tmp --timeout 10 --profile gb10 -- sh -c 'exec 3<>/dev/nvidiactl && exec 4<>/dev/nvidia0 && exec 5<>/dev/nvidia-uvm && exec 6<>/dev/dri/renderD128 && echo opened' 2>&1) 72 [[ $out == opened ]] && ok "gb10 profile opens /dev/nvidiactl, nvidia0, nvidia-uvm, dri/renderD128" || bad "gb10 devices" "$out" 73 out=$(run --cwd /tmp --timeout 10 --profile qemu -- sh -c 'exec 3<>/dev/kvm && echo kvm' 2>&1) 74 run --cwd /tmp --timeout 10 --profile host -- sh -c 'exec 3<>/dev/kvm' >/dev/null 2>&1; rc=$? 75 [[ $out == kvm && $rc -ne 0 ]] && ok "qemu profile opens /dev/kvm, host profile cannot" || bad "kvm" "qemu=$out host_rc=$rc" 76 77 # 10 secrets of the trusted side are unreadable (direct sudo -u, as the inventory demands) 78 for f in "$OP_HOME/.aien/verify.key" "$OP_HOME/.config/gh/hosts.yml" "$OP_HOME/.ssh/id_`ed25519`"; do 79 sudo -n -u aien-run cat "$f" >/dev/null 2>&1 && bad "secret $f" "READABLE" || ok "denied: $f" 80 done 81 sudo -n -u aien-run ls "$OP_HOME/workspace" >/dev/null 2>&1 && bad "workspace" "listable" || ok "denied: $OP_HOME/workspace (0700)" 82 83 # 11 toolchain as aien-run 84 out=$(run --cwd /tmp --timeout 60 --profile host -- cargo --version 2>&1) 85 [[ $out == cargo\ 1.98.1* ]] && ok "cargo as aien-run: $out" || bad "cargo" "$out" 86 87 # 12 crash recovery: kill -9 the running child; exit non-zero, no strays in the scope. Only this test's scope 88 # counts (its unit is named after the helper pid): a judge running at the same time holds scopes of its own. 89 sudo -n "$X" --cwd /tmp --timeout 120 --profile host -- sh -c 'sleep 300 & exec sleep 200' >/dev/null 2>&1 & 90 bg=$! 91 sleep 2 92 victim=$(pgrep -u aien-run -f '^sleep 200$' | head -1) 93 helper=$(pgrep -P "$bg" | head -1) 94 [[ -n $victim ]] && sudo -n kill -9 "$victim" 95 wait $bg; rc=$? 96 sleep 1 97 strays=$(pgrep -u aien-run -f '^sleep 300$' | wc -l) 98 scopes=$(systemctl list-units --no-legend --plain "aien-run-exec-${helper:-none}-*.scope" 2>/dev/null | wc -l) 99 [[ -n $helper && $rc -ne 0 && $strays -eq 0 && $scopes -eq 0 ]] && ok "crash recovery: rc=$rc, strays=0, scopes=0" || bad "crash recovery" "helper=${helper:-not found} rc=$rc strays=$strays scopes=$scopes" 100 101 # 13 worktree protection (if a worktree exists; also used by the tests below) 102 # Only worktrees made by wt.sh (root-owned .git pointing into the mirror). Other lanes may be creating and removing 103 # their own worktrees under wt/ while this runs; those are skipped. 104 wt_sh_worktrees() { 105 local d 106 # run directory layout wt//// (siblings beside it), or the older flat wt/// 107 for d in "$RUN_HOME"/wt/*/*/ "$RUN_HOME"/wt/*/*/*/; do 108 d=${d%/} 109 [[ -f $d/.git && $(stat -c %u "$d/.git" 2>/dev/null) == 0 ]] || continue 110 grep -q "^gitdir: $RUN_HOME/mirror/" "$d/.git" 2>/dev/null && printf '%s\n' "$d" 111 done 112 } 113 wt=$(wt_sh_worktrees | head -1) 114 if [[ -n $wt ]]; then 115 out=$(run --cwd "$wt" --timeout 30 --profile host -- sh -c 'git rev-parse --short HEAD >/dev/null && echo git-ok; rm -f .git 2>/dev/null && echo REMOVED; m=$(sed "s|gitdir: ||;s|/worktrees/.*||" .git); touch "$m/refs/x" 2>/dev/null && echo MIRROR-WRITABLE; echo t > .probe && rm .probe && echo tree-writable' 2>&1 | tr '\n' ' ') 116 [[ $out == *git-ok* && $out != *REMOVED* && $out != *MIRROR-WRITABLE* && $out == *tree-writable* ]] && ok "worktree: git reads, .git and mirror protected, tree writable" || bad "worktree" "$out" 117 fi 118 119 # sibling checkouts (SANDBOX lane): wt.sh sibling puts a read-only checkout at ../ of the checkout under test; 120 # aien-run reads it and its git history, cannot write it or the run directory; wt.sh remove takes both away. 121 if [[ -d $RUN_HOME/mirror/aien-protocols.git && -d $RUN_HOME/mirror/aien-architecture.git ]]; then 122 sa=$(git -C "$RUN_HOME/mirror/aien-architecture.git" rev-parse --verify -q 'refs/remotes/origin/main^{commit}') 123 sp=$(git -C "$RUN_HOME/mirror/aien-protocols.git" rev-parse --verify -q 'refs/remotes/origin/main^{commit}') 124 rd="$RUN_HOME/wt/aien-architecture/$sa" 125 if [[ -e $rd ]]; then 126 printf 'SKIP sibling test: %s is in use\n' "$rd" 127 else 128 co=$(bash "$here/../wt.sh" add aien-architecture "$sa") && bash "$here/../wt.sh" sibling aien-architecture "$sa" aien-protocols aien-protocols "$sp" >/dev/null 129 out=$(run --cwd "$co" --timeout 30 --profile host -- sh -c 'git -C ../aien-protocols rev-parse HEAD; test -f ../aien-protocols/Cargo.toml && echo sib-read; touch ../aien-protocols/x 2>/dev/null && echo SIB-WRITABLE; touch ../x 2>/dev/null && echo RUNDIR-WRITABLE; echo t > .p && rm .p && echo tree-writable' 2>&1 | tr '\n' ' ') 130 bash "$here/../wt.sh" remove aien-architecture "$sa" >/dev/null 131 left=$(git -C "$RUN_HOME/mirror/aien-protocols.git" worktree list | grep -c "$rd" || true) 132 [[ $out == "$sp sib-read tree-writable " && ! -e $rd && $left -eq 0 ]] \ 133 && ok "sibling checkout: readable with history, read-only, run dir closed, removed with the run" || bad "sibling" "$out left=$left" 134 fi 135 fi 136 137 # 14c mirror origin URL (PIPELINE-FINISH): `wt.sh sync` copies the trusted clone's origin URL into the mirror, so a 138 # gate that reads `git remote get-url origin` in a sandbox checkout sees the GitHub URL, as on a GitHub runner. 139 cl="$HOME/workspace/pipeline/clones/aien-architecture" 140 if [[ -d $cl/.git ]]; then 141 bash "$here/../wt.sh" sync aien-architecture "$cl" >/dev/null 142 want=$(git -C "$cl" remote get-url origin) 143 got=$(git -C "$RUN_HOME/mirror/aien-architecture.git" remote get-url origin 2>&1) 144 [[ -n $want && $got == "$want" ]] && ok "mirror carries the trusted clone's origin URL ($got)" || bad "mirror origin" "want=$want got=$got" 145 fi 146 147 # ---- review fixes (INFRA-2): nothing a check writes can reach a later check ---- 148 refused() { [[ $1 -eq 2 ]]; } # exit 2 = refused by aien-run-exec before anything ran 149 T_SHA=`0000000000000000000000000000000000000a15`; T_SHA2=`0000000000000000000000000000000000000b15` 150 T_PR="$RUN_HOME/target/aien-sovereign-core/pr/$T_SHA"; T_MAIN="$RUN_HOME/target/aien-sovereign-core/main/$T_SHA" 151 T_PR2="$RUN_HOME/target/aien-sovereign-core/pr/$T_SHA2" 152 153 # 14b the operator's ~/models is visible read-only at /var/lib/aien-run/models (model gates), never writable 154 if [[ -d $HOME/models && -d /var/lib/aien-run/models ]]; then 155 probe=$(cd "$HOME/models" && ls | head -1) 156 out=$(run --cwd /tmp --timeout 20 --profile host -- sh -c "M=/var/lib/aien-run/models 157 [ -e \"\$M/$probe\" ] && echo SEEN 158 touch \$M/aien-run-probe 2>/dev/null && echo MODELS-WRITABLE 159 echo done" 2>&1 | tr '\n' ' ') 160 [[ $out == "SEEN done " ]] && ok "host: ~/models mounted read-only at /var/lib/aien-run/models" || bad "models read-only" "$out" 161 else 162 printf 'SKIP 14b: no ~/models or no /var/lib/aien-run/models mount point\n' 163 fi 164 # 14 the sandbox home is read-only inside every profile: no ~/.cargo/config.toml, no CARGO_HOME config, 165 # no swapping the registry or the cargo proxies, no new dotfiles 166 for p in host gb10; do 167 out=$(run --cwd /tmp --timeout 20 --profile $p -- sh -c 'H=/var/lib/aien-run 168 mkdir -p $H/.cargo 2>/dev/null && echo HOME-WRITABLE 169 touch $H/cargo/config.toml 2>/dev/null && echo CARGO_HOME-WRITABLE 170 mv $H/cargo/bin $H/cargo/bin.x 2>/dev/null && echo BIN-RENAMED 171 mv $H/cargo/registry $H/cargo/r.x 2>/dev/null && echo REGISTRY-RENAMED 172 touch $H/.gitconfig 2>/dev/null && echo GITCONFIG-WRITABLE 173 echo done' 2>&1 | tr '\n' ' ') 174 [[ $out == "done " ]] && ok "$p: sandbox home, CARGO_HOME, registry, proxies, .gitconfig all read-only" || bad "$p home read-only" "$out" 175 done 176 177 # 15 trust classes and heads: a PR run can write its own target//pr/ only, never main and never another 178 # head's dir; a main run never pr; a run whose cwd is not in a worktree can write no worktree 179 sudo -n install -d -o aien-run -g aien-run -m 0755 "$T_PR2" 180 out=$(run --cwd /tmp --timeout 20 --profile host --env CARGO_TARGET_DIR="$T_PR" -- sh -c "touch $T_PR/.p && rm $T_PR/.p && echo pr-rw; touch $T_MAIN/.p 2>/dev/null && echo MAIN-WRITABLE; touch $T_PR2/.p 2>/dev/null && echo OTHER-HEAD-WRITABLE; echo end" 2>&1 | tr '\n' ' ') 181 [[ $out == "pr-rw end " ]] && ok "class pr: own head dir writable, main and another head's dir read-only" || bad "class pr" "$out" 182 out=$(run --cwd /tmp --timeout 20 --profile gb10 --env CARGO_TARGET_DIR="$T_MAIN" -- sh -c "touch $T_MAIN/.p && rm $T_MAIN/.p && echo main-rw; touch $T_PR/.p 2>/dev/null && echo PR-WRITABLE; echo end" 2>&1 | tr '\n' ' ') 183 [[ $out == "main-rw end " ]] && ok "class main (gb10): own head dir writable, target/pr read-only" || bad "class main" "$out" 184 sudo -n rm -rf "$T_PR" "$T_MAIN" "$T_PR2" 185 if [[ -n $wt ]]; then 186 out=$(run --cwd /tmp --timeout 20 --profile host -- sh -c "touch $wt/.p 2>/dev/null && echo WT-WRITABLE; echo end" 2>&1 | tr '\n' ' ') 187 [[ $out == "end " ]] && ok "a run outside a worktree cannot write any worktree" || bad "foreign worktree" "$out" 188 fi 189 190 # 16 argument refusals (exit 2, nothing runs) 191 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR=/tmp/t -- true >/dev/null 2>&1; r1=$? 192 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/../target/x/main" -- true >/dev/null 2>&1; r2=$? 193 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/aien-sovereign-core/other" -- true >/dev/null 2>&1; r3=$? 194 run --cwd /tmp --timeout 5 --profile host --env FOO=1 --env FOO=2 -- true >/dev/null 2>&1; r4=$? 195 # the old shared class dir, a head dir with a bad sha, and a dir one level too deep 196 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/aien-sovereign-core/pr" -- true >/dev/null 2>&1; r5=$? 197 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/aien-sovereign-core/pr/abc" -- true >/dev/null 2>&1; r6=$? 198 run --cwd /tmp --timeout 5 --profile host --env CARGO_TARGET_DIR="$T_PR/x" -- true >/dev/null 2>&1; r7=$? 199 refused $r1 && refused $r2 && refused $r3 && refused $r4 && refused $r5 && refused $r6 && refused $r7 \ 200 && ok "CARGO_TARGET_DIR other than target//pr|main/ (incl. the old shared dir) and duplicate --env refused" \ 201 || bad "env refusals" "$r1 $r2 $r3 $r4 $r5 $r6 $r7" 202 if [[ -n $wt ]]; then 203 # inside a worktree the target dir must be that head's own: another head's dir is refused 204 wrel=${wt#"$RUN_HOME"/wt/}; wrepo=${wrel%%/*}; wsha=${wrel#*/}; wsha=${wsha%%/*} 205 had_class=0; [[ -d $RUN_HOME/target/$wrepo/pr ]] && had_class=1 206 run --cwd "$wt" --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/$wrepo/pr/$T_SHA2" -- true >/dev/null 2>&1; r1=$? 207 run --cwd "$wt" --timeout 5 --profile host --env CARGO_TARGET_DIR="$RUN_HOME/target/$wrepo/pr/$wsha" -- true >/dev/null 2>&1; r2=$? 208 sudo -n rm -rf "$RUN_HOME/target/$wrepo/pr/$wsha" 209 (( had_class )) || sudo -n rmdir "$RUN_HOME/target/$wrepo/pr" 2>/dev/null || true 210 refused $r1 && [[ $r2 -eq 0 ]] && ok "in a worktree only that head's own target dir is accepted" || bad "head-bound target dir" "$r1 $r2" 211 fi 212 run --cwd "$RUN_HOME/target" --timeout 5 --profile host -- true >/dev/null 2>&1; r1=$? 213 run --cwd "$RUN_HOME/cargo" --timeout 5 --profile host -- true >/dev/null 2>&1; r2=$? 214 run --cwd "$RUN_HOME/wt/../wt" --timeout 5 --profile host -- true >/dev/null 2>&1; r3=$? 215 r4=2 216 if [[ -n $wt ]]; then # a symlink planted by a check inside its worktree, pointing at another directory 217 run --cwd "$wt" --timeout 10 --profile host -- ln -sfn /tmp cwdlink >/dev/null 2>&1 218 run --cwd "$wt/cwdlink" --timeout 5 --profile host -- true >/dev/null 2>&1; r4=$? 219 run --cwd "$wt" --timeout 10 --profile host -- rm -f cwdlink >/dev/null 2>&1 220 fi 221 refused $r1 && refused $r2 && refused $r3 && refused $r4 && ok "--cwd outside wt// inside the home, with .., or through a symlink refused" || bad "cwd refusals" "$r1 $r2 $r3 $r4" 222 run --cwd /tmp --timeout 5 --profile host -- LD_PRELOAD=/nonexistent.so true >/dev/null 2>&1; r1=$? 223 run --cwd /tmp --timeout 5 --profile host -- -i true >/dev/null 2>&1; r2=$? 224 refused $r1 && refused $r2 && ok "PROGRAM shaped like an env assignment or option refused" || bad "program refusals" "$r1 $r2" 225 226 # 17 private scratch dirs: host cannot see the operator's /tmp; every profile gets a private /var/tmp 227 probe=/tmp/aien-infra-probe.$$; : > "$probe"; : > /var/tmp/aien-infra-probe.$$ 228 out=$(run --cwd /tmp --timeout 10 --profile host -- sh -c "test -e $probe && echo SEES-HOST-TMP; test -e /var/tmp/aien-infra-probe.$$ && echo SEES-VARTMP; ls -A /tmp | wc -l" 2>&1 | tr '\n' ' ') 229 [[ $out == "0 " ]] && ok "host: private empty /tmp and /var/tmp" || bad "host private tmp" "$out" 230 out=$(run --cwd /tmp --timeout 10 --profile gb10 -- sh -c "test -e $probe && echo sees-host-tmp; test -e /var/tmp/aien-infra-probe.$$ && echo SEES-VARTMP; echo end" 2>&1 | tr '\n' ' ') 231 [[ $out == "sees-host-tmp end " ]] && ok "gb10: shares host /tmp (documented), private /var/tmp" || bad "gb10 tmp" "$out" 232 rm -f "$probe" /var/tmp/aien-infra-probe.$$ 233 out=$(run --cwd /tmp --timeout 10 --profile host -- sh -c 'echo $(ls -A /run/lock /run/screen /dev/mqueue /dev/shm 2>/dev/null | grep -vc -e "^$" -e ":$") $(ipcs -m | grep -c "^0x") $(ipcs -s | grep -c "^0x")' 2>&1) 234 host_ipc="$(ipcs -m | grep -c "^0x") $(ipcs -s | grep -c "^0x")" 235 [[ $out == "0 0 0" ]] && ok "host: private /run/lock, /run/screen, /dev/shm, /dev/mqueue and IPC namespace (host has shm+sem: $host_ipc)" || bad "host ipc" "$out" 236 237 # 18 trusted crumb on the sandbox PATH; `crumb verify .` runs as aien-run in a sandboxed worktree; a `crumb` 238 # planted inside the worktree is never picked up by a bare name 239 out=$(run --cwd /tmp --timeout 10 --profile host -- sh -c 'command -v crumb; stat -c "%U %a" "$(command -v crumb)"' 2>&1 | tr '\n' ' ') 240 [[ $out == "/usr/local/bin/crumb root 755 " ]] && ok "crumb on sandbox PATH: $out" || bad "crumb PATH" "$out" 241 if [[ -n $wt ]]; then 242 # every worktree: the sandboxed verdict equals the trusted side's verdict on a clean trusted checkout of the same 243 # commit (operator git refuses to run inside a sandbox worktree: dubious ownership, by design); at least one 244 # worktree (a crumb-current commit) must verify OK, so the PASS path is exercised, not only the STALE path 245 agree=0; total=0; okrun=0 246 for w in $(wt_sh_worktrees); do 247 total=$((total+1)) 248 s_out=$(run --cwd "$w" --timeout 60 --profile host -- crumb verify . 2>&1); s_rc=$? 249 tc=$(mktemp -d); rel=${w#"$RUN_HOME"/wt/}; repo=${rel%%/*}; rest=${rel#*/}; sha=${rest%%/*} 250 git clone --quiet --shared --no-checkout "$RUN_HOME/mirror/$repo.git" "$tc/t" && git -C "$tc/t" checkout --quiet "$sha" 251 t_out=$(cd "$tc/t" && /usr/local/bin/crumb verify . 2>&1); t_rc=$? 252 rm -rf "$tc" 253 [[ $s_rc -eq $t_rc && $s_out == "$t_out" ]] && agree=$((agree+1)) 254 [[ $s_rc -eq 0 ]] && okrun=$((okrun+1)) 255 printf ' %s: sandbox rc=%s, trusted rc=%s, %s\n' "$(basename "$w" | cut -c1-7)" "$s_rc" "$t_rc" "$(tail -1 <<<"$s_out")" 256 done 257 [[ $agree -eq $total && $okrun -ge 1 ]] && ok "crumb verify . as aien-run in $total sandboxed worktrees (agrees with trusted side; $okrun OK)" \ 258 || bad "crumb verify" "agree=$agree/$total ok=$okrun" 259 run --cwd "$wt" --timeout 10 --profile host -- sh -c 'printf "#!/bin/sh\necho PLANTED\n" > crumb && chmod +x crumb' >/dev/null 2>&1 260 o1=$(run --cwd "$wt" --timeout 10 --profile host -- crumb status . 2>&1 | head -3) 261 o2=$(run --cwd "$wt" --timeout 10 --profile host -- sh -c 'exec crumb status .' 2>&1 | head -3) 262 o3=$(run --cwd "$wt" --timeout 10 --profile host -- sh -c 'test -x ./crumb && echo planted-present' 2>&1) 263 run --cwd "$wt" --timeout 10 --profile host -- rm -f crumb >/dev/null 2>&1 264 [[ $o3 == planted-present && $o1 != *PLANTED* && $o2 != *PLANTED* && -n $o1 && -n $o2 ]] \ 265 && ok "planted ./crumb in the worktree ignored (PROGRAM and sh exec both use /usr/local/bin/crumb)" || bad "planted crumb" "o1=$o1 o2=$o2 o3=$o3" 266 fi 267 printf '\n%d passed, %d failed\n' "$pass" "$fail" 268 [[ $fail -eq 0 ]]