Commit graph

4 commits

Author SHA1 Message Date
Julian Knutsen
b7dba4d4e4
test: ban ungated host go/gofmt execs under Bazel; pin compact_gc_fixture pure/norace (#7485)
* test: ban ungated host go/gofmt execs under Bazel; pin compact_gc_fixture pure/norace

Follow-up to #7478. Adds two policy tests on //scripts:go_sources_test:

- host_tool_exec_policy_test.go: an AST scan of every *_test.go file and
  internal/testutil's non-test .go files for exec.Command/CommandContext/
  LookPath("go"/"gofmt") that isn't gated by bazeltest.IsBazel()/TEST_SRCDIR
  in its enclosing function, with an explicit, justified allowlist for the
  handful of sites gated by caller dataflow instead (bazeltest.PrebuiltBD()
  checked before calling a separate helper). "dolt" is out of scope: the
  hermetic copy resolves first on Bazel's PATH, unlike go/gofmt.
- host_tool_shell_policy_test.go: the same policy for the shell scripts
  under scripts/ that Bazel sh_test/go_test targets actually execute
  (fmt-check.sh, the repochecks guards, gofmt-bin.sh, the migration-test
  harness), matching the gating pattern #7478 added to fmt-check.sh and
  scripts/ci/lib/test-env.sh.

Both are mutation-verified (an added ungated exec.Command("go","version")/
`go build` is detected, then reverted cleanly).

Also sets pure = "on" and race = "off" on cmd/bd/BUILD.bazel's
compact_gc_fixture go_binary, matching :bd_for_tests/:cmd_norace: it is a
testonly, stdlib-only fixture, so neither cgo nor the race detector buys it
anything, under any --config. Verified TestRunCompactDoltTargetsOnlyAuthorizedActiveDatabase
still passes via `bazel --nohome_rc test` under both --config=prcore and
--config=doltserver-cmd.

Known pre-existing issue, out of scope here: gosec's GoVersion() call still
execs a host `go` from third-party code this policy doesn't reach.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(scripts): address review of host-tool exec/shell policy (#7485)

Fixes all 6 maintainer-city-c3 review items against the ban-ungated-go/
gofmt-exec policy, each with a mutation test proving the fix catches
the described regression:

1. Shell scan now gates per-branch/per-call-site (shellLineGating),
   not by any TEST_SRCDIR mention anywhere in the whole file.
2. Shell scanner adds gofmt and `go tool` detection, fixes the
   heredoc-start regex (no longer swallows the rest of the script on an
   arithmetic `<<` shift or a `<<<` here-string), and replaces the
   blanket printf/echo/git-grep line skip with a quoted-span/command-
   substitution-aware check that still catches a real exec joined onto
   a message line with `&&`.
3. shellPolicyScope gains pr-lint.sh, check-versions.sh,
   upgrade-smoke-test.sh and the 4 .github/scripts shard fallbacks,
   each cited against its real BUILD.bazel/.bzl wiring; corrects two
   factually wrong "not executed" doc-comment claims (pr-lint.sh and
   upgrade-smoke-test.sh ARE Bazel-executed); and adds
   TestShellPolicyScopeCoversBazelShellData, a mechanical backstop that
   fails on a Bazel-referenced .sh under scripts/ or .github/scripts/
   missing from scope.
4. hostToolExecAllowlist no longer exempts goBuildBDCommand's 9 call
   sites by helper name; helperIsGatedByAllCallers checks every real
   call site is itself gated.
5. Both allowlists are keyed by file + enclosing function + exact
   snippet, not line number.
6. gated()/shellLineGating understand condition polarity, so an
   inverted `if !IsBazel() { t.Skip() }` (or its shell equivalent) is
   correctly NOT counted as a gate.

Also extends the Go scanner's condPolarity to recognize
findPrebuiltBDBinary()/bazeltest.PrebuiltBD() result variables as a
TEST_SRCDIR-equivalent gate (proven safe by reading their
implementation), and the shell scanner's analogous shellBazelSetVars
for CANDIDATE_BIN/SOURCE_TAG_SQLITE_BIN/BEADS_TEST_*_BINARY, including
through a script's own default-value variable alias
(`VAR="${BAZEL_VAR:-default}"`).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(scripts): give go_sources_test runfiles access to the new shell scope

The shell-policy rewrite (host_tool_shell_policy_test.go) added
shellPolicyScope entries for scripts/ci/pr-lint.sh,
scripts/check-versions.sh, scripts/upgrade-smoke-test.sh, and the four
.github/scripts/*-test-shard.sh files, plus a scope-coverage guard
(TestShellPolicyScopeCoversBazelShellData) that walks every tracked
BUILD.bazel file. None of those were runfiles of
//scripts:go_sources_test, so bazel test passed locally under plain
`go test` but failed in CI's hermetic Bazel sandbox with "no such file
or directory" for the new scope entries and "found only 0 BUILD.bazel
files" for the guard's walk.

Add //:repo_other_files (every tracked non-Go, non-Markdown file,
including every BUILD/.bzl file) to go_sources_test's data, mirroring
the same pattern already used by //scripts:scripts_test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(scripts): rename AST-fixture function so it isn't counted as a real test

tools/bazel/equivalence.py compares `go test`'s discovered top-level
tests against what Bazel actually ran, using a raw-text regex
(`^func\s+(Test\w*)\s*\(\s*\w+\s+\*testing\.T\s*\)`) rather than
compiling the file. The "inverted IsBazel skip" fixture in
host_tool_exec_policy_test.go embeds a column-0
`func TestSomething(t *testing.T) {` inside a backtick string used to
build an AST for findHostToolExecCalls, which the regex scan counted
as a real top-level test that Bazel's go_sources_test then "failed to
run" (CI's Bazel / test leg: EQUIVALENCE: FAIL on "scripts
TestSomething"). Rename the fixture's inner function to
bazelOnlyFixture; the test's behavior is unchanged since the name was
never semantically significant to the scan being exercised.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(scripts): close host-go-policy gaps from PR #7485 re-review

Four fixes from the final review round:

1. test.sh/conformance.sh/release.sh ARE in scope (they run under Bazel
   via scripts/** data globs); drop the false "not in scope" claims and
   add justified fn-keyed allowlist entries for their 8 flagged execs.
2. Go AST: an exec inside the Bazel-true branch, before its own abort,
   is no longer wrongly counted as gated (M17); a gate inside a sibling
   closure no longer covers execs outside it.
3. Shell scanner: abort/skip gate state now resets at function-scope end
   (a top-level `go build` after build_candidate in
   upgrade-smoke-test.sh is correctly flagged), and `bash -c 'go build'`
   is detected again.
4. Split host_tool_shell_policy_test.go into its own go_test
   (shell_host_tool_policy_test) with narrow, curated data instead of
   riding go_sources_test's //:repo_other_files; restored
   go_sources_test's data to its pre-PR scope. Dropped
   TestShellPolicyScopeCoversBazelShellData: its regex backstop could
   not see Starlark labels/.bzl/globs and still missed real in-scope
   scripts, so it wasn't earning its cache-rerun cost. The new target
   carries no tags, so it still runs in the required "Bazel / test"
   lane.

Each of 1-3 ships with a mutation-proof fixture that fails on the prior
code and passes on the fix.

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

* fix(scripts): rename sibling-closure fixture to avoid false test-equivalence hit

tools/bazel/equivalence.py line-scans *_test.go files for a column-0
`func Test\w*(t *testing.T)` to build its "what go test runs" list; it
reads raw text, not compiled Go, so the fixture's embedded raw-string
Go source (used to feed findHostToolExecCalls a parseable AST) was
mistaken for a real top-level test the package defines, and the
equivalence check failed because no go_test target "ran" it. Rename
the fixture function from TestX to siblingClosureFixture, matching the
existing convention a few lines down (bazelOnlyFixture) that documents
the same pitfall.

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

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-10 23:51:34 +00:00
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
Julian Knutsen
9d13485b71
ci(bazel): retire main.yml's Linux jobs, nightly's go test jobs and ci-measurements (#7354)
Push to main and the nightly schedule no longer run go test or repo checks
on GitHub runners (ga-96smfk.22, ga-96smfk.58):

- main.yml keeps only the macOS -race -short suite, the Windows smoke build
  and the push-to-main savers of the GOCACHEs pr.yml's Windows/macOS jobs
  restore. Its Linux jobs (migration hygiene, build artifacts, build tags,
  versions, duplicate migrations, doc flags, package gates, PR policy
  wrapper, gofmt, the Linux and setup-go cache seeders, the Nix flake
  check) are gated on the merge queue's pr.yml/pr-risk.yml run of the
  same commit and re-run as Bazel targets by bazel.yml's push run.
- nightly.yml is the fresh bazel.yml call plus the worker-env check; its
  Full Test Suite, PR Core go-test-json side and measure dispatch are gone,
  as are ci-measurements.yml and bazel.yml's go-test-json-artifact input.
- The non-race embedded batch-apply step becomes
  //internal/storage/embeddeddolt:embeddeddolt_batch_apply_nonrace_test
  (go_test_race_off, BEADS_TEST_EMBEDDED_DOLT=1) in the embedded tier.
- make ci-pr-policy and scripts/ci/pr-policy.sh go: every check it ran is
  a Bazel test (TestPRPolicyChecksRunAsBazelTargets).

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 10:06:59 +00:00
Julian Knutsen
b1fe68e63a
ci(bazel): run pr.yml's repository guards as Bazel tests (#7329)
fast-checks, PR Policy, and the Linux leg of check-doc-freshness-platforms
ran repository guards on GitHub runners. They now run as Bazel tests in
bazel.yml's `test` lane (remote, cached), each over only the files it reads:

- tools/bazel/repo_subset.bzl picks a narrow, path-selected slice of
  //:repo_files at analysis time. scripts/repochecks/run_check.sh copies that
  slice into a throwaway git checkout and runs the unchanged guard there.
- //scripts/repochecks: build_tags, workflow_tags, go_install_guidance,
  winget_portable_alias, migration_hygiene (checks A and B),
  fmt (registered SDK gofmt), doc_freshness, workapi_frontend_boundary,
  types_gen_drift (`make api-check` drift, oapi-codegen from go.mod).
- //scripts:doc_freshness_required_test (integration lane, -required-suite)
  and //scripts/gitattributespolicy:gitattributespolicy_required_host_test
  cover the Linux doc-freshness leg.
- check-versions stays covered by //internal/versioncheck:versioncheck_test.
  check-testing-short stays covered by //scripts:scripts_test.

pr-policy-wrapper is deleted. fast-checks keeps only the two checks that
need the PR base: migration hygiene's delta half (MIGRATION_HYGIENE_SCOPE=
delta) and the .beads diff. check-doc-flags stays, because it builds bd from
the pinned release tag. The example Go modules leave .bazelignore so gofmt
and the grep guards see them. check_testcases.py now accepts --not-go
//pkg:all.

Refs: ga-96smfk.20

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 00:59:18 +00:00