Commit graph

9 commits

Author SHA1 Message Date
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
a4509deb2d
ci(bazel): nogo replaces go vet and golangci-lint (ga-96smfk.18) (#7341)
* ci(bazel): nogo replaces go vet and golangci-lint (ga-96smfk.18)

Lint and vet now run as nogo inside the Bazel build, so they gate wherever
the Bazel lanes execute (rbe-west), and the golangci-lint and go vet jobs
leave pr.yml and main.yml.

- //tools/nogo (own go.mod, joined to beads' for go_deps only through
  gazelle.go.work): go test's vet checks (cmd/go's defaultVetFlags, the set
  scripts/ci/go-test-vet.sh ran) plus the eight linters .golangci.yml
  enables, each a wrapper over the library version golangci-lint v2.10.1
  uses (depguard, errcheck, forbidigo, gosec, misspell, sloglint, unconvert,
  unparam).
- .golangci.yml stays the single lint policy: Bazel embeds it and
  tools/nogo/internal/golangci applies it as golangci-lint does (enabled
  set, settings, run.tests: false as library-unit-only analysis, lax
  generated-file detection, path/path-except/text exclusion rules), with
  strict decoding so an unimplemented key fails the build.
- gascity's rules_go //nolint-range patch and x/tools ctrlflow patch,
  byte-identical.
- Windows/darwin: cross-configured, not a golangci leg. The pure lane's
  release cross-compile (//tools/bazel:release_cross, every library and
  binary for all eight release platforms, cgo off) runs nogo on every
  compile, a superset of golangci-lint's windows and darwin legs.
  scripts/pr-lint (make ci-pr-lint, bd preflight) runs `bazel build
  --config=nogo //...` plus release_cross for windows_amd64,darwin_arm64.
  release_cross skips tools/nogo, a separate Go module `go build ./...`
  never compiled.
- pr.yml: scripts-go-checks (vet) and pr-lint-wrapper (x3) are gone, with
  their ci-gate entries; main.yml: pr-lint-wrapper (x6) and go-vet-cache.
  scripts/ci/go-test-vet.sh and install-golangci-lint.sh are deleted.
- pre-commit hook and .pre-commit-config.yaml run `make lint-changed
  LINT_CHANGED_SCOPE=staged` (nogo over the staged packages); Makefile adds
  lint, vet and lint-changed. pr-lint.sh no longer runs gofmt
  (//scripts/repochecks:fmt_test owns it; ga-96smfk.41).
- internal/testutil/integration: five gosec findings in integration-tagged
  library files golangci-lint never built, now linted by the integration
  lanes, carry reasoned //nolint directives.

Parity: with the exclusion rules removed, golangci-lint and nogo report the
same 3,916 findings natively and 3,859 each for windows and darwin (file,
line, linter, text); with .golangci.yml as committed both report none.

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

* ci(bazel): equivalence.py leaves nested Go modules' tests out of go test's set

tools/nogo is its own Go module, so `go test ./...` in the root never runs
its tests; Bazel's unit lane does. Its packages are neither expected nor
extra.

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-07 05:17:22 +00:00
Julian Knutsen
0500fc6f40
ci(bazel): run the scripts and source-walking tests remotely; retire their go test legs (#7320)
//scripts:scripts_test and //scripts/check-versions:check-versions_test
drop their host-tools/no-remote-exec/no-remote-cache tags and run on the
rbe-west workers like every other target (the worker image ships bash, git,
python3, jq, yq, curl, openssl, unzip and coreutils; a missing tool fails the
test under Bazel rather than skipping it). Go comes in hermetically as the
registered SDK; check-versions.sh's `go build` is stood in for by the
Bazel-built checker.

The tests that walked the source checkout now get it as data:
tools/bazel/go_srcs.py keeps a managed `repo_files` filegroup in every
package and aggregates them into //:repo_files (exactly the tracked files
Bazel can see; make bazel-sync-check fails on a package without one).
scripts_test and docsync_test take it instead of hand-listed filegroups,
and every TEST_SRCDIR/IsBazel skip and go-test-only block in them is gone.
The release formula under .bazelignore'd .beads/ comes in through a
@beads_formulas local repository; npm-package/ and .claude/ are visible to
Bazel again (only their node_modules/worktrees stay ignored), so the npm
manifest release check and the AGENTS.md skill links run under Bazel too.
TestZZStdioNotLeaked falls back to TestMain's pre-run streams instead of
skipping in a shard without its baseline.

tools/bazel/equivalence_allowlist.txt shrinks from 20 skip entries to the
two cmd/bd tests of plain go test's own bd build fallback, which Bazel never
takes; pr-preflight-platforms now runs them on Linux, macOS and Windows. The
scripts-go-checks scripts-test and allowlisted legs, their scripts
(scripts-go-test.sh, allowlisted-go-tests.sh, run_allowlisted_go_tests.py)
and main.yml's --compile-only warm for them are removed. The vet leg stays
(ga-96smfk.18).

Refs: ga-96smfk.16

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-06 22:20:16 +00:00
Julian Knutsen
d2844318a1
fix(tests): prlintmake runs go.mod's toolchain from the Bazel Go SDK (#7138)
Under Bazel, prlintmake_test resolved go.mod's toolchain (go1.26.7)
through whatever go the executor has on PATH. When that is another
release, gofmt-bin.sh's GOTOOLCHAIN=go1.26.7 fallback downloads the
toolchain from proxy.golang.org on every run, and fails where actions
have no network: rbe-west's fork pool runs every action in its own
network namespace with loopback only (NETNS=1). Three tests failed
there (TestGofmtBinMatchesGoModToolchain, TestGofmtBinIgnoresPathGofmt,
TestFmtCheckReportsGofmtVersion) and passed with NETNS=0.

The registered SDK is go.mod's toolchain (bazel_policy_test pins them),
so declare it as data and have testGo put it first on PATH. gofmt-bin.sh
then takes its "host go already is the pinned one" path and fetches
nothing. Plain `go test` is unchanged.

Co-authored-by: gascity-agent <agent@gascity.ai>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-03 13:33:54 -07:00
ecuthiell
6899813df6
fix(preflight): share checkout lint authority (#5780)
* fix(preflight): share checkout lint authority

Move the Beads repository's native and Windows non-CGO lint policy into a checkout-owned Go driver. The supported Make/Bash wrapper and bd preflight now execute that same authority, while generic Go repositories retain their direct lint contract and formatting is rooted at the detected project.

Fixes #5300.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* docs(lint): clarify shared driver scope and timeout limits

Address PR #5780 review 5191123668. Document existing inherited-tag semantics and distinguish the wrapper/preflight driver from standalone workflow and pre-commit callers.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(lint): prefer the selected Windows Go toolchain (#6865)

Keep per-pass toolchain requests and deadlines while avoiding the extra auto-selection launcher under the linter. Nonstandard SDKs retain their original PATH.

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* fix(lint): retain PATH for SDK directories containing separators (#6865)

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* test(preflight): declare lint fixture executable for Bazel (#5300)

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* fix(bazel): keep cmd/bd/testdata out of gazelle's package scan

PR #5780 adds the compilable fixture cmd/bd/testdata/preflight-go.go. Left to
itself gazelle generates a BUILD.bazel for cmd/bd/testdata, which makes it its
own package and then (a) empties cmd/bd's data = glob(["testdata/**"]) under the
default allow_empty = False and (b) puts testdata/preflight-go.go across a
package boundary from the preflight_go_fixture target that lists it.

bazel.yml's "BUILD files in sync" step runs `make bazel-sync` and fails on any
resulting drift, and fork PRs always run that job, so this was a live red whose
prescribed remedy ("commit the result") would have broken the build further.
Exclude the directory instead, and take gazelle's ordering for the data list.

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

* fix(preflight): bound the lint deadline and report each check's scope

Review iteration 1 for PR #5780. Synthesis and scorecard both approve (975/1000,
no blocker or major), so this addresses non-gating findings only.

Finding 4 (Resource Lifecycle) - the 13-minute deadline could not bound the call
it guards. CombinedOutput collects through a pipe every descendant inherits, so
Wait kept blocking on a surviving golangci-lint after the context killed the
direct `go run` child. Measured on the same process shape (direct child killed at
1s, descendant holding the pipe for 8s): without WaitDelay the call returned in
8.00s, with WaitDelay in 1.50s. Sets cmd.WaitDelay so the deadline is a real
bound and the "lint check exceeded" line can actually print.

Also gates that line on err != nil, which retires the claude lane's nit (a): a
child that exits cleanly as the deadline fires is a pass, not a timeout. Measured
at the crossover, 68 of 300 passing runs would have carried a false "exceeded"
line; 0 after the gate.

Finding 1 (Change Impact) and nit 7 (Debuggability), one remedy - the PR re-roots
lint and fmt at preflightProjectRoot() but leaves runTestCheck in the caller's
cwd, so a --check run from a subdirectory mixes a repo-wide verdict with a
subtree-only one "with nothing in the output distinguishing them", and the
reported command is only reproducible from the root. CheckResult now carries the
directory each check resolved to, and the report prints it.

Took the synthesis's second arm (state the scope split) rather than re-rooting
runTestCheck, because re-rooting is a behaviour change neither lane priced: it
widens a subdirectory user's test run from 5 packages to 128, including every
Dolt-dependent package, on a repo whose full test gate the PR body already
discloses as red. The stated hazard is that the scopes are indistinguishable,
which reporting the directory discharges directly.

Finding 2 (Architectural Consistency), second clause - adds
TestBuildFlagsContractMatchesShellSource, which parses .buildflags and pins the
driver constants to it. The existing mirror test asserts today's values from the
Go side only, so the files could drift silently; buildEnvironment overrides
rather than merges -tags, so a tag added to .buildflags alone would be dropped
with every test still green. Each of the three legs was mutation-proved to red.

Declined, with the measurements that decided it:

- Finding 2's first clause (route the key comparisons through
  internal/execenv.KeyEqualForOS). The two are provably equivalent today -
  execenv's keyIdentityForWindows is strings.ToLower for the same documented
  reason - so this is de-duplication, not a defect, and the hazard it closes
  (os/exec key-identity semantics changing) is far less live than the
  .buildflags drift the second clause pins. The faithful swap means threading
  goos through five driver functions and ~27 test call sites in this PR's
  centerpiece file, and it would put a non-stdlib dependency into pr-lint_lib,
  which the binary currently does not have. Worth doing on its own footing, not
  inside a non-gating cleanup.

- Nit 6 (parse GOFLAGS into fields instead of a substring test). .buildflags:22
  guards its own append with `!= *gms_pure_go*`, a substring test, and the Go
  code is a deliberate mirror of it. Making only the Go side stricter would
  manufacture exactly the drift finding 2 warns about: on
  GOFLAGS=-tags=gms_pure_go_x the shell would skip its append while the driver
  performed one. The fix belongs to .buildflags and the driver together, and
  .buildflags is outside this PR. The new mirror test now pins that agreement.

- Nit 5 (probe golangci-lint as well as `go`). The claude lane examined the
  LookPath target change and recorded it as deliberate, with the driver's own
  missing-linter error as the mitigation. The suggested alternative - have the
  driver emit preflight's `--skip-lint` hint - puts a bd-specific flag into a
  driver that CI also invokes, where that advice is wrong.

- Finding 3 (two false PR-body claims). Correcting the body is outward-facing
  and belongs to finalize; stamped for it. Swept the in-tree copies: the PR's own
  LINTING.md sentence "Toolchain requests, formatting, and lint deadlines are
  unchanged" is scoped to the Windows SDK-preference paragraph it sits in and is
  true there, so it is graded rather than repaired. CHANGELOG.md contains no
  pr-lint entry, so the remedy's CHANGELOG half has no target in this PR.

Validation: go build, go vet and gofmt clean on the changed packages;
./scripts/pr-lint/ 12 pass / 2 Windows-only skip; ./scripts/prlintmake/ pass;
cmd/bd preflight selector pass; scripts/check-doc-freshness.sh PASSED;
make bazel-sync idempotent and bazel test //scripts/pr-lint:pr-lint_test PASSED.

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

* test(prlintmake): inject the pr-lint wrapper's gofmt shim through GOFMT

The merge with #6294 (be-gx8) left runPRLintWrapper relying on a
code path #6294 made deliberately loud. The helper put its gofmt shim
on PATH. Since #6294, fmt-check.sh resolves gofmt through
scripts/ci/gofmt-bin.sh, which ignores a PATH gofmt by design.

Both TestPRLintWrapper* tests still passed, but only via the
resolver's fallback. The go shim answers `go env GOVERSION` and
`go env GOROOT` with nothing, so gofmt-bin.sh warns "could not resolve
a gofmt from go.mod's go1.26.7 toolchain" and falls back to whatever
gofmt is first on PATH, which happened to be the shim. With GOFMT set
in the environment, which is #6294's documented override, the
resolver uses that value instead. Both tests then fail: exit status
127 from fmt-check.sh, and a missing aggregate failure diagnostic
because pr-lint.sh stops before `go run`. At the pre-merge head
(7f37ba5165) the same ambient GOFMT=/nonexistent run passed all 5
tests.

Pass the shim through GOFMT, as main's runFmtCheck does, and keep it
off PATH so only the go shim is found there. gofmt-bin.sh now returns
the override immediately, and the go shim sees only `version <shim>`
and `run ... ./scripts/pr-lint`. Both wrapper assertions, on the
driver arguments and on the failure diagnostic, are unchanged.

go test ./scripts/prlintmake/: 9/9 pass by default and 9/9 pass with
GOFMT=/nonexistent in the environment. Before this change the second
run was 7/9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 22:41:55 -07:00
mtccressall
1f7a5f1eaf
fix(ci): resolve gofmt from go.mod's toolchain, not PATH (be-gx8) (#6294)
* fix(ci): resolve gofmt from go.mod's toolchain, not PATH (be-gx8)

gofmt's output is not stable across Go releases, so whichever binary runs
decides the formatting verdict. Three sites reached for a bare `gofmt` on
PATH -- scripts/ci/fmt-check.sh, the Makefile fmt target, and
.githooks/pre-commit -- and PATH belongs to whatever Go is installed
locally. CI has no such freedom: actions/setup-go installs exactly the
go.mod version via go-version-file.

GOTOOLCHAIN=auto does not correct for this, which is why `go env GOROOT`
or `go fmt` would not have been a fix either. The toolchain switch only
ever moves UP to satisfy the go directive, never down, so a host running
a newer Go keeps formatting with the newer gofmt. Measured against
go.mod's go 1.26.5 on a go1.27.0 host: 1.27 flags three
role_fixture_kit_test.go files that 1.26.5 calls clean, and no branch
touches them.

The failure ran in the dangerous direction. The required lint gate went
red on untouched code, which reads as "main's lint is broken" and poisons
the pre-existing-on-main judgement every PR author uses to decide whether
a red gate is theirs. Its own advice -- "Run 'make fmt' to fix
formatting" -- then rewrote those files into a form CI's pinned gofmt
rejects. The pre-commit hook did that same rewrite and re-staged it
silently on every Go commit, with nobody choosing it.

Route all three through one resolver rather than patch three sites, so
the next gofmt call site cannot drift. scripts/ci/gofmt-bin.sh names
go.mod's toolchain explicitly and reads GOROOT from it, short-circuiting
to a plain `go env GOROOT` when the host go already is the pinned version
(the CI case, so nothing is fetched where nothing needs fetching). A
fallback to the PATH binary stays available but warns loudly on stderr:
silently falling back is indistinguishable from resolving correctly, and
reintroduces exactly this skew. fmt-check.sh now prints the gofmt version
it used, so a skew presents as a skew instead of as a repo defect.

The new tests pin the resolution, not the reporting, because the
resolution is where the bug lived: every output assertion around the bare
gofmt stayed green. Reverting gofmt-bin.sh to `command -v gofmt` fails
all three. The pre-existing fmt-check tests move their shim from PATH to
GOFMT -- a PATH shim is now correctly ignored, so leaving them there
would have made them grade the real toolchain instead of the case they
name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PoN7f9TMmGTCLRpDPzSH4y

Executed-By: beadsrig/polecats/nux

* fix(ci): resolve gofmt from go.mod's toolchain directive, and declare it to Bazel

Maintainer review fixes for #6294 (adoption iterations 1 and 2, one squashed
commit). Sections 1-6 address all six findings in the attempt-1 synthesis; the
two majors are the substantive ones. Sections 7-8 address the two minors the
attempt-2 synthesis left (it decided approve, 1000/1000, no blocker or major).

1. Contract & Interface Fidelity (major, the scorecard's only Required Change).
   gofmt-bin.sh read the `go` directive (1.26.5) while go.mod also carries
   `toolchain go1.26.7`, and toolchain-first is the repo's own declared
   precedence -- Makefile:85-90 exports GOTOOLCHAIN from the same pair for
   every make target, and scripts/bazel_policy_test.go's goModToolchainVersion
   is the same rule in Go. The consequence was not cosmetic: `go env GOVERSION`
   at the repo root is go1.26.7 (the directive auto-switches), so the fast-path
   test compared go1.26.7 against go1.26.5 and was false by construction on
   every route, sending each required fmt-check run down the elif arm to fetch
   a second, older toolchain. Parse `toolchain go<version>` first, fall back to
   the `go` directive. Measured after the change: pinned=1.26.7, the fast path
   fires (`go env GOVERSION` then `go env GOROOT`, no GOTOOLCHAIN= prefix and
   nothing fetched), and `make fmt-check` now reports
   `Using gofmt go1.26.7 (.../toolchain@v0.0.1-go1.26.7.../bin/gofmt)`.
   .githooks/pre-commit:24's `go`-directive read is deliberately left alone --
   its comment explains it is a golangci-lint pin for a different reason.

   gofmtbin_test.go's helper now implements the same precedence, and
   TestGofmtBinMatchesGoModDirective is renamed TestGofmtBinMatchesGoModToolchain
   so the pinned contract is legible from the test name.

   Deviation from the prescription, recorded deliberately: the review asked for
   a helper "name" change as well. The name goModToolchainVersion already
   described toolchain-first semantics; it was the implementation that did not.
   Correcting the semantics is what removes the collision with
   scripts/bazel_policy_test.go's identically-named, opposite-behaving helper,
   so the name is kept and the doc comment now states the precedence and cites
   both in-repo sources of it.

2. Release Safety (major). fmt-check.sh now execs a sibling script
   unconditionally under `set -euo pipefail`. Live origin/main gives
   //scripts/prlintmake a `data` list containing exactly ci/fmt-check.sh, so on
   merge all three TestFmtCheck* cases would have died at rc 127 in the Bazel
   runfiles sandbox -- the GOFMT short-circuit cannot rescue them because it
   lives inside the missing script. Export ci/gofmt-bin.sh to
   //scripts/prlintmake and put it in the target's `data`, and add
   gofmtbin_test.go to `srcs` (it carries no build tag, so its omission was not
   explained away).

   Only ci/gofmt-bin.sh is exported here, not ci/fmt-check.sh: main already
   exports that one for this same package, and a second exports_files call
   naming the same file in one package is an error. This base predates both of
   main's additions, which is also why editing the three-line go_test rule
   conflicts with main's independent edit of it. Verified by materialising the
   merge: every other file auto-merges and the resolution is the union of the
   two attribute sets (srcs = both test files; data = both scripts plus
   //:go.mod per section 7; keep main's deps on //internal/testutil/bazeltest).
   That deps edge is load-bearing at main even though it was stale at this base:
   main rewrote sourceRepoRoot to bazeltest.CallerDir, so the union must keep it.

3. Test Evidence Quality (minor). environment() starts from os.Environ(), so
   deleting GOFMT from the override map did not unset it. Export it empty
   instead -- gofmt-bin.sh reads `[[ -n "${GOFMT:-}" ]]`, so empty already is
   its "not set" case, and the override test stays distinguishable by setting a
   non-empty value.

4. Architectural Consistency (minor). "Every gofmt invocation in this repo goes
   through here" was false at authoring: cmd/bd/preflight.go's doctor check is
   a fourth front door on bare PATH gofmt. Scope the claim to the repo's
   shell-side call sites (re-censused: fmt-check.sh, the Makefile fmt target,
   and .githooks/pre-commit are the complete set; the two workflow "Check
   gofmt" steps and scripts/ci/pr-lint.sh reach them through make fmt-check),
   and name the in-binary exception with the reason it is one -- bd runs
   against whatever project the user points it at, so it has no scripts/ci/ to
   call. preflight.go is byte-identical at base, at HEAD and at origin/main, so
   nothing in this PR widens it; converting it is a separate change.

5. Test Evidence Quality (minor). describe_gofmt's version-bearing arm had zero
   coverage -- all three existing cases inject a bash script, for which
   `go version` errors and only the bare-path arm can run. Add
   TestFmtCheckReportsGofmtVersion against a real Go-built no-op binary, which
   is the only shim shape `go version` can report on.

6. Error Handling & Resilience (nit). Warn (without refusing) when GOFMT names
   something non-executable, so a typo is reported by the resolver that
   accepted it rather than as a "not found" from whichever call site ran it;
   and guard the fields index in the resolver test.

Mutation proofs, each red isolated to the intended test with the other six
green (7/7 pass unmutated, `go test ./scripts/prlintmake/`):

  - revert the toolchain-first parse -> resolver returns the 1.26.5 gofmt and
    TestGofmtBinMatchesGoModToolchain alone fails.
  - delete describe_gofmt's `if command -v go` block (codex's own mutation,
    previously all-green) -> TestFmtCheckReportsGofmtVersion alone fails, the
    three incumbents stay green. That asymmetry is both the coverage-hole proof
    and the proof the new case is not a duplicate.
  - ambient GOFMT, two values x two arms: with the fix both /nonexistent and a
    correctly-pinned gofmt leave all three resolver tests passing; with the
    delete restored, /nonexistent fails TestGofmtBinMatchesGoModToolchain with a
    message blaming the script, and a correctly-pinned value turns all three
    green vacuously without the resolver ever running.

7. Release Safety (minor, iteration 2). The target now reads go.mod at run
   time -- the resolver opens "$REPO_ROOT/go.mod" and the test helper opens
   filepath.Join(sourceRepoRoot(), "go.mod"), where the base test read it not at
   all -- but go.mod appeared in no `data` list, so the rule declared strictly
   less than it uses. Add //:go.mod to //scripts/prlintmake's `data`. No new
   export is needed: //:BUILD.bazel already exports go.mod publicly, and
   //internal/storage/dolt and //internal/testutil/integration already consume
   it as "//:go.mod" in `data`, so this is the sanctioned shape rather than a
   new one.

8. Contract & Interface Fidelity (minor, iteration 2). `toolchain default` is a
   legal go.mod directive value, and the parse matched on the field name alone,
   so sub(/^go/, "", "default") no-opped and left pinned=default. Because that
   is non-empty, neither the `go`-directive fallback nor the "no toolchain or go
   directive" guard could fire, and the script degraded to the bare PATH gofmt
   it exists to eliminate while a usable `go 1.26.5` sat two lines above. The
   mangled "godefault" in the warning was the tell. Require the literal `go`
   prefix, which is exactly what the repo's two other readers of this pair
   already do (Makefile:85's `s/^toolchain go//p` and bazel_policy_test.go's
   `^toolchain\s+go(\S+)\s*$`), so `default` falls through to the `go`
   directive.

   The same guard is added to gofmtbin_test.go's goModToolchainVersion, and that
   is not redundant: strings.TrimPrefix("default", "go") returns "default"
   unchanged and withPatchComponent leaves a dotless string alone, so the helper
   mirrored the bug exactly and the test could never have caught it. Guarding
   only the script would have left the test agreeing with a buggy resolver.

   Measured on a synthetic tree, five arms (the script resolves REPO_ROOT from
   its own location, so each arm is a copied script beside a written go.mod):

     - `toolchain default` + `go 1.26.5`: before, /usr/local/go/bin/gofmt with
       the "godefault" warning; after, the go1.26.5 toolchain gofmt -- i.e. the
       `go` directive, identical to the arm where no toolchain line exists.
     - `toolchain go1.26.7`: unchanged before and after (no regression).
     - `go 1.26.5` alone: unchanged before and after (no regression).
     - `toolchain default` with no `go` directive: now reaches the previously
       bypassed "no toolchain or go directive" guard and falls back loudly, with
       the correct message rather than the mangled one.
     - `toolchain default` written before `go`: also resolves 1.26.5, so the
       fallthrough is order-independent.

   The Go helper's parse was checked over the same six inputs and now agrees
   with the shell on every one.

   No regression test is added for this case. Doing so would need a new
   synthetic-go.mod fixture -- every existing case runs the real script against
   the real repo go.mod through sourceRepoRoot() -- which is a new test
   instrument rather than the prescribed remedy, on a finding whose gate impact
   is none (go.mod carries `toolchain go1.26.7`, so nothing can fire today).

Iteration 2 validation: go test ./scripts/prlintmake/ -count=1 -v 7/7 PASS
(same roster as iteration 1, no test added or removed), go vet rc 0,
go test ./scripts/ -run 'Bazel|BUILD' 11/11 PASS (the BUILD-policy gate, run
because this touches a BUILD file), python3 tools/bazel/go_srcs.py --check
rc 0 (`srcs` is unchanged; only `data` moved), make fmt-check rc 0 still
reporting go1.26.7, shellcheck clean, git diff --check clean.

Also run: go vet ./scripts/prlintmake, go test ./scripts/... (all packages ok),
make fmt-check (rc 0), python3 tools/bazel/go_srcs.py --check (rc 0),
shellcheck on both changed scripts.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 18:38:46 -07:00
Julian Knutsen
ae1a493e01
test(bazel): fully green //..., tag taxonomy + docker lane, sharding, test sandbox ceiling (#6871)
* fix(doctor): detect test binaries with testing.Testing(), not the file name

getBdBinary refuses to return a test binary as "bd" so fix tests cannot
fork-bomb by re-running themselves. The guard matched only the `go test`
naming (<pkg>.test). Bazel names test binaries <target>_test, so under
`bazel test` every fix that shells out to bd re-ran the whole fix_test suite,
recursively (~60 levels), until the 300s timeout.

testing.Testing() is true for any binary linked as a test by `go test` or
rules_go (both set testing.testBinary=1), whatever its name. The name check
stays as a fallback. bd already links package testing, so the product binary
gains no dependency. Behavior under `go test` is unchanged.

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

* test(bazel): tag taxonomy, docker lane, and green //scripts targets (slice B5)

`bazel test //... --config=ci` is now fully green, locally and with
--config=remote-exec.

- scripts_test declares what it reads and runs: this package's own tree
  (:scripts_files), .github/** (//:workflow_files, widened from the
  workflows), and .buildflags/.test-skip for scripts/test.sh. The complexity
  diff test builds a one-commit git fixture instead of git-archiving the
  real checkout's HEAD. Under Bazel it skips the whole-repo testing.Short()
  scan (it would pass vacuously over the runfiles) and the two release
  formula tests (.beads is in .bazelignore). Tagged host-tools +
  no-remote-exec: it runs the host's git/python3/coreutils and some subtests
  skip without git.
- prlintmake_test resolves fmt-check.sh through bazeltest.CallerDir and
  declares it; it needs only bash (gofmt is shimmed), so it stays untagged
  and runs remotely.
- //cmd/bd/doctor/fix:fix_docker_test reruns the fix_test binary (no second
  compile, tools/bazel/go_test_variant.sh) with BEADS_FIX_REQUIRE_DOLT=1, like
  pr.yml's container-backed doctor/fix job. Tagged requires-docker +
  no-remote-exec; `--config=docker` selects it (race, no -short, no
  BEADS_TEST_SKIP=dolt). fix_test itself stays untagged: under prcore it
  skips the Dolt-backed tests exactly as pr-core's `go test` does.
- scripts/bazel_policy_test.go: every BUILD `tags` value must be in the
  taxonomy, be named in the comment above its rule, and host-bound tags must
  come with no-remote-exec; test:prcore must exclude requires-docker,
  embedded and manual.

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

* test(bd): reset git's cwd cache in TestContextRoutesNameOneWorkspaceTheSameWay

The test chdirs into a fresh git repo but reset only beads' caches. git
caches the cwd's repository context process-wide, so when an earlier test in
the same process had resolved it from a non-repo directory (for example
TestCollectMetadataEntriesNoBeadsDir), GetMainRepoRoot kept answering "not a
git repository". Test order hid it under `go test ./cmd/bd`; Bazel sharding
reorders tests and exposed it. Reproduces with plain go test:

  go test -run '^(TestCollectMetadataEntriesNoBeadsDir|TestContextRoutesNameOneWorkspaceTheSameWay)$' ./cmd/bd

The cache is reset on entry only. Resetting it again in cleanup changes what
later tests inherit, and TestCreateRemoteRepoSkipsLocalDatabaseGuard (which
never resets it) then fails under the unsharded go test order.

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

* test(bazel): shard bd_test and embeddeddolt_test; keep test re-execs shard-free (slice B6)

- //cmd/bd:bd_test shard_count = 16, //internal/storage/embeddeddolt:
  embeddeddolt_test shard_count = 8. Remote -race under --config=ci: bd_test
  max shard 61-82s (unsharded 252-264s), embeddeddolt max shard 84-122s
  (unsharded 207-377s). The embeddeddolt max is a single test
  (TestWithPeerAuth, ~93s), so more shards would not lower it. Every shard
  runs tests (bd 161-172 top-level tests each, embeddeddolt 15-20).
  protocol (4s), legacysqlite (4s) and dbproxy/server (22s) stay unsharded.
- Tests that re-exec their own binary now pass bazeltest.ShardFreeEnv
  (a no-op under go test), so a helper child does not inherit
  TEST_SHARD_INDEX/TEST_TOTAL_SHARDS/TEST_SHARD_STATUS_FILE and filter away
  the one test it was asked to run: dolt suite_leak_linux, dbproxy
  force_stop_linux, workspacegate (3 helpers), metrics spawn_reap, bd
  worktree_remove, conformance role_bundle, linear synclock (windows).
  scripts/test_script_test.go (child env built from scratch) and
  repro-dolt-prod-timeouts (copies the binary, never runs it) need nothing.

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

* test(bazel): keep sharded bd_test off ~/.beads and keep its stdio leak guard

Two things sharding //cmd/bd:bd_test exposed:

- config.Initialize walks up from the test's cwd for .beads/config.yaml and,
  under BEADS_TEST_IGNORE_REPO_CONFIG, stops at the module root (go.mod).
  The runfiles tree had no go.mod, so the walk left it; with the output base
  under $HOME it loaded the developer's ~/.beads/config.yaml (here
  dolt.shared-server: true) and two embedded-mode autocommit tests failed
  locally, though not on remote workers. bd_test now declares //:go.mod, so
  the walk stops at the runfiles root as it stops at the checkout under go
  test. Unsharded runs hid this: an earlier test re-initialized config first.
- TestZZStdioNotLeaked skipped in every shard, because the baseline test is
  always in shard 1 and the guard in another. Without a baseline it now
  checks the descriptors instead (a leaked capture leaves a pipe where fd 1
  or 2 was). Under go test the baseline is always captured, so nothing
  changes there.

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

* chore(bazel): sync BUILD files with test files added on main

Gazelle picks up cmd/bd and internal/notion tests that landed on main after
the last sync (make bazel-sync).

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

* fix(discovery): add BEADS_CEILING_DIRECTORIES; bound bazel tests' walks

bd finds its workspace by walking up from the working directory for .beads
and .beads/config.yaml. Under `bazel test` the working directory is in the
runfiles tree under the output base, usually below the developer's HOME, so
the walks left the sandbox: tests read the developer's ~/.beads/config.yaml
(results depended on it) and wrote into ~/.beads (interactions.jsonl from the
audit log, .local_version from version tracking).

BEADS_CEILING_DIRECTORIES takes git's GIT_CEILING_DIRECTORIES form (a PATH-
style list of absolute directories): a search starting inside a ceiling never
examines the ceiling or anything above it; the start itself is always
examined. Unset, nothing changes. Honored by every upward .beads/config
search: beads.AncestorDirWalk (all FindBeadsDir walks), config.Initialize
(the go.mod and config.yaml walks, and the worktree-fallback git probe, whose
routing scrub drops GIT_CEILING_DIRECTORIES), findProjectBeadsDir, the legacy
upgrade guard, the --db beads-dir walk, store reopen and findBeadsRepoRoot.
The migration-freeze marker walk is left alone on purpose: it is a write
safety gate, and BD_MIGRATION_FREEZE_FILE is already its explicit override.

tools/bazel/test_env.sh sets BEADS_CEILING_DIRECTORIES and
GIT_CEILING_DIRECTORIES to the runfiles root, TEST_TMPDIR and its own temp
root. It does not fail on an ancestor .beads: a live ~/.beads above the
output base is normal on a developer machine. bd_test no longer needs
//:go.mod as a walk stop.

Canary check: with an invalid-YAML .beads above a scratch --output_base,
compact, issueops, validation and bd_test pass under --config=ci and nothing
is written there; the previous wrapper fails on it and writes
interactions.jsonl into it.

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

* test(bd): check for leaked stdio after m.Run in every process

TestZZStdioNotLeaked only sees the tests that ran before it in the same
process. Under Bazel's 16-way sharding that is ~1/16 of bd_test: the baseline
test is in shard 1, the guard in another shard, and leaks in the other shards
were never checked.

TestMain now compares os.Stdout/os.Stderr after m.Run with the streams from
before it (runTestsAndSweep, so every shard and every go test run) and fails
the process on a leak. The one allowed change is the framework's own
os.Stderr = os.Stdout under -json. TestZZStdioNotLeaked stays for its go test
report and skips when it has no baseline; the descriptor fallback added for
sharding is gone.

Verified: a test that leaks os.Stdout fails `go test -run` for it alone, with
and without -json; a clean -json run passes.

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

* test(bazel): keep host-tools results out of the remote cache; tighten tag policy

- //scripts:scripts_test (host-tools, no-remote-exec) ran locally but its
  result was still uploaded to the remote cache and served to other clients,
  though the action key does not cover the host's git/python3/bash. It is now
  also tagged no-remote-cache (neither read nor uploaded). Checked: after a
  --config=remote-exec run and `bazel clean`, a rerun without the disk cache
  executes the test again instead of taking a remote cache hit.
- Under Bazel a missing git or bash now fails those tests instead of
  skipping (the host-tools tag promises them); under go test they still skip.
- Tag policy: host-tools requires no-remote-exec and no-remote-cache;
  `tags = [...] + X` is rejected as non-literal; every --test_tag_filters set
  by test:prcore or a config that expands it (test:ci, transitively) must
  exclude requires-docker/embedded/manual, not only the first prcore line.

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

* fix(bazel): run go_test variants from their package directory

rules_go gives a go_test GO_TEST_RUN_FROM_BAZEL=1 (and its `env`) through
RunEnvironmentInfo; an sh_test that reruns the binary gets neither, so the
binary skipped its chdir into the package directory and ran from the
runfiles root. go_test_variant.sh now exports GO_TEST_RUN_FROM_BAZEL=1, and
its header says the variant target must repeat the go_test's `env`.

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

* test(bazel): docker-lane variants for domain/db, uow and protocol

--config=docker only ran doctor/fix. pr.yml's container jobs also run
internal/storage/domain/... + uow/... (race, no -short, Dolt image pulled)
and cmd/bd/protocol (BEADS_PROTOCOL_REQUIRE_DOLT=1). Under --config=ci those
container suites skip (BEADS_TEST_SKIP=dolt), so without variants their
coverage would vanish if Bazel replaced those jobs.

- testutil: BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 makes RequireDoltContainer
  and StartIsolatedDoltContainer(Handle) fail instead of skip when the Dolt
  container is unavailable (the generic form of BEADS_FIX_REQUIRE_DOLT).
- db_docker_test, uow_docker_test (4 shards) and protocol_docker_test
  (8 shards, BEADS_PROTOCOL_REQUIRE_DOLT=1) rerun the go_test binaries via
  go_test_variant.sh, repeating their `env`; tagged requires-docker +
  no-remote-exec. The other domain/tracker packages have no container tests
  and already run under --config=ci.

`bazel test //... --config=docker --test_arg=-test.v`: 4/4 PASS; db 908
PASS / 0 SKIP, uow 985 PASS / 32 SKIP (conformance capabilities the backend
does not implement, as under go test), protocol 151 PASS / 2 SKIP (tracked
known gaps). With --test_env=BEADS_TEST_SKIP=dolt, db_docker_test fails.

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

* test: shard-free env for the embeddeddolt concurrency helper; 2m bd init timeout

- concurrency_test re-execs its test binary with -test.run=^TestHelperProcess$
  inside the now-sharded embeddeddolt_test; pass bazeltest.ShardFreeEnv so a
  child cannot inherit TEST_SHARD_* and filter its one test away (it is
  gated by BEADS_TEST_EMBEDDED_DOLT=1, so dark today).
- initBeadsWorkspace / runBDStdout (TestClose_UpdatesLastTouched and the
  gemini prime hook tests) allowed 30s per bd subprocess. A -race bd on a
  loaded host exceeded that for a single `bd init` (killed at 30.18s in 1 of
  3 sharded remote runs; the whole test otherwise passes in ~21s), so allow
  2 minutes.

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

* test(bd): give TestCreateRemoteRepoSkipsLocalDatabaseGuard its own git state

The test chdirs into a fresh non-repo temp dir but used whatever git/beads
cwd caches earlier tests left. When an earlier test had reset git's cache and
a later one refilled it from the package directory, workspace discovery in
the test returned the checkout's .beads (from a git worktree: the MAIN
checkout's live .beads via the worktree fallback) and `bd create` tried to
open it, so it failed with "could not verify workspace identity" instead of
the expected downstream error. It passed only on stale state (a cache
pointing at a deleted temp repo).

It now resets the git and beads caches after its chdir and again in cleanup,
so it neither depends on nor leaks cwd state. With that fixed,
TestContextRoutesNameOneWorkspaceTheSameWay also resets git's cache in
cleanup. Reproduced with the context-test cleanup reset in place, running
every cmd/bd test declared up to this one (the failing go test order); now
passes there, alone, with the two context tests, and under -shuffle seeds
1-5 (other pre-existing order dependencies show up under shuffle; this test
is not among them).

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

* build(bazel): re-sync BUILD files with main

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

* test(bazel): pin BD_MIGRATION_FREEZE_FILE in test_env

The freeze-marker ancestor walk is intentionally not ceiling-bounded; an
explicit BD_MIGRATION_FREEZE_FILE replaces the walk, so a MIGRATION-FREEZE
above the output base can no longer change test results.

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

* test(scripts): give the complexity diff fixture a Go package

complexity.sh expands "${analyzer_paths[@]}" under set -u; with an empty
fixture tree that is an unbound-variable error on bash 3.2 (macOS runners).

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-27 20:19:38 -07:00
Julian Knutsen
57ef364501
build(bazel): side-by-side Bazel scaffold + policy tests (#6798)
* build(bazel): add side-by-side Bazel scaffold (module + gazelle)

Add a Bzlmod Bazel build alongside the Go toolchain. `go build` and
`go test` are unchanged; nothing in CI invokes Bazel yet.

- MODULE.bazel: rules_go 0.63.0, gazelle 0.53.0, Go SDK 1.26.7 (matches
  the go.mod toolchain directive), go_deps from go.mod.
- ICU policy (engdocs/ICU-POLICY.md): a go-mysql-server gazelle_override
  selects the pure-Go regex backend and excludes regex_cgo.go, and
  .bazelrc builds with --@rules_go//go/config:tags=gms_pure_go, so no
  target depends on go-icu-regex or links libicu.
- third_party/patches: three module_override patches for dolt deps that
  ship WORKSPACE-era BUILD files, adapted from the gascity project.
- .bazelrc: prcore/ci test configs (inert for now; they match pr-core's
  test selection, not yet its environment isolation) and a generic
  remote-exec config with a bounded remote timeout. Executor endpoints and
  TLS credentials come only from a gitignored .bazelrc.local/user.bazelrc
  or a CI rc outside the workspace.
- .bazelversion pins Bazel 9.2.0; .bazelignore skips separate modules,
  non-Go trees, nested agent worktrees (.claude, .worktrees) and local
  data/output dirs (.beads, .dolt, dist, .runtime, tmp), so a primary
  checkout neither builds nor gazelle-rewrites nested worktree copies.
- Gazelle-generated BUILD.bazel files for every Go package.
- Makefile: `make bazel-sync` (gazelle + bazel mod tidy).
- .gitignore: bazel-* output symlinks and machine-local rc files.

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

* test(bazel): policy tests for the Bazel configuration

Add scripts/bazel_policy_test.go, plain Go tests that run under both
`go test ./scripts` and `bazel test //scripts:scripts_test`:

- MODULE.bazel go_sdk.download version equals the go.mod toolchain.
- ICU policy: .bazelrc sets gms_pure_go for build, the go-mysql-server
  gazelle_override excludes regex_cgo.go, and the root BUILD.bazel
  carries `# gazelle:build_tags gms_pure_go`.
- .bazelversion pins an exact Bazel release.
- .bazelrc.local and user.bazelrc are gitignored (parsed from .gitignore
  and cross-checked with git check-ignore when in a checkout).
- No remote-execution endpoints or credentials in committed bazelrc-like
  files, Markdown docs or .github/**: remote/BES/TLS flags
  (--remote_executor, --remote_cache, --bes_backend, --remote_header,
  --tls_client_certificate, ...) with a literal value, with or without a
  URL scheme, and non-loopback gRPC URLs in rc/.github files. Placeholders,
  $VARIABLES, and loopback are allowed; Markdown gRPC URLs (OTel exporter
  docs) are not flagged. Skipped outside a git checkout, e.g. in the Bazel
  sandbox.

Each check is a pure function also exercised against fixtures that break
the invariant. The files the tests read are declared as data via
//:bazel_policy_files so they resolve from runfiles under Bazel.

scripts/check-build-tags.sh now treats Bazel invocations as governed by
.bazelrc: the shell command segment that invokes Bazel (split on &&, ||,
;, |, $( and backticks) is exempt from the per-line `go` tag check, while
a bare `go` in another segment of the same line is still flagged. When
any scanned file invokes Bazel (or .bazelrc exists) .bazelrc must set
--@rules_go//go/config:tags=gms_pure_go for build.
scripts/check_build_tags_test.go covers both in a temp repository.

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

* fix(scripts): split bazel lines in pure bash so check-build-tags works with BSD sed

BSD sed (macOS) does not expand \n in s/// replacements, so the segment
split never happened and the Bazel-exemption tests failed on macos-latest.

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

* test(scripts): skip check-build-tags tests when bash lacks mapfile

macOS runners use /bin/bash 3.2, which has no mapfile; check-build-tags.sh
has always required bash >= 4, so the new tests are skipped there.

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-27 03:41:02 -07:00
ecuthiell
1b67d0b1fb
fix(ci): remove recursive Make from lint formatting (#5302) (#5320)
Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
2026-08-10 21:43:59 -07:00