beads/cmd/bd/protocol
Julian Knutsen 4f2f8f2b79
test(bazel): hermetic test env + inject bd binary into subprocess tests (#6843)
* test(bazel): isolate the bazel test environment like pr-core's go test

Every `bazel test` process now runs under //tools/bazel:test_env (wired with
`test --run_under`), a wrapper that mirrors scripts/ci/lib/test-env.sh: a
private HOME/USERPROFILE, XDG_CONFIG_HOME, DOLT_ROOT_PATH and empty
GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM, BEADS_TEST_IGNORE_REPO_CONFIG, and
the same scrub of workspace/Dolt-server variables. Everything lives in one
fresh mktemp directory under /tmp that is removed when the test exits, so
TMPDIR (t.TempDir) stays short enough for unix sockets and is never shared
between concurrent runs.

This replaces `--test_env=HOME` (the client's HOME string entered the action
key and was shipped to remote workers, where it does not exist: the
embeddeddolt suite panicked on "stat /home/ubuntu") and the shared
`--test_tmpdir=/tmp/bbt`. No host path or client env enters the action key.

bd_test (~10 min under -race -short) and embeddeddolt_test (~6 min) get
size = "large" / timeout = "long" instead of Bazel's 300 s default; pr-core
gives go test -timeout=30m. rules_shell (already in the module graph) becomes
a direct dep for sh_binary. MODULE.bazel.lock records the pybind11 extension
that building these test targets evaluates, so `make bazel-sync` is stable.

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

* test(bazel): inject the bd binary into subprocess tests (slice B3)

Tests that exec bd used to `go build` it themselves, which cannot work under
`bazel test` (no Go toolchain or module tree in the sandbox or on a remote
worker): 135 cmd/bd subtests failed with "go build failed", and protocol,
doctor and uow failed the same way.

- //cmd/bd:bd_for_tests: a go_binary named bd, race = "off" (the non-race
  gms_pure_go binary these tests build today, even under --config=prcore).
- bd_test, protocol_test, doctor_test and uow_test declare it as data and set
  BEADS_TEST_BD_BINARY to its $(rlocationpath).
- bazeltest.PrebuiltBD is the one resolver: under Bazel it resolves the
  rlocationpath through runfiles (via the new bazeltest.RunfileEnv) and
  requires it; under plain go test it keeps today's semantics (absolute form
  of BEADS_TEST_BD_BINARY, or "" so the caller builds bd).
- cmd/bd's findPrebuiltBDBinary delegates to it, and the sites that read the
  variable by hand (init_embedded, shared_server_integration, cli_fast,
  migrate front door) now go through findPrebuiltBDBinary; uow calls it
  directly.
- Raw `go build` sites that never honored the variable (protocol, doctor
  dolt_e2e, test/conformance e2e, internal/beads integration TestMain) use
  it only under Bazel, so go test is unchanged; protocol and doctor fail
  instead of skipping when the injection is miswired. tests/regression is
  left alone (it builds candidate and baseline binaries on purpose).
- The read-only canary still forces a source build under go test; under
  Bazel the injected binary is already built from this tree.

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

* test(bazel): declare what cmd/bd and doctor tests read under bazel

With bd injected, the remaining //cmd/bd:bd_test and //cmd/bd/doctor failures
under `bazel test` were inputs the tests read from the checkout without
declaring them (they were hidden behind the go-build failures before):

- source-scanning guards (capability registry, events-journal construction,
  serve database source) parse cmd/bd, cmd/bd/doctor, cmd/bd/doctor/fix and
  internal/storage/embeddeddolt/cmd: those packages get go_srcs filegroups
  (tools/bazel/go_srcs.py) declared as data; serve_test resolves its package
  dir with bazeltest.CallerDir.
- .githooks (managed-section parity) and examples/formulas/primitives are
  declared through //:bd_test_files.
- the gofmt preflight tests exec gofmt: under Bazel they use the Go SDK's,
  declared as data and named by BEADS_TEST_GOFMT (bazeltest.RunfileEnv).
- TestGOMODCACHENotUnderTestHome guards in-test `go build`, which does not
  happen under Bazel, so it skips there.
- doctor's TestCheckDeletionsManifest_LegacyFile only passed because the
  process cwd happened to be inside a git checkout; its fixture is now a git
  repo and the check runs in it.

go test behavior is unchanged except that the deletions-manifest test no
longer depends on the caller's cwd.

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

* fix(bazel): give test_env a dolt identity; never fail on cleanup

beads_test_env_enter sets a dolt user.name/user.email in the fresh
DOLT_ROOT_PATH; test_env.sh created it empty, so tests that shell out to
dolt (remotecache, storage/dolt) failed with 'Author identity unknown'.
Write config_global.json directly (no dolt exec per test).

Also keep rm -rf in the EXIT trap from overriding the test's exit status
when a leftover child is still writing to the tmp root.

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

* build(bazel): re-sync BUILD files with main

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 11:38:03 -07:00
..
testdata/corpus Merge release/1.3.0 into main (post-tag forward-port) 2026-09-15 22:09:13 +00:00
assignee_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
blocked_status_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
blocked_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
blocking_semantics_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
BUILD.bazel test(bazel): hermetic test env + inject bd binary into subprocess tests (#6843) 2026-09-27 11:38:03 -07:00
canonicalize_test.go test(protocol): make corpus determinism pure (bd-qq1qn) (#5281) 2026-08-02 07:14:30 -07:00
CATALOG.md Merge remote-tracking branch 'upstream/main' into pr-4232-fix 2026-07-13 20:43:10 -07:00
child_id_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
children_test.go fix(cli): implement children pretty and defer reason 2026-06-13 21:22:38 -07:00
close_guard_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
comments_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
corpus.go fix(contracts): JSON contract fixes before 1.3.0 freezes them — string revision tokens, --set-metadata scalar typing, create --json nano timestamps (#6053) 2026-08-29 05:20:27 +00:00
corpus_test.go test(protocol): make corpus determinism pure (bd-qq1qn) (#5281) 2026-08-02 07:14:30 -07:00
defer_test.go fix(cli): implement children pretty and defer reason 2026-06-13 21:22:38 -07:00
dep_identity_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
errors_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
exit_codes_init_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
exit_codes_test.go Beads #6648: report partial batch-close failure (#6740) 2026-09-26 13:55:44 -07:00
helpers_test.go test(bazel): hermetic test env + inject bd binary into subprocess tests (#6843) 2026-09-27 11:38:03 -07:00
input_validation_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
interchange_test.go test(protocol): pin the §J interchange clauses; fix the bd import header gap (wy-ltox1) 2026-07-13 11:20:06 -07:00
json_contract_test.go fix(show): flag comment_count as omitted when comments are not streamed (#4865) 2026-07-25 16:16:41 -07:00
lease_claim_test.go test: fix red main — init-cancel E2E deadline + reclaim JSON assertion (#5039) 2026-07-25 10:10:18 -07:00
lifecycle_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
memory_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
preservation_test.go test(protocol): realign show --json contract tests with count-only payload (wy-017ry) 2026-07-13 10:08:34 -07:00
ready_front_test.go test: make ready ordering setup deterministic (bd-y9cjq) (#5238) 2026-08-01 09:55:11 -07:00
roundtrip_test.go test(protocol): realign show --json contract tests with count-only payload (wy-017ry) 2026-07-13 10:08:34 -07:00
stale_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
status_validation_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
versioning_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
wp4_helpers_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00