beads/scripts/ci/install-dolt.sh
Julian Knutsen 469462d56a
test(bazel): run every Bazel test against a hermetic, pinned dolt CLI (#6853)
* test(bazel): run every test against a hermetic, pinned dolt CLI (slice B4)

Tests that shell out to dolt ran whatever /usr/local/bin/dolt the executor
had, a version outside the action key, and skipped (a vacuous, cacheable
PASS) on an executor without one.

- tools/bazel/dolt.bzl: dolt_release repository rule fetching the upstream
  release pinned to scripts/ci/install-dolt.sh (2.2.0), sha256 for
  linux/darwin amd64/arm64; MODULE.bazel declares one repo per platform and
  //tools/bazel:dolt selects the one for the execution platform.
- //tools/bazel:test_env (the --run_under wrapper) carries the pinned dolt
  as data. Bazel merges the run_under runfiles into every test's runfiles, so
  every test action declares dolt as an input; test_env.sh puts it first on
  PATH, exports BEADS_TEST_DOLT_BINARY, and fails the test if it is missing.
  DOLT_ROOT_PATH identity seeding stays in test_env.sh.
- testutil.requireDoltBinaryPresent fails instead of skipping under Bazel.
- TestPinnedDoltCLIMatchesContainerImage also checks tools/bazel/dolt.bzl.
  scripts_test declares the pin files and resolves the repo root through
  bazeltest, so the three dolt pin tests now pass under bazel test.

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

* test(bazel): declare the Go source dolt_test's scope guards scan

TestEveryRawTxJournalScopeIsScopedOrExempt, TestEveryRawTxVersionScopeIsScopedOrExempt,
TestTxMintingWrappersScopeVersionedHistory and TestHelperSubprocessSentinelsAreComplete
parse internal/storage/dolt and internal/storage/issueops at test time; under
bazel test that source was not in the runfiles, so all four failed.

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

* fix(bazel): tie hermetic dolt download to its version; skip on unpinned platforms

- Key DOLT_SHA256 by version and pass canonical_id=url, so bumping
  DOLT_VERSION without new digests fails instead of silently reusing the
  previous release from the sha256-keyed repository cache.
- //tools/bazel:dolt_version_test runs the hermetic dolt and checks it
  reports DOLT_VERSION.
- Unpinned platforms (e.g. windows) resolve to an incompatible target, so
  bazel build //... skips the wrapper there instead of failing analysis.
- test_env.sh also unsets BEADS_DOLT_BIN so it cannot bypass the pin.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 14:29:49 -07:00

84 lines
3.6 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
# Install a pinned Dolt CLI. Every CI job that needs `dolt` on PATH must go
# through this script instead of piping the upstream install.sh from
# releases/latest, because "latest" silently changes the binary under test.
#
# Keep this version in sync with internal/testutil/testdoltcommon.go:
# DoltDockerImage, scripts/ci/pull-dolt-image.sh and tools/bazel/dolt.bzl
# (DOLT_VERSION plus its per-platform sha256). Tests run the CLI (the
# per-test sql-server that doltserver.Start launches) and the container
# side by side against the same databases; letting the two drift means the
# suite is exercising a Dolt pair no release ever shipped.
#
# Why pinned rather than latest: Dolt 2.3.0 (released 2026-08-13) regressed
# CALL DOLT_RESET('--hard') so that roughly one freshly created database in
# twenty comes up with the procedure permanently broken --
# "Error 1105 (HY000): context canceled" on every connection, from any
# session, for the life of the server process. Measured 2026-08-20 by
# creating fresh databases and immediately calling the procedure: 2.1.8 0/40
# broken, 2.2.0 0/60, 2.3.0 3/60, 2.3.1 3/100. That is what made
# TestFreshBootstrapHealIncarnation fail on a coin flip the day
# releases/latest moved to 2.3.x, and it also puts bd dolt compact/flatten
# and the #4566 fresh-bootstrap heal at risk on 2.3.x. Raise this pin only
# once a Dolt release is confirmed clean by that same measurement.
readonly version="2.2.0"
readonly max_attempts=3
readonly retry_delay_seconds=5
arch="$(uname -m)"
case "$arch" in
x86_64 | amd64) arch="amd64" ;;
aarch64 | arm64) arch="arm64" ;;
*)
printf 'Unsupported architecture for pinned dolt install: %s\n' "$arch" >&2
exit 1
;;
esac
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
readonly asset="dolt-${os}-${arch}.tar.gz"
readonly url="https://github.com/dolthub/dolt/releases/download/v${version}/${asset}"
workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT
for ((attempt = 1; attempt <= max_attempts; attempt++)); do
# Capture curl's status directly. `status=$?` after an `if curl ...; then
# break; fi` reads the status of the *if compound*, which is 0 when the
# condition fails and there is no else branch -- so a download that never
# succeeded exited 0 and the job carried on with whatever dolt was already
# on PATH, which is exactly the unpinned binary this script exists to
# prevent.
status=0
curl -fsSL -o "$workdir/$asset" "$url" || status=$?
if ((status == 0)); then
break
fi
if ((attempt == max_attempts)); then
printf 'Failed to download %s after %d attempts (curl exit %d).\n' "$url" "$max_attempts" "$status" >&2
exit "$status"
fi
printf 'Failed to download %s (attempt %d/%d); retrying in %d seconds.\n' \
"$url" "$attempt" "$max_attempts" "$retry_delay_seconds" >&2
sleep "$retry_delay_seconds"
done
tar -xzf "$workdir/$asset" -C "$workdir"
sudo install -m 0755 "$workdir/dolt-${os}-${arch}/bin/dolt" /usr/local/bin/dolt
# Fail loudly if PATH resolves to some other dolt: a stale runner-image copy
# earlier on PATH would silently put the suite back on an unpinned binary.
# No `| head` here: pipefail turns dolt's SIGPIPE into a failed install.
# Compare the version token exactly rather than as a substring: `*"2.2.0"*`
# also matches 12.2.0 and 2.2.0-rc1, so a substring test would wave through
# releases the pin exists to keep out.
installed="$(dolt version)"
installed="${installed%%$'\n'*}"
if [[ "${installed##* }" != "$version" ]]; then
printf 'dolt on PATH reports "%s", want version %s (which dolt: %s)\n' \
"$installed" "$version" "$(command -v dolt)" >&2
exit 1
fi
printf 'Installed pinned %s\n' "$installed"