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/scripts/test-install-release.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 / scripts / test-install-release.sh` 406 lines ยท 30162 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 # Exercise install.sh release mode offline. A fixture release is signed with a 18 # throwaway key and served over file://. Checks: 19 # 1. the key pinned inside install.sh equals docs/release/allowed_signers 20 # 2. a valid signed release installs from a checkout 21 # 3. a tampered archive installs nothing (checksum) 22 # 4. a release signed by another key installs nothing (signature) 23 # 5. a standalone copy of install.sh (no source tree, clean HOME) installs the 24 # valid release offline when the signer file is given, imprint included 25 # 6. the same standalone copy with no signer override falls back to the key 26 # pinned in install.sh, so the fixture (throwaway key) is refused 27 set -euo pipefail 28 29 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 30 WORK="$(mktemp -d "${TMPDIR:-/tmp}/aien-test-install-release.XXXXXX")" 31 [[ -n "${KEEP:-}" ]] || trap 'rm -rf "$WORK"' EXIT 32 fail() { echo "FAIL: $*" >&2; [[ -z "${KEEP:-}" ]] || echo "WORK=$WORK" >&2; exit 1; } 33 # kill9_at_point : kill -9 a paused installer exactly where it stands. The installer first, 34 # then the `sleep` of its pause loop. Killing the sleep first (the old order) made install.sh exit 35 # on its own under `set -e` (a killed child returns 137) through its EXIT trap, which is a clean 36 # exit, not a kill at the point; and when that exit won the race, `kill -9` found no process and 37 # failed the test (sc #452, 1 of 4 runs under load). 38 kill9_at_point() { 39 local pid="$1" kids 40 kids="$(pgrep -P "$pid" 2>/dev/null || true)" 41 kill -9 "$pid" 2>/dev/null || true 42 # shellcheck disable=SC2086 43 [[ -z "$kids" ]] || kill -9 $kids 2>/dev/null || true 44 wait "$pid" 2>/dev/null || true 45 } 46 47 case "$(uname -s)" in Linux) OS=linux ;; Darwin) OS=macos ;; *) fail "unsupported OS" ;; esac 48 case "$(uname -m)" in x86_64|amd64) ARCH=x86_64 ;; aarch64|arm64) ARCH=aarch64 ;; *) fail "unsupported arch" ;; esac 49 [[ "$OS-$ARCH" != macos-aarch64 ]] || ARCH=arm64 50 ASSET="sovereign-$OS-$ARCH.tar.gz" 51 52 # 1. pinned keys: install.sh AIEN_RELEASE_SIGNER equals the key lines of docs/release/allowed_signers (both empty 53 # while the placeholder stands); AIEN_INTERNAL_TEST_SIGNER equals docs/release/internal_test_signers; the 54 # internal test key is never in allowed_signers (Drake ruling 1, sc#385: the old key is not reused) 55 keylines() { grep -vE "^[[:space:]]*(#|\$)" "$1" || true; } 56 pinned() { sed -n "s/^$1='\(.*\)'\$/\1/p" "$ROOT/install.sh"; } 57 grep -qE "^AIEN_RELEASE_SIGNER=" "$ROOT/install.sh" || fail "install.sh has no AIEN_RELEASE_SIGNER line" 58 [[ "$(pinned AIEN_RELEASE_SIGNER)" == "$(keylines "$ROOT/docs/release/allowed_signers")" ]] \ 59 || fail "AIEN_RELEASE_SIGNER in install.sh differs from the key lines of docs/release/allowed_signers" 60 INTERNAL="$(pinned AIEN_INTERNAL_TEST_SIGNER)" 61 [[ -n "$INTERNAL" && "$INTERNAL" == "$(keylines "$ROOT/docs/release/internal_test_signers")" ]] \ 62 || fail "AIEN_INTERNAL_TEST_SIGNER in install.sh differs from docs/release/internal_test_signers" 63 ! grep -qF "${INTERNAL#aien-release }" "$ROOT/docs/release/allowed_signers" || fail "the internal test key is in allowed_signers" 64 if [[ -z "$(pinned AIEN_RELEASE_SIGNER)" ]]; then 65 grep -q "PLACEHOLDER" "$ROOT/docs/release/allowed_signers" || fail "allowed_signers holds no key and no PLACEHOLDER label" 66 fi 67 68 ssh-keygen -q -t `ed25519` -N '' -C test -f "$WORK/key" 69 ssh-keygen -q -t `ed25519` -N '' -C other -f "$WORK/other" 70 printf 'aien-release %s\n' "$(cut -d' ' -f1,2 "$WORK/key.pub")" > "$WORK/allowed_signers" 71 72 make_release() { # dir signing-key [candidate] [variant] [dry: label the manifest dry-run] 73 local d="$1" k="$2" cand="${3:-CAND-1}" variant="${4:-a}" dry="${5:-}" f aien 74 rm -rf "$WORK/pkg" 75 mkdir -p "$d" "$WORK/pkg/bin" "$WORK/pkg/imprints/en2-trinity" 76 printf '#!/bin/sh\necho aien-%s\nexit 0\n' "$variant" > "$WORK/pkg/bin/aien" 77 printf '#!/bin/sh\nexit 0\n' > "$WORK/pkg/bin/cortex-rs" 78 printf 'fixture imprint\n' > "$WORK/pkg/imprints/en2-trinity/soul.md" 79 chmod 755 "$WORK/pkg/bin/"* 80 aien="$(sha256sum "$WORK/pkg/bin/aien" 2>/dev/null | cut -d' ' -f1 || shasum -a 256 "$WORK/pkg/bin/aien" | cut -d' ' -f1)" 81 { 82 printf 'schema = "AienReleaseV1"\ncandidate = "%s"\naien-cli-sha256 = "%s"\n' "$cand" "$aien" 83 [[ -z "$dry" ]] || printf 'dry-run = true\n' 84 printf '\n[files]\n' 85 (cd "$WORK/pkg" && find . -type f ! -name release.toml | LC_ALL=C sort | sed 's|^\./||') | while read -r f; do 86 printf '"%s" = "%s"\n' "$f" "$(sha256sum "$WORK/pkg/$f" | cut -d' ' -f1)" 87 done 88 } > "$WORK/pkg/release.toml" 89 tar -czf "$d/$ASSET" -C "$WORK/pkg" . 90 (cd "$d" && sha256sum "$ASSET" 2>/dev/null > SHA256SUMS.txt || shasum -a 256 "$ASSET" > SHA256SUMS.txt) 91 ssh-keygen -q -Y sign -f "$k" -n aien-release "$d/SHA256SUMS.txt" 92 } 93 94 run_install() { # release-dir bin-dir config-dir installer [VAR=value ...] 95 local rel="$1" bin="$2" cfg="$3" installer="$4" 96 shift 4 97 env AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$rel" \ 98 AIEN_BIN_DIR="$bin" AIEN_CONFIG_DIR="$cfg" AIEN_INSTALL_NO_PROFILE=1 "$@" \ 99 bash "$installer" > "$WORK/log" 2>&1 100 } 101 102 # 2. valid release, from the checkout 103 make_release "$WORK/good" "$WORK/key" 104 run_install "$WORK/good" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" \ 105 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers" \ 106 || { cat "$WORK/log" >&2; fail "valid signed release did not install"; } 107 [[ -x "$WORK/bin-good/aien" && -x "$WORK/bin-good/cortex" ]] || fail "binaries missing after valid install" 108 109 # 3. tampered archive 110 make_release "$WORK/tamper" "$WORK/key" 111 printf 'x' >> "$WORK/tamper/$ASSET" 112 if run_install "$WORK/tamper" "$WORK/bin-tamper" "$WORK/cfg-tamper" "$ROOT/install.sh" \ 113 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers"; then 114 fail "tampered archive was installed" 115 fi 116 grep -q "checksum mismatch" "$WORK/log" || fail "tampered archive not rejected for checksum" 117 [[ ! -e "$WORK/bin-tamper/aien" ]] || fail "tampered install left a binary" 118 119 # 4. signature from another key 120 make_release "$WORK/forged" "$WORK/other" 121 if run_install "$WORK/forged" "$WORK/bin-forged" "$WORK/cfg-forged" "$ROOT/install.sh" \ 122 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers"; then 123 fail "release signed by another key was installed" 124 fi 125 grep -q "signature is NOT valid" "$WORK/log" || fail "forged signature not rejected" 126 [[ ! -e "$WORK/bin-forged/aien" ]] || fail "forged install left a binary" 127 128 # 5. standalone installer, no source tree, clean HOME, offline, signer file given 129 mkdir -p "$WORK/standalone" "$WORK/home" 130 cp "$ROOT/install.sh" "$WORK/standalone/install.sh" 131 run_install "$WORK/good" "$WORK/bin-alone" "$WORK/cfg-alone" "$WORK/standalone/install.sh" \ 132 HOME="$WORK/home" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers" \ 133 || { cat "$WORK/log" >&2; fail "standalone offline install did not install"; } 134 grep -q "Release mode without a source tree" "$WORK/log" || fail "standalone install used a source tree" 135 [[ -x "$WORK/bin-alone/aien" && -x "$WORK/bin-alone/cortex" ]] || fail "binaries missing after standalone install" 136 [[ -f "$WORK/cfg-alone/imprints/en2/soul.md" ]] || fail "imprint from the release archive was not installed" 137 [[ -z "$(ls -A "$WORK/home")" ]] || fail "standalone install wrote into HOME: $(ls -A "$WORK/home")" 138 139 # 6. standalone installer, no signer override: the pinned key refuses the fixture 140 if run_install "$WORK/good" "$WORK/bin-pinned" "$WORK/cfg-pinned" "$WORK/standalone/install.sh" \ 141 HOME="$WORK/home"; then 142 fail "fixture signed by a throwaway key was accepted by the pinned signer" 143 fi 144 grep -q "signature is NOT valid" "$WORK/log" || fail "pinned-signer fallback did not reject the fixture" 145 [[ ! -e "$WORK/bin-pinned/aien" ]] || fail "pinned-signer refusal left a binary" 146 147 148 # 7. upgrade: a newer candidate installs over the first; one previous release is kept; the 149 # record names both; operator.toml is untouched 150 SIGN_ENV=(AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers") 151 live() { readlink "$1/releases/current"; } 152 inst_args() { # bin cfg args... : run install.sh with arguments in explicit dirs 153 local bin="$1" cfg="$2"; shift 2 154 env AIEN_BIN_DIR="$bin" AIEN_CONFIG_DIR="$cfg" AIEN_INSTALL_NO_PROFILE=1 HOME="$WORK/home" \ 155 bash "$ROOT/install.sh" "$@" > "$WORK/log" 2>&1 156 } 157 echo '# local edit' >> "$WORK/cfg-good/operator.toml" 158 OP_BEFORE="$(sha256sum "$WORK/cfg-good/operator.toml" | cut -d' ' -f1)" 159 ID1="$(live "$WORK/cfg-good")" 160 [[ -n "$ID1" && -f "$WORK/cfg-good/installed.toml" ]] || fail "first install left no live release or record" 161 [[ "$("$WORK/bin-good/aien")" == "aien-a" ]] || fail "first install does not run" 162 make_release "$WORK/rel2" "$WORK/key" CAND-2 b 163 run_install "$WORK/rel2" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}" \ 164 || { cat "$WORK/log" >&2; fail "upgrade did not install"; } 165 ID2="$(live "$WORK/cfg-good")" 166 [[ "$ID2" != "$ID1" ]] || fail "upgrade did not change the live release" 167 [[ "$("$WORK/bin-good/aien")" == "aien-b" ]] || fail "installed aien is not the upgraded one" 168 grep -q "^previous = \"$ID1\"" "$WORK/cfg-good/installed.toml" || fail "record does not name the previous release" 169 grep -q 'candidate = "CAND-2"' "$WORK/cfg-good/installed.toml" || fail "record lacks the new candidate" 170 [[ "$(sha256sum "$WORK/cfg-good/operator.toml" | cut -d' ' -f1)" == "$OP_BEFORE" ]] || fail "upgrade changed operator.toml" 171 [[ "$(ls "$WORK/cfg-good/releases" | grep -vc '^current$')" -eq 2 ]] || fail "expected exactly two releases kept" 172 173 # 8. rollback returns to the first release and records it; a second rollback goes forward again 174 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || { cat "$WORK/log" >&2; fail "rollback failed"; } 175 [[ "$(live "$WORK/cfg-good")" == "$ID1" && "$("$WORK/bin-good/aien")" == "aien-a" ]] || fail "rollback did not restore the first release" 176 grep -q '^last-action = "rollback"' "$WORK/cfg-good/installed.toml" || fail "rollback not recorded" 177 grep -q "^previous = \"$ID2\"" "$WORK/cfg-good/installed.toml" || fail "record does not name the rolled-back-from release" 178 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || fail "second rollback failed" 179 [[ "$(live "$WORK/cfg-good")" == "$ID2" ]] || fail "second rollback did not swap forward" 180 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || fail "third rollback failed" 181 if inst_args "$WORK/bin-none" "$WORK/cfg-none" --rollback; then fail "rollback with nothing installed succeeded"; fi 182 grep -q "no previous release" "$WORK/log" || fail "rollback with nothing installed not explained" 183 184 # 9. downgrade guard: an older candidate is refused unless --allow-downgrade 185 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback >/dev/null || true # live = ID2 (CAND-2) 186 [[ "$(live "$WORK/cfg-good")" == "$ID2" ]] || fail "setup for the downgrade case failed" 187 make_release "$WORK/rel0" "$WORK/key" CAND-1 c 188 if run_install "$WORK/rel0" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then 189 fail "older candidate installed without --allow-downgrade" 190 fi 191 grep -q "allow-downgrade" "$WORK/log" || fail "downgrade refusal not explained" 192 [[ "$(live "$WORK/cfg-good")" == "$ID2" ]] || fail "refused downgrade changed the live release" 193 env AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$WORK/rel0" AIEN_BIN_DIR="$WORK/bin-good" \ 194 AIEN_CONFIG_DIR="$WORK/cfg-good" AIEN_INSTALL_NO_PROFILE=1 "${SIGN_ENV[@]}" \ 195 bash "$ROOT/install.sh" --allow-downgrade > "$WORK/log" 2>&1 \ 196 || { cat "$WORK/log" >&2; fail "downgrade with --allow-downgrade failed"; } 197 198 # 10. package that does not match its own release.toml installs nothing 199 make_release "$WORK/badpkg" "$WORK/key" CAND-9 d 200 mkdir -p "$WORK/unp"; tar -xzf "$WORK/badpkg/$ASSET" -C "$WORK/unp"; printf 'x' >> "$WORK/unp/bin/cortex-rs" 201 tar -czf "$WORK/badpkg/$ASSET" -C "$WORK/unp" . 202 (cd "$WORK/badpkg" && sha256sum "$ASSET" > SHA256SUMS.txt && rm -f SHA256SUMS.txt.sig \ 203 && ssh-keygen -q -Y sign -f "$WORK/key" -n aien-release SHA256SUMS.txt) 204 LIVE_BEFORE="$(live "$WORK/cfg-good")" 205 if run_install "$WORK/badpkg" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then 206 fail "package with a file that does not match release.toml was installed" 207 fi 208 grep -q "does not match its release.toml" "$WORK/log" || fail "manifest mismatch not reported" 209 [[ "$(live "$WORK/cfg-good")" == "$LIVE_BEFORE" ]] || fail "rejected package changed the live release" 210 211 # 11. interrupted install: kill the installer mid-copy and before the swap; the live install is 212 # still the old version, runs, and a rerun completes the upgrade 213 make_release "$WORK/rel3" "$WORK/key" CAND-3 e 214 for point in mid-copy after-copy before-swap; do 215 OLD="$(live "$WORK/cfg-good")" 216 env AIEN_TEST_PAUSE_AT="$point" AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$WORK/rel3" \ 217 AIEN_BIN_DIR="$WORK/bin-good" AIEN_CONFIG_DIR="$WORK/cfg-good" AIEN_INSTALL_NO_PROFILE=1 \ 218 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers" \ 219 bash "$ROOT/install.sh" > "$WORK/log-int" 2>&1 & 220 IPID=$! 221 for _ in $(seq 1 100); do grep -q "paused at $point" "$WORK/log-int" 2>/dev/null && break; sleep 0.1; done 222 grep -q "paused at $point" "$WORK/log-int" || fail "installer never reached $point" 223 kill9_at_point "$IPID" 224 [[ "$(live "$WORK/cfg-good")" == "$OLD" ]] || fail "killed at $point changed the live release" 225 out="$("$WORK/bin-good/aien")"; [[ "$out" == "aien-b" || "$out" == "aien-c" ]] || fail "live install does not run after kill at $point ($out)" 226 done 227 # 11b. kill after the single rename (current already switched, links and record not yet written): 228 # the new release is live and runs, the record still names the old one, a rerun repairs the record 229 ID_NEW="$(sha256sum "$WORK/pkg/bin/aien" | cut -c1-12)" 230 OLD="$(live "$WORK/cfg-good")" 231 [[ "$OLD" != "$ID_NEW" ]] || fail "setup for the after-swap case failed" 232 env AIEN_TEST_PAUSE_AT=after-swap AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$WORK/rel3" \ 233 AIEN_BIN_DIR="$WORK/bin-good" AIEN_CONFIG_DIR="$WORK/cfg-good" AIEN_INSTALL_NO_PROFILE=1 \ 234 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers" \ 235 bash "$ROOT/install.sh" > "$WORK/log-int" 2>&1 & 236 IPID=$! 237 for _ in $(seq 1 100); do grep -q "paused at after-swap" "$WORK/log-int" 2>/dev/null && break; sleep 0.1; done 238 grep -q "paused at after-swap" "$WORK/log-int" || fail "installer never reached after-swap" 239 kill9_at_point "$IPID" 240 [[ "$(live "$WORK/cfg-good")" == "$ID_NEW" ]] || fail "after-swap: the rename did not take effect" 241 [[ "$("$WORK/bin-good/aien")" == "aien-e" ]] || fail "after-swap: the live release does not run" 242 grep -q "^current = \"$OLD\"" "$WORK/cfg-good/installed.toml" || fail "after-swap: record unexpectedly updated before the kill" 243 [[ -d "$WORK/cfg-good/releases/$OLD" ]] || fail "after-swap: the previous release was pruned before the record was written" 244 run_install "$WORK/rel3" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}" \ 245 || { cat "$WORK/log" >&2; fail "rerun after interruption failed"; } 246 [[ "$("$WORK/bin-good/aien")" == "aien-e" ]] || fail "rerun did not install the new release" 247 grep -q "^current = \"$ID_NEW\"" "$WORK/cfg-good/installed.toml" || fail "rerun after the after-swap kill did not repair the record" 248 grep -q "^previous = \"$OLD\"" "$WORK/cfg-good/installed.toml" || fail "rerun after the after-swap kill lost the previous release" 249 [[ -z "$(ls -A "$WORK/cfg-good/releases" | grep '^\.stage\.' || true)" ]] || fail "leftover stage after rerun" 250 251 # 12. an existing release directory that is incomplete is never overwritten 252 ID3="$(live "$WORK/cfg-good")" 253 make_release "$WORK/rel4" "$WORK/key" CAND-4 f 254 ID4="$(sha256sum "$WORK/pkg/bin/aien" | cut -c1-12)" 255 mkdir -p "$WORK/cfg-good/releases/$ID4"; echo partial > "$WORK/cfg-good/releases/$ID4/junk" 256 if run_install "$WORK/rel4" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then 257 fail "install over an incomplete release directory succeeded" 258 fi 259 grep -q "was not overwritten" "$WORK/log" || fail "incomplete release directory not reported" 260 [[ "$(live "$WORK/cfg-good")" == "$ID3" && -f "$WORK/cfg-good/releases/$ID4/junk" ]] || fail "refusal changed state" 261 262 # 12b. kill -9 at the final switch itself. install.sh switches releases with one rename(2) of a 263 # temp symlink over releases/current. After every kill the install is wholly old or wholly new: 264 # it runs, its record is readable, and a rerun (or --rollback) finishes cleanly. 265 kill_at() { # point release-dir [install.sh args...]: run install.sh held at point, then kill -9 it 266 local point="$1" rel="$2" ipid 267 shift 2 268 env AIEN_TEST_PAUSE_AT="$point" AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$rel" \ 269 AIEN_BIN_DIR="$WORK/bin-good" AIEN_CONFIG_DIR="$WORK/cfg-good" AIEN_INSTALL_NO_PROFILE=1 \ 270 AIEN_SOURCE_DIR="$ROOT" AIEN_DRY_RUN_SIGNERS="$WORK/allowed_signers" HOME="$WORK/home" \ 271 bash "$ROOT/install.sh" "$@" > "$WORK/log-int" 2>&1 & 272 ipid=$! 273 for _ in $(seq 1 100); do grep -q "paused at $point" "$WORK/log-int" 2>/dev/null && break; sleep 0.1; done 274 grep -q "paused at $point" "$WORK/log-int" || fail "installer never reached $point" 275 kill9_at_point "$ipid" 276 } 277 rec_cur() { sed -n 's/^current = "\(.*\)"$/\1/p' "$WORK/cfg-good/installed.toml"; } 278 strays() { ls -A "$WORK/cfg-good/releases" | grep -c '^\.current\.new\.' || true; } 279 280 # A. install killed after the temp link exists, before the rename: wholly old 281 make_release "$WORK/rel5" "$WORK/key" CAND-5 g 282 ID5="$(sha256sum "$WORK/pkg/bin/aien" | cut -c1-12)" 283 ID_OLD="$(live "$WORK/cfg-good")" 284 kill_at pre-rename "$WORK/rel5" 285 [[ "$(live "$WORK/cfg-good")" == "$ID_OLD" && "$("$WORK/bin-good/aien")" == "aien-e" ]] || fail "pre-rename kill: install is not wholly old" 286 [[ "$(strays)" -ge 1 ]] || fail "pre-rename: no temp link, the hold is not at the rename" 287 [[ "$(rec_cur)" == "$ID_OLD" ]] || fail "pre-rename kill: record changed" 288 run_install "$WORK/rel5" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}" \ 289 || { cat "$WORK/log" >&2; fail "rerun after pre-rename kill failed"; } 290 [[ "$(live "$WORK/cfg-good")" == "$ID5" && "$("$WORK/bin-good/aien")" == "aien-g" && "$(rec_cur)" == "$ID5" ]] || fail "rerun after pre-rename kill is not wholly new" 291 [[ "$(strays)" -eq 0 ]] || fail "temp link left after rerun" 292 293 # B. install killed after the rename and the links, before the record: wholly new, record repaired by rerun 294 make_release "$WORK/rel6" "$WORK/key" CAND-6 h 295 ID6="$(sha256sum "$WORK/pkg/bin/aien" | cut -c1-12)" 296 kill_at after-links "$WORK/rel6" 297 [[ "$(live "$WORK/cfg-good")" == "$ID6" && "$("$WORK/bin-good/aien")" == "aien-h" ]] || fail "after-links kill: install is not wholly new" 298 [[ "$(rec_cur)" == "$ID5" && -d "$WORK/cfg-good/releases/$ID5" ]] || fail "after-links kill: record or previous release lost" 299 run_install "$WORK/rel6" "$WORK/bin-good" "$WORK/cfg-good" "$ROOT/install.sh" "${SIGN_ENV[@]}" \ 300 || { cat "$WORK/log" >&2; fail "rerun after after-links kill failed"; } 301 [[ "$(rec_cur)" == "$ID6" ]] && grep -q "^previous = \"$ID5\"" "$WORK/cfg-good/installed.toml" || fail "rerun did not repair the record" 302 303 # C. --rollback killed before its rename: wholly old (the release it was leaving); rerun completes 304 kill_at pre-rename "$WORK/none" --rollback 305 [[ "$(live "$WORK/cfg-good")" == "$ID6" && "$("$WORK/bin-good/aien")" == "aien-h" && "$(rec_cur)" == "$ID6" ]] || fail "rollback killed pre-rename: not wholly old" 306 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || { cat "$WORK/log" >&2; fail "rollback rerun failed"; } 307 [[ "$(live "$WORK/cfg-good")" == "$ID5" && "$("$WORK/bin-good/aien")" == "aien-g" && "$(rec_cur)" == "$ID5" ]] || fail "rollback rerun: not wholly rolled back" 308 [[ "$(strays)" -eq 0 ]] || fail "temp link left after rollback rerun" 309 310 # D. --rollback killed after its rename, before the record: wholly new (the target); rerun is safe and 311 # leaves a consistent record; a further rollback still swaps back and verifies 312 kill_at after-swap "$WORK/none" --rollback 313 [[ "$(live "$WORK/cfg-good")" == "$ID6" && "$("$WORK/bin-good/aien")" == "aien-h" ]] || fail "rollback killed after-swap: not wholly switched" 314 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || { cat "$WORK/log" >&2; fail "rollback rerun after after-swap kill failed"; } 315 [[ "$(live "$WORK/cfg-good")" == "$(rec_cur)" ]] || fail "record and live release disagree after the rerun" 316 [[ "$("$WORK/bin-good/aien")" == "aien-h" || "$("$WORK/bin-good/aien")" == "aien-g" ]] || fail "install does not run after the rerun" 317 inst_args "$WORK/bin-good" "$WORK/cfg-good" --rollback || fail "rollback after recovery failed" 318 [[ "$(live "$WORK/cfg-good")" == "$(rec_cur)" ]] || fail "record and live release disagree after a further rollback" 319 320 # 13. release gate: the candidate must be named and omega.lock must be the candidate's omega commit 321 GT="$WORK/gate"; mkdir -p "$GT/scripts" "$GT/release" 322 cp "$ROOT/scripts/check-release-candidate.sh" "$GT/scripts/"; cp "$ROOT/release/candidate.toml" "$GT/release/" 323 # A matching tree by construction: Cargo.lock sources at exactly the candidate's [pins], as omega.lock below is 324 # the candidate's omega commit. The live Cargo.lock moves with dependency updates (sc#906 left one aien-protocols-mv 325 # source) and is not CAND-4; pin mismatches are covered by scripts/test-release-checks.sh. 326 pin() { sed -n '/^\[pins\]/,/^\[/p' "$GT/release/candidate.toml" | sed -n "s/^$1 *= *\"\([0-9a-f]*\)\".*/\1/p"; } 327 for r in aien-protocols crumb-spec spark-crumbs; do 328 printf '[[package]]\nsource = "git+https://github.com/aien-dev/%s?rev=%s#%s"\n' "$r" "$(pin "$r")" "$(pin "$r")" 329 done > "$GT/Cargo.lock" 330 gate() { (cd "$GT" && bash scripts/check-release-candidate.sh "$@" > "$WORK/log-gate" 2>&1); } 331 OM="$(sed -n 's/^omega-commit *= *"\(.*\)"$/\1/p' "$GT/release/candidate.toml")" 332 echo "$OM" > "$GT/omega.lock" 333 gate --model "$WORK/model.toml" || { cat "$WORK/log-gate" >&2; fail "gate refused a matching tree"; } 334 grep -q '^\[model\]' "$WORK/model.toml" && grep -q '^model-safetensors-sha256' "$WORK/model.toml" || fail "gate did not extract the model table" 335 echo `0000000000000000000000000000000000000000` > "$GT/omega.lock" 336 if gate; then fail "gate accepted an omega.lock that is not the candidate's"; fi 337 grep -q "cannot be released" "$WORK/log-gate" || fail "omega mismatch not explained" 338 echo "$OM" > "$GT/omega.lock" 339 sed -i 's/^candidate = .*/candidate = "unknown"/' "$GT/release/candidate.toml" 340 if gate; then fail "gate accepted candidate unknown"; fi 341 rm "$GT/release/candidate.toml" 342 if gate; then fail "gate accepted a missing candidate file"; fi 343 344 # 14. offline-signing handoff (sc#385): signature classes, labelled receipts, negative rows. Every key here is a 345 # throwaway made above; nothing in this section touches a real key. 346 rcpt() { sed -n "s/^ \"$2\": \"\{0,1\}\([^\",]*\)\"\{0,1\},\{0,1\}\$/\1/p" "$1/install-receipt.json"; } 347 # A. a dry-run artifact (manifest labelled dry-run, signed by a throwaway key given explicitly) installs and is 348 # recorded as signature_check dry-run-key in installed.toml and in install-receipt.json 349 make_release "$WORK/dry" "$WORK/key" CAND-1 a dry 350 run_install "$WORK/dry" "$WORK/bin-dry" "$WORK/cfg-dry" "$ROOT/install.sh" "${SIGN_ENV[@]}" \ 351 || { cat "$WORK/log" >&2; fail "dry-run artifact did not install with the throwaway signer"; } 352 grep -q '^signature-check = "dry-run-key"$' "$WORK/cfg-dry/installed.toml" || fail "installed.toml does not record dry-run-key" 353 [[ "$(rcpt "$WORK/cfg-dry" signature_check)" == dry-run-key ]] || fail "install receipt does not record signature_check dry-run-key" 354 [[ "$(rcpt "$WORK/cfg-dry" dry_run)" == true ]] || fail "install receipt does not record the dry-run manifest label" 355 [[ "$(rcpt "$WORK/cfg-dry" artifact_sha256)" == "$(sha256sum "$WORK/dry/$ASSET" | cut -d' ' -f1)" ]] || fail "receipt artifact_sha256 is not the artifact's digest" 356 [[ "$(rcpt "$WORK/cfg-dry" files_verified)" =~ ^[1-9][0-9]*$ ]] || fail "receipt files_verified is not a positive count" 357 [[ "$(rcpt "$WORK/cfg-dry" cli_sha256)" =~ ^[0-9a-f]{64}$ ]] || fail "receipt cli_sha256 missing" 358 grep -q 'signature_check: dry-run-key' "$WORK/log" || fail "installer output does not say dry-run-key" 359 # B. one byte changed in the middle of the archive (same size): refused, names the checksum, nothing installed 360 make_release "$WORK/flip" "$WORK/key" CAND-1 a dry 361 SZ="$(wc -c < "$WORK/flip/$ASSET")"; OFF=$((SZ / 2)) 362 B="$(dd if="$WORK/flip/$ASSET" bs=1 skip="$OFF" count=1 2>/dev/null | od -An -tu1 | tr -d ' ')" 363 printf "$(printf '\\%03o' $(( (B + 1) % 256 )))" | dd of="$WORK/flip/$ASSET" bs=1 seek="$OFF" count=1 conv=notrunc 2>/dev/null 364 [[ "$(wc -c < "$WORK/flip/$ASSET")" == "$SZ" ]] || fail "byte flip changed the size" 365 if run_install "$WORK/flip" "$WORK/bin-flip" "$WORK/cfg-flip" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then fail "artifact with one byte changed was installed"; fi 366 grep -qi "checksum" "$WORK/log" || fail "one-byte change not refused by name (checksum)" 367 [[ ! -e "$WORK/bin-flip/aien" && ! -e "$WORK/cfg-flip/install-receipt.json" ]] || fail "one-byte refusal left a binary or a receipt" 368 # C. one byte changed in the signed checksum list: refused, names the signature 369 make_release "$WORK/flipsum" "$WORK/key" CAND-1 a dry 370 C1="$(head -c1 "$WORK/flipsum/SHA256SUMS.txt")"; [[ "$C1" == 0 ]] && R=1 || R=0; sed -i "1s/^./$R/" "$WORK/flipsum/SHA256SUMS.txt" 371 if run_install "$WORK/flipsum" "$WORK/bin-fs" "$WORK/cfg-fs" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then fail "edited checksum list was installed"; fi 372 grep -q "signature" "$WORK/log" || fail "edited checksum list not refused by name (signature)" 373 [[ ! -e "$WORK/bin-fs/aien" ]] || fail "edited checksum list left a binary" 374 # D. missing signature: refused, says unsigned, nothing installed 375 make_release "$WORK/nosig" "$WORK/key" CAND-1 a dry 376 rm -f "$WORK/nosig/SHA256SUMS.txt.sig" 377 if run_install "$WORK/nosig" "$WORK/bin-ns" "$WORK/cfg-ns" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then fail "release without a signature was installed"; fi 378 grep -q "SHA256SUMS.txt.sig is missing" "$WORK/log" || fail "missing signature not refused by name" 379 [[ ! -e "$WORK/bin-ns/aien" && ! -e "$WORK/cfg-ns/install-receipt.json" ]] || fail "missing-signature refusal left a binary or a receipt" 380 # E. wrong key: a dry-run artifact signed by another throwaway key is refused 381 make_release "$WORK/wrong" "$WORK/other" CAND-1 a dry 382 if run_install "$WORK/wrong" "$WORK/bin-wk" "$WORK/cfg-wk" "$ROOT/install.sh" "${SIGN_ENV[@]}"; then fail "wrong-key artifact was installed"; fi 383 grep -q "signature is NOT valid" "$WORK/log" || fail "wrong key not refused by name" 384 # F. a dry-run artifact can never be recorded as a release. Simulate a pinned release key with a copy of install.sh 385 # whose AIEN_RELEASE_SIGNER is the throwaway key: an unlabelled package signed by it records release (positive 386 # control); a dry-run-labelled package signed by the same key is refused and leaves no receipt. 387 mkdir -p "$WORK/pinned-sim" 388 sed "s|^AIEN_RELEASE_SIGNER=.*|AIEN_RELEASE_SIGNER='$(cat "$WORK/allowed_signers")'|" "$ROOT/install.sh" > "$WORK/pinned-sim/install.sh" 389 grep -q "^AIEN_RELEASE_SIGNER='aien-release ssh-`ed25519` " "$WORK/pinned-sim/install.sh" || fail "release-key simulation did not apply" 390 run_install "$WORK/good" "$WORK/bin-rel" "$WORK/cfg-rel" "$WORK/pinned-sim/install.sh" HOME="$WORK/home" \ 391 || { cat "$WORK/log" >&2; fail "simulated release did not install"; } 392 [[ "$(rcpt "$WORK/cfg-rel" signature_check)" == release ]] || fail "release-key signature not recorded as release (control)" 393 if run_install "$WORK/dry" "$WORK/bin-dryrel" "$WORK/cfg-dryrel" "$WORK/pinned-sim/install.sh" HOME="$WORK/home"; then 394 fail "dry-run artifact signed by the release key was installed" 395 fi 396 grep -q "labelled dry-run" "$WORK/log" || fail "dry-run artifact under the release key not refused by name" 397 [[ ! -e "$WORK/cfg-dryrel/install-receipt.json" ]] || fail "refused dry-run artifact left a receipt" 398 # G. with the placeholder in place (no release key pinned) and no throwaway signer, nothing verifies as a release 399 if [[ -z "$(pinned AIEN_RELEASE_SIGNER)" ]]; then 400 if run_install "$WORK/good" "$WORK/bin-ph" "$WORK/cfg-ph" "$ROOT/install.sh" HOME="$WORK/home"; then fail "placeholder accepted a release"; fi 401 grep -q "no public-release key is pinned" "$WORK/log" || fail "placeholder refusal does not say no release key is pinned" 402 fi 403 # H. a release signed by the internal test key would be labelled internal-test-key (classification is by the 404 # verifying key; checked by grepping the installer, because that private key is not on this machine) 405 grep -q 'SIG_CHECK=internal-test-key' "$ROOT/install.sh" || fail "install.sh has no internal-test-key class" 406 echo "PASS: release gate fails closed, release install verifies signature, checksum and every package file, labels the signature class (release, internal-test-key, dry-run-key) in installed.toml and install-receipt.json, never records a dry-run artifact as a release, refuses a one-byte change, an edited checksum list, a missing signature and a wrong key, rejects tampered and forged releases, installs standalone offline, pinned key matches allowed_signers, upgrades atomically, keeps one previous release, rolls back, refuses downgrades, survives an interrupted install (including kill -9 just before the rename, just after it, and during rollback)"