beads/scripts/BUILD.bazel
Julian Knutsen 8988340994
ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane (#7708)
* test(cmd/bd): repair the embedded-gated tests that rotted while no lane ran them

These tests skip unless BEADS_TEST_EMBEDDED_DOLT=1 but no CI lane selected
them, so they rotted unseen. Running them shows:

- TestEventsTailFollowReportsTruncationOnTheStream raced on a plain
  bytes.Buffer that os/exec's copy goroutine writes while the test polls it.
  Use the package's syncBuffer.
- TestCorruptMetadataDiagnosticsRunAndDataFailsLoud still asserted that
  doctor and init run on a corrupt metadata.json. #4857 deliberately made
  every workspace command refuse instead (pinned for doctor by
  TestDoctorRejectsCorruptMetadataBeforeSharedServerChecks). Rewrite it to
  the shipped contract as TestEmbeddedCorruptMetadataFailsLoudUntilRestored:
  version warns, doctor/list/init refuse naming the file without touching
  it, and restoring the file brings the data back.
- dolt_remote_origin_guard_embedded_test.go was tagged
  `embeddeddolt && cgo`, a tag no lane sets, so it never compiled in CI
  (gazelle left it out of bd_test srcs). Retag it `cgo`, as #4153 did for
  its dolt_local_only sibling, and add it to srcs. Drop its four bd doctor
  git-origin tests: bd doctor runs no checks on an embedded workspace
  (GH#3794), so two could never pass and two passed vacuously on empty
  output. Rename the surviving tests into the TestEmbedded* prefix.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane

The embedded-Dolt cmd lane selected tests with
grep '^func TestEmbedded' cmd/bd/*_embedded_test.go, and only its two
Bazel targets set BEADS_TEST_EMBEDDED_DOLT. A test that skips without the
variable but missed the name prefix or the file suffix skipped in every
lane and reported green: 92 of them, including #7203's --if-revision CLI
coverage (TestIfRevisionMatchAndMismatch, TestReassignFenceCLI, ...).

- embedded-test-shard.sh and gen_embedded_cmd_shard_manifest.py select
  TestEmbedded* by name across cmd/bd/*_test.go, as proxied-test-shard.sh
  does, leaving authors one rule.
- Rename the gated tests into the TestEmbedded* prefix
  (TestDoctorEmbedded<X> -> TestEmbeddedDoctor<X>) and update every
  reference.
- Place the new names with gen_embedded_cmd_shard_manifest.py 100
  --weights=duration --write (incremental).
- Add TestEmbeddedGatedTestsRunInTheEmbeddedLane: it walks cmd/bd's tests
  for any that reach os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" and fails
  if a shard of the lane never lists one. The proxied guard's helpers now
  take the variable and the script; a fixture test pins the walk.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
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-10-19 22:02:22 +00:00

451 lines
16 KiB
Python

load("@rules_go//go:def.bzl", "go_test")
# CI and repo-policy tests: they parse the workflows, run the CI shell scripts
# against fixtures, and check repository-wide rules (BUILD tag taxonomy, skip
# allowlist, managed BUILD blocks, shard manifests, tracked-file scans).
#
# They are one Go package but several go_test targets, each compiling only
# the files whose tests it runs and declaring only what those tests read, so
# that a change re-runs only the targets that read it: a Go-only change runs
# no workflow policy test, a docs-only or workflow-only change no Go-source
# scan. The data are the partitions of the checkout that tools/bazel/go_srcs.py
# generates (//:repo_go_srcs, //:repo_go_test_srcs, //:repo_doc_files,
# //:repo_other_files, and per package) or single files; only
# :tracked_files_test declares //:repo_files, every tracked file.
#
# Every *_test.go here is in exactly one of these targets, except the
# helpers-only files (no Test functions) that several compile; srcs are kept
# by hand (`# keep` stops gazelle from putting every file back into
# scripts_test), and TestScriptsTestTargetsPartitionTheTests
# (scripts_targets_test.go) fails on a file in no target or a test in two.
#
# No tags: they run remotely like any other target. The scripts and fixtures
# run bash, git, python3, jq, yq, curl, openssl, unzip and coreutils from the
# executor (the rbe-west worker image, or the runner in fork-cache mode); a
# missing tool fails the test under Bazel instead of skipping it
# (host_tools_test.go), so a cached pass never stands for an executor that
# could not run it. Go and the release formula come in hermetically.
# The CI and Bazel policy tests: workflows, the setup-bazel action, .bazelrc,
# MODULE.bazel, every BUILD and .bzl file, tools/bazel and the CI scripts,
# all in //:repo_other_files (every tracked file but Go and Markdown source),
# plus the one Go file whose dolt image pin they compare.
go_test(
name = "scripts_test",
srcs = [
"bazel_autofix_push_test.go",
"bazel_cache_mode_test.go",
"bazel_dolt_int_test.go",
"bazel_dolt_race_test.go",
"bazel_farm_workflow_test.go",
"bazel_fork_mode_test.go",
"bazel_go_repository_tools_test.go",
"bazel_hermetic_cc_test.go",
"bazel_invocations_test.go",
"bazel_policy_test.go",
"bazel_rbe_prewarm_test.go",
"bazel_rrc_test.go",
"ci_actions_policy_test.go",
"ci_analytics_workflow_test.go",
"ci_blacksmith_runner_test.go",
"ci_f7b_review_test.go",
"ci_f7c_advisory_test.go",
"ci_merge_queue_test.go",
"ci_workflow_apt_get_timeout_test.go",
"ci_workflow_core_test.go",
"ci_workflow_test.go",
"embedded_shard_count_test.go",
"host_tools_test.go",
"makefile_bazel_primary_test.go",
"migration_corpus_bazel_test.go",
"nogo_integration_step_script_test.go",
"nogo_lint_policy_test.go",
"pinned_shards_helpers_test.go",
"pinned_shards_test.go",
"pr_lanes_bazel_coverage_test.go",
"pr_risk_bazel_coverage_test.go",
"rbe_worker_env_test.go",
"repo_helpers_test.go",
"worker_env_autosync_test.go",
], # keep
data = [
"//:repo_other_files",
"//internal/testutil:testdoltcommon.go",
"@go_sdk//:bin/go",
"@go_sdk//:files",
],
# The Go SDK is go.mod's toolchain, whatever go the executor has on PATH.
# No //:repo_go_srcs here (F5 S2, cost fix, independent review of #7486):
# T4 (TestNogoIntegrationStepCoversItsConfiguration) and the
# unvalidated_integration_tests.txt exactness check moved to their own
# :nogo_integration_scan_test target below, which alone depends on
# //:repo_go_srcs and //:repo_go_test_srcs, so a Go-only change no longer
# re-runs the rest of this suite too.
env = {"BEADS_TEST_GO": "$(rlocationpath @go_sdk//:bin/go)"},
deps = [
"//internal/doltversion",
"//internal/formula",
"//internal/testutil/bazeltest",
"//scripts/internal/testbash",
"@in_gopkg_yaml_v3//:yaml_v3",
],
)
# T4 (TestNogoIntegrationStepCoversItsConfiguration) and T6
# (TestUnvalidatedIntegrationTestsFileIsExact, independent review of #7486
# must-fix 6): both source-scan every tracked .go file (test and non-test)
# for the "integration" build tag, so they alone depend on //:repo_go_srcs
# and //:repo_go_test_srcs. Carved out of scripts_test (cost fix, same
# review): with this data in scripts_test, any Go-only change re-ran the
# whole nogo-policy suite, raising scripts_test's rerun rate from 73% to 91%
# of main commits. bazel_invocations_test.go and ci_workflow_core_test.go are
# helper-only files (no Test functions) shared with scripts_test, so neither
# copy duplicates the other's parsing logic.
go_test(
name = "nogo_integration_scan_test",
srcs = [
"bazel_invocations_test.go",
"ci_workflow_core_test.go",
"nogo_integration_scan_test.go",
"repo_helpers_test.go",
], # keep
data = [
"//:repo_go_srcs",
"//:repo_go_test_srcs",
"//:repo_other_files",
],
deps = [
"//internal/testutil/bazeltest",
"@in_gopkg_yaml_v3//:yaml_v3",
],
)
# The shell scripts' own behavior, run against fixtures: this package's
# scripts and their testdata, the few root files they read, and the release
# formula.
go_test(
name = "shell_scripts_test",
srcs = [
"check_build_tags_test.go",
"check_doc_freshness_test.go",
"check_release_cross_compile_test.go",
"check_testing_short_test.go",
"check_winget_portable_alias_test.go",
"ci_analytics_extract_test.go",
"complexity_script_test.go",
"conformance_script_test.go",
"host_tools_test.go",
"install_dolt_test.go",
"oracle_a_script_test.go",
"pr_preflight_test.go",
"pre_push_suite_test.go",
"pull_dolt_image_test.go",
"release_script_test.go",
"repo_helpers_test.go",
"required_suite_test.go",
"test_script_test.go",
"update_nix_vendorhash_test.go",
"update_nix_vendorhash_unix_test.go",
"upgrade_smoke_loop_test.go",
],
data = [
":repo_other_files",
"//:.buildflags",
"//:.githooks/pre-push",
"//:.test-skip",
"//:tests/oracle-a/run-oracle-a.sh",
"//internal/httpclient:repo_other_files",
"//test/conformance:repo_go_test_srcs",
"//test/conformance:repo_other_files",
"//tools/bazel:repo_other_files",
"@beads_formulas//:beads-release.formula.toml",
],
# The release formula lives in .beads/ (in .bazelignore: it also holds
# live bd data), so it comes in through its own local repository.
env = {"BEADS_TEST_RELEASE_FORMULA": "$(rlocationpath @beads_formulas//:beads-release.formula.toml)"},
deps = [
"//internal/formula",
"//internal/testutil/bazeltest",
"//scripts/internal/testbash",
],
)
# Scans of the Go test files: the Bazel-skip allowlist, the managed local
# lane, and the shard manifests and scripts against the tests they shard.
# Every _test.go file (//:repo_go_test_srcs) but no non-test Go source, so a
# non-test Go change leaves it cached.
go_test(
name = "go_test_sources_test",
srcs = [
"bazel_skip_allowlist_test.go",
"embedded_lane_coverage_test.go",
"embedded_shard_count_test.go",
"host_tools_test.go",
"managed_local_lane_test.go",
"pinned_shards_helpers_test.go",
"pinned_shards_sources_test.go",
"proxied_lane_coverage_test.go",
"repo_helpers_test.go",
"scripts_targets_test.go",
"shard_manifest_test.go",
],
data = [
"BUILD.bazel",
"ci/_embedded_shard_manifest_lib.py",
"ci/embedded_cmd_test_durations.json",
"ci/embedded_storage_test_durations.json",
"ci/gen_embedded_cmd_shard_manifest.py",
"ci/gen_embedded_storage_shard_manifest.py",
"ci/gen_proxied_shard_manifest.py",
"ci/proxied_test_durations.json",
"//:.github/scripts/embedded-cmd-test-shards.txt",
"//:.github/scripts/embedded-storage-test-shard.sh",
"//:.github/scripts/embedded-storage-test-shards.txt",
"//:.github/scripts/embedded-test-shard.sh",
"//:.github/scripts/proxied-cmd-test-shards.txt",
"//:.github/scripts/proxied-test-shard.sh",
"//:.github/scripts/server-storage-test-shard.sh",
"//:.github/scripts/server-storage-test-shards.txt",
"//:nested_go_modules",
"//:repo_go_test_srcs",
"//backend/http:repo_other_files",
"//backend/http/corpus:repo_other_files",
"//cmd/bd:repo_other_files",
"//internal/httpclient:repo_other_files",
"//internal/storage/dolt:repo_other_files",
"//internal/storage/embeddeddolt:repo_other_files",
"//tests/regression:repo_other_files",
"//tools/bazel:check_shard_coverage.py",
"//tools/bazel:equivalence_allowlist.txt",
],
deps = ["//internal/testutil/bazeltest"],
)
# check-testing-short.sh over every Go file, test and non-test, plus the
# Go-exec half of the host-go-under-Bazel policy (host_tool_exec_policy_test.go
# scans //:repo_go_srcs and //:repo_go_test_srcs for a literal go/gofmt exec).
# The shell-script half (host_tool_shell_policy_test.go) is its own
# :shell_host_tool_policy_test below: it reads a fixed, narrow list of shell
# scripts, not every Go source file, so it would otherwise pay this target's
# full re-run cost for files it never looks at.
go_test(
name = "go_sources_test",
srcs = [
"host_tool_exec_policy_test.go",
"repo_helpers_test.go",
"testing_short_tree_test.go",
],
data = [
"check-testing-short.sh",
"//:repo_go_srcs",
"//:repo_go_test_srcs",
],
deps = ["//internal/testutil/bazeltest"],
)
# The shell-script half of the host-go-under-Bazel policy
# (host_tool_shell_policy_test.go: see its package comment for shellPolicyScope
# and the detection tradeoffs). Split out of go_sources_test (which otherwise
# re-ran on every Go-source change to serve only this file) with data limited
# to exactly the shell scripts shellPolicyScope names -- no BUILD.bazel/.bzl
# walk, and so no //:repo_other_files: TestShellPolicyScopeCoversBazelShellData
# (dropped; see that test's old doc comment in version control) could not
# parse a `//pkg:file.sh` label or a glob() either, so paying 758 extra input
# files and ~4 points of cache-rerun rate across the whole repo for a walk
# that demonstrably still missed real in-scope scripts was not worth it.
go_test(
name = "shell_host_tool_policy_test",
srcs = [
"host_tool_shell_policy_test.go",
"repo_helpers_test.go",
],
data = [
"check-build-tags.sh",
"check-doc-freshness.sh",
"check-go-install-guidance.sh",
"check-migration-hygiene.sh",
"check-testing-short.sh",
"check-versions.sh",
"check-winget-portable-alias.sh",
"check-workapi-frontend-boundary.sh",
"ci/fmt-check.sh",
"ci/gofmt-bin.sh",
"ci/pr-lint.sh",
"conformance.sh",
"migrate-legacy-to-current.sh",
"migration-test/historical-dolt-upgrade-test.sh",
"migration-test/legacy-bridge-test.sh",
"migration-test/lib/binary.sh",
"release.sh",
"test.sh",
"upgrade-smoke-test.sh",
"//:.github/scripts/embedded-storage-test-shard.sh",
"//:.github/scripts/embedded-test-shard.sh",
"//:.github/scripts/proxied-test-shard.sh",
"//:.github/scripts/server-storage-test-shard.sh",
"//scripts/repochecks:run_check.sh",
"//scripts/repochecks:types_gen_drift_test.sh",
],
deps = ["//internal/testutil/bazeltest"],
)
# Scans of every tracked file (//:repo_files): any change re-runs them, so
# keep them few and fast.
go_test(
name = "tracked_files_test",
srcs = [
"repo_helpers_test.go",
"tracked_files_test.go",
],
data = ["//:repo_files"],
deps = ["//internal/testutil/bazeltest"],
)
# pr.yml's check-doc-freshness-platforms Linux leg: `go test
# -tags integration ./scripts -count=1 -run '^(TestDocFreshness.*|
# TestRequiredSuiteContract)$' -args -required-suite=doc-freshness`, whose
# TestMain fails unless exactly the doc-freshness inventory is compiled and
# selected. shell_scripts_test runs those tests too (in the integration lane);
# this target adds the inventory and selection contract, over only the files
# the suite reads (its fixtures copy check-doc-freshness.sh). The macOS and
# Windows legs stay in pr.yml.
# Tags:
# integration-only: every TestDocFreshness test is //go:build integration,
# so --config=integration's lane runs it.
go_test(
name = "doc_freshness_required_test",
srcs = [
"check_doc_freshness_test.go",
"repo_helpers_test.go",
"required_suite_test.go",
],
args = [
"-test.count=1",
"-test.run=^(TestDocFreshness.*|TestRequiredSuiteContract)$$",
"-required-suite=doc-freshness",
],
data = ["check-doc-freshness.sh"],
tags = ["integration-only"],
deps = [
"//internal/testutil/bazeltest",
"//scripts/internal/testbash",
],
)
exports_files(
["migration-test/release-catalog.json"],
visibility = ["//scripts/migration-test/catalog:__pkg__"],
)
# The historical-upgrade harness (scripts/migration-test) and the public
# SQLite bridge it drives, for //tests/migration's per-release targets.
filegroup(
name = "migration_harness",
srcs = [
"migrate-legacy-to-current.sh",
"migration-test/historical-dolt-upgrade-test.sh",
"migration-test/legacy-bridge-test.sh",
"migration-test/lib/binary.sh",
"migration-test/lib/versions.sh",
],
visibility = ["//tests/migration:__pkg__"],
)
exports_files(
["upgrade-smoke-test.sh"],
visibility = ["//tests/upgrade_smoke:__pkg__"],
)
exports_files(
[
"ci/fmt-check.sh",
"ci/lib/timing.sh",
"ci/pr-lint.sh",
],
visibility = ["//scripts/prlintmake:__pkg__"],
)
exports_files(
["ci/gofmt-bin.sh"],
visibility = ["//scripts/prlintmake:__pkg__"],
)
# The compatibility entrypoint whose exit-status contract
# //scripts/check-versions:check-versions_test drives.
exports_files(
["check-versions.sh"],
visibility = ["//scripts/check-versions:__pkg__"],
)
# Scripts the docs and agent instructions link to by path, which
# //test/docsync checks resolve.
exports_files(
[
"bump-version.sh",
"check-cli-docs-drift.sh",
"generate-cli-docs.sh",
"test.sh",
],
visibility = ["//test/docsync:__pkg__"],
)
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "repo_doc_files",
srcs = glob(
[
"**/*.md",
"**/*.mdx",
],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_srcs",
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = [
"**/*_test.go",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_test_srcs",
srcs = glob(
["**/*_test.go"],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_other_files",
srcs = glob(
["**"],
exclude = [
"**/*.db",
"**/*.exe",
"**/*.go",
"**/*.md",
"**/*.mdx",
"**/*.out",
"**/*.prof",
"**/*.pyc",
"**/*.test",
"**/__pycache__/**",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
# --- end repo_files ---