beads/MODULE.bazel
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

45 lines
2.8 KiB
Python

module(
name = "beads",
version = "0.0.0",
)
bazel_dep(name = "rules_go", version = "0.63.0")
bazel_dep(name = "gazelle", version = "0.53.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
name = "go_sdk",
version = "1.26.7",
)
use_repo(go_sdk, "go_sdk")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
# beads builds go-mysql-server with its stdlib-regex backend (ICU policy):
# gazelle must see gms_pure_go as satisfied so it selects regex_pure.go and
# drops the go-icu-regex (libicu, cgo) edge entirely.
go_deps.gazelle_override(
directives = [
"gazelle:build_tags gms_pure_go",
"gazelle:exclude internal/regex/regex_cgo.go",
],
path = "github.com/dolthub/go-mysql-server",
)
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:eventsapi_schema_build.patch"],
path = "github.com/dolthub/eventsapi_schema",
)
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:flatbuffers_v23_importpath.patch"],
path = "github.com/dolthub/flatbuffers/v23",
)
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:dolt_go_serial.patch"],
path = "github.com/dolthub/dolt/go",
)
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")