ci(bazel): PR-gate parity lanes (docker, pure-Go, js/wasm) + bd artifact (#6887)

* test(bazel): require exclude read-permission coverage in test:prcore

pr.yml's PR Core step sets BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1 so
TestAddExcludePatternsRefusesReadErrors fails, rather than skips, on a root
or non-POSIX executor. test:prcore now sets it too, and a policy test keeps
the two in step.

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

* feat(bazel): compare Bazel runs with one CI job's go test results

equivalence.py --job takes a job's `go test -json` as the complete expected
set, so a Bazel selection can be shown to replace that job: every top-level
test the job ran must run under Bazel, no other test in those packages may,
and nothing the job passed may be skipped. --bep is repeatable (a job can map
to --config=ci plus --config=docker), and go_test_variant.sh sh_tests count,
since their go_test binary writes the same test.xml. In job mode a test seen
in several targets keeps its best status: the prcore run skips what the
docker variant exists to run.

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

* test(bazel): docker-lane variant for internal/tracker

pr.yml's "Test (storage domain + uow)" job runs ./internal/tracker/... with
-race and without -short or BEADS_TEST_SKIP=dolt, so tracker's TestMain
starts the shared dolt container and all 112 top-level tests run. Under
--config=prcore they skip. tracker_docker_test reruns tracker_test that way
in the docker lane, and tracker's TestMain now fails instead of skipping when
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 and the container does not start.

The job's other packages (storage/domain, domain/fs, domain/git,
tracker/conformance) consult neither testing.Short nor the dolt skip, and
pass identically under --config=ci.

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

* ci(bazel): publish the Bazel-built bd as a ci-build-artifacts artifact

pr.yml's build-artifacts job uploads ci-build-artifacts (bd-linux-gms-pure,
SHA256SUMS, build-manifest.txt), which PR Core, the domain+uow job and both
package gates download and check with `sha256sum -c`. The Bazel lane now
uploads the same name and layout from //cmd/bd:bd_for_tests, the non-race
gms_pure_go cgo bd its own tests exec (//cmd/bd:bd is race-built under
--config=ci); test:ci downloads it under --remote_download_minimal. No
consumer is repointed yet.

A rules_go binary has no vcs.* or CGO_ENABLED build settings: `bd version`
shows no commit, and scripts/verify-cgo.sh would pass it vacuously. No
consumer of this artifact reads either; the manifest records the commit.

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

* ci(bazel): pure-Go and js/wasm lane for pr.yml's boundary job

pr.yml's "Check pure-Go and js/wasm boundaries (CGO_ENABLED=0)" job builds
bd and three test binaries with CGO off, runs a 16-name -short cmd/bd subset,
and runs the js/wasm hook refusal test under node with an exact count guard.
bazel.yml's new bazel-pure job does the same with Bazel binaries:

- --config=pure (--@rules_go//go/config:pure, -test.short) builds //cmd/bd:bd,
  bd_test, embeddeddolt_test and tracker_test, and runs bd_test unsharded
  with the job's -run selector (policy-tested to stay equal to pr.yml's).
- --config=js-wasm builds //internal/hooks:hooks_test for js/wasm
  (--use_target_platform_for_tests satisfies the test toolchain; nothing is
  tested by Bazel under it); the Go SDK's go_js_wasm_exec runs it under node
  with pr.yml's selector and count guard, verbatim.

rules_go compiles every declared dep, and gazelle's deps ignore the cgo
constraint of beads' embedded-Dolt files, so a pure build compiled dolt's
store/nbs and failed in github.com/dolthub/gozstd (cgo only; go build never
imports it with CGO_ENABLED=0). third_party/patches/gozstd_nocgo.patch adds
panicking !cgo stubs for the API dolt uses.

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

* test(bazel): run prcore tests with -test.parallel=4 like pr-core.sh

pr-core.sh runs go test -parallel 4. test:prcore passed no -test.parallel,
so Go defaulted to GOMAXPROCS: the executor's core count (192 on a farm
worker) instead of a runner's 4, which let dozens of t.Parallel bd
subprocesses run at once. A policy test keeps the value equal to
pr-core.sh's GO_TEST_PARALLEL default.

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

* test(bazel): -test.parallel=4 in the pure lane

pr.yml's pure-Go job passes no -parallel, so go test uses GOMAXPROCS, 4 on
ubuntu-latest; under Bazel the default would be the executor's core count.

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

* test(bazel): run the contract corpus non-race in the docker lane

pr.yml's Contract corpus job runs go test ./cmd/bd/protocol without -race,
but --config=docker races every target. protocol_docker_test now runs
:protocol_race_off, protocol_test built through a race=false transition
(tools/bazel/race.bzl), so no second go_test rule has to track gazelle's
srcs. Tagged manual so other lanes do not build it; the extra non-race work
is protocol_test's link plus ~100 test-only libraries.

The docker lane also mirrors the jobs' concurrency now: they pass no -p or
-parallel, so go test uses GOMAXPROCS, 4 on ubuntu-latest, for both; the
lane runs at most 4 test processes (so at most 4 dolt containers start at
once) with -test.parallel=4. It writes -test.v test.xml like test:ci, for
equivalence.py.

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

* ci(bazel): run the docker lane in bazel.yml

New advisory job bazel-docker runs `bazel test //... --config=docker` on
ubuntu-latest after pre-pulling the dolt image like pr.yml's container jobs.
The requires-docker variants (domain/db, uow, tracker, doctor/fix,
protocol) run on the runner against its docker daemon (no-remote-exec);
their builds use remote execution when setup-bazel configured it. With
bazel-test's --config=ci this covers "Test (storage domain + uow)" and
"Contract corpus". The lane name is one env var, so a hermetic dolt-server
lane can replace it.

Policy tests now cover every bazel.yml job: an exact job list, timeouts, no
continue-on-error, pinned actions (setup-node added), one setup-bazel step
per job as the only secret reader, cache saves only in bazel-test, plus
job-specific mirrors of pr.yml (the docker job's runner, image pull and
lane; a requires-docker target in each container-backed package).

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

* perf(bazel): build the non-race contract corpus in bd_for_tests' configuration

go_test_race_off only set race=false, while rules_go's go_transition (as
used by //cmd/bd:bd_for_tests, race = "off") also records the overridden
value in original_race. The two non-race configurations differed, so the
docker lane (and --config=ci, which builds protocol_docker_test through
//...) compiled the whole dolt graph twice without race. Record
original_race the same way: aquery GoCompilePkg for
deps(protocol_docker_test) under race drops from ~2630 actions in two
configurations to 1359 in one.

Fix the BUILD comment: manual does not keep protocol_race_off out of other
lanes' builds; protocol_docker_test pulls it in.

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

* fix(bazel): job-mode equivalence fails on any target's failure or missing test.xml

In --job mode a test seen in several targets keeps its best status, so a
failure in one variant was hidden when another target passed the test, and
a go_test_variant.sh sh_test without a test.xml was skipped silently. List
every failed test per target and every target in the job's packages whose
test.xml is missing, and fail on either.

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

* fix(bazel): gate pure-lane contamination, never cache docker-lane results

- gozstd_nocgo.patch: the stubs' package init panics, so a pure binary
  that links gozstd (which CGO_ENABLED=0 go build rejects at compile time)
  fails at startup. bazel-pure starts every pure artifact (bd version, and
  embeddeddolt_test/tracker_test with -test.run=^$; bd_test runs its
  subset) so contamination fails the lane.
- test:docker --nocache_test_results: the requires-docker variants depend on
  host state no action key covers, like the container jobs' -count=1.
  build:remote-exec --noremote_upload_local_results in the committed rc, so
  local runs cannot seed the shared cache with host-dependent results.
- The artifact packaging moves to scripts/ci/package-bazel-bd.sh, which
  sources .buildflags itself; sourcing it in bazel.yml exempted the whole
  workflow from the build-tag scan.
- bazel-pure and bazel-docker use bazel-test's runs-on (Blacksmith when
  remote execution is possible); the policy test pins it for every job.

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

* ci(bazel): put the pure and docker lanes behind the rbe-west gate

Apply bazel-test's rbe-west setup-bazel env (RBE_WEST_EXECUTOR, instance
oss, RBE_WEST_WORKERS) and its job if to bazel-pure and bazel-docker, so
same-repo runs of all three lanes skip together until the variable is set
and forks and rbe=off dispatches still run locally. The policy test pins
runs-on, if and the setup-bazel env for every bazel.yml job.

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

* fix(ci): run the js/wasm hook test with a minimal environment

wasm_exec.js caps argv+env size, and the Blacksmith runner's environment
exceeds it ("total length of command line and environment variables
exceeds limit").

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-09-28 02:03:51 -07:00 • committed by GitHub
commit fc4d7d3958
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 858 additions and 52 deletions

View file

@ -26,8 +26,14 @@ test --test_env=BD_DISABLE_EVENT_FLUSH=1
# -short, skips, tag filters); the environment comes from the wrapper above.
test:prcore --@rules_go//go/config:race
test:prcore --test_arg=-test.short
# pr-core.sh's -parallel 4. Without it -test.parallel defaults to GOMAXPROCS,
# the executor's core count (192 on a farm worker), not a runner's 4.
test:prcore --test_arg=-test.parallel=4
test:prcore --test_arg=-test.skip=^TestEmbedded
test:prcore --test_env=BEADS_TEST_SKIP=dolt
# As in pr.yml's PR Core step: a root or non-POSIX executor fails
# TestAddExcludePatternsRefusesReadErrors instead of skipping it.
test:prcore --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1
test:prcore --test_tag_filters=-requires-docker,-embedded,-manual
test:ci --config=prcore
@ -38,16 +44,55 @@ test:ci --keep_going --test_summary=terse
# test.xml on the remote side, so ask for both.
test:ci --test_env=GO_TEST_WRAP_TESTV=1
test:ci --remote_download_regex=.*/test\.xml$
# bazel.yml publishes the non-race bd as pr.yml's ci-build-artifacts.
test:ci --remote_download_regex=.*/bin/cmd/bd/bd_for_tests/bd$
# Docker lane: only the requires-docker targets (pr.yml's container-backed
# jobs), on a host with a docker daemon. Race like those jobs, but no -short
# and no BEADS_TEST_SKIP=dolt, which would keep the containers from starting.
# Those targets are also tagged no-remote-exec, so they run on the host even
# with --config=remote-exec.
# jobs "Test (storage domain + uow)" and "Contract corpus"), on a host with a
# docker daemon. Race like the domain+uow job (//cmd/bd/protocol's variant
# opts out, like the non-race Contract corpus job), but no -short and no
# BEADS_TEST_SKIP=dolt, which would keep the containers from starting. Those
# targets are also tagged no-remote-exec, so they run on the host even with
# --config=remote-exec; their builds may still run remotely. -test.v in
# test.xml, as in test:ci, lets equivalence.py see which tests ran.
test:docker --@rules_go//go/config:race
test:docker --test_tag_filters=requires-docker
test:docker --build_tests_only
test:docker --keep_going
test:docker --test_env=GO_TEST_WRAP_TESTV=1
# Those jobs pass no -p/-parallel, so go test uses GOMAXPROCS, ubuntu-latest's
# 4 vCPUs, for both. Match that on any host: 4 test processes (hence at most
# 4 dolt containers starting at once) and -test.parallel=4.
test:docker --local_test_jobs=4
test:docker --test_arg=-test.parallel=4
# The variants depend on host state no action key sees (the docker daemon,
# the pulled dolt image, the network), so a cached result proves nothing about
# this host: always run them, like the jobs' `go test -count=1`.
test:docker --nocache_test_results
# Pure-Go lane: pr.yml's "Check pure-Go and js/wasm boundaries
# (CGO_ENABLED=0)" job. CGO is off for every Go target (rules_go drops
# cgo-constrained files like go build does; third_party/patches/
# gozstd_nocgo.patch lets dolt's store/nbs, an unused but declared dep,
# compile; its package init panics, so a pure binary that links it fails when
# run). bazel.yml builds bd and the job's pure test binaries, runs each of
# them once (the contamination check `go build` does at compile time) and runs
# its -short cmd/bd subset.
build:pure --@rules_go//go/config:pure
test:pure --test_arg=-test.short
# The job passes no -parallel: GOMAXPROCS on a 4-vCPU runner.
test:pure --test_arg=-test.parallel=4
test:pure --test_env=GO_TEST_WRAP_TESTV=1
test:pure --remote_download_regex=.*/test\.xml$
# js/wasm hook boundary (same job): build for GOOS=js GOARCH=wasm. Bazel
# cannot run the wasm test binary itself; bazel.yml runs it with the Go SDK's
# go_js_wasm_exec (node), like `go test -exec`. The test toolchain needs an
# exec platform matching the target platform, hence
# --use_target_platform_for_tests (no test action runs under this config).
build:js-wasm --platforms=@rules_go//go/toolchain:js_wasm
build:js-wasm --use_target_platform_for_tests
build:js-wasm --remote_download_outputs=toplevel
# Remote execution against any REAPI-compatible service. Only generic tuning
# lives here; the executor endpoint and TLS credentials are never committed.
@ -57,6 +102,10 @@ build:remote-exec --jobs=64
build:remote-exec --remote_download_minimal
build:remote-exec --remote_timeout=600
build:remote-exec --remote_retries=3
# Upload only remotely executed results. A locally executed action (a
# no-remote-exec test, a host-dependent docker-lane result) must not seed the
# shared cache that CI and every other developer read.
build:remote-exec --noremote_upload_local_results
try-import %workspace%/.bazelrc.local
try-import %workspace%/user.bazelrc

View file

@ -23,7 +23,8 @@
# write the runner cache. In place: secrets are referenced by the setup step
# alone and never by a workflow- or job-level env (policy-tested), decoded key
# material is masked in logs, and CI uploads only remotely executed results
# (--noremote_upload_local_results in the generated rc), and the certificate
# (--noremote_upload_local_results in .bazelrc's remote-exec config and in
# the generated rc), and the certificate
# is issued to beads CI alone, so it can be revoked without affecting other
# clients. Maintainers decided (2026-09-28) that same-repo PRs keep remote
# execution under this model. Still open: a beads-only RBE_INSTANCE and
@ -173,6 +174,25 @@ jobs:
echo >> "$GITHUB_STEP_SUMMARY"
exit "$rc"
# pr.yml's build-artifacts job, built by Bazel: the same artifact name
# and layout (bd-linux-gms-pure, SHA256SUMS, build-manifest.txt), so its
# consumers (PR Core, domain+uow, the package gates) can switch to it.
# None does yet. The script documents which binary and how it differs
# from `go build`'s.
- name: Package bd (ci-build-artifacts layout)
id: bd-artifact
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: ./scripts/ci/package-bazel-bd.sh "$RUNNER_TEMP/bd-artifacts"
- name: Upload build artifacts
if: ${{ always() && steps.bd-artifact.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-build-artifacts
path: ${{ runner.temp }}/bd-artifacts/
retention-days: 1
if-no-files-found: error
- name: Critical-path report
if: ${{ always() && steps.test.outcome != 'skipped' }}
env:
@ -248,3 +268,177 @@ jobs:
with:
path: ${{ runner.temp }}/bazel-ci-cache
key: bazel-repo-v2-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel.lock') }}
# pr.yml's check-cmd-bd-puregeo-tests job ("Check pure-Go and js/wasm
# boundaries (CGO_ENABLED=0)") with Bazel-built binaries: --config=pure
# builds bd and the job's three pure test binaries and runs its -short
# cmd/bd subset (PURE_CMD_BD_TESTS, kept equal to the job's -run selector by
# scripts/ci_workflow_test.go); --config=js-wasm builds the hooks test for
# js/wasm, which the Go SDK's go_js_wasm_exec runs under node with the job's
# exact pass-count guard.
bazel-pure:
name: Bazel / pure-Go and js/wasm (advisory)
# Same runner, rbe-west gate and skip rule as bazel-test.
runs-on: ${{ (inputs.rbe || 'on') != 'off' && github.event.pull_request.head.repo.fork != true && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ vars.RBE_WEST_WORKERS == 'true' || inputs.rbe == 'off' || github.event.pull_request.head.repo.fork == true }}
timeout-minutes: 90
env:
PURE_CMD_BD_TESTS: '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag)'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
# Only for go_js_wasm_exec and wasm_exec_node.js, which must match the
# Go version Bazel compiles with (go.mod's; policy-tested).
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
cache: false
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
with:
node-version: '24'
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && 'oss' || '' }}
- name: Run js/wasm hook boundary
run: |
set -euo pipefail
bazel build --config=js-wasm //internal/hooks:hooks_test
bin="$(bazel cquery --config=js-wasm --output=files //internal/hooks:hooks_test)"
cd internal/hooks
# Same selector and count guard as pr.yml's job.
test_status=0
# wasm_exec.js caps argv+env size; the Blacksmith runner's environment
# exceeds it, so run with only what the hook test needs.
wasm_exec="$(go env GOROOT)/lib/wasm/go_js_wasm_exec"
test_output="$(env -i PATH="$PATH" HOME="$HOME" TMPDIR="$RUNNER_TEMP" \
BD_DISABLE_METRICS=1 BD_DISABLE_EVENT_FLUSH=1 \
"$wasm_exec" "$GITHUB_WORKSPACE/$bin" \
-test.run '^TestRunHookReportsUnsupportedExecution$' \
-test.v 2>&1)" || test_status=$?
printf '%s\n' "$test_output"
(( test_status == 0 )) || exit "$test_status"
run_count=0
pass_count=0
nonpass_count=0
pass_pattern='^--- PASS: TestRunHookReportsUnsupportedExecution \([0-9.]+s\)$'
nonpass_pattern='^[[:space:]]*--- (FAIL|SKIP): '
while IFS= read -r line; do
if [[ "$line" == "=== RUN TestRunHookReportsUnsupportedExecution" ]]; then
((run_count += 1))
fi
if [[ "$line" =~ $pass_pattern ]]; then
((pass_count += 1))
fi
if [[ "$line" =~ $nonpass_pattern ]]; then
((nonpass_count += 1))
fi
done <<< "$test_output"
if (( run_count != 1 || pass_count != 1 || nonpass_count != 0 )); then
printf 'expected one exact js/wasm hook test run and pass with no failures or skips; got runs=%s passes=%s nonpasses=%s\n' \
"$run_count" "$pass_count" "$nonpass_count" >&2
exit 1
fi
- name: Build cmd/bd and pure-Go test binaries (--config=pure)
run: >-
bazel build --config=pure
//cmd/bd:bd
//cmd/bd:bd_test
//internal/storage/embeddeddolt:embeddeddolt_test
//internal/tracker:tracker_test
# `go build` with CGO_ENABLED=0 rejects a pure binary whose imports reach
# dolt's cgo-only store/nbs (gozstd). Bazel compiles gozstd's pure stubs
# instead, whose init panics (third_party/patches/gozstd_nocgo.patch), so
# the check happens here: every pure artifact is started once. bd_test
# starts in the next step. -test.run=^$ runs no test (TestMain still
# runs; BEADS_TEST_SKIP=dolt keeps tracker's from starting a container).
- name: Start every pure-Go artifact (gozstd contamination check)
run: |
set -euo pipefail
bazel run --config=pure //cmd/bd:bd -- version
bazel test --config=pure \
//internal/storage/embeddeddolt:embeddeddolt_test \
//internal/tracker:tracker_test \
--test_sharding_strategy=disabled \
'--test_arg=-test.run=^$' \
--test_env=BEADS_TEST_SKIP=dolt
# One unsharded process, like `go test -run`; the test.xml check keeps a
# selector that matches nothing from passing.
- name: Run pure-Go cmd/bd test subset (--config=pure)
run: |
set -euo pipefail
bazel test --config=pure //cmd/bd:bd_test \
--test_sharding_strategy=disabled \
"--test_arg=-test.run=$PURE_CMD_BD_TESTS"
n="$(grep -c '<testcase ' bazel-testlogs/cmd/bd/bd_test/test.xml || true)"
echo "pure cmd/bd subset: $n test cases"
(( n > 0 ))
# pr.yml's container-backed jobs, "Test (storage domain + uow)" and
# "Contract corpus", as Bazel's docker lane: --config=docker runs the
# requires-docker variants (domain/db, uow, tracker, doctor/fix, protocol)
# on this runner against its docker daemon (they are no-remote-exec);
# builds still execute remotely when configured. The other packages of the
# domain+uow job pass identically under bazel-test's --config=ci. The lane
# is named in one variable, so a hermetic dolt-server lane can replace it.
bazel-docker:
name: Bazel / docker lane (advisory)
# Same runner, rbe-west gate and skip rule as bazel-test.
runs-on: ${{ (inputs.rbe || 'on') != 'off' && github.event.pull_request.head.repo.fork != true && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ vars.RBE_WEST_WORKERS == 'true' || inputs.rbe == 'off' || github.event.pull_request.head.repo.fork == true }}
timeout-minutes: 90
env:
BAZEL_DOCKER_LANE: docker
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && 'oss' || '' }}
# As in the mirrored jobs; tests fail rather than skip without it.
- name: Pull Dolt sql-server image
run: ./scripts/ci/pull-dolt-image.sh
- name: bazel test //... --config=docker
id: test
timeout-minutes: 80
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... "--config=$BAZEL_DOCKER_LANE" 2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=$BAZEL_DOCKER_LANE: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
- name: Upload test logs
if: ${{ failure() && steps.test.outcome == 'failure' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-docker-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7

View file

@ -43,6 +43,13 @@ go_deps.module_override(
patches = ["//third_party/patches:dolt_go_serial.patch"],
path = "github.com/dolthub/dolt/go",
)
# Pure-Go stubs so --config=pure can compile dolt's store/nbs (see the patch).
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:gozstd_nocgo.patch"],
path = "github.com/dolthub/gozstd",
)
use_repo(go_deps, "com_github_anthropics_anthropic_sdk_go", "com_github_burntsushi_toml", "com_github_cenkalti_backoff_v4", "com_github_charmbracelet_x_ansi", "com_github_data_dog_go_sqlmock", "com_github_dolthub_dolt_go", "com_github_dolthub_driver_v2", "com_github_dolthub_eventkit", "com_github_dolthub_go_mysql_server", "com_github_go_sql_driver_mysql", "com_github_google_uuid", "com_github_gowebpki_jcs", "com_github_invopop_jsonschema", "com_github_johanneskaufmann_html_to_markdown_v2", "com_github_mattn_go_sqlite3", "com_github_microcosm_cc_bluemonday", "com_github_oapi_codegen_oapi_codegen_v2", "com_github_olebedev_when", "com_github_spf13_cobra", "com_github_spf13_pflag", "com_github_spf13_viper", "com_github_stretchr_testify", "com_github_subosito_gotenv", "com_github_testcontainers_testcontainers_go", "com_github_testcontainers_testcontainers_go_modules_dolt", "com_github_yuin_goldmark", "in_gopkg_yaml_v3", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlpmetric_otlpmetrichttp", "io_opentelemetry_go_otel_exporters_stdout_stdoutmetric", "io_opentelemetry_go_otel_exporters_stdout_stdouttrace", "io_opentelemetry_go_otel_metric", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_sdk_metric", "io_opentelemetry_go_otel_trace", "io_rsc_script", "land_charm_glamour_v2", "land_charm_huh_v2", "land_charm_lipgloss_v2", "org_golang_x_mod", "org_golang_x_net", "org_golang_x_sync", "org_golang_x_sys", "org_golang_x_term")
# Hermetic Dolt CLI for tests (tools/bazel/dolt.bzl pins the release to

View file

@ -1,5 +1,6 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//tools/bazel:race.bzl", "go_test_race_off")
go_library(
name = "protocol",
@ -51,11 +52,32 @@ go_test(
],
)
# protocol_test as pr.yml's "Contract corpus" job runs it: TestMain starts a
# dolt sql-server container and BEADS_PROTOCOL_REQUIRE_DOLT=1 turns a missing
# container into a failure instead of a skip. It repeats protocol_test's `env`
# (go_test_variant.sh cannot inherit it). protocol_test itself stays untagged:
# under --config=prcore (BEADS_TEST_SKIP=dolt) its Dolt-backed tests skip.
# protocol_test without the race detector, which --config=docker otherwise
# turns on for every target: pr.yml's "Contract corpus" job runs
# `go test ./cmd/bd/protocol` without -race (PR Core covers the race build).
# Matching it is cheap: tools/bazel/race.bzl lands protocol_test's deps in
# the configuration the non-race //cmd/bd:bd_for_tests already builds them in,
# so the extra work is protocol_test's test-only libraries and one link.
# Racing it instead would also be acceptable (a race-only failure is a real
# bug); then drop this target and point protocol_docker_test back at
# :protocol_test.
#
# Tags:
# manual: only protocol_docker_test's input, never a build target of its
# own. `bazel test //...` in every lane still builds it through
# protocol_docker_test (a test tag filter does not stop the build).
go_test_race_off(
name = "protocol_race_off",
tags = ["manual"],
test = ":protocol_test",
)
# protocol_test as pr.yml's "Contract corpus" job runs it: non-race, TestMain
# starts a dolt sql-server container and BEADS_PROTOCOL_REQUIRE_DOLT=1 turns a
# missing container into a failure instead of a skip. It repeats
# protocol_test's `env` (go_test_variant.sh cannot inherit it). protocol_test
# itself stays untagged: under --config=prcore (BEADS_TEST_SKIP=dolt) its
# Dolt-backed tests skip.
#
# Tags:
# requires-docker: needs a docker daemon; excluded from --config=prcore/ci,
@ -65,9 +87,9 @@ sh_test(
name = "protocol_docker_test",
size = "large",
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :protocol_test)"],
args = ["$(rootpath :protocol_race_off)"],
data = [
":protocol_test",
":protocol_race_off",
"//cmd/bd:bd_for_tests",
],
env = {

View file

@ -1,4 +1,5 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
go_library(
name = "tracker",
@ -58,3 +59,26 @@ go_test(
"//internal/types",
],
)
# tracker_test as pr.yml's "Test (storage domain + uow)" job runs it: no
# -short and no BEADS_TEST_SKIP=dolt, so TestMain starts the shared dolt
# sql-server container, and BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 turns a missing
# container into a failure instead of a suite of skips. tracker_test itself
# stays untagged: under --config=prcore its Dolt-backed tests skip.
#
# Tags:
# requires-docker: needs a docker daemon; excluded from --config=prcore/ci,
# selected by --config=docker.
# no-remote-exec: the daemon is on the host, not on remote workers.
sh_test(
name = "tracker_docker_test",
size = "large",
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :tracker_test)"],
data = [":tracker_test"],
env = {"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1"},
tags = [
"no-remote-exec",
"requires-docker",
],
)

View file

@ -41,6 +41,10 @@ func testMainInner(m *testing.M) int {
// AD-01 (be-c5p): allow tracker tests to connect to the test container.
os.Setenv("BEADS_TEST_SERVER", "1")
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
if os.Getenv(testutil.EnvRequireDoltContainer) == "1" {
fmt.Fprintf(os.Stderr, "FATAL: %v, but %s=1: this lane must not skip the Dolt tests\n", err, testutil.EnvRequireDoltContainer)
return 1
}
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
} else {
defer testutil.TerminateDoltContainer()

View file

@ -676,7 +676,7 @@ var allowedBazelTestTags = map[string]string{
"no-remote-cache": "result depends on the host, so it is neither read from nor uploaded to the remote cache",
"requires-docker": "needs a docker daemon; excluded from --config=prcore/ci, run by --config=docker",
"embedded": "embedded-Dolt tier variant; its own config",
"manual": "repro/bench harness; never part of //...",
"manual": "never part of //...: a repro/bench harness, or a build input only another target needs",
}
// bazelTagsRequiring maps tags whose targets depend on the host to the tags
@ -885,3 +885,54 @@ func TestBazelrcPrcoreExcludesNonPRTags(t *testing.T) {
}
}
}
// TestBazelrcPrcoreRequiresExcludePermission keeps test:prcore in step with
// pr.yml's PR Core step (TestPRCoreRequiresExcludeReadPermissionCoverage):
// without the variable, TestAddExcludePatternsRefusesReadErrors skips on a
// root executor instead of failing.
func TestBazelrcPrcoreRequiresExcludePermission(t *testing.T) {
const want = "test:prcore --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1"
for _, line := range strings.Split(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "\n") {
if strings.TrimSpace(line) == want {
return
}
}
t.Fatalf(".bazelrc lacks %q", want)
}
// TestBazelrcPrcoreMatchesPRCoreParallel keeps test:prcore's -test.parallel
// equal to pr-core.sh's -parallel default: without it Go uses GOMAXPROCS, the
// executor's core count, and runs far more tests at once than PR Core does.
func TestBazelrcPrcoreMatchesPRCoreParallel(t *testing.T) {
root := bazelPolicyRoot(t)
m := regexp.MustCompile(`(?m)^GO_TEST_PARALLEL="\$\{GO_TEST_PARALLEL:-(\d+)\}"$`).FindStringSubmatch(readPolicyFile(t, root, "scripts/ci/pr-core.sh"))
if m == nil {
t.Fatal("scripts/ci/pr-core.sh has no GO_TEST_PARALLEL default")
}
want := "test:prcore --test_arg=-test.parallel=" + m[1]
for _, line := range strings.Split(readPolicyFile(t, root, ".bazelrc"), "\n") {
if strings.TrimSpace(line) == want {
return
}
}
t.Fatalf(".bazelrc lacks %q (pr-core.sh runs go test -parallel %s)", want, m[1])
}
// Docker-lane results depend on host state no action key sees (daemon, dolt
// image, network), so they must always execute, like the container jobs'
// -count=1; and no remote-exec run may upload a locally executed result to
// the shared cache.
func TestBazelrcDockerLaneNeverCached(t *testing.T) {
lines := map[string]bool{}
for _, line := range strings.Split(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "\n") {
lines[strings.TrimSpace(line)] = true
}
for _, want := range []string{
"test:docker --nocache_test_results",
"build:remote-exec --noremote_upload_local_results",
} {
if !lines[want] {
t.Errorf(".bazelrc lacks %q", want)
}
}
}

39
scripts/ci/package-bazel-bd.sh Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Packages the Bazel-built bd in pr.yml's ci-build-artifacts layout
# (bd-linux-gms-pure, SHA256SUMS, build-manifest.txt) for bazel.yml.
#
# The binary is //cmd/bd:bd_for_tests, the non-race gms_pure_go cgo bd that
# Bazel's own tests exec (//cmd/bd:bd is race built under --config=ci); run
# after `bazel test //... --config=ci`, whose test:ci downloads it. Unlike
# `go build`, it carries no vcs.* or CGO_ENABLED build settings, so
# `bd version` shows no commit and scripts/verify-cgo.sh would pass
# vacuously; no consumer of the artifact reads either.
#
# Usage: scripts/ci/package-bazel-bd.sh OUT_DIR
set -euo pipefail
out="${1:?usage: $0 OUT_DIR}"
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$repo_root"
# For BEADS_BUILD_TAGS (the manifest's build_tags, as in pr.yml).
# shellcheck source=/dev/null
source ./.buildflags
mapfile -t found < <(find -H bazel-out -path '*/bin/cmd/bd/bd_for_tests/bd' -type f)
if [ "${#found[@]}" -ne 1 ]; then
echo "::error::want exactly one //cmd/bd:bd_for_tests output, found ${#found[@]}: ${found[*]}"
exit 1
fi
mkdir -p "$out"
install -m 755 "${found[0]}" "$out/bd-linux-gms-pure"
cd "$out"
./bd-linux-gms-pure version
sha256sum bd-linux-gms-pure > SHA256SUMS
{
echo "commit=$(git -C "$repo_root" rev-parse HEAD)"
echo "go_version=$(go version bd-linux-gms-pure | sed 's/^[^:]*: //')"
echo "build_tags=${BEADS_BUILD_TAGS}"
echo "artifact=bd-linux-gms-pure"
echo "builder=bazel //cmd/bd:bd_for_tests"
} > build-manifest.txt

View file

@ -1170,6 +1170,7 @@ type ciWorkflowJob struct {
ContinueOnError bool `yaml:"continue-on-error"`
TimeoutMinutes int `yaml:"timeout-minutes"`
Strategy ciWorkflowStrategy `yaml:"strategy"`
Env map[string]string `yaml:"env"`
}
type ciWorkflowStrategy struct {
@ -1423,6 +1424,8 @@ func captureOne(t *testing.T, pattern, body, source string) string {
const (
bazelWorkflowName = "bazel.yml"
bazelJobName = "bazel-test"
bazelPureJobName = "bazel-pure"
bazelDockerJobName = "bazel-docker"
setupBazelActionDir = ".github/actions/setup-bazel"
uploadArtifactSHA = "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"
downloadArtifactSHA = "3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c"
@ -1436,6 +1439,10 @@ const (
"steps.bazel.outcome == 'success' && steps.bazel.outputs.cache-hit != 'true' }}"
)
// bazel.yml's jobs: the --config=ci lane, and one job per pr.yml job a Bazel
// config mirrors.
var bazelJobNames = []string{bazelDockerJobName, bazelPureJobName, bazelJobName}
// The only triggers bazel.yml may have. pull_request_target (and
// workflow_run) would run with secrets in the context of fork PRs.
var bazelWorkflowTriggers = []string{"merge_group", "pull_request", "push", "workflow_call", "workflow_dispatch"}
@ -1468,17 +1475,48 @@ func readSetupBazelAction(t *testing.T) ciCompositeAction {
// it: no ci-gate may need it or list it in CI_GATE_REQUIRED.
func TestBazelWorkflowIsAdvisory(t *testing.T) {
workflow := readCIWorkflow(t, bazelWorkflowName)
if len(workflow.Jobs) != 1 {
t.Errorf("%s jobs = %d, want only %q", bazelWorkflowName, len(workflow.Jobs), bazelJobName)
var names []string
for name, job := range workflow.Jobs {
names = append(names, name)
if job.ContinueOnError {
t.Errorf("%s continue-on-error hides failures; the lane is advisory by staying out of ci-gate", name)
}
if job.TimeoutMinutes == 0 {
t.Errorf("%s has no timeout-minutes", name)
}
}
job := workflow.job(t, bazelJobName)
// The farm admits the Blacksmith pool only; forks (no secrets) and rbe=off
sort.Strings(names)
if !reflect.DeepEqual(names, bazelJobNames) {
t.Errorf("%s jobs = %v, want %v", bazelWorkflowName, names, bazelJobNames)
}
// Every job uses setup-bazel's remote executor when secrets allow. The
// farm admits the Blacksmith pool only; forks (no secrets) and rbe=off
// build locally on the GitHub-hosted runner.
if want := "${{ (inputs.rbe || 'on') != 'off' && github.event.pull_request.head.repo.fork != true && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}"; job.RunsOn != want {
t.Errorf("%s runs-on = %q, want %q", bazelJobName, job.RunsOn, want)
const wantRunsOn = "${{ (inputs.rbe || 'on') != 'off' && github.event.pull_request.head.repo.fork != true && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}"
// rbe-west (instance "oss") is switched on by the repo variable
// RBE_WEST_WORKERS; until then same-repo runs are skipped and only fork
// PRs and rbe=off dispatches run, locally.
const wantIf = "${{ vars.RBE_WEST_WORKERS == 'true' || inputs.rbe == 'off' || github.event.pull_request.head.repo.fork == true }}"
gate := "(inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && "
wantSetupEnv := map[string]string{
"BAZEL_REMOTE_EXECUTOR": "${{ " + gate + "secrets.RBE_WEST_EXECUTOR || '' }}",
"RBE_TLS_CERT": "${{ " + gate + "secrets.RBE_TLS_CERT || '' }}",
"RBE_TLS_KEY": "${{ " + gate + "secrets.RBE_TLS_KEY || '' }}",
"RBE_TLS_CA": "${{ " + gate + "secrets.RBE_TLS_CA || '' }}",
"RBE_INSTANCE": "${{ " + gate + "'oss' || '' }}",
}
if job.ContinueOnError {
t.Errorf("%s continue-on-error hides failures; the lane is advisory by staying out of ci-gate", bazelJobName)
for name, job := range workflow.Jobs {
if job.RunsOn != wantRunsOn {
t.Errorf("%s runs-on = %q, want %q", name, job.RunsOn, wantRunsOn)
}
if job.If != wantIf {
t.Errorf("%s if = %q, want %q", name, job.If, wantIf)
}
for _, step := range job.Steps {
if step.Uses == "./"+setupBazelActionDir && !reflect.DeepEqual(step.Env, wantSetupEnv) {
t.Errorf("%s setup-bazel env = %v, want %v", name, step.Env, wantSetupEnv)
}
}
}
for _, name := range []string{"pr.yml", "pr-risk.yml"} {
for jobName, j := range readCIWorkflow(t, name).Jobs {
@ -1504,10 +1542,13 @@ func TestBazelWorkflowIsAdvisory(t *testing.T) {
// here too (restore everywhere, save only where the topology says).
func TestBazelWorkflowActionsArePinned(t *testing.T) {
steps := map[string][]ciWorkflowStep{
bazelWorkflowName: readCIWorkflow(t, bazelWorkflowName).job(t, bazelJobName).Steps,
setupBazelActionDir + "/action.yml": readSetupBazelAction(t).Runs.Steps,
}
for name, job := range readCIWorkflow(t, bazelWorkflowName).Jobs {
steps[bazelWorkflowName+" "+name] = job.Steps
}
want := map[string]string{
setupNodeActionFamily: setupNodeSHA,
"actions/checkout": checkoutSHA,
setupGoActionFamily: setupGoSHA,
cacheRestoreActionFamily: cacheSHA,
@ -1538,8 +1579,8 @@ func TestBazelWorkflowActionsArePinned(t *testing.T) {
if family == setupGoActionFamily && step.With["cache"] != "false" {
t.Errorf("%s setup-go cache = %q, want false", file, step.With["cache"])
}
if family == cacheSaveActionFamily && file != bazelWorkflowName {
t.Errorf("%s step %q saves a cache; only %s's push-to-main step may", file, step.Name, bazelWorkflowName)
if family == cacheSaveActionFamily && file != bazelWorkflowName+" "+bazelJobName {
t.Errorf("%s step %q saves a cache; only %s's push-to-main step may", file, step.Name, bazelJobName)
}
}
for _, step := range list {
@ -1634,6 +1675,182 @@ func TestBazelWorkflowRunsCIConfigWithReports(t *testing.T) {
}
}
// bazel.yml publishes a Bazel-built bd under pr.yml's build-artifacts contract
// (artifact name, file names, checksum file, retention), so the jobs that
// download ci-build-artifacts can switch to it without other edits.
func TestBazelWorkflowPublishesBuildArtifacts(t *testing.T) {
var prUpload ciWorkflowStep
for _, step := range readCIWorkflow(t, "pr.yml").job(t, "build-artifacts").Steps {
if actionFamily(step.Uses) == "actions/upload-artifact" {
prUpload = step
}
}
job := readCIWorkflow(t, bazelWorkflowName).job(t, bazelJobName)
pkg := job.step(t, "Package bd (ci-build-artifacts layout)")
upload := job.step(t, "Upload build artifacts")
if prUpload.With["name"] != "ci-build-artifacts" || upload.With["name"] != prUpload.With["name"] {
t.Errorf("artifact name = %q, want pr.yml's %q (ci-build-artifacts)", upload.With["name"], prUpload.With["name"])
}
for _, key := range []string{"retention-days", "if-no-files-found"} {
if upload.With[key] != prUpload.With[key] {
t.Errorf("upload %s = %q, want pr.yml's %q", key, upload.With[key], prUpload.With[key])
}
}
if pkg.ID == "" || upload.If != "${{ always() && steps."+pkg.ID+".outcome == 'success' }}" {
t.Errorf("upload if = %q; want it gated on the package step's success", upload.If)
}
// The commands live in a script that sources .buildflags itself, so the
// build-tag scan (scripts/check-build-tags.sh) still covers bazel.yml.
const script = "scripts/ci/package-bazel-bd.sh"
if pkg.Run != "./"+script+` "$RUNNER_TEMP/bd-artifacts"` {
t.Errorf("package step = %q, want %s", pkg.Run, script)
}
if strings.Contains(readPolicyFile(t, bazelPolicyRoot(t), ".github/workflows/"+bazelWorkflowName), ".buildflags") {
t.Errorf("%s mentions .buildflags; sourcing it would exempt the whole file from the build-tag scan", bazelWorkflowName)
}
body := readPolicyFile(t, bazelPolicyRoot(t), script)
for _, required := range []string{
"set -euo pipefail", "source ./.buildflags",
"/bin/cmd/bd/bd_for_tests/bd", "bd-linux-gms-pure", "sha256sum bd-linux-gms-pure > SHA256SUMS",
"build-manifest.txt", "commit=", "go_version=", "build_tags=", "artifact=bd-linux-gms-pure",
} {
if !strings.Contains(body, required) {
t.Errorf("%s does not contain %q", script, required)
}
}
// test:ci must download the binary under --remote_download_minimal.
if !strings.Contains(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "test:ci --remote_download_regex=.*/bin/cmd/bd/bd_for_tests/bd$") {
t.Error(".bazelrc test:ci does not download //cmd/bd:bd_for_tests")
}
}
// bazel-docker replaces pr.yml's container-backed jobs: --config=docker on a
// runner with a docker daemon and the same pre-pulled dolt image, and a
// requires-docker variant in every package those jobs start containers in.
func TestBazelDockerJobMirrorsContainerJobs(t *testing.T) {
pr := readCIWorkflow(t, "pr.yml")
job := readCIWorkflow(t, bazelWorkflowName).job(t, bazelDockerJobName)
for _, name := range []string{"test-domain-uow", "contract-corpus"} {
prJob := pr.job(t, name)
if pull := prJob.step(t, "Pull Dolt sql-server image").Run; job.step(t, "Pull Dolt sql-server image").Run != pull {
t.Errorf("%s pulls the dolt image differently from %s (%q)", bazelDockerJobName, name, pull)
}
}
if job.Env["BAZEL_DOCKER_LANE"] != "docker" {
t.Errorf("%s BAZEL_DOCKER_LANE = %q, want docker", bazelDockerJobName, job.Env["BAZEL_DOCKER_LANE"])
}
test := job.step(t, "bazel test //... --config=docker")
if !strings.Contains(test.Run, `bazel test //... "--config=$BAZEL_DOCKER_LANE"`) || !strings.Contains(test.Run, "set -o pipefail") {
t.Errorf("docker lane step does not run the lane over //...:\n%s", test.Run)
}
if strings.Contains(test.Run, "--config=remote-exec") {
t.Errorf("docker lane step selects remote-exec itself; setup-bazel's rc does that only when secrets are present")
}
assertTestStepKeepsExitStatus(t, test)
// The packages whose tests start dolt containers in those jobs
// (test-domain-uow: domain/..., uow, tracker/... and doctor/fix;
// contract-corpus: protocol) each need a requires-docker target. Only
// under go test: scripts_test's runfiles hold no other package's BUILD.
if os.Getenv("TEST_SRCDIR") != "" {
return
}
root := sourceRepoRoot(t)
for _, pkg := range []string{"internal/storage/domain/db", "internal/storage/uow", "internal/tracker", "cmd/bd/doctor/fix", "cmd/bd/protocol"} {
if !strings.Contains(readPolicyFile(t, root, pkg+"/BUILD.bazel"), `"requires-docker"`) {
t.Errorf("%s/BUILD.bazel has no requires-docker variant for the docker lane", pkg)
}
}
}
// bazel-pure replaces pr.yml's check-cmd-bd-puregeo-tests job: the same pure
// cmd/bd test selector, the same pure build set, and the js/wasm hook test
// under the same exact-count guard.
func TestBazelPureJobMirrorsPureGoJob(t *testing.T) {
pr := readCIWorkflow(t, "pr.yml").job(t, "check-cmd-bd-puregeo-tests")
job := readCIWorkflow(t, bazelWorkflowName).job(t, bazelPureJobName)
prSubset := pr.step(t, "Run pure-Go cmd/bd test subset (CGO_ENABLED=0)").Run
m := regexp.MustCompile(`-run '([^']+)' \./cmd/bd`).FindStringSubmatch(prSubset)
if m == nil {
t.Fatalf("cannot find the -run selector in pr.yml's pure subset step:\n%s", prSubset)
}
if job.Env["PURE_CMD_BD_TESTS"] != m[1] || !strings.Contains(prSubset, "-short") {
t.Errorf("%s PURE_CMD_BD_TESTS = %q, want pr.yml's -short -run selector %q", bazelPureJobName, job.Env["PURE_CMD_BD_TESTS"], m[1])
}
run := job.step(t, "Run pure-Go cmd/bd test subset (--config=pure)").Run
for _, required := range []string{"bazel test --config=pure //cmd/bd:bd_test", `"--test_arg=-test.run=$PURE_CMD_BD_TESTS"`, "(( n > 0 ))"} {
if !strings.Contains(run, required) {
t.Errorf("pure subset step does not contain %q:\n%s", required, run)
}
}
if !strings.Contains(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "test:pure --test_arg=-test.short") {
t.Error(".bazelrc test:pure does not pass -test.short like the pr.yml subset")
}
build := job.step(t, "Build cmd/bd and pure-Go test binaries (--config=pure)").Run
prBuild := pr.step(t, "Build cmd/bd (CGO_ENABLED=0, gms_pure_go)").Run + pr.step(t, "Compile pure-Go test binaries (CGO_ENABLED=0, gms_pure_go)").Run
for pkg, target := range map[string]string{
"go build -tags gms_pure_go -o /tmp/bd-puregeo ./cmd/bd": "//cmd/bd:bd",
"-o /tmp/bd-cmd-puregeo-test ./cmd/bd": "//cmd/bd:bd_test",
"-o /tmp/bd-embeddeddolt-puregeo-test ./internal/storage/embeddeddolt": "//internal/storage/embeddeddolt:embeddeddolt_test",
"-o /tmp/bd-tracker-puregeo-test ./internal/tracker": "//internal/tracker:tracker_test",
} {
if !strings.Contains(prBuild, pkg) {
t.Errorf("pr.yml pure build steps no longer contain %q; update %s to match", pkg, bazelPureJobName)
}
if !strings.Contains(build, target) || !strings.Contains(build, "bazel build --config=pure") {
t.Errorf("pure build step does not build %s:\n%s", target, build)
}
}
// `go build` rejects a pure binary that imports gozstd at compile time;
// Bazel compiles gozstd's stubs, whose init panics, so the lane must start
// every pure artifact (bd_test starts in the subset step above).
start := job.step(t, "Start every pure-Go artifact (gozstd contamination check)").Run
for _, required := range []string{
"set -euo pipefail",
"bazel run --config=pure //cmd/bd:bd -- version",
"bazel test --config=pure",
"//internal/storage/embeddeddolt:embeddeddolt_test",
"//internal/tracker:tracker_test",
"'--test_arg=-test.run=^$'",
} {
if !strings.Contains(start, required) {
t.Errorf("pure artifact start step does not contain %q:\n%s", required, start)
}
}
if os.Getenv("TEST_SRCDIR") == "" {
patch := readPolicyFile(t, sourceRepoRoot(t), "third_party/patches/gozstd_nocgo.patch")
if !strings.Contains(patch, "+func init() { panic(") {
t.Error("gozstd_nocgo.patch stubs no longer panic in init; a contaminated pure binary would start")
}
}
prWasm := pr.step(t, "Run js/wasm hook boundary").Run
wasm := job.step(t, "Run js/wasm hook boundary").Run
for _, required := range []string{"bazel build --config=js-wasm //internal/hooks:hooks_test", "go_js_wasm_exec"} {
if !strings.Contains(wasm, required) {
t.Errorf("js/wasm step does not contain %q:\n%s", required, wasm)
}
}
// The selector and everything from the count guard on are pr.yml's.
const selector = "run '^TestRunHookReportsUnsupportedExecution$'"
if !strings.Contains(prWasm, " -"+selector) || !strings.Contains(wasm, " -test."+selector) {
t.Errorf("js/wasm selector drifted from pr.yml's %q", selector)
}
guard := func(script string) string {
i := strings.Index(script, "run_count=0")
if i < 0 {
return ""
}
return script[i:]
}
if guard(wasm) == "" || guard(wasm) != guard(prWasm) {
t.Errorf("js/wasm count guard differs from pr.yml's:\n--- pr.yml\n%s\n--- %s\n%s", guard(prWasm), bazelPureJobName, guard(wasm))
}
}
// swallowedExit matches shell that hides a failing command's status.
var swallowedExit = regexp.MustCompile(`\bexit\b|\|\|\s*(true|:)|;\s*(true|:)\s*$|\bset\s+\+e\b|\btrap\b`)
@ -1787,13 +2004,17 @@ func TestBazelWorkflowSecretsAndFailureSurface(t *testing.T) {
}
setupSteps := map[string]bool{}
for i, step := range readCIWorkflow(t, bazelWorkflowName).job(t, bazelJobName).Steps {
if step.Uses == "./"+setupBazelActionDir {
setupSteps[fmt.Sprintf(".jobs.%s.steps[%d].env.", bazelJobName, i)] = true
for name, job := range readCIWorkflow(t, bazelWorkflowName).Jobs {
n := 0
for i, step := range job.Steps {
if step.Uses == "./"+setupBazelActionDir {
setupSteps[fmt.Sprintf(".jobs.%s.steps[%d].env.", name, i)] = true
n++
}
}
if n != 1 {
t.Errorf("%s job %s has %d setup-bazel steps, want 1", bazelWorkflowName, name, n)
}
}
if len(setupSteps) != 1 {
t.Errorf("%s has %d setup-bazel steps, want 1", bazelWorkflowName, len(setupSteps))
}
secretRef := regexp.MustCompile(`\bsecrets\s*(\.|\[)`)
walkYAML(root, "", func(path string, key bool, value string) {

View file

@ -6,6 +6,11 @@
# dolt_go_serial.patch are adapted from the gascity project
# (github.com/gastownhall/gascity, third_party/patches). Keep them in sync
# when bumping the pinned dolt versions in go.mod.
#
# gozstd_nocgo.patch is beads' own: panicking !cgo stubs for the gozstd API
# dolt uses, so `--config=pure` (CGO off) can compile store/nbs, which rules_go
# builds as a declared dep even though no pure-Go file imports it. Their init
# panics, so a pure binary that does link gozstd fails when started.
package(default_visibility = ["//visibility:public"])

69
third_party/patches/gozstd_nocgo.patch vendored Normal file
View file

@ -0,0 +1,69 @@
diff --git a/BUILD.bazel b/BUILD.bazel
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -25,6 +25,7 @@ go_library(
"fse_compress.c",
"fse_decompress.c",
"gozstd.go",
+ "nocgo.go",
"hist.c",
"hist.h",
"huf.h",
diff --git a/nocgo.go b/nocgo.go
new file mode 100644
--- /dev/null
+++ b/nocgo.go
@@ -0,0 +1,44 @@
+//go:build !cgo
+
+// Added by beads (third_party/patches/gozstd_nocgo.patch). gozstd wraps the
+// zstd C library, so without cgo it does not compile, and rules_go compiles
+// every declared dep even when only cgo-constrained files import it. These
+// stubs let `bazel build --config=pure` compile dolt's store/nbs (a dep of
+// beads' cgo-only embedded-Dolt files); `go build` never compiles them because
+// a CGO_ENABLED=0 bd does not import nbs. The package init panics, so a pure
+// binary that links gozstd (the contamination `go build` rejects with
+// CGO_ENABLED=0) fails at startup; bazel.yml's pure lane runs every pure
+// artifact to catch it. The entry points panic as well.
+package gozstd
+
+const DefaultCompressionLevel = 3
+
+const errNoCgo = "gozstd: built without cgo"
+
+func init() { panic(errNoCgo + " (linked into a pure binary)") }
+
+type CDict struct{}
+
+type DDict struct{}
+
+func (cd *CDict) Release() {}
+
+func (dd *DDict) Release() {}
+
+func NewCDict(dict []byte) (*CDict, error) { panic(errNoCgo) }
+
+func NewCDictLevel(dict []byte, compressionLevel int) (*CDict, error) { panic(errNoCgo) }
+
+func NewDDict(dict []byte) (*DDict, error) { panic(errNoCgo) }
+
+func BuildDict(samples [][]byte, desiredDictLen int) []byte { panic(errNoCgo) }
+
+func Compress(dst, src []byte) []byte { panic(errNoCgo) }
+
+func CompressLevel(dst, src []byte, compressionLevel int) []byte { panic(errNoCgo) }
+
+func CompressDict(dst, src []byte, cd *CDict) []byte { panic(errNoCgo) }
+
+func Decompress(dst, src []byte) ([]byte, error) { panic(errNoCgo) }
+
+func DecompressDict(dst, src []byte, dd *DDict) ([]byte, error) { panic(errNoCgo) }
diff --git a/stream.go b/stream.go
--- a/stream.go
+++ b/stream.go
@@ -1,3 +1,5 @@
+//go:build cgo
+
package gozstd
import (

View file

@ -30,6 +30,18 @@ Two checks always run, a third when `go test -json` output is supplied:
test but run under Bazel) are reported, not failed: a failing test already
fails its own lane.
Job mode (--job, with --go-test-json): the go test JSON is the whole expected
set instead of `go list ./...`. Use it to prove that a Bazel selection (one or
more --bep runs, e.g. --config=ci plus --config=docker) replaces one specific
CI job: every top-level test the job's command ran must have run under Bazel,
Bazel must run no other test in those packages, and no test the job passed may
be skipped under Bazel. A test seen in several targets (a go_test and its
go_test_variant.sh sh_test) keeps its best status here, since each variant is
a different way of running it and the job needs one run that does what it
does; the default mode keeps the worst. A failure in any target still fails a
job comparison (listed per target), and so does a missing test.xml of any
target in the job's packages, variant or not.
Divergences listed in the allowlist (tools/bazel/equivalence_allowlist.txt)
are expected; anything else fails. The allowlist format is one entry per line:
@ -58,6 +70,9 @@ GO_LIST_ARGS = ["list", "-e", "-race", "-tags", "gms_pure_go", "-json", "./..."]
SKIP_RE = re.compile(r"^TestEmbedded")
TEST_FUNC_RE = re.compile(r"^func\s+(Test\w*)\s*\(\s*\w+\s+\*testing\.T\s*\)", re.M)
STATUS_RANK = {"skipped": 0, "passed": 1, "failed": 2}
# Job mode: the variant that actually ran a test wins (a failure still fails
# the Bazel run that produced it).
BEST_RANK = {"failed": 0, "skipped": 1, "passed": 2}
GO_TEST_STATUS = {"pass": "passed", "fail": "failed", "skip": "skipped"}
ALLOW_KINDS = ("run", "skip")
DEFAULT_ALLOWLIST = os.path.join(os.path.dirname(os.path.abspath(__file__)), "equivalence_allowlist.txt")
@ -142,10 +157,16 @@ def query_go_test_pkgs(root, bazel):
return {label_pkg(l) for l in out.split()}
# go_test_variant.sh variants are sh_tests that run a go_test binary, which
# writes the same test.xml.
TEST_KINDS = ("go_test rule", "sh_test rule")
def read_bep(path):
"""Return ({label: shard_count} for tested go_test targets, set of go_test
labels configured, this invocation's testlogs dir or None)."""
go_tests, shards = set(), {}
"""Return ({label: shard_count} for tested go_test targets and sh_test
variants, set of go_test labels configured, this invocation's testlogs dir
or None)."""
go_tests, tests, shards = set(), set(), {}
exec_root, testlogs_rel = None, None
with open(path, encoding="utf-8") as f:
for line in f:
@ -160,12 +181,15 @@ def read_bep(path):
if link.get("path", "").endswith("testlogs") and link.get("target"):
testlogs_rel = link["target"]
elif "targetConfigured" in eid:
if ev.get("configured", {}).get("targetKind") == "go_test rule":
kind = ev.get("configured", {}).get("targetKind")
if kind in TEST_KINDS:
tests.add(eid["targetConfigured"]["label"])
if kind == "go_test rule":
go_tests.add(eid["targetConfigured"]["label"])
elif "testResult" in eid:
tr = eid["testResult"]
shards[tr["label"]] = max(shards.get(tr["label"], 0), int(tr.get("shard", 1) or 1))
tested = {l: n for l, n in shards.items() if l in go_tests}
tested = {l: n for l, n in shards.items() if l in tests}
testlogs = None
if exec_root and testlogs_rel:
# The symlink target is relative to the output base, two levels above
@ -183,14 +207,24 @@ def testlog_xmls(testlogs, label, shard_count):
return [os.path.join(base, f"shard_{i}_of_{shard_count}", "test.xml") for i in range(1, shard_count + 1)]
def bazel_observed(tested, testlogs):
"""Return ({pkg: {test: status}}, [problems])."""
observed, problems = {}, []
def bazel_observed(tested, testlogs, go_tests, best=False, observed=None, failures=None, no_xml=None):
"""Return ({pkg: {test: status}}, [problems]), merged into observed.
Job mode (best) also collects (pkg, "Test (label)") for every failed test
in failures and (pkg, label) for every missing test.xml in no_xml."""
observed, problems = ({} if observed is None else observed), []
for label, n in sorted(tested.items()):
pkg = label_pkg(label)
per = observed.setdefault(pkg, {})
for xml_path in testlog_xmls(testlogs, label, n):
if not os.path.exists(xml_path):
if best and no_xml is not None:
# Bazel writes a test.xml for every test, so a variant's
# is missing only if it was never downloaded.
no_xml.append((pkg, f"{label}: {os.path.relpath(xml_path, testlogs)}"))
continue
if label not in go_tests:
continue # an sh_test that is not a variant may write none
problems.append(f"{label}: {xml_path} missing (was test.xml downloaded? run with --config=ci)")
continue
try:
@ -211,10 +245,14 @@ def bazel_observed(tested, testlogs):
status = "skipped"
else:
status = "passed"
# A test seen in several targets keeps its worst status.
if name not in per or STATUS_RANK[status] > STATUS_RANK[per[name]]:
if status == "failed" and failures is not None:
failures.append((pkg, f"{name} ({label})"))
# A test seen in several targets keeps its worst status (best in
# job mode).
rank = BEST_RANK if best else STATUS_RANK
if name not in per or rank[status] > rank[per[name]]:
per[name] = status
if count == 0 and os.path.getsize(xml_path) < 64:
if count == 0 and label in go_tests and os.path.getsize(xml_path) < 64:
# An empty <testsuites/> means the binary ran no tests at all
# (or GO_TEST_WRAP_TESTV was off). The test-name diff reports
# which tests are missing; note it here for the log.
@ -253,7 +291,10 @@ def allowed(entries, pkg, test, kind="run"):
def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--bep", required=True, help="--build_event_json_file of the bazel test run")
ap.add_argument(
"--bep", required=True, action="append",
help="--build_event_json_file of a bazel test run (repeatable: results are merged)",
)
ap.add_argument("--root", default=os.getcwd(), help="workspace root (default: cwd)")
ap.add_argument("--testlogs", default=None, help="default: from the BEP, else <root>/bazel-testlogs")
ap.add_argument("--allowlist", default=DEFAULT_ALLOWLIST)
@ -266,18 +307,40 @@ def main(argv=None):
ap.add_argument("--no-query", action="store_true", help="skip the bazel query package-set check")
ap.add_argument("--details", action="store_true", help="list every divergence (nightly)")
ap.add_argument("--summary", default=None, help="append Markdown here (default: $GITHUB_STEP_SUMMARY)")
ap.add_argument(
"--job", action="store_true",
help="compare with --go-test-json as one CI job's complete test set (see Job mode above)",
)
args = ap.parse_args(argv)
if args.job and not args.go_test_json:
ap.error("--job needs --go-test-json")
root = os.path.abspath(args.root)
entries, allow_errors = load_allowlist(args.allowlist)
expected, dirs = go_expected(root, args.go_list_json)
tested, configured, bep_testlogs = read_bep(args.bep)
# Prefer the BEP's own testlogs dir: the bazel-testlogs symlink follows
# whatever bazel command ran last, possibly in another output base.
testlogs = args.testlogs or bep_testlogs or os.path.join(root, "bazel-testlogs")
observed, problems = bazel_observed(tested, testlogs)
target_pkgs = None if args.no_query else query_go_test_pkgs(root, args.bazel)
observed, problems, configured, tested = {}, [], set(), {}
failures, no_xml = [], []
for bep in args.bep:
bep_tested, bep_configured, bep_testlogs = read_bep(bep)
configured |= bep_configured
tested.update(bep_tested)
# Prefer the BEP's own testlogs dir: the bazel-testlogs symlink follows
# whatever bazel command ran last, possibly in another output base.
testlogs = args.testlogs or bep_testlogs or os.path.join(root, "bazel-testlogs")
_, bep_problems = bazel_observed(
bep_tested, testlogs, bep_configured, args.job, observed,
failures if args.job else None, no_xml if args.job else None)
problems += bep_problems
target_pkgs = None if (args.no_query or args.job) else query_go_test_pkgs(root, args.bazel)
go_status = go_test_statuses(args.go_test_json, dirs) if args.go_test_json else None
if args.job:
# The job's own results are the expected set; other packages Bazel
# ran are out of scope.
expected = {pkg: set(ts) for pkg, ts in go_status.items()}
observed = {pkg: seen for pkg, seen in observed.items() if pkg in expected}
failures = sorted(set(f for f in failures if f[0] in expected))
no_xml = sorted(set(m for m in no_xml if m[0] in expected))
no_target, missing, extra, allowlisted = [], [], [], []
if target_pkgs is not None:
@ -295,7 +358,6 @@ def main(argv=None):
# Skip parity: passed under go test, skipped under Bazel.
skip_div, skip_allowed, parity_notes = [], [], []
go_status = go_test_statuses(args.go_test_json, dirs) if args.go_test_json else None
if go_status is not None:
for pkg, seen in sorted(observed.items()):
gs = go_status.get(pkg, {})
@ -312,14 +374,16 @@ def main(argv=None):
# Dedupe allowlisted pairs (a package-level entry also covers its tests).
allowlisted = sorted(set(allowlisted))
# Skip entries can only be exercised when go test statuses are known.
unused = [e for e in entries if not e["used"] and (e["kind"] == "run" or go_status is not None)]
# (The allowlist describes the --config=ci lane; a job comparison uses only
# the entries that apply.)
unused = [] if args.job else [e for e in entries if not e["used"] and (e["kind"] == "run" or go_status is not None)]
statuses = {"passed": 0, "skipped": 0, "failed": 0}
for seen in observed.values():
for s in seen.values():
statuses[s] += 1
n_expected = sum(len(v) for v in expected.values())
ok = not (no_target or missing or extra or skip_div or allow_errors)
ok = not (no_target or missing or extra or skip_div or failures or no_xml or allow_errors)
limit = None if args.details else 40
@ -353,6 +417,8 @@ def main(argv=None):
("tests go test runs that Bazel did not", missing),
("tests Bazel ran that go test would not", extra),
("tests go test passed that Bazel skipped", skip_div),
("tests that failed in a Bazel target", failures),
("Bazel targets without test.xml", no_xml),
):
if pairs:
lines += listing(title, pairs)

55
tools/bazel/race.bzl Normal file
View file

@ -0,0 +1,55 @@
"""go_test_race_off: an existing go_test built without the race detector.
The docker lane (--config=docker) sets --@rules_go//go/config:race for every
target, because pr.yml's container jobs run `go test -race`, except the
Contract corpus job, which does not. A go_test_variant.sh sh_test over this
rule's output runs such a package the way that job does, without a second
go_test rule (whose srcs gazelle would not maintain). The go_test keeps its own
`race = "auto"` and so follows the setting this transition gives it.
"""
_RACE = "@rules_go//go/config:race"
# rules_go's go_transition (go_binary/go_test with race = "off", e.g.
# //cmd/bd:bd_for_tests) records the setting it overrides in this private
# flag. Recording it the same way puts the test's deps in the configuration
# bd_for_tests already builds them in, instead of a second non-race copy of
# the whole graph.
_ORIGINAL_RACE = "@rules_go//go/private/rules:original_race"
def _race_off_impl(settings, _attr):
out = {_RACE: False, _ORIGINAL_RACE: settings[_ORIGINAL_RACE]}
if settings[_RACE] and not settings[_ORIGINAL_RACE]:
out[_ORIGINAL_RACE] = json.encode(True)
return out
_race_off = transition(
implementation = _race_off_impl,
inputs = [_RACE, _ORIGINAL_RACE],
outputs = [_RACE, _ORIGINAL_RACE],
)
def _go_test_race_off_impl(ctx):
target = ctx.attr.test[0]
src = target[DefaultInfo].files_to_run.executable
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.symlink(output = out, target_file = src, is_executable = True)
runfiles = ctx.runfiles(files = [out]).merge(target[DefaultInfo].default_runfiles)
return [DefaultInfo(files = depset([out]), runfiles = runfiles, executable = out)]
_go_test_race_off = rule(
implementation = _go_test_race_off_impl,
doc = "The executable of `test`, built with --@rules_go//go/config:race=false.",
attrs = {
"test": attr.label(
cfg = _race_off,
executable = True,
mandatory = True,
),
},
executable = True,
)
def go_test_race_off(name, test, **kwargs):
"""Declares `name`, the executable of go_test `test` built without race."""
_go_test_race_off(name = name, test = test, testonly = True, **kwargs)