gitgram/aitimemachine/beads/scripts/upgrade-smoke-test.sh
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

534 lines
18 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
# =============================================================================
# Upgrade Smoke Tests — Release Stability Gate
# =============================================================================
#
# Verifies that upgrading from a previous release preserves:
# 1. Issue data (issues created before upgrade are visible after)
# 2. Storage mode (embedded stays embedded, shared stays shared)
# 3. Role config (beads.role git config is not cleared or changed)
# 4. Doctor health (bd doctor quick passes after upgrade)
# 5. Mutations (bd update after upgrade persists correctly)
#
# Usage:
# ./scripts/upgrade-smoke-test.sh # test previous release → candidate
# ./scripts/upgrade-smoke-test.sh v0.62.0 # test specific version → candidate
# CANDIDATE_BIN=./bd ./scripts/upgrade-smoke-test.sh # use prebuilt candidate
#
# # Test multiple versions (space-separated):
# SMOKE_VERSIONS="v0.62.0 v0.61.0 v0.60.0" ./scripts/upgrade-smoke-test.sh
#
# The candidate binary is built from the current worktree if CANDIDATE_BIN
# is not set. The previous release binary is downloaded and cached in
# ~/.cache/beads-regression/.
#
# Exit codes:
# 0 All scenarios passed
# 1 One or more scenarios failed
# =============================================================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Canonical build flags (GOFLAGS=-tags=gms_pure_go, CGO_ENABLED=1).
# shellcheck source=../.buildflags
source "$PROJECT_ROOT/.buildflags"
# ---------------------------------------------------------------------------
# Multi-version mode: SMOKE_VERSIONS overrides single-version argument
# ---------------------------------------------------------------------------
if [ -n "${SMOKE_VERSIONS:-}" ]; then
# Run ourselves once per version, collecting exit codes
OVERALL_FAIL=0
for _ver in $SMOKE_VERSIONS; do
if ! CANDIDATE_BIN="${CANDIDATE_BIN:-}" "$0" "$_ver"; then
OVERALL_FAIL=1
fi
done
exit $OVERALL_FAIL
fi
# ---------------------------------------------------------------------------
# Single-version mode
# ---------------------------------------------------------------------------
# Determine previous release version
if [ -n "${1:-}" ]; then
PREV_VERSION="$1"
else
# Default: fetch the latest release tag before the current version
CURRENT_VERSION=$(grep 'Version = ' "$PROJECT_ROOT/cmd/bd/version.go" \
| head -1 | sed 's/.*"\(.*\)".*/\1/')
# Try to get the previous release tag from git
PREV_VERSION=$(git -C "$PROJECT_ROOT" tag --sort=-version:refname \
| grep '^v' | head -2 | tail -1 2>/dev/null || echo "")
if [ -z "$PREV_VERSION" ]; then
echo -e "${RED}Cannot determine previous release version.${NC}"
echo "Specify explicitly: $0 v0.62.0"
exit 1
fi
fi
# Strip 'v' prefix for download URL, keep for display
PREV_VER_BARE="${PREV_VERSION#v}"
PREV_VERSION="v${PREV_VER_BARE}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Upgrade Smoke Tests: ${PREV_VERSION} → candidate"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# ---------------------------------------------------------------------------
# Binary management
# ---------------------------------------------------------------------------
CACHE_DIR="${HOME}/.cache/beads-regression"
mkdir -p "$CACHE_DIR"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
esac
get_previous_binary() {
local cached="$CACHE_DIR/bd-${PREV_VER_BARE}"
if [ -x "$cached" ]; then
echo "$cached"
return
fi
local asset="beads_${PREV_VER_BARE}_${OS}_${ARCH}.tar.gz"
local url="https://github.com/gastownhall/beads/releases/download/${PREV_VERSION}/${asset}"
echo -e "${YELLOW}Downloading ${PREV_VERSION} binary...${NC}" >&2
local tmpdir
tmpdir=$(mktemp -d)
if ! curl -fsSL "$url" -o "$tmpdir/archive.tar.gz"; then
echo -e "${RED}Failed to download ${url}${NC}" >&2
rm -rf "$tmpdir"
exit 1
fi
tar -xzf "$tmpdir/archive.tar.gz" -C "$tmpdir"
local bd_path
bd_path=$(find "$tmpdir" -name bd -type f | head -1)
if [ -z "$bd_path" ]; then
echo -e "${RED}bd binary not found in archive${NC}" >&2
rm -rf "$tmpdir"
exit 1
fi
cp -f "$bd_path" "$cached"
chmod +x "$cached"
rm -rf "$tmpdir"
echo "$cached"
}
build_candidate() {
if [ -n "${CANDIDATE_BIN:-}" ] && [ -x "${CANDIDATE_BIN}" ]; then
echo "$(cd "$(dirname "$CANDIDATE_BIN")" && pwd)/$(basename "$CANDIDATE_BIN")"
return
fi
local candidate="$CACHE_DIR/bd-candidate-$$"
echo -e "${YELLOW}Building candidate binary...${NC}" >&2
(cd "$PROJECT_ROOT" && go build -o "$candidate" ./cmd/bd) >&2
echo "$candidate"
}
PREV_BIN=$(get_previous_binary)
CAND_BIN=$(build_candidate)
echo "Previous: $PREV_BIN (${PREV_VERSION})"
echo "Candidate: $CAND_BIN"
echo ""
# ---------------------------------------------------------------------------
# Test helpers
# ---------------------------------------------------------------------------
PASS=0
FAIL=0
SCENARIO=""
scenario() {
SCENARIO="$1"
echo -e "● ${SCENARIO}"
}
pass() {
echo -e " ${GREEN}✓ $1${NC}"
}
fail() {
echo -e " ${RED}✗ $1${NC}"
FAIL=$((FAIL + 1))
}
check() {
local desc="$1"
shift
if "$@" >/dev/null 2>&1; then
pass "$desc"
else
fail "$desc"
fi
}
finish_scenario() {
if [ $FAIL -eq 0 ]; then
PASS=$((PASS + 1))
fi
}
# Create an isolated workspace with git init
new_workspace() {
local dir
dir=$(mktemp -d -t bd-upgrade-XXXXXX)
git -C "$dir" init --quiet
git -C "$dir" config user.name "upgrade-test"
git -C "$dir" config user.email "test@beads.test"
echo "$dir"
}
# Run previous/candidate binary FROM the workspace directory.
# This is critical: git operations (beads.role, remote detection) must use
# $WS's git repo, not whichever repo this script is running from.
prev() { (cd "$WS" && "$PREV_BIN" "$@"); }
cand() { (cd "$WS" && "$CAND_BIN" "$@"); }
prev_init() { prev init --quiet --non-interactive --skip-hooks --skip-agents; }
cand_init() { cand init --quiet --non-interactive --skip-hooks --skip-agents; }
# Create an issue with the previous binary, tolerating missing --silent flag.
# Older binaries don't have --silent; we just need to know creation succeeded.
# Sets _CREATED_ID to a non-empty value on success.
prev_create() {
local out
# Try --silent first (newer previous binaries)
out=$(prev create --silent "$@" 2>/dev/null) && _CREATED_ID="${out:-created}" && return 0
# Fallback: run without --silent, parse any ID-like token from output
out=$(prev create "$@" 2>/dev/null) || return 1
_CREATED_ID=$(printf '%s' "$out" | grep -oE '[a-zA-Z0-9_]+-[0-9]+' | head -1)
_CREATED_ID="${_CREATED_ID:-created}"
}
# Return true when the embedded Dolt database directory (or legacy beads.db)
# exists inside the workspace .beads directory.
embedded_db_exists() {
[ -d "$WS/.beads/embeddeddolt" ] || [ -f "$WS/.beads/beads.db" ]
}
# ---------------------------------------------------------------------------
# Scenario 1: Embedded maintainer upgrade
# ---------------------------------------------------------------------------
scenario "Embedded maintainer: init → create → upgrade → verify"
WS=$(new_workspace)
# Init with previous version (run from $WS so git ops use $WS's repo)
prev_init 2>/dev/null || true
git -C "$WS" config beads.role maintainer
# Create test data (prev_create handles missing --silent in older binaries)
_CREATED_ID=""
prev_create --title "Pre-upgrade issue" --type task --priority 1 || true
ID1="${_CREATED_ID}"
prev_create --title "Another issue" --type bug || true
# Upgrade: run candidate init (simulates upgrade)
cand_init 2>/dev/null || true
# Verify
ROLE=$(git -C "$WS" config --get beads.role 2>/dev/null || echo "MISSING")
if [ "$ROLE" = "maintainer" ]; then
pass "beads.role preserved (maintainer)"
else
fail "beads.role changed to '$ROLE' (expected maintainer)"
fi
if [ -n "${ID1:-}" ]; then
LIST_OUT=$(cand list --json 2>/dev/null || echo "")
if echo "$LIST_OUT" | grep -q "Pre-upgrade issue"; then
pass "Pre-upgrade issues visible after upgrade"
else
fail "Pre-upgrade issues NOT visible after upgrade"
fi
else
# Old binary could not create issues — early embedded releases (e.g. v0.63.x)
# may have had init bugs that prevented writes. Skip data-migration check.
pass "Data migration check skipped (old binary could not write issues)"
fi
# Doctor check
if cand doctor quick 2>/dev/null; then
pass "bd doctor quick passes"
else
fail "bd doctor quick fails after upgrade"
fi
rm -rf "$WS"
finish_scenario
# ---------------------------------------------------------------------------
# Scenario 2: Contributor upgrade
# ---------------------------------------------------------------------------
scenario "Contributor: init --contributor → upgrade → verify role preserved"
WS=$(new_workspace)
# Init as contributor with previous version
prev_init 2>/dev/null || true
git -C "$WS" config beads.role contributor
# Upgrade
cand_init 2>/dev/null || true
ROLE=$(git -C "$WS" config --get beads.role 2>/dev/null || echo "MISSING")
if [ "$ROLE" = "contributor" ]; then
pass "beads.role preserved (contributor)"
else
fail "beads.role changed to '$ROLE' (expected contributor)"
fi
rm -rf "$WS"
finish_scenario
# ---------------------------------------------------------------------------
# Scenario 3: Mode preservation (embedded must stay embedded)
# ---------------------------------------------------------------------------
scenario "Mode preservation: embedded init must not switch to shared-server"
WS=$(new_workspace)
# Init with previous version
prev_init 2>/dev/null || true
git -C "$WS" config beads.role maintainer
# Check if old binary was able to initialize .beads/.
# Pre-embedded releases (< v0.63.0) used server mode and require an external
# Dolt server that is not available in CI, so their init may not create .beads/.
if [ -d "$WS/.beads" ]; then
pass "Beads initialized before upgrade"
else
pass "Pre-upgrade check skipped (old binary may require external Dolt server)"
fi
# Upgrade with candidate (always runs — verifies candidate defaults to embedded)
cand_init 2>/dev/null || true
# Verify candidate created an embedded DB
if embedded_db_exists; then
pass "Embedded DB present after candidate init"
else
fail "Embedded DB missing after candidate init"
fi
# Verify candidate does not switch to shared-server mode.
# storage.mode key may not be set at all when using embedded mode (it's the
# default), so "not set" and empty output are both acceptable.
SHOW_OUT=$(cand config get storage.mode 2>/dev/null || echo "")
if [ -z "$SHOW_OUT" ] || echo "$SHOW_OUT" | grep -qi "embedded\|sqlite\|local\|not set"; then
pass "Storage mode is embedded (or default)"
else
fail "Storage mode reports '$SHOW_OUT' (expected embedded)"
fi
rm -rf "$WS"
finish_scenario
# ---------------------------------------------------------------------------
# Scenario 4: Role must not be left unset after non-interactive init
# ---------------------------------------------------------------------------
scenario "Non-interactive init: beads.role must be set"
WS=$(new_workspace)
# Fresh init with candidate (no previous version; runs from $WS so git
# config is written to $WS's repo, not the repo this script runs from)
cand_init 2>/dev/null || true
ROLE=$(git -C "$WS" config --get beads.role 2>/dev/null || echo "MISSING")
if [ "$ROLE" != "MISSING" ] && [ -n "$ROLE" ]; then
pass "beads.role set after non-interactive init ($ROLE)"
else
fail "beads.role NOT set after non-interactive init"
fi
rm -rf "$WS"
finish_scenario
# ---------------------------------------------------------------------------
# Scenario 5: Mutation — bd update after version upgrade must persist
# ---------------------------------------------------------------------------
scenario "MUTATION: init with old → create → upgrade → bd update → verify persisted"
WS=$(new_workspace)
# Init and create an issue with the previous version
prev_init 2>/dev/null || true
git -C "$WS" config beads.role maintainer
_CREATED_ID=""
prev_create --title "Mutation target issue" --type task || true
MUT_ID="${_CREATED_ID}"
if [ -z "${MUT_ID:-}" ]; then
# Old binary could not create issues — skip mutation test gracefully.
# Early embedded releases (e.g. v0.63.x) may have had init bugs that
# prevented writes; that is a known historical issue, not a regression.
pass "Mutation test skipped (old binary could not write issues)"
rm -rf "$WS"
finish_scenario
else
pass "Issue created with previous binary (id: $MUT_ID)"
# Upgrade: run candidate init
cand_init 2>/dev/null || true
# Mutate using the candidate binary
cand update "$MUT_ID" --notes "smoke test mutation" 2>/dev/null || true
pass "bd update ran without fatal error"
# Read back and verify the mutation persisted
SHOW_OUT=$(cand show "$MUT_ID" 2>/dev/null || echo "")
if echo "$SHOW_OUT" | grep -q "smoke test mutation"; then
pass "Updated notes persisted and visible after mutation"
else
fail "Updated notes NOT visible after bd update (mutation did not persist)"
fi
rm -rf "$WS"
finish_scenario
fi
# ---------------------------------------------------------------------------
# Scenario 6: Dependency blocker paths must survive upgrade
# ---------------------------------------------------------------------------
#
# Release gate for the dependencies-split migrations (0035, 0041–0045, 0047).
# Earlier scenarios create issues but no dependencies, so the data-copy in
# 0041_split_dependencies_target only ever runs as DDL on an empty table and
# the rewritten ready_issues/blocked_issues views never get queried on a
# migrated DB. This scenario populates a dependency with the OLD binary (so the
# row is written in the pre-0041 schema), upgrades, then exercises the exact
# blocker paths that fail when the data-copy is wrong: bd ready, bd blocked,
# bd close — the surface of the current Dolt errno 1105 on a stale schema.
scenario "Dependency blocker paths survive upgrade (ready/blocked/close on migrated deps)"
WS=$(new_workspace)
prev_init 2>/dev/null || true
git -C "$WS" config beads.role maintainer
# Blocker (task) and a dependent (bug depends-on task → bug is blocked).
_CREATED_ID=""
prev_create --title "Blocker task" --type task --priority 1 || true
BLOCKER_ID="${_CREATED_ID}"
_CREATED_ID=""
prev_create --title "Blocked bug" --type bug --priority 2 || true
BLOCKED_ID="${_CREATED_ID}"
# Wire the dependency with the previous binary so the dependencies table is
# populated in the old (pre-split) schema. `dep add <blocked> <blocker>` means
# blocked depends on blocker; default type is "blocks".
DEP_CREATED=false
if [ -n "${BLOCKER_ID:-}" ] && [ -n "${BLOCKED_ID:-}" ] \
&& [ "$BLOCKER_ID" != "created" ] && [ "$BLOCKED_ID" != "created" ]; then
if prev dep add "$BLOCKED_ID" "$BLOCKER_ID" >/dev/null 2>&1; then
DEP_CREATED=true
fi
fi
if ! $DEP_CREATED; then
# Old binary could not create a parseable dependency — early releases lack
# --silent (so IDs aren't captured) or predate positional dep add. The
# data-copy is still covered by the migration-test harness; skip gracefully.
pass "Dependency blocker-path check skipped (old binary could not add a parseable dependency)"
rm -rf "$WS"
finish_scenario
else
pass "Dependency created with previous binary ($BLOCKED_ID depends on $BLOCKER_ID)"
# Upgrade (runs migrations 0041–0047, including the data-copy).
cand_init 2>/dev/null || true
# 1. Blocker queries must not error on the migrated dependency rows.
if cand ready >/dev/null 2>&1; then
pass "bd ready succeeds after upgrade"
else
fail "bd ready errors after upgrade (migrated dependency schema regression)"
fi
if cand blocked >/dev/null 2>&1; then
pass "bd blocked succeeds after upgrade"
else
fail "bd blocked errors after upgrade (migrated dependency schema regression)"
fi
# 2. The dependent must still be reported blocked post-migration — proves
# the data-copy populated depends_on_issue_id, not just the DDL.
BLOCKED_OUT=$(cand blocked 2>/dev/null || echo "")
if echo "$BLOCKED_OUT" | grep -q "$BLOCKED_ID"; then
pass "Migrated dependency still blocks dependent (blocked issue listed)"
else
fail "Blocked issue '$BLOCKED_ID' not reported blocked after upgrade (data-copy may have dropped the row)"
fi
# 3. Closing the blocker must succeed (this is the bd close errno 1105
# surface) and must unblock the dependent (is_blocked recompute).
if cand close "$BLOCKER_ID" >/dev/null 2>&1; then
pass "bd close on blocker succeeds after upgrade"
else
fail "bd close errors after upgrade (errno 1105 / stale depends_on_id regression)"
fi
READY_OUT=$(cand ready 2>/dev/null || echo "")
if echo "$READY_OUT" | grep -q "$BLOCKED_ID"; then
pass "Dependent becomes ready after blocker closed (unblock path works)"
else
fail "Dependent '$BLOCKED_ID' not ready after closing blocker (is_blocked recompute wrong)"
fi
rm -rf "$WS"
finish_scenario
fi
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo -e " ${GREEN}All $TOTAL scenarios passed${NC}"
else
echo -e " ${RED}$FAIL scenario(s) failed${NC} out of $TOTAL"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Clean up candidate if we built it
if [ -z "${CANDIDATE_BIN:-}" ] && [ -f "$CAND_BIN" ]; then
rm -f "$CAND_BIN"
fi
[ $FAIL -eq 0 ]