* feat(schema): never migrate an existing database without explicit consent (bd-qhn8y) Beads 1.2 release remediation. 1.2.0/1.2.1 auto-applied migrations 54-65 at store open on ANY command, including reads; older binaries then refuse the migrated database. MigrateUp now refuses pending main-sequence migrations on an existing database before any write (dolt_ignore seeding included) unless the operator consented: bd migrate / bd migrate schema (preview flags withhold), bd migrate --force, or BD_ALLOW_MIGRATE=1 (BD_ALLOW_REMOTE_MIGRATE honored as an alias). Fresh init and at-latest databases are unaffected; the #4259 remote gate keeps all its protections. Also: freeze shipped migrations (hash-pin test, main 0001-0065 + ignored 0001-0024), retract v1.2.0/v1.2.1 in go.mod, agent-executable un-migrate runbook (docs/recovery/unmigrate-schema-v65.md), and the upgrade smoke + historical migration harnesses now model the consent contract and assert the refusal carries guidance. No version bump here by design: cutting the release stays with the release owner. Rebased onto main800d43eb8d: the go.mod retract hunk is dropped - main already retracts v1.2.0/v1.2.1 (and v1.1.1) since #5782. The uow consent grant moves into the TestMain main added in #6441 (a second TestMain no longer compiles), and the new files are listed in the BUILD.bazel targets main now carries (gazelle). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(schema): cloned-workspace bootstrap carries creation-consent (bd-qhn8y) The consent gate treated a workspace `bd init --remote` / `bd bootstrap` just cloned into existence like a pre-existing database, refusing the smart gate's provably-safe first-mover migration and stranding init in the generic open-error path (bypassing the bd-4mpy7 finalize+guidance ergonomics). Cloning IS creating: those paths now record consent explicitly, and the #4259 remote-migrate gate still applies to them unchanged (consent is not its designated-migrator override). Fixes CI TestEmbeddedInit/remote_behind_schema_gate. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(migration): consent first in main's wisp lanes too (bd-qhn8y) The rebase onto800d43eb8dbrought in #6049's wisp-plane lanes, which postdate this PR's harness changes. Each one makes an ordinary candidate command the first touch on an old-schema database, and the consent gate refuses it: - historical-dolt-upgrade-test.sh run_wisp_plane_upgrade opens with `bd list` before any migrate: "candidate could not open the seeded wisp workspace" for v1.0.1, v1.1.0, v1.1.2 and v1.2.2 (the Migration Test Harness dolt-runtime shard). - run_dirty_tracked_wisp_scenario (v1.1.2): the consent refusal stops the open before MigrateUp reaches the #5816 dirty tables, so the lane fails "without naming them". - upgrade-smoke-test.sh "Wisp plane survives upgrade" upgrades with a bare cand_init, so list/ready/blocked/update all hit the refusal (4 failures each for v1.3.0 and v1.3.1, both in the PR smoke set). Use the PR's own pattern: the explicit `bd migrate schema` is the first candidate touch (cand_upgrade in the smoke script). Base800d43eb8dpasses these lanes unchanged; with this fixup the full 14-version historical corpus and all five PR smoke versions pass. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(schema): close consent-gate review findings (bd-qhn8y) Review fixes for the migration-consent gate (adopt-pr review, attempts 1 and 2). Majors: - #4566 deadlock rebuilt one check earlier: on a database that is both behind and dirty, the consent refusal fired before the dirty-table guard, whose remedy (`bd dolt commit`) opens without consent. The working-set-reconcile opens now tolerate MigrateConsentError: embedded (toleratesConsentRefusal, WSR intent only) and server mode (LenientOpen's warnLenientOpenRefusal) print WorkingSetWarning and commit at the current schema; strict, read-only and RemoteSync opens still refuse. Covered by an embedded test (a refused open writes nothing: dolt_status, dolt_ignore and schema_migrations unchanged) and a server-mode integration subtest. - Bare `bd migrate` consented: isMigrateConsentCommand now matches only the schema verb, so `bd migrate` (metadata reconcile, including --update-repo-id, --inspect and --dry-run) no longer consents to a one-way migration; `bd migrate schema` and --force do. TestLocalMigrateConsentScope pins the scope through the root pre-run. The dirty-table warnings name `bd migrate schema` accordingly. - Runnable JSON hint: the JSON refusal follows the #4259 AgentDirective convention, a non-runnable hint plus a migrate_consent object (versions, pending, severity, human_decision_required, options) whose commands are retargeted with --global for the shared global database. The text refusal prints the same --global hint under `bd --global`. - Freeze floor: the hash-pinned freeze now covers what v1.3.x shipped, main 0001-0066 and ignored 0001-0026; the CHANGELOG puts new migrations in 0070+ / 0028+. - Fresh-bootstrap heal: MigrateUpWithLock with heal authority takes the consent-free migrate path, so a retried bd init whose first pass left a non-zero cursor converges; other lock callers keep the gate. Minors: the uow team-server guards are repinned on `bd migrate schema`; the un-migrate runbook is linked from the recovery index and cross-linked with the 1.2.1 repair-forward doc; the CHANGELOG BREAKING entry matches the shipped contract; harness comment grammar. Docs: the user docs and README named bare `bd migrate` as the step that applies schema migrations; they now say `bd migrate schema`, which also exists in the pinned docs release (v1.2.2) and in v1.3.x. The `bd migrate schema` help no longer claims migrations run automatically on store open. The Go remedy that sends a remote-gate stop to bare `bd migrate` for its migrate-or-adopt options is unchanged (pinned by TestNoticeSharedMigrateRefusalPerDecision). Upgrade smoke (attempt 2): the consent-gate assertion is graded only when the old binary left a database. Releases before v1.0 have no `init --non-interactive`, so prev_init creates nothing there and the candidate's `bd list` fails with "no beads database found", which has no consent guidance. Main's Bazel smoke lane (#7331) runs the newest 30 releases, 20 of them pre-1.0, under the required ci-gate; all 20 went red on the merge. The 10 v1.x releases still take the refusal branch. Shard manifest (pre-approval CI): the new embedded test TestEmbeddedMigrateConsent_BehindAndDirtyWorkingSetReconcileRecovers is listed in the Bazel 15-shard block of embedded-storage-test-shards.txt (incremental --write; shard 15). Main's ci lane runs TestStorageEmbeddedShardManifestGeneratorNotStale in //scripts:scripts_test, which fails on any unlisted top-level embeddeddolt test. Not addressed (optional): env-only consent docs for embedders, the unparseable BD_ALLOW_REMOTE_MIGRATE alias hint, and the harness `|| true` on `cand migrate schema`. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com> Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
672 lines
24 KiB
Bash
Executable file
672 lines
24 KiB
Bash
Executable file
#!/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 ! SMOKE_VERSIONS= 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() {
|
||
# PREV_BIN (set by //tests/upgrade_smoke's targets) is the previous
|
||
# release already pinned and sha256-verified against the release catalog,
|
||
# so nothing is downloaded; it must report PREV_VERSION.
|
||
if [ -n "${PREV_BIN:-}" ]; then
|
||
if ! "$PREV_BIN" version 2>/dev/null | grep -qF " ${PREV_VER_BARE} "; then
|
||
echo -e "${RED}PREV_BIN=${PREV_BIN} does not report ${PREV_VERSION}${NC}" >&2
|
||
exit 1
|
||
fi
|
||
echo "$PREV_BIN"
|
||
return
|
||
fi
|
||
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; }
|
||
|
||
# Upgrade an existing workspace to the candidate. Since the migration-consent
|
||
# gate (Beads 1.2 release remediation) the candidate never migrates an
|
||
# existing database from ordinary commands — `bd migrate schema` is the
|
||
# consent step every real upgrade now includes, so the smoke upgrade includes
|
||
# it too. Tolerates a workspace the old binary could not initialize (the
|
||
# migrate is a no-op failure there and cand_init creates a fresh database).
|
||
cand_upgrade() {
|
||
cand migrate schema >/dev/null 2>&1 || true
|
||
cand_init 2>/dev/null || true
|
||
}
|
||
|
||
# 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
|
||
|
||
# Migration-consent gate: before consenting, an ordinary candidate command on
|
||
# the old-schema database must either work as-is (previous release already
|
||
# ships the candidate's schema — nothing pending) or refuse WITH the consent
|
||
# guidance. A failure without the guidance is a regression. Graded only when
|
||
# the old binary left a database to gate: releases before v1.0 have no
|
||
# `init --non-interactive`, so prev_init creates nothing there.
|
||
if ! embedded_db_exists; then
|
||
pass "Consent gate check skipped (old binary could not initialize a database)"
|
||
else
|
||
GATE_OUT=$(cand list 2>&1) && GATE_RC=0 || GATE_RC=$?
|
||
if [ "$GATE_RC" -eq 0 ]; then
|
||
pass "Candidate operates database directly (schema already current)"
|
||
elif echo "$GATE_OUT" | grep -q "bd migrate schema"; then
|
||
pass "Candidate refuses un-migrated database with consent guidance"
|
||
else
|
||
fail "Candidate failed on old database without consent guidance"
|
||
fi
|
||
fi
|
||
|
||
# Upgrade: consent + candidate init (simulates upgrade)
|
||
cand_upgrade
|
||
|
||
# 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_upgrade
|
||
|
||
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_upgrade
|
||
|
||
# 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: consent + candidate init
|
||
cand_upgrade
|
||
|
||
# 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 (consents to and runs migrations 0041+, including the data-copy).
|
||
cand_upgrade
|
||
|
||
# 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
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Scenario 7: Wisp plane must survive upgrade
|
||
# ---------------------------------------------------------------------------
|
||
#
|
||
# Release gate for the wisp-plane migrations (0054-0066 and ignored 0012-0025).
|
||
# Every earlier scenario works entirely in the versioned plane, so the wisp
|
||
# tables reach the candidate empty and those migrations only ever run as DDL
|
||
# over zero rows. This seeds a wisp with the OLD binary — including a dependency
|
||
# edge, which is what makes the is_blocked recompute do real work — then
|
||
# upgrades and exercises the surfaces that break when the replay is wrong:
|
||
# listing wisps, the blocker queries that now have to be wisp-aware, and writing
|
||
# to a wisp through the migrated storage_class default.
|
||
#
|
||
# This matrix reaches back thirty releases on a tag push, so anything the old
|
||
# binary cannot do has to SKIP rather than fail.
|
||
|
||
scenario "Wisp plane survives upgrade (list/ready/blocked/update on migrated wisps)"
|
||
|
||
WS=$(new_workspace)
|
||
|
||
prev_init 2>/dev/null || true
|
||
git -C "$WS" config beads.role maintainer
|
||
|
||
_CREATED_ID=""
|
||
prev_create --ephemeral --title "Smoke wisp" --type task || true
|
||
WISP_ID="${_CREATED_ID}"
|
||
|
||
if [ -z "${WISP_ID:-}" ] || [ "$WISP_ID" = "created" ]; then
|
||
# Pre-wisp release, or one whose create output we cannot parse for an id.
|
||
pass "Wisp check skipped (old binary has no parseable wisp support)"
|
||
rm -rf "$WS"
|
||
finish_scenario
|
||
else
|
||
pass "Wisp created with previous binary ($WISP_ID)"
|
||
|
||
# A blocker edge makes the migrated is_blocked recompute meaningful. Older
|
||
# binaries may not route wisp-source dependencies, so tolerate failure.
|
||
_CREATED_ID=""
|
||
prev_create --title "Wisp blocker task" --type task --priority 1 || true
|
||
WISP_BLOCKER="${_CREATED_ID}"
|
||
WISP_DEP=false
|
||
if [ -n "${WISP_BLOCKER:-}" ] && [ "$WISP_BLOCKER" != "created" ]; then
|
||
if prev dep add "$WISP_ID" "$WISP_BLOCKER" >/dev/null 2>&1; then
|
||
WISP_DEP=true
|
||
pass "Wisp blocked on a task with previous binary"
|
||
fi
|
||
fi
|
||
if ! $WISP_DEP; then
|
||
pass "Wisp dependency skipped (old binary could not block a wisp on a task)"
|
||
fi
|
||
|
||
# Upgrade: consent + candidate init
|
||
cand_upgrade
|
||
|
||
# 1. The wisp survived the 0054-0066 + ignored 0012-0025 replay. --all
|
||
# because the default listing hides closed wisps.
|
||
WISP_OUT=$(cand mol wisp list --all 2>/dev/null || echo "")
|
||
if echo "$WISP_OUT" | grep -q "Smoke wisp"; then
|
||
pass "Wisp visible after upgrade"
|
||
else
|
||
fail "Wisp 'Smoke wisp' NOT visible after upgrade (ignored-plane replay dropped it)"
|
||
fi
|
||
|
||
# 2. Blocker queries must not error on the migrated wisp plane. These read
|
||
# wisps and wisp_dependencies through views the chain rewrites.
|
||
if cand ready >/dev/null 2>&1; then
|
||
pass "bd ready succeeds on the migrated wisp plane"
|
||
else
|
||
fail "bd ready errors after upgrade (migrated wisp schema regression)"
|
||
fi
|
||
if cand blocked >/dev/null 2>&1; then
|
||
pass "bd blocked succeeds on the migrated wisp plane"
|
||
else
|
||
fail "bd blocked errors after upgrade (migrated wisp schema regression)"
|
||
fi
|
||
|
||
# 3. Wisps must stay writable — this is the storage_class default path.
|
||
if cand update "$WISP_ID" --notes "smoke wisp mutation" >/dev/null 2>&1; then
|
||
SHOW_OUT=$(cand show "$WISP_ID" 2>/dev/null || echo "")
|
||
if echo "$SHOW_OUT" | grep -q "smoke wisp mutation"; then
|
||
pass "Wisp writable after upgrade (mutation persisted)"
|
||
else
|
||
fail "Wisp mutation did not persist after upgrade"
|
||
fi
|
||
else
|
||
fail "bd update on a migrated wisp errors after upgrade"
|
||
fi
|
||
|
||
if cand doctor quick >/dev/null 2>&1; then
|
||
pass "bd doctor quick passes on the migrated wisp plane"
|
||
else
|
||
fail "bd doctor quick fails after the wisp upgrade"
|
||
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 ]
|