The host-tool-exec policy scanner (scripts/host_tool_exec_policy_test.go)
had two remaining soundness gaps flagged in gastownhall/beads#7491's
review:
- M19: a discarded PrebuiltBD()/findPrebuiltBDBinary() error (e.g.
`bd, _ := PrebuiltBD()`) kept the "never empty under Bazel" invariant
trusted for `bd`, even though a real lookup failure under Bazel also
returns "" there. prebuiltResultVars now only trusts the result when
the error is bound to a named variable that is itself checked with an
aborting `if err != nil`.
- M21: an abort-style gate (`if bazeltest.IsBazel() { return }`) counted
as gating an exec that ran before it, in source order, within the same
block. The abort-style check now requires the gate to dominate the
exec (ifStmt.End() <= pos); containment-style gating is unaffected
since nesting already guarantees order.
Flips the two tests that pinned these as documented limitations into
mutation fixtures that must fail, adds three new M19 fixtures (discarded
error, bound-but-unchecked error, and the fixed/checked shape), and
updates the package and gated() doc comments. TestNoUngatedHostToolExecs
UnderBazel confirms no real call site in the tree regresses.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(ci-policy): close review leftovers from #7485/#7486
Follow-ups from maintainer review on the host-tool exec/shell policy
tests and the bazel.yml integration gate:
- host_tool_shell_policy_test.go: recognize indented function headers
and `function name {` forms when finding a function's closing brace,
so scripts/test.sh's indented cleanup_shared_server() no longer
mis-attributes its trailing lines to the wrong function; classify
same-line `command -v gofmt && gofmt` (and `go`) as the guarded
presence-check idiom instead of flagging it.
- host_tool_exec_policy_test.go: make condPolarity reject mixed-polarity
&& / || compounds (one recognized side, one not) instead of guessing
at the recognized side's polarity, which was unsound in both
directions; add pinning tests documenting the exec-before-gate and
function-value-helper cases as known, safety-conservative limitations
rather than bugs. Fixing this exposed a real ungated fallback in
cmd/bd/scripttest_test.go (a `go build` that could still run under
Bazel on a prebuilt-binary basename mismatch); fixed by symlinking the
prebuilt binary under the expected name instead of rebuilding it.
- bazel.yml: bazel-server-storage now honors the `integration` input
like bazel-integration/bazel-cmd-dolt do, so an explicit "off" skips
it too (latent today: no caller passes "off"). Updated
ci_workflow_test.go's policy tests to match.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(ci-policy): close should-fix B (go command -v guard evasion) on #7491
shellCommandVGuard previously excused go the same as gofmt, but under an
exit-127 host-tool stub `command -v` finds the stub and the guarded exec
still runs, and on a worker genuinely lacking go the exec was silently
skipped -- the worker-dependent behavior this policy exists to ban. Drop
go from the guard entirely, require the guarded exec to sit directly after
the guard's own `&&` (no intervening `;`, `||`, `|`, or leading `!`), and
require an exact gofmt match so a same-prefixed sibling like `gofmt-foo`/
`go-junit-report` can't borrow the guard. Add every should-fix B shape as
a fixture that must still be flagged, plus the generalized gofmt-side
cases (leading `!`, exact-name, post-`;` exec).
Also: correct host_tool_exec_policy_test.go's doc claim that a
function-value helper call site is "not a soundness hole" -- mixed with
one gated direct call site, the invisible function-value call site's
ungated-ness is silently lost and the combined verdict flips to gated;
pinned as review M22. And recognize a function closed by `} >&2` as
ended, so abort-style safety computed inside it does not leak into the
rest of the file (no scoped script has this shape today, but a bare `}`
equality check would silently miss it the moment one does).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
* 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>