beads/scripts/bazel_policy_test.go
Julian Knutsen fc4d7d3958
ci(bazel): PR-gate parity lanes (docker, pure-Go, js/wasm) + bd artifact (#6887)
* test(bazel): require exclude read-permission coverage in test:prcore

pr.yml's PR Core step sets BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1 so
TestAddExcludePatternsRefusesReadErrors fails, rather than skips, on a root
or non-POSIX executor. test:prcore now sets it too, and a policy test keeps
the two in step.

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

* feat(bazel): compare Bazel runs with one CI job's go test results

equivalence.py --job takes a job's `go test -json` as the complete expected
set, so a Bazel selection can be shown to replace that job: every top-level
test the job ran must run under Bazel, no other test in those packages may,
and nothing the job passed may be skipped. --bep is repeatable (a job can map
to --config=ci plus --config=docker), and go_test_variant.sh sh_tests count,
since their go_test binary writes the same test.xml. In job mode a test seen
in several targets keeps its best status: the prcore run skips what the
docker variant exists to run.

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

* test(bazel): docker-lane variant for internal/tracker

pr.yml's "Test (storage domain + uow)" job runs ./internal/tracker/... with
-race and without -short or BEADS_TEST_SKIP=dolt, so tracker's TestMain
starts the shared dolt container and all 112 top-level tests run. Under
--config=prcore they skip. tracker_docker_test reruns tracker_test that way
in the docker lane, and tracker's TestMain now fails instead of skipping when
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 and the container does not start.

The job's other packages (storage/domain, domain/fs, domain/git,
tracker/conformance) consult neither testing.Short nor the dolt skip, and
pass identically under --config=ci.

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

* ci(bazel): publish the Bazel-built bd as a ci-build-artifacts artifact

pr.yml's build-artifacts job uploads ci-build-artifacts (bd-linux-gms-pure,
SHA256SUMS, build-manifest.txt), which PR Core, the domain+uow job and both
package gates download and check with `sha256sum -c`. The Bazel lane now
uploads the same name and layout from //cmd/bd:bd_for_tests, the non-race
gms_pure_go cgo bd its own tests exec (//cmd/bd:bd is race-built under
--config=ci); test:ci downloads it under --remote_download_minimal. No
consumer is repointed yet.

A rules_go binary has no vcs.* or CGO_ENABLED build settings: `bd version`
shows no commit, and scripts/verify-cgo.sh would pass it vacuously. No
consumer of this artifact reads either; the manifest records the commit.

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

* ci(bazel): pure-Go and js/wasm lane for pr.yml's boundary job

pr.yml's "Check pure-Go and js/wasm boundaries (CGO_ENABLED=0)" job builds
bd and three test binaries with CGO off, runs a 16-name -short cmd/bd subset,
and runs the js/wasm hook refusal test under node with an exact count guard.
bazel.yml's new bazel-pure job does the same with Bazel binaries:

- --config=pure (--@rules_go//go/config:pure, -test.short) builds //cmd/bd:bd,
  bd_test, embeddeddolt_test and tracker_test, and runs bd_test unsharded
  with the job's -run selector (policy-tested to stay equal to pr.yml's).
- --config=js-wasm builds //internal/hooks:hooks_test for js/wasm
  (--use_target_platform_for_tests satisfies the test toolchain; nothing is
  tested by Bazel under it); the Go SDK's go_js_wasm_exec runs it under node
  with pr.yml's selector and count guard, verbatim.

rules_go compiles every declared dep, and gazelle's deps ignore the cgo
constraint of beads' embedded-Dolt files, so a pure build compiled dolt's
store/nbs and failed in github.com/dolthub/gozstd (cgo only; go build never
imports it with CGO_ENABLED=0). third_party/patches/gozstd_nocgo.patch adds
panicking !cgo stubs for the API dolt uses.

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

* test(bazel): run prcore tests with -test.parallel=4 like pr-core.sh

pr-core.sh runs go test -parallel 4. test:prcore passed no -test.parallel,
so Go defaulted to GOMAXPROCS: the executor's core count (192 on a farm
worker) instead of a runner's 4, which let dozens of t.Parallel bd
subprocesses run at once. A policy test keeps the value equal to
pr-core.sh's GO_TEST_PARALLEL default.

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

* test(bazel): -test.parallel=4 in the pure lane

pr.yml's pure-Go job passes no -parallel, so go test uses GOMAXPROCS, 4 on
ubuntu-latest; under Bazel the default would be the executor's core count.

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

* test(bazel): run the contract corpus non-race in the docker lane

pr.yml's Contract corpus job runs go test ./cmd/bd/protocol without -race,
but --config=docker races every target. protocol_docker_test now runs
:protocol_race_off, protocol_test built through a race=false transition
(tools/bazel/race.bzl), so no second go_test rule has to track gazelle's
srcs. Tagged manual so other lanes do not build it; the extra non-race work
is protocol_test's link plus ~100 test-only libraries.

The docker lane also mirrors the jobs' concurrency now: they pass no -p or
-parallel, so go test uses GOMAXPROCS, 4 on ubuntu-latest, for both; the
lane runs at most 4 test processes (so at most 4 dolt containers start at
once) with -test.parallel=4. It writes -test.v test.xml like test:ci, for
equivalence.py.

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

* ci(bazel): run the docker lane in bazel.yml

New advisory job bazel-docker runs `bazel test //... --config=docker` on
ubuntu-latest after pre-pulling the dolt image like pr.yml's container jobs.
The requires-docker variants (domain/db, uow, tracker, doctor/fix,
protocol) run on the runner against its docker daemon (no-remote-exec);
their builds use remote execution when setup-bazel configured it. With
bazel-test's --config=ci this covers "Test (storage domain + uow)" and
"Contract corpus". The lane name is one env var, so a hermetic dolt-server
lane can replace it.

Policy tests now cover every bazel.yml job: an exact job list, timeouts, no
continue-on-error, pinned actions (setup-node added), one setup-bazel step
per job as the only secret reader, cache saves only in bazel-test, plus
job-specific mirrors of pr.yml (the docker job's runner, image pull and
lane; a requires-docker target in each container-backed package).

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

* perf(bazel): build the non-race contract corpus in bd_for_tests' configuration

go_test_race_off only set race=false, while rules_go's go_transition (as
used by //cmd/bd:bd_for_tests, race = "off") also records the overridden
value in original_race. The two non-race configurations differed, so the
docker lane (and --config=ci, which builds protocol_docker_test through
//...) compiled the whole dolt graph twice without race. Record
original_race the same way: aquery GoCompilePkg for
deps(protocol_docker_test) under race drops from ~2630 actions in two
configurations to 1359 in one.

Fix the BUILD comment: manual does not keep protocol_race_off out of other
lanes' builds; protocol_docker_test pulls it in.

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

* fix(bazel): job-mode equivalence fails on any target's failure or missing test.xml

In --job mode a test seen in several targets keeps its best status, so a
failure in one variant was hidden when another target passed the test, and
a go_test_variant.sh sh_test without a test.xml was skipped silently. List
every failed test per target and every target in the job's packages whose
test.xml is missing, and fail on either.

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

* fix(bazel): gate pure-lane contamination, never cache docker-lane results

- gozstd_nocgo.patch: the stubs' package init panics, so a pure binary
  that links gozstd (which CGO_ENABLED=0 go build rejects at compile time)
  fails at startup. bazel-pure starts every pure artifact (bd version, and
  embeddeddolt_test/tracker_test with -test.run=^$; bd_test runs its
  subset) so contamination fails the lane.
- test:docker --nocache_test_results: the requires-docker variants depend on
  host state no action key covers, like the container jobs' -count=1.
  build:remote-exec --noremote_upload_local_results in the committed rc, so
  local runs cannot seed the shared cache with host-dependent results.
- The artifact packaging moves to scripts/ci/package-bazel-bd.sh, which
  sources .buildflags itself; sourcing it in bazel.yml exempted the whole
  workflow from the build-tag scan.
- bazel-pure and bazel-docker use bazel-test's runs-on (Blacksmith when
  remote execution is possible); the policy test pins it for every job.

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

* ci(bazel): put the pure and docker lanes behind the rbe-west gate

Apply bazel-test's rbe-west setup-bazel env (RBE_WEST_EXECUTOR, instance
oss, RBE_WEST_WORKERS) and its job if to bazel-pure and bazel-docker, so
same-repo runs of all three lanes skip together until the variable is set
and forks and rbe=off dispatches still run locally. The policy test pins
runs-on, if and the setup-bazel env for every bazel.yml job.

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

* fix(ci): run the js/wasm hook test with a minimal environment

wasm_exec.js caps argv+env size, and the Blacksmith runner's environment
exceeds it ("total length of command line and environment variables
exceeds limit").

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-28 02:03:51 -07:00

938 lines
36 KiB
Go

package scripts_test
import (
"bufio"
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
)
// Policy tests for the side-by-side Bazel configuration. They are plain Go
// tests so they run under `go test ./scripts` and `bazel test //scripts:...`
// alike. Each invariant is a pure check function exercised against the real
// repository files and against synthetic fixtures that break it.
// bazelPolicyRoot returns the repository root holding the Bazel policy files.
// Under `bazel test` those files are declared as data (//:bazel_policy_files)
// and resolved from the runfiles tree; under `go test` the source checkout is
// used directly.
func bazelPolicyRoot(t *testing.T) string {
t.Helper()
if srcdir := os.Getenv("TEST_SRCDIR"); srcdir != "" {
workspace := os.Getenv("TEST_WORKSPACE")
if workspace == "" {
workspace = "_main"
}
return filepath.Join(srcdir, workspace)
}
return sourceRepoRoot(t)
}
func readPolicyFile(t *testing.T, root, name string) string {
t.Helper()
data, err := os.ReadFile(filepath.Join(root, name))
if err != nil {
t.Fatalf("read %s: %v", name, err)
}
return string(data)
}
// --- go_sdk version == go.mod toolchain -------------------------------------
var (
goModToolchainRe = regexp.MustCompile(`(?m)^toolchain\s+go(\S+)\s*$`)
goModGoRe = regexp.MustCompile(`(?m)^go\s+(\S+)\s*$`)
goSDKDownloadRe = regexp.MustCompile(`(?s)go_sdk\.download\((.*?)\)`)
starlarkVersion = regexp.MustCompile(`\bversion\s*=\s*"([^"]+)"`)
)
// goModToolchainVersion returns the Go version go.mod selects: the toolchain
// directive when present, otherwise the go directive.
func goModToolchainVersion(goMod string) (string, error) {
if m := goModToolchainRe.FindStringSubmatch(goMod); m != nil {
return m[1], nil
}
if m := goModGoRe.FindStringSubmatch(goMod); m != nil {
return m[1], nil
}
return "", errors.New("go.mod has neither a toolchain nor a go directive")
}
// moduleGoSDKVersions returns the version of every go_sdk.download(...) call.
func moduleGoSDKVersions(module string) []string {
var versions []string
for _, call := range goSDKDownloadRe.FindAllStringSubmatch(stripStarlarkComments(module), -1) {
if m := starlarkVersion.FindStringSubmatch(call[1]); m != nil {
versions = append(versions, m[1])
} else {
versions = append(versions, "")
}
}
return versions
}
func stripStarlarkComments(src string) string {
var out strings.Builder
for _, line := range strings.Split(src, "\n") {
if strings.HasPrefix(strings.TrimSpace(line), "#") {
continue
}
out.WriteString(line)
out.WriteByte('\n')
}
return out.String()
}
func checkGoSDKMatchesToolchain(module, goMod string) error {
want, err := goModToolchainVersion(goMod)
if err != nil {
return err
}
versions := moduleGoSDKVersions(module)
if len(versions) == 0 {
return errors.New("MODULE.bazel has no go_sdk.download(...) call")
}
for _, got := range versions {
if got != want {
return errors.New("MODULE.bazel go_sdk.download version " + strconv.Quote(got) +
" != go.mod toolchain " + strconv.Quote(want) + "; update them in lockstep")
}
}
return nil
}
func TestBazelGoSDKMatchesGoModToolchain(t *testing.T) {
root := bazelPolicyRoot(t)
if err := checkGoSDKMatchesToolchain(readPolicyFile(t, root, "MODULE.bazel"), readPolicyFile(t, root, "go.mod")); err != nil {
t.Fatal(err)
}
goMod := "module example.com/m\n\ngo 1.26.0\n\ntoolchain go1.26.7\n"
for name, module := range map[string]string{
"skewed": "go_sdk.download(\n name = \"go_sdk\",\n version = \"1.26.6\",\n)\n",
"missing": "bazel_dep(name = \"rules_go\", version = \"0.63.0\")\n",
"no version": "go_sdk.download(name = \"go_sdk\")\n",
"commented": "# go_sdk.download(version = \"1.26.7\")\n",
"second skew": "go_sdk.download(version = \"1.26.7\")\ngo_sdk.download(version = \"1.25.0\")\n",
} {
if err := checkGoSDKMatchesToolchain(module, goMod); err == nil {
t.Errorf("%s: expected a mismatch error for MODULE.bazel fixture:\n%s", name, module)
}
}
if err := checkGoSDKMatchesToolchain("go_sdk.download(version = \"1.26.7\")\n", goMod); err != nil {
t.Errorf("matching fixture rejected: %v", err)
}
if err := checkGoSDKMatchesToolchain("go_sdk.download(version = \"1.26.0\")\n", "module m\n\ngo 1.26.0\n"); err != nil {
t.Errorf("go directive fallback rejected: %v", err)
}
}
// --- ICU policy: gms_pure_go under Bazel ------------------------------------
var bazelrcPureGoTagRe = regexp.MustCompile(
`^(build|common)\s+(?:.*\s)?--@@?rules_go//go/config:tags=(?:[^\s,]+,)*gms_pure_go(?:,[^\s,]+)*(?:\s|$)`)
// checkBazelrcSetsPureGo requires a build (or common) line that sets the
// gms_pure_go tag, so every bazel build/test/run links the pure-Go regex
// backend (engdocs/ICU-POLICY.md).
func checkBazelrcSetsPureGo(bazelrc string) error {
for _, line := range strings.Split(bazelrc, "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
}
if bazelrcPureGoTagRe.MatchString(line) {
return nil
}
}
return errors.New(".bazelrc must contain `build --@rules_go//go/config:tags=gms_pure_go` (engdocs/ICU-POLICY.md)")
}
// checkModulePrunesICU requires the go-mysql-server gazelle_override that
// selects the pure-Go regex file and excludes the cgo/ICU one; without it
// gazelle keeps the go-icu-regex (libicu) dependency edge.
func checkModulePrunesICU(module string) error {
module = stripStarlarkComments(module)
for _, call := range regexp.MustCompile(`(?s)go_deps\.gazelle_override\((.*?)\n\)`).FindAllStringSubmatch(module, -1) {
body := call[1]
if !strings.Contains(body, `"github.com/dolthub/go-mysql-server"`) {
continue
}
if !strings.Contains(body, `"gazelle:build_tags gms_pure_go"`) {
return errors.New("go-mysql-server gazelle_override lacks \"gazelle:build_tags gms_pure_go\"")
}
if !strings.Contains(body, `"gazelle:exclude internal/regex/regex_cgo.go"`) {
return errors.New("go-mysql-server gazelle_override lacks \"gazelle:exclude internal/regex/regex_cgo.go\"")
}
return nil
}
return errors.New("MODULE.bazel has no go_deps.gazelle_override for github.com/dolthub/go-mysql-server")
}
func TestBazelICUPolicy(t *testing.T) {
root := bazelPolicyRoot(t)
if err := checkBazelrcSetsPureGo(readPolicyFile(t, root, ".bazelrc")); err != nil {
t.Error(err)
}
if err := checkModulePrunesICU(readPolicyFile(t, root, "MODULE.bazel")); err != nil {
t.Error(err)
}
if !regexp.MustCompile(`(?m)^# gazelle:build_tags (?:\S+,)*gms_pure_go(?:,\S+)*\s*$`).MatchString(readPolicyFile(t, root, "BUILD.bazel")) {
t.Error("root BUILD.bazel must carry `# gazelle:build_tags gms_pure_go`")
}
for name, rc := range map[string]string{
"absent": "build --incompatible_strict_action_env\n",
"commented": "# build --@rules_go//go/config:tags=gms_pure_go\n",
"test only": "test --@rules_go//go/config:tags=gms_pure_go\n",
"config only": "build:remote-exec --@rules_go//go/config:tags=gms_pure_go\n",
"lookalike": "build --@rules_go//go/config:tags=gms_pure_go_x\n",
} {
if err := checkBazelrcSetsPureGo(rc); err == nil {
t.Errorf("%s: expected .bazelrc fixture to be rejected:\n%s", name, rc)
}
}
for _, rc := range []string{
"build --@rules_go//go/config:tags=gms_pure_go\n",
"common --@rules_go//go/config:tags=foo,gms_pure_go\n",
"build --@@rules_go//go/config:tags=gms_pure_go,bar # trailing\n",
} {
if err := checkBazelrcSetsPureGo(rc); err != nil {
t.Errorf("valid .bazelrc fixture rejected: %q: %v", rc, err)
}
}
override := "go_deps.gazelle_override(\n directives = [\n \"gazelle:build_tags gms_pure_go\",\n%s ],\n path = \"github.com/dolthub/go-mysql-server\",\n)\n"
if err := checkModulePrunesICU(strings.Replace(override, "%s", "", 1)); err == nil {
t.Error("gazelle_override without the regex_cgo.go exclude was accepted")
}
if err := checkModulePrunesICU(strings.Replace(override, "%s", " \"gazelle:exclude internal/regex/regex_cgo.go\",\n", 1)); err != nil {
t.Errorf("complete gazelle_override rejected: %v", err)
}
}
// --- .bazelversion pinned ---------------------------------------------------
func checkBazelVersionPin(content string) error {
v := strings.TrimSpace(content)
if !regexp.MustCompile(`^\d+\.\d+\.\d+(?:rc\d+)?$`).MatchString(v) {
return errors.New(".bazelversion must pin an exact Bazel release (e.g. 9.2.0), got " + strconv.Quote(v))
}
return nil
}
func TestBazelVersionPinned(t *testing.T) {
root := bazelPolicyRoot(t)
content, err := os.ReadFile(filepath.Join(root, ".bazelversion"))
if err != nil {
t.Fatalf(".bazelversion must exist so bazelisk pins one Bazel release: %v", err)
}
if err := checkBazelVersionPin(string(content)); err != nil {
t.Error(err)
}
for _, bad := range []string{"", "latest", "9.x", "9", "last_green"} {
if checkBazelVersionPin(bad) == nil {
t.Errorf(".bazelversion fixture %q was accepted", bad)
}
}
}
// --- machine-local rc files are gitignored ----------------------------------
// bazelLocalRCFiles hold a developer's remote-executor endpoint and TLS
// credential paths; they must never be committed.
var bazelLocalRCFiles = []string{".bazelrc.local", "user.bazelrc"}
// checkGitignoreCoversLocalRCs reports local rc files that no top-level
// .gitignore pattern ignores (or that a later negation re-includes). It
// understands the literal and root-anchored forms used for these files.
func checkGitignoreCoversLocalRCs(gitignore string) []string {
ignored := map[string]bool{}
for _, line := range strings.Split(gitignore, "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
}
negate := strings.HasPrefix(line, "!")
pattern := strings.TrimPrefix(strings.TrimPrefix(line, "!"), "/")
for _, name := range bazelLocalRCFiles {
if ok, _ := filepath.Match(pattern, name); ok {
ignored[name] = !negate
}
}
}
var missing []string
for _, name := range bazelLocalRCFiles {
if !ignored[name] {
missing = append(missing, name)
}
}
return missing
}
func TestBazelLocalRCFilesGitignored(t *testing.T) {
root := bazelPolicyRoot(t)
if missing := checkGitignoreCoversLocalRCs(readPolicyFile(t, root, ".gitignore")); len(missing) > 0 {
t.Errorf(".gitignore must ignore %v (they carry remote endpoints and credential paths)", missing)
}
// Cross-check with git itself when running from a checkout.
if gitRepoAvailable(root) {
for _, name := range bazelLocalRCFiles {
cmd := exec.Command("git", "-C", root, "check-ignore", "-q", "--no-index", name)
if err := cmd.Run(); err != nil {
t.Errorf("git check-ignore %s: not ignored (%v)", name, err)
}
}
}
if missing := checkGitignoreCoversLocalRCs("/bazel-*\n"); len(missing) != 2 {
t.Errorf("fixture without rc patterns: missing = %v, want both", missing)
}
if missing := checkGitignoreCoversLocalRCs("/.bazelrc.local\n/user.bazelrc\n!user.bazelrc\n"); len(missing) != 1 || missing[0] != "user.bazelrc" {
t.Errorf("fixture with negation: missing = %v, want [user.bazelrc]", missing)
}
if missing := checkGitignoreCoversLocalRCs("*.bazelrc.local\nuser.bazelrc\n"); len(missing) != 0 {
t.Errorf("fixture with glob patterns: missing = %v, want none", missing)
}
}
// --- no remote-execution endpoints in tracked files -------------------------
// Remote-execution endpoints, credentials and TLS material belong in a
// gitignored user.bazelrc/.bazelrc.local or a CI-generated rc outside the
// workspace, never in the repository. The scan covers committed bazelrc-like
// files, Markdown docs and .github/** (plan §3.8) and flags:
// - any remote/BES/TLS flag below whose value is a literal (not a
// <placeholder>, a $VARIABLE/${{ expression }}, empty, or loopback);
// - in rc and .github files, any gRPC URL that is not loopback. Markdown is
// exempt from this rule because beads documents OTel gRPC exporters.
var (
remoteFlagNames = `remote_executor|remote_cache|remote_downloader|remote_header|remote_instance_name|` +
`bes_backend|bes_results_url|bes_header|tls_client_certificate|tls_client_key|tls_certificate`
// `--flag=value` is recognized everywhere; `--flag value` only in rc and
// workflow files, where prose ("--remote_executor and ...") does not occur.
remoteFlagEqRe = regexp.MustCompile(`--(` + remoteFlagNames + `)=("[^"]*"|'[^']*'|[^\s"'` + "`" + `]*)`)
remoteFlagSpaceRe = regexp.MustCompile(`--(` + remoteFlagNames + `)\s+("[^"]*"|'[^']*'|[^\s"'` + "`" + `]+)`)
remoteEndpointRe = regexp.MustCompile(`\bgrpcs?://[^\s"'<>)\]]+`)
loopbackValueRe = regexp.MustCompile(`^(?:[a-z][a-z0-9+.-]*://)?(?:127\.0\.0\.1|localhost|\[::1\])(?:[:/]|$)`)
// remoteScanPrefilter: a file lacking all of these cannot produce a hit.
remoteScanPrefilter = [][]byte{[]byte("--remote_"), []byte("--bes_"), []byte("--tls_"), []byte("grpc")}
)
type endpointHit struct {
path string
line int
what string
}
// remoteScanKind classifies a tracked path for the endpoint scan.
func remoteScanKind(rel string) (scan, strict bool) {
base := filepath.Base(rel)
switch {
case strings.Contains(base, "bazelrc"), strings.HasPrefix(rel, ".github/"):
return true, true
case strings.HasSuffix(base, ".md"):
return true, false
}
return false, false
}
func allowedRemoteValue(v string) bool {
v = strings.Trim(v, `"'`)
if i := strings.Index(v, "://"); i >= 0 {
v = v[i+len("://"):]
}
return v == "" || strings.HasPrefix(v, "<") || strings.HasPrefix(v, "$") || loopbackValueRe.MatchString(v)
}
// findRemoteEndpoints reports literal remote endpoints/credentials in content.
// strict enables the whitespace-separated flag form and the gRPC URL rule.
func findRemoteEndpoints(path string, content []byte, strict bool) []endpointHit {
if bytes.IndexByte(content, 0) >= 0 { // binary
return nil
}
relevant := false
for _, needle := range remoteScanPrefilter {
if bytes.Contains(content, needle) {
relevant = true
break
}
}
if !relevant {
return nil
}
flagRes := []*regexp.Regexp{remoteFlagEqRe}
if strict {
flagRes = append(flagRes, remoteFlagSpaceRe)
}
var hits []endpointHit
scanner := bufio.NewScanner(bytes.NewReader(content))
scanner.Buffer(make([]byte, 0, 64*1024), 16*1024*1024)
for n := 1; scanner.Scan(); n++ {
line := scanner.Text()
for _, re := range flagRes {
for _, m := range re.FindAllStringSubmatch(line, -1) {
if !allowedRemoteValue(m[2]) {
hits = append(hits, endpointHit{path: path, line: n, what: m[0]})
}
}
}
if strict {
for _, url := range remoteEndpointRe.FindAllString(line, -1) {
if !allowedRemoteValue(url) {
hits = append(hits, endpointHit{path: path, line: n, what: url})
}
}
}
}
return hits
}
func gitRepoAvailable(root string) bool {
if _, err := exec.LookPath("git"); err != nil {
return false
}
return exec.Command("git", "-C", root, "rev-parse", "--is-inside-work-tree").Run() == nil
}
func TestBazelNoRemoteEndpointsInTrackedFiles(t *testing.T) {
// Fixtures are assembled at runtime so this file never contains a literal
// endpoint itself.
scheme := "grpc" + "s://"
flag := func(name string) string { return "--" + name }
for _, bad := range []string{
"build:remote-exec " + flag("remote_executor") + "=" + scheme + "rbe.example.com:443\n",
"build:remote-exec " + flag("remote_executor") + "=rbe.example.com:443\n",
"build:remote-exec " + flag("remote_executor") + " rbe.example.com:443\n",
"build " + flag("remote_cache") + "=https://cache.example.com\n",
"build " + flag("bes_backend") + "=bes.example.com\n",
"build " + flag("bes_results_url") + "=https://results.example.com/inv/\n",
"build " + flag("remote_header") + "=x-api-key=abc123\n",
"build " + flag("tls_client_certificate") + "=/etc/rbe/client.crt\n",
"build " + flag("tls_client_key") + "=\"/etc/rbe/client.key\"\n",
"# farm: " + scheme + "10.0.0.5:8980\n",
"REMOTE=" + "grpc" + "://cache.internal:9092\n",
} {
if len(findRemoteEndpoints(".bazelrc", []byte(bad), true)) == 0 {
t.Errorf("endpoint fixture not detected: %q", bad)
}
}
for _, ok := range []string{
"build:remote-exec " + flag("remote_executor") + "=" + scheme + "<endpoint>\n",
"build:remote-exec " + flag("remote_executor") + "=<endpoint>\n",
"build:remote-exec " + flag("tls_client_certificate") + "=<path>\n",
" run: echo \"build " + flag("remote_executor") + "=${{ secrets.BAZEL_REMOTE_EXECUTOR }}\" >> \"$RUNNER_TEMP/ci.bazelrc\"\n",
" " + flag("tls_client_key") + " \"$RUNNER_TEMP/rbe.key\"\n",
" " + flag("remote_executor") + "=" + scheme + "${{ secrets.RBE_HOST }}\n",
flag("remote_cache") + "=" + "grpc" + "://127.0.0.1:50052\n",
flag("remote_cache") + "=localhost:9092\n",
flag("remote_cache") + "=\n",
"build " + flag("remote_timeout") + "=600\n",
"use grpc for transport\n",
} {
if hits := findRemoteEndpoints(".bazelrc", []byte(ok), true); len(hits) != 0 {
t.Errorf("allowed fixture flagged: %q -> %v", ok, hits)
}
}
// Markdown: OTel gRPC exporter URLs and prose mentioning the flag are fine;
// a literal flag value is not.
for _, ok := range []string{
"Set OTEL_EXPORTER_OTLP_ENDPOINT=" + "grpc" + "://collector:4317\n",
"Pass " + flag("remote_executor") + " and TLS flags from user.bazelrc.\n",
} {
if hits := findRemoteEndpoints("docs/x.md", []byte(ok), false); len(hits) != 0 {
t.Errorf("allowed Markdown fixture flagged: %q -> %v", ok, hits)
}
}
if len(findRemoteEndpoints("docs/x.md", []byte("bazel build "+flag("remote_executor")+"=rbe.example.com:443 //...\n"), false)) == 0 {
t.Error("literal remote_executor in Markdown not detected")
}
for rel, want := range map[string][2]bool{
".bazelrc": {true, true},
"tools/ci.bazelrc": {true, true},
".bazelrc.local": {true, true},
".github/workflows/x.yml": {true, true},
"docs/BAZEL.md": {true, false},
"issues.jsonl": {false, false},
"internal/telemetry/x.go": {false, false},
} {
if scan, strict := remoteScanKind(rel); scan != want[0] || strict != want[1] {
t.Errorf("remoteScanKind(%q) = %v,%v, want %v,%v", rel, scan, strict, want[0], want[1])
}
}
root := bazelPolicyRoot(t)
if !gitRepoAvailable(root) {
t.Skip("not a git checkout (e.g. Bazel sandbox); tracked-file scan runs under go test and CI")
}
out, err := exec.Command("git", "-C", root, "ls-files", "-z", "--", "*bazelrc*", "*.md", ".github").Output()
if err != nil {
t.Fatalf("git ls-files: %v", err)
}
var hits []endpointHit
for _, rel := range strings.Split(strings.TrimRight(string(out), "\x00"), "\x00") {
scan, strict := remoteScanKind(rel)
if !scan {
continue
}
info, err := os.Lstat(filepath.Join(root, rel))
if err != nil || !info.Mode().IsRegular() {
continue // deleted in the worktree, submodule, or symlink
}
content, err := os.ReadFile(filepath.Join(root, rel))
if err != nil {
t.Fatalf("read %s: %v", rel, err)
}
hits = append(hits, findRemoteEndpoints(rel, content, strict)...)
}
for _, h := range hits {
t.Errorf("%s:%d: remote endpoint or credential %q in a tracked file; it belongs in a gitignored user.bazelrc/.bazelrc.local or a CI-generated rc outside the workspace", h.path, h.line, h.what)
}
}
// --- generated go_srcs filegroups are current -------------------------------
// These checks walk the source checkout, which is not declared as Bazel data,
// so they run under plain `go test` (the gating lane) and skip under Bazel.
var (
treeGoSrcsRe = regexp.MustCompile(`(?s)filegroup\(\s*name\s*=\s*"tree_go_srcs",\s*srcs\s*=\s*\[(.*?)\]`)
goSrcsLabelRe = regexp.MustCompile(`"//([^":]+):go_srcs"`)
)
// treeGoSrcsMembers returns the packages whose go_srcs a tree_go_srcs
// filegroup aggregates, other than the tree root's own ":go_srcs".
func treeGoSrcsMembers(build string) ([]string, bool) {
m := treeGoSrcsRe.FindStringSubmatch(stripStarlarkComments(build))
if m == nil {
return nil, false
}
var members []string
for _, l := range goSrcsLabelRe.FindAllStringSubmatch(m[1], -1) {
members = append(members, l[1])
}
return members, true
}
// bazelPackagesUnder lists the repo-relative directories below treeRel (not
// treeRel itself) holding a BUILD.bazel, skipping the directories
// tools/bazel/go_srcs.py skips.
func bazelPackagesUnder(root, treeRel string) ([]string, error) {
var pkgs []string
err := filepath.WalkDir(filepath.Join(root, filepath.FromSlash(treeRel)), func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
name := d.Name()
if name == "testdata" || name == "node_modules" || (strings.HasPrefix(name, ".") && name != ".") {
return filepath.SkipDir
}
return nil
}
if d.Name() != "BUILD.bazel" {
return nil
}
rel, err := filepath.Rel(root, filepath.Dir(path))
if err != nil {
return err
}
if rel = filepath.ToSlash(rel); rel != treeRel {
pkgs = append(pkgs, rel)
}
return nil
})
return pkgs, err
}
func diffStringSets(want, got []string) (missing, extra []string) {
gotSet := map[string]bool{}
for _, g := range got {
gotSet[g] = true
}
wantSet := map[string]bool{}
for _, w := range want {
wantSet[w] = true
if !gotSet[w] {
missing = append(missing, w)
}
}
for _, g := range got {
if !wantSet[g] {
extra = append(extra, g)
}
}
return missing, extra
}
// goSrcsTrees are the tools/bazel/go_srcs.py TREES roots. A test that walks
// one of these trees under Bazel sees only the packages its tree_go_srcs
// lists, so an unlisted package makes the walk pass vacuously.
var goSrcsTrees = []string{"internal/storage"}
func TestBazelTreeGoSrcsListsEveryPackage(t *testing.T) {
build := "filegroup(\n name = \"tree_go_srcs\",\n srcs = [\n \":go_srcs\",\n \"//a/b:go_srcs\",\n # \"//a/c:go_srcs\",\n ],\n)\n"
if got, ok := treeGoSrcsMembers(build); !ok || len(got) != 1 || got[0] != "a/b" {
t.Errorf("treeGoSrcsMembers(fixture) = %v, %v; want [a/b], true", got, ok)
}
if missing, extra := diffStringSets([]string{"a/b", "a/c"}, []string{"a/b", "a/d"}); len(missing) != 1 || missing[0] != "a/c" || len(extra) != 1 || extra[0] != "a/d" {
t.Errorf("diffStringSets fixture: missing=%v extra=%v", missing, extra)
}
if os.Getenv("TEST_SRCDIR") != "" {
t.Skip("walks the source checkout; runs under go test")
}
root := sourceRepoRoot(t)
script := readPolicyFile(t, root, "tools/bazel/go_srcs.py")
for _, tree := range goSrcsTrees {
if !strings.Contains(script, strconv.Quote(tree)) {
t.Errorf("tools/bazel/go_srcs.py no longer lists tree %q; update goSrcsTrees", tree)
}
members, ok := treeGoSrcsMembers(readPolicyFile(t, root, tree+"/BUILD.bazel"))
if !ok {
t.Errorf("%s/BUILD.bazel has no tree_go_srcs filegroup; run `make bazel-sync`", tree)
continue
}
pkgs, err := bazelPackagesUnder(root, tree)
if err != nil {
t.Fatalf("walk %s: %v", tree, err)
}
if len(pkgs) == 0 {
t.Fatalf("found no BUILD.bazel packages under %s; the walk is broken", tree)
}
missing, extra := diffStringSets(pkgs, members)
for _, m := range missing {
t.Errorf("//%s:tree_go_srcs does not list //%s:go_srcs; run `make bazel-sync` (tools/bazel/go_srcs.py)", tree, m)
}
for _, e := range extra {
t.Errorf("//%s:tree_go_srcs lists //%s:go_srcs, which has no BUILD.bazel; run `make bazel-sync`", tree, e)
}
}
}
// TestBazelGoSrcsBlocksCurrent runs `tools/bazel/go_srcs.py --check`, which
// compares every managed block with what the script would generate.
func TestBazelGoSrcsBlocksCurrent(t *testing.T) {
if os.Getenv("TEST_SRCDIR") != "" {
t.Skip("reads the source checkout; runs under go test")
}
python, err := exec.LookPath("python3")
if err != nil {
t.Skip("python3 not available; TestBazelTreeGoSrcsListsEveryPackage still guards tree membership")
}
cmd := exec.Command(python, filepath.Join("tools", "bazel", "go_srcs.py"), "--check")
cmd.Dir = sourceRepoRoot(t)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("go_srcs.py --check: %v; run `make bazel-sync`\n%s", err, out)
}
}
// --- no Bazel packages under the docs trees ---------------------------------
// //:docsync_files globs docs/** and engdocs/**; a glob stops at a package
// boundary, so a BUILD file under either tree would silently drop that
// subtree from //test/docsync's orphan and link checks.
func TestBazelNoPackagesUnderDocsTrees(t *testing.T) {
if os.Getenv("TEST_SRCDIR") != "" {
t.Skip("walks the source checkout; runs under go test")
}
root := sourceRepoRoot(t)
for _, tree := range []string{"docs", "engdocs"} {
err := filepath.WalkDir(filepath.Join(root, tree), func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() && d.Name() == "node_modules" {
return filepath.SkipDir
}
if !d.IsDir() && (d.Name() == "BUILD.bazel" || d.Name() == "BUILD") {
rel, _ := filepath.Rel(root, path)
t.Errorf("%s: no Bazel package may live under %s/ (it would cut that subtree out of //:docsync_files)", filepath.ToSlash(rel), tree)
}
return nil
})
if err != nil {
t.Fatalf("walk %s: %v", tree, err)
}
}
}
// --- test tag taxonomy ---------------------------------------------------------
// allowedBazelTestTags is the tag taxonomy. A target with no tags is hermetic
// and runs everywhere (local, remote, PR). Every other tag must be one of
// these and must be justified in a comment right above the rule that uses it.
var allowedBazelTestTags = map[string]string{
"requires-dolt": "uses the hermetic pinned dolt CLI (informational)",
"host-tools": "needs host tools (bash/git/make/jq/...) beyond the test wrapper's",
"no-remote-exec": "must run on the Bazel client's host, never on a remote worker",
"no-remote-cache": "result depends on the host, so it is neither read from nor uploaded to the remote cache",
"requires-docker": "needs a docker daemon; excluded from --config=prcore/ci, run by --config=docker",
"embedded": "embedded-Dolt tier variant; its own config",
"manual": "never part of //...: a repro/bench harness, or a build input only another target needs",
}
// bazelTagsRequiring maps tags whose targets depend on the host to the tags
// they must also carry: no-remote-exec, or remote execution would run them on a
// worker that lacks the tool or daemon; and for host-tools, no-remote-cache,
// because the action key does not cover the host's tool inventory, so a result
// produced on one host must not be served to another. (requires-docker
// targets fail rather than skip without their daemon, so their passes are
// safe to share.)
var bazelTagsRequiring = map[string][]string{
"host-tools": {"no-remote-exec", "no-remote-cache"},
"requires-docker": {"no-remote-exec"},
}
var (
bazelTagsAttrRe = regexp.MustCompile(`\btags\s*=\s*`)
bazelTopRuleRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_.]*\(`)
bazelQuotedStrRe = regexp.MustCompile(`"([^"]*)"`)
)
// checkBazelBuildTags checks every `tags = [...]` in one BUILD file: the list
// is a literal, each tag is in the taxonomy and is named in the comment block
// directly above its rule, and host-bound tags come with no-remote-exec.
func checkBazelBuildTags(name, build string) []error {
var errs []error
lines := strings.Split(build, "\n")
for _, loc := range bazelTagsAttrRe.FindAllStringIndex(build, -1) {
line := strings.Count(build[:loc[0]], "\n")
rest := build[loc[1]:]
if !strings.HasPrefix(rest, "[") {
errs = append(errs, errors.New(name+":"+strconv.Itoa(line+1)+": tags must be a literal list"))
continue
}
end := strings.Index(rest, "]")
if end < 0 {
errs = append(errs, errors.New(name+":"+strconv.Itoa(line+1)+": unterminated tags list"))
continue
}
// `tags = ["x"] + OTHER` is not a literal either: only a comma, the
// rule's closing paren or the end of the line may follow the list.
if after := strings.TrimLeft(rest[end+1:], " \t"); after != "" && !strings.ContainsAny(after[:1], ",)\n#") {
errs = append(errs, errors.New(name+":"+strconv.Itoa(line+1)+": tags must be a literal list"))
continue
}
var tags []string
for _, m := range bazelQuotedStrRe.FindAllStringSubmatch(rest[:end], -1) {
tags = append(tags, m[1])
}
// The rule is the nearest top-level call above; its justification is
// the contiguous comment block right above that.
start := line
for start > 0 && !bazelTopRuleRe.MatchString(lines[start]) {
start--
}
var comment strings.Builder
for i := start - 1; i >= 0 && strings.HasPrefix(strings.TrimSpace(lines[i]), "#"); i-- {
comment.WriteString(lines[i])
comment.WriteByte('\n')
}
where := name + ":" + strconv.Itoa(start+1)
have := map[string]bool{}
for _, tag := range tags {
have[tag] = true
if _, ok := allowedBazelTestTags[tag]; !ok {
errs = append(errs, errors.New(where+": tag "+strconv.Quote(tag)+" is not in the taxonomy (allowedBazelTestTags)"))
continue
}
if !strings.Contains(comment.String(), tag) {
errs = append(errs, errors.New(where+": tag "+strconv.Quote(tag)+" is not justified in a comment directly above the rule"))
}
}
for _, tag := range tags {
for _, need := range bazelTagsRequiring[tag] {
if !have[need] {
errs = append(errs, errors.New(where+": tag "+strconv.Quote(tag)+" also requires "+need))
}
}
}
}
return errs
}
func TestBazelTestTagsFollowTaxonomy(t *testing.T) {
for name, good := range map[string]string{
"docker": "# Tags:\n# requires-docker: needs a daemon.\n# no-remote-exec: the daemon is local.\n" +
"sh_test(\n name = \"x\",\n tags = [\n \"no-remote-exec\",\n \"requires-docker\",\n ],\n)\n",
"host-tools": "# host-tools, no-remote-exec, no-remote-cache: git.\n" +
"go_test(\n name = \"x\",\n tags = [\"host-tools\", \"no-remote-exec\", \"no-remote-cache\"], # why\n)\n",
} {
if errs := checkBazelBuildTags(name, good); len(errs) != 0 {
t.Errorf("%s: justified fixture rejected: %v", name, errs)
}
}
for name, build := range map[string]string{
"unknown tag": "# flaky: why\ngo_test(\n name = \"x\",\n tags = [\"flaky\"],\n)\n",
"no comment": "go_test(\n name = \"x\",\n tags = [\"manual\"],\n)\n",
"comment too far": "# manual: harness\n\ngo_test(\n name = \"x\",\n tags = [\"manual\"],\n)\n",
"other rule's": "# manual: harness\ngo_test(name = \"a\", tags = [\"manual\"])\n\ngo_test(\n name = \"b\",\n tags = [\"manual\"],\n)\n",
"docker unpinned": "# requires-docker: daemon\ngo_test(\n name = \"x\",\n tags = [\"requires-docker\"],\n)\n",
"not a literal": "# manual\ngo_test(\n name = \"x\",\n tags = MANUAL,\n)\n",
"literal plus": "# manual\ngo_test(\n name = \"x\",\n tags = [\"manual\"] + MORE,\n)\n",
"host cacheable": "# host-tools no-remote-exec\ngo_test(\n name = \"x\",\n tags = [\"host-tools\", \"no-remote-exec\"],\n)\n",
"one-line rule": "go_test(name = \"x\", tags = [\"manual\"])\n",
} {
if errs := checkBazelBuildTags(name, build); len(errs) == 0 {
t.Errorf("%s: expected a tag policy error for fixture:\n%s", name, build)
}
}
if os.Getenv("TEST_SRCDIR") != "" {
t.Skip("walks every BUILD file in the source checkout; runs under go test")
}
root := sourceRepoRoot(t)
pkgs, err := bazelPackagesUnder(root, ".")
if err != nil {
t.Fatalf("walk: %v", err)
}
if len(pkgs) == 0 {
t.Fatal("found no BUILD.bazel packages; the walk is broken")
}
for _, pkg := range append([]string{"."}, pkgs...) {
rel := filepath.ToSlash(filepath.Join(pkg, "BUILD.bazel"))
for _, err := range checkBazelBuildTags(rel, readPolicyFile(t, root, rel)) {
t.Error(err)
}
}
}
// checkBazelrcPrcoreTagFilter requires --config=prcore to exclude the tags
// that never run in the PR-core lane. Every --test_tag_filters set by prcore or
// by a config that expands it (test:ci) is checked, since a later one would
// override the first.
func checkBazelrcPrcoreTagFilter(bazelrc string) error {
type option struct{ config, flag string }
var opts []option
for _, line := range strings.Split(bazelrc, "\n") {
fields := strings.Fields(line)
if len(fields) < 2 || strings.HasPrefix(fields[0], "#") {
continue
}
_, config, ok := strings.Cut(fields[0], ":")
if !ok {
continue
}
for i := 1; i < len(fields); i++ {
flag := fields[i]
if (flag == "--config" || flag == "--test_tag_filters") && i+1 < len(fields) {
i++
flag += "=" + fields[i]
}
opts = append(opts, option{config, flag})
}
}
lane := map[string]bool{"prcore": true}
for grew := true; grew; {
grew = false
for _, o := range opts {
if !lane[o.config] && strings.HasPrefix(o.flag, "--config=") && lane[strings.TrimPrefix(o.flag, "--config=")] {
lane[o.config] = true
grew = true
}
}
}
prcoreFilter := false
for _, o := range opts {
if !lane[o.config] || !strings.HasPrefix(o.flag, "--test_tag_filters=") {
continue
}
prcoreFilter = prcoreFilter || o.config == "prcore"
filters := map[string]bool{}
for _, f := range strings.Split(strings.TrimPrefix(o.flag, "--test_tag_filters="), ",") {
filters[f] = true
}
for _, tag := range []string{"requires-docker", "embedded", "manual"} {
if !filters["-"+tag] {
return errors.New(o.config + " --test_tag_filters does not exclude " + tag)
}
}
}
if !prcoreFilter {
return errors.New(".bazelrc has no test:prcore --test_tag_filters line")
}
return nil
}
func TestBazelrcPrcoreExcludesNonPRTags(t *testing.T) {
if err := checkBazelrcPrcoreTagFilter(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc")); err != nil {
t.Fatal(err)
}
for name, rc := range map[string]string{
"missing": "test:ci --keep_going\n",
"no docker": "test:prcore --test_tag_filters=-embedded,-manual\n",
"ci override": "test:prcore --test_tag_filters=-requires-docker,-embedded,-manual\n" +
"test:ci --config=prcore\ntest:ci --test_tag_filters=requires-docker\n",
"second prcore line": "test:prcore --test_tag_filters=-requires-docker,-embedded,-manual\n" +
"test:prcore --test_tag_filters=-manual\n",
"transitive": "test:prcore --test_tag_filters=-requires-docker,-embedded,-manual\n" +
"test:ci --config=prcore\nbuild:nightly --config ci --test_tag_filters=\n",
} {
if err := checkBazelrcPrcoreTagFilter(rc); err == nil {
t.Errorf("%s: expected an error for .bazelrc fixture:\n%s", name, rc)
}
}
}
// TestBazelrcPrcoreRequiresExcludePermission keeps test:prcore in step with
// pr.yml's PR Core step (TestPRCoreRequiresExcludeReadPermissionCoverage):
// without the variable, TestAddExcludePatternsRefusesReadErrors skips on a
// root executor instead of failing.
func TestBazelrcPrcoreRequiresExcludePermission(t *testing.T) {
const want = "test:prcore --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1"
for _, line := range strings.Split(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "\n") {
if strings.TrimSpace(line) == want {
return
}
}
t.Fatalf(".bazelrc lacks %q", want)
}
// TestBazelrcPrcoreMatchesPRCoreParallel keeps test:prcore's -test.parallel
// equal to pr-core.sh's -parallel default: without it Go uses GOMAXPROCS, the
// executor's core count, and runs far more tests at once than PR Core does.
func TestBazelrcPrcoreMatchesPRCoreParallel(t *testing.T) {
root := bazelPolicyRoot(t)
m := regexp.MustCompile(`(?m)^GO_TEST_PARALLEL="\$\{GO_TEST_PARALLEL:-(\d+)\}"$`).FindStringSubmatch(readPolicyFile(t, root, "scripts/ci/pr-core.sh"))
if m == nil {
t.Fatal("scripts/ci/pr-core.sh has no GO_TEST_PARALLEL default")
}
want := "test:prcore --test_arg=-test.parallel=" + m[1]
for _, line := range strings.Split(readPolicyFile(t, root, ".bazelrc"), "\n") {
if strings.TrimSpace(line) == want {
return
}
}
t.Fatalf(".bazelrc lacks %q (pr-core.sh runs go test -parallel %s)", want, m[1])
}
// Docker-lane results depend on host state no action key sees (daemon, dolt
// image, network), so they must always execute, like the container jobs'
// -count=1; and no remote-exec run may upload a locally executed result to
// the shared cache.
func TestBazelrcDockerLaneNeverCached(t *testing.T) {
lines := map[string]bool{}
for _, line := range strings.Split(readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc"), "\n") {
lines[strings.TrimSpace(line)] = true
}
for _, want := range []string{
"test:docker --nocache_test_results",
"build:remote-exec --noremote_upload_local_results",
} {
if !lines[want] {
t.Errorf(".bazelrc lacks %q", want)
}
}
}