beads/scripts/test.sh
beads/crew/emma 2137693dad revert: restore embedded Dolt mode (was only supposed to be removed from Gas Town)
Revert commits e5330641 and 0df41523 which removed embedded Dolt mode
from the beads codebase. The embedded Dolt removal was only intended for
Gas Town, not for Beads.

Restores:
- dolthub/driver dependency and embedded connection path
- Advisory flock (AccessLock) for concurrent process protection
- Embedded connector lifecycle management in DoltStore
- All CGO build tags across ~45 files
- Vendored go-icu-regex library
- nocgo stub files for non-CGO builds
- Bootstrap and embedded_uow helpers
- factory_dolt_test.go and dolt_singleprocess_test.go

Merge conflict resolutions:
- store.go: TCP fail-fast check wrapped inside if cfg.ServerMode
- store.go: backtick-quoting for embedded CREATE DATABASE (prefix-based names)
- perf_dolt.go: port references updated from 3306 to 3307
- ci.yml: restored continue-on-error for Nix (dolthub/driver requires Go 1.25.6+)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-07 21:21:24 -08:00

115 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Test runner that automatically skips known broken tests
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SKIP_FILE="$REPO_ROOT/.test-skip"
# ICU4C is keg-only on macOS (Homebrew doesn't symlink it into /opt/homebrew).
# Dolt's go-icu-regex dependency needs these paths to compile and link.
if [[ "$(uname)" == "Darwin" ]]; then
ICU_PREFIX="$(brew --prefix icu4c 2>/dev/null || true)"
if [[ -n "$ICU_PREFIX" ]]; then
export CGO_CFLAGS="${CGO_CFLAGS:+$CGO_CFLAGS }-I${ICU_PREFIX}/include"
export CGO_CPPFLAGS="${CGO_CPPFLAGS:+$CGO_CPPFLAGS }-I${ICU_PREFIX}/include"
export CGO_LDFLAGS="${CGO_LDFLAGS:+$CGO_LDFLAGS }-L${ICU_PREFIX}/lib"
fi
fi
# Build skip pattern from .test-skip file
build_skip_pattern() {
if [[ ! -f "$SKIP_FILE" ]]; then
echo ""
return
fi
# Read non-comment, non-empty lines and join with |
local pattern=$(grep -v '^#' "$SKIP_FILE" | grep -v '^[[:space:]]*$' | paste -sd '|' -)
echo "$pattern"
}
# Default values
TIMEOUT="${TEST_TIMEOUT:-3m}"
SKIP_PATTERN=$(build_skip_pattern)
VERBOSE="${TEST_VERBOSE:-}"
RUN_PATTERN="${TEST_RUN:-}"
COVERAGE="${TEST_COVER:-}"
COVERPROFILE="${TEST_COVERPROFILE:-/tmp/beads.coverage.out}"
COVERPKG="${TEST_COVERPKG:-}"
# Parse arguments
PACKAGES=()
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose)
VERBOSE="-v"
shift
;;
-timeout)
TIMEOUT="$2"
shift 2
;;
-run)
RUN_PATTERN="$2"
shift 2
;;
-skip)
# Allow additional skip patterns
if [[ -n "$SKIP_PATTERN" ]]; then
SKIP_PATTERN="$SKIP_PATTERN|$2"
else
SKIP_PATTERN="$2"
fi
shift 2
;;
*)
PACKAGES+=("$1")
shift
;;
esac
done
# Default to all packages if none specified
if [[ ${#PACKAGES[@]} -eq 0 ]]; then
PACKAGES=("./...")
fi
# Build go test command
CMD=(go test -timeout "$TIMEOUT")
if [[ -n "$VERBOSE" ]]; then
CMD+=(-v)
fi
if [[ -n "$SKIP_PATTERN" ]]; then
CMD+=(-skip "$SKIP_PATTERN")
fi
if [[ -n "$RUN_PATTERN" ]]; then
CMD+=(-run "$RUN_PATTERN")
fi
if [[ -n "$COVERAGE" ]]; then
CMD+=(-covermode=atomic -coverprofile "$COVERPROFILE")
if [[ -n "$COVERPKG" ]]; then
CMD+=(-coverpkg "$COVERPKG")
fi
fi
CMD+=("${PACKAGES[@]}")
echo "Running: ${CMD[*]}" >&2
echo "Skipping: $SKIP_PATTERN" >&2
echo "" >&2
"${CMD[@]}"
status=$?
if [[ -n "$COVERAGE" ]]; then
total=$(go tool cover -func="$COVERPROFILE" | awk '/^total:/ {print $NF}')
echo "Total coverage: ${total} (profile: ${COVERPROFILE})" >&2
fi
exit $status