beads/scripts/migration-test/lib/binary.sh
matt wilkie e4fca03f6b
feat: add migration test harness for cross-era upgrade fidelity (#3067)
* wip: add migration test harness for cross-era upgrade fidelity

Rich dataset generator, field-level fidelity checker, and migration
recipes for SQLite/Dolt-server/embedded-Dolt eras. Addresses GH#2938
upgrade pain by testing and documenting working upgrade paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: snapshot JSON format handling and self-test mode

- show --json returns array, not object — use jq array concatenation
- Field is issue_type not type in bd JSON output
- Normalize empty comment_count to 0 (show vs list field differences)
- Add --self-test flag for harness validation without old binaries
- Fix local variable outside function in self-test block

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* ci: re-trigger Kilo Code Review

* address review: timeouts, env var docs, quoting

- Add BD_OP_TIMEOUT (30s) for bd operations via timeout(1)
- Add DOWNLOAD_TIMEOUT (60s) for curl binary downloads
- Document all environment variables in run.sh header
- Convert init_flags from word-split string to proper bash array

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: fall back to source build when release binary has missing shared libs

Downloaded release binaries dynamically link ICU (libicui18n.so.74),
which isn't available on all systems. Now download_binary verifies the
binary actually runs, and falls back to building from source with
gms_pure_go tag when it doesn't. Also applies gms_pure_go to
build_candidate for consistency.

Ref: gastownhall/beads#3065

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 14:30:35 -07:00

104 lines
3.4 KiB
Bash
Executable file

#!/bin/bash
# Binary management — download old releases, build candidate.
# Extracted from cross-version-smoke-test.sh for reuse.
CACHE_DIR="${HOME}/.cache/beads-regression"
mkdir -p "$CACHE_DIR"
DOWNLOAD_TIMEOUT="${DOWNLOAD_TIMEOUT:-60}"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
esac
download_binary() {
local version="$1"
local ver_bare="${version#v}"
local cached="$CACHE_DIR/bd-${ver_bare}"
if [ -x "$cached" ]; then
# Verify the cached binary actually runs (shared lib deps satisfied)
if "$cached" version >/dev/null 2>&1; then
echo "$cached"
return
fi
echo -e " ${YELLOW:-}cached binary broken (missing libs?), rebuilding...${NC:-}" >&2
rm -f "$cached"
fi
# Try downloading the release binary first
local asset="beads_${ver_bare}_${OS}_${ARCH}.tar.gz"
local url="https://github.com/steveyegge/beads/releases/download/${version}/${asset}"
echo -e " ${YELLOW:-}downloading ${version}...${NC:-}" >&2
local tmpdir
tmpdir=$(mktemp -d)
if curl -fsSL --max-time "$DOWNLOAD_TIMEOUT" "$url" -o "$tmpdir/archive.tar.gz" 2>/dev/null; then
tar -xzf "$tmpdir/archive.tar.gz" -C "$tmpdir"
local bd_path
bd_path=$(find "$tmpdir" -name bd -type f | head -1)
if [ -n "$bd_path" ]; then
cp -f "$bd_path" "$cached"
chmod +x "$cached"
rm -rf "$tmpdir"
# Verify it actually runs
if "$cached" version >/dev/null 2>&1; then
echo "$cached"
return
fi
echo -e " ${YELLOW:-}downloaded binary unusable (missing shared libs), building from source...${NC:-}" >&2
rm -f "$cached"
else
rm -rf "$tmpdir"
fi
else
rm -rf "$tmpdir"
fi
# Fallback: build from source at the given tag
build_from_source "$version" "$cached"
}
# Build a specific version from source by checking out its tag in a temp dir.
build_from_source() {
local version="$1"
local output="$2"
echo -e " ${YELLOW:-}building ${version} from source...${NC:-}" >&2
local srcdir
srcdir=$(mktemp -d)
if ! git clone --depth 1 --branch "$version" "$PROJECT_ROOT" "$srcdir" 2>/dev/null; then
# Tag might not exist locally; try the remote
if ! git clone --depth 1 --branch "$version" \
"https://github.com/steveyegge/beads.git" "$srcdir" 2>/dev/null; then
rm -rf "$srcdir"
echo -e " ${RED:-}ERROR: cannot clone tag ${version}${NC:-}" >&2
return 1
fi
fi
# Use gms_pure_go to avoid ICU header dependency; fall back to plain build
if ! (cd "$srcdir" && go build -tags gms_pure_go -o "$output" ./cmd/bd) 2>&1 | tail -5 >&2; then
rm -rf "$srcdir"
return 1
fi
chmod +x "$output"
rm -rf "$srcdir"
echo "$output"
}
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 -tags gms_pure_go -o "$candidate" ./cmd/bd) >&2
echo "$candidate"
}