From e87ecdb3e5cc77f364509b6ad4d39a7e3dea1d46 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Wed, 2 Sep 2026 20:23:18 -0500 Subject: [PATCH] test(release): release-layer selftests (#12) 14 cases: RELEASE validation (valid/invalid/missing), tag consistency, status on empty state, fault-injected refusal with no pointer + single valid refusal log line, healthy activation, pointer fields, repeat activation append-only log, rollback-without-previous refusal. Harness fix learned the hard way: restore RELEASE from backup inline after the missing-file case (mv-back restored the mutated file); single exit trap self-heals the repo state. Closes #12 --- scripts/test-release.sh | 98 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 scripts/test-release.sh diff --git a/scripts/test-release.sh b/scripts/test-release.sh new file mode 100755 index 00000000..762da30e --- /dev/null +++ b/scripts/test-release.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +# Sandboxed selftests for the release layer. +# +# Fast cases (version validation) need no Docker. State-machine cases +# (status/activate/refusal) run against a sandboxed config and therefore +# require the Docker daemon; they are skipped when it is unavailable. +set -uo pipefail +cd "$(dirname "$0")/.." + +SANDBOX="$(mktemp -d)" +RELEASE_BACKUP="$(mktemp)" +cp RELEASE "$RELEASE_BACKUP" +# One exit trap: the repo RELEASE is ALWAYS restored from the backup, +# regardless of how the test run ends. +trap 'cp "$RELEASE_BACKUP" RELEASE 2>/dev/null; rm -rf "$SANDBOX" "$RELEASE_BACKUP"' EXIT + +PASS=0 +FAIL=0 + +expect_exit() { + local name="$1" expected="$2" + shift 3 + local rc + "$@" >/dev/null 2>&1 + rc=$? + if [ "$rc" -eq "$expected" ]; then + PASS=$((PASS+1)); echo "ok $name (exit $rc)" + else + FAIL=$((FAIL+1)); echo "FAIL $name (exit $rc, expected $expected)" + fi +} + +check() { + if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "ok $1"; else FAIL=$((FAIL+1)); echo "FAIL $1"; fi +} + +# ---------- fast: release identity ---------- +expect_exit "valid RELEASE resolves" 0 -- bash -c 'source scripts/common.sh && load_release' + +printf 'garbage\n' > RELEASE +expect_exit "invalid RELEASE exits 1" 1 -- bash -c 'source scripts/common.sh && load_release' + +mv RELEASE "$SANDBOX/RELEASE.hidden" +expect_exit "missing RELEASE exits 1" 1 -- bash -c 'source scripts/common.sh && load_release' +cp "$RELEASE_BACKUP" RELEASE + +bash -c 'source scripts/common.sh && load_release' >/dev/null 2>&1 +bash -c 'source scripts/common.sh && load_release && case "$MOSAIC_IMAGE_TAG" in mosaic-poc-agent:*-r'"$(cat RELEASE)"') exit 0;; *) exit 1;; esac' >/dev/null 2>&1 +check "valid RELEASE leaves image tag consistent with version" $? + +# ---------- sandboxed state machine (Docker required) ---------- +if docker info >/dev/null 2>&1; then + mkdir -p "$SANDBOX/data" + cat > "$SANDBOX/config.json" <