fix(bazel): the root go_srcs glob skips Bazel's convenience symlinks, so //cmd/bd tests cache (#7714)

The root //:go_srcs filegroup is glob(["**/*.go"]), and a glob follows the
checkout's bazel-bin/bazel-out/bazel-testlogs/bazel-beads symlinks into the
output tree. CI's test step is the first build in a fresh checkout, so it never
sees them, but in any checkout that has built before every test that reads
//:go_srcs (bd_test, bd_embedded_test, bd_embedded_part2_test,
bd_dolt_server_test, bd_proxied_test, bd_managed_local_test) gains the output
base's .go files: their inputs differ on every run, they are never cached, and
loading grows with the output tree.

Measured on main 2563f021ed with the symlinks present, `bazel test
//cmd/bd:bd_test --config=ci --test_filter='^TestResolveCommitHash$'` twice:
both runs executed all 16 shards remotely, and the analysed graph grew from
20,773 to 56,941 configured targets (14 s, then 25 s). With this change the
second run is `(cached)` in 3.6 s. In agent worktrees the glob had reached
433,026 output-tree files, a cached re-run took 36 s to load against ~3 s
without them, and 135 of 202 blocking test minutes of the factory's beads
seats went to these six targets (formula-overhead audit 4; bead ga-ylpbsy.24).

tools/bazel/go_srcs.py gives the root block exclude = ["bazel-*/**"] (the
same pattern ROOT_REPO_FILES_EXCLUDE already uses for //:repo_files); only
the root BUILD.bazel changes. CI's action keys do not change: its checkout has
no such files. scripts/bazel_policy_test.go's
TestBazelRootGoSrcsSkipsConvenienceSymlinks fails without the exclude.

Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
gascity-eddie[bot] 2026-10-19 23:30:10 +00:00 • committed by GitHub
commit 4df395698b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 3 deletions

View file

@ -260,6 +260,7 @@ filegroup(
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = ["bazel-*/**"],
),
visibility = ["//:__subpackages__"],
)

View file

@ -351,6 +351,29 @@ func diffStringSets(want, got []string) (missing, extra []string) {
return missing, extra
}
// rootGoSrcsGlobRe matches the glob of the root package's go_srcs filegroup.
var rootGoSrcsGlobRe = regexp.MustCompile(`(?s)filegroup\(\s*name\s*=\s*"go_srcs",\s*srcs\s*=\s*glob\((.*?)\),\s*visibility`)
// Bazel's convenience symlinks (bazel-bin, bazel-out, bazel-testlogs,
// bazel-beads) sit at the repository root, and a glob follows them into the
// output tree. CI's test step is the first build in a fresh checkout, but in
// any checkout that has built before (every agent worktree) an unexcluded
// root glob(["**/*.go"]) puts the output base's .go files into //:go_srcs and
// so into every test that reads it (//cmd/bd's test targets): their inputs
// change on every build, they never come from the cache, and loading them
// takes ~36 s instead of ~3 s (433,026 such files after a few runs, measured
// 2026-10-19, ga-ylpbsy.24).
func TestBazelRootGoSrcsSkipsConvenienceSymlinks(t *testing.T) {
root := sourceRepoRoot(t)
m := rootGoSrcsGlobRe.FindStringSubmatch(stripStarlarkComments(readPolicyFile(t, root, "BUILD.bazel")))
if m == nil {
t.Fatal("BUILD.bazel has no root go_srcs glob: the block tools/bazel/go_srcs.py writes changed shape; update rootGoSrcsGlobRe")
}
if !strings.Contains(m[1], `"bazel-*/**"`) {
t.Errorf("the root //:go_srcs glob does not exclude \"bazel-*/**\", so it follows Bazel's convenience symlinks into the output tree; fix tools/bazel/go_srcs.py and run `make bazel-sync`")
}
}
// goSrcsTrees are the tools/bazel/go_srcs.py TREES roots. A test that walks
// one of these trees through its tree_go_srcs sees only the packages listed
// there, so an unlisted package makes that walk pass vacuously.

View file

@ -199,15 +199,23 @@ def packages_under(root: str) -> list[str]:
return sorted(found)
# Bazel's convenience symlinks (bazel-bin, bazel-out, bazel-testlogs,
# bazel-beads) sit at the repository root, and a glob follows them into the
# output tree: unexcluded, the root go_srcs would hold the output base's .go
# files in any checkout that has built before, so every test that reads it
# would re-run (and reload) on each build (scripts/bazel_policy_test.go
# TestBazelRootGoSrcsSkipsConvenienceSymlinks).
ROOT_GO_SRCS_EXCLUDE = ["bazel-*/**"]
def block(pkg: str, tree_members: list[str] | None) -> str:
glob = _partition_glob(("**/*.go",), ROOT_GO_SRCS_EXCLUDE if pkg == "." else [], allow_empty=True)
lines = [
BEGIN,
"",
"filegroup(",
' name = "go_srcs",',
' srcs = glob(',
' ["**/*.go"],',
" allow_empty = True,",
*glob,
" ),",
' visibility = ["//:__subpackages__"],',
")",