beads/scripts/host_tools_test.go
Julian Knutsen d90823480a
ci(bazel): split //scripts:scripts_test by what it reads; partition //:repo_files (#7414)
* ci(bazel): split //scripts:scripts_test by what it reads; partition //:repo_files

//scripts:scripts_test declared //:repo_files (the whole checkout), so every
PR re-ran it, and it took ~181s on rbe-west. Most of that (60-79s) was
TestBazelGatedLanesNeverRetryFlakyTests line-regexping the --run_under
wrapper's pinned dolt binary (tools/bazel/hermetic_bin/dolt, in every
test's runfiles); it now skips binary files, as git grep -I does.

tools/bazel/go_srcs.py's per-package repo_files block now partitions each
package's files into repo_go_srcs, repo_go_test_srcs, repo_doc_files and
repo_other_files, aggregated at the root; //:repo_files is their union
(same 4679 files). The //scripts tests are split into go_test targets by
what they read (traced per test with strace over a runfiles-shaped tree):

  scripts_test          CI/Bazel policy: //:repo_other_files (+1 Go file)
  shell_scripts_test    script fixtures: //scripts files, a few root files
  go_test_sources_test  _test.go scans: //:repo_go_test_srcs + shard files
  go_sources_test       check-testing-short.sh: every .go file
  tracked_files_test    every tracked file: //:repo_files

Shared helpers move to helpers-only files; TestScriptsTestTargetsPartition-
TheTests fails on a test file in no target or in two. //test/docsync and
the //scripts/repochecks slices declare partitions or single files instead
of //:repo_files where they can.

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

* ci(bazel): skip only the non-checkout hermetic_bin dir in the flaky-retry walk

Skipping every binary file also stopped scanning tracked binaries (images,
.binpb fixtures). Skip just tools/bazel/hermetic_bin, the --run_under
wrapper's runfiles directory, which is not in the checkout, so the walk's
coverage of tracked files is unchanged.

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-09 05:13:07 +00:00

58 lines
1.8 KiB
Go

package scripts_test
import (
"os/exec"
"testing"
"github.com/steveyegge/beads/internal/testutil/bazeltest"
)
// skipOrFailWithoutHostTool handles a missing host tool. Under go test the
// test skips, as it always has. Under Bazel it fails: the //scripts go_tests
// rely on the executor's bash, git, python3 and friends (the rbe-west
// worker image, or the runner in fork-cache mode), so a skip there would
// hide an executor that lacks one behind a green, cacheable result.
func skipOrFailWithoutHostTool(t *testing.T, format string, args ...any) {
t.Helper()
if bazeltest.IsBazel() {
t.Fatalf("executor lacks a host tool: "+format, args...)
}
t.Skipf(format, args...)
}
// requireHostTool returns the path of a host tool, or skips/fails via
// skipOrFailWithoutHostTool when it is missing.
func requireHostTool(t *testing.T, name string) string {
t.Helper()
path, err := exec.LookPath(name)
if err != nil {
skipOrFailWithoutHostTool(t, "%s not available: %v", name, err)
}
return path
}
// testGo returns the go binary to run. Under Bazel that is the registered Go
// SDK (BUILD data, BEADS_TEST_GO), which is go.mod's toolchain: the go on the
// executor's PATH may be another release.
func testGo(t *testing.T) string {
t.Helper()
if bazeltest.IsBazel() {
path, err := bazeltest.RunfileEnv("BEADS_TEST_GO")
if err != nil {
t.Fatal(err)
}
return path
}
return requireHostTool(t, "go")
}
// requireAutofixBash skips when bash cannot run the autofix scripts: they run
// on Linux runners and use bash 4 associative arrays, and macOS runners ship
// /bin/bash 3.2.
func requireAutofixBash(t *testing.T) {
t.Helper()
requireHostTool(t, "bash")
if err := exec.Command("bash", "-c", "declare -A probe=()").Run(); err != nil {
t.Skip("bash lacks associative arrays (bash >= 4 required)")
}
}