beads/scripts/ci/fmt-check.sh
Julian Knutsen 3e7705a2cd
fix(bazel): remove host-go dep from compact GC test; drop frozen shard blocks (#7478)
* fix(bazel): remove host-go dep from compact GC test; drop frozen shard blocks

Replace the ungated `go build` in compact_gc_target_test.go's dolt-stand-in
fixture with a Bazel-built go_binary (cmd/bd:compact_gc_fixture) wired via
rlocationpath env + data, mirroring the existing preflight_go_fixture
pattern. Falls back to `go build` only when not running under Bazel
(bazeltest.IsBazel()). Also gate test_repo_beads_guard_test.go's `go env
GOCACHE`/`GOMODCACHE` probes on !bazeltest.IsBazel(), since they previously
ran unconditionally in every cmd/bd TestMain.

Separately, delete the legacy 20-shard embedded-cmd and 15-shard
proxied-cmd "frozen" manifest blocks in .github/scripts/*-test-shards.txt:
their only consumers were pr-risk.yml fork/push jobs that have since
migrated to bazel.yml. Update gen_embedded_cmd_shard_manifest.py and
gen_proxied_shard_manifest.py to drop the frozen-block rendering/guard
logic and default to the live Bazel-only shard counts (100 and 34),
and refresh stale comments/docs (cmd/bd/BUILD.bazel,
scripts/shard_manifest_test.go, engdocs/TESTING.md,
engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md) that still described the deleted
blocks. Verified no other BUILD/.github/scripts references read them.

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

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/38069936930
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* fix(bazel): gate remaining host-go calls; fix shard-manifest --weights footgun

Address PR #7478 review findings (bee-ghosttrack):

- scripts/ci/lib/test-env.sh: skip the GOCACHE/GOMODCACHE `go env` probes
  when TEST_SRCDIR is set, so scripts/test.sh's beads_test_env_enter never
  shells out to a bare `go` when reached from a Bazel-run go_test (e.g.
  //scripts:shell_scripts_test's TestTestScriptPrebuiltTestBinaryContract),
  where a farm masks host go/dolt to exit 127. Nothing on that path needs a
  cache directory.
- scripts/ci/fmt-check.sh: describe_gofmt() no longer calls a PATH `go`
  under Bazel. It now resolves BEADS_TEST_GO (the hermetic SDK go already
  wired into scripts/prlintmake:prlintmake_test's env) via TEST_SRCDIR, and
  skips the version-reporting arm entirely when that isn't set (e.g.
  scripts/repochecks:fmt_test), rather than ever touching a possibly-masked
  PATH `go`.
- Verified with a PATH stub (go/dolt scripts that log and exit 127) via
  `bazel --nohome_rc test --config=prcore //scripts/... //cmd/bd:bd_test
  --test_env=PATH=<stubdir>:/usr/bin:/bin:/usr/local/bin`: 26/26 targets
  pass, zero stub invocations logged.
- gen_proxied_shard_manifest.py / gen_embedded_cmd_shard_manifest.py:
  default --weights to duration now that the manifests' only remaining
  blocks are duration-packed (the legacy inits-packed blocks were deleted
  alongside the PR Risk fork/push jobs that read them). Previously the bare
  `--write` default (inits) silently clobbered the live block's duration
  header and repacked with the wrong cost model; --check couldn't see it.
  Added TestProxiedShardManifestBareWriteIsIdempotent and
  TestEmbeddedCmdShardManifestBareWriteIsIdempotent to pin a bare --write
  as a no-op against the committed files.
- cmd/bd/compact_gc_target_test.go: resolve the non-Bazel fallback fixture
  path from this file's own directory (runtime.Caller) instead of the test
  binary's working directory.
- Refresh stale comments in .github/workflows/bazel.yml,
  scripts/shard_manifest_test.go, scripts/pr_risk_bazel_coverage_test.go,
  and scripts/embedded_shard_count_test.go that still described the deleted
  legacy 20/15-shard blocks and their retired fork/push jobs in the present
  tense.
- Confirmed cmd/bd/BUILD.bazel's compact_gc_fixture go_binary (implicit
  pure/race defaults) still passes TestRunCompactDoltTargetsOnlyAuthorizedActiveDatabase
  under `bazel test //cmd/bd:bd_test`.

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

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-10-10 19:24:21 +00:00

67 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Shared Go formatting check for Make and PR lint wrappers.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$REPO_ROOT"
# Which gofmt runs decides the verdict, so resolve it from go.mod instead of
# PATH and report it. Naming the binary here is what makes a toolchain skew
# legible as a skew, rather than as unformatted files in code no branch
# touched. See scripts/ci/gofmt-bin.sh.
GOFMT_BIN="$("$SCRIPT_DIR/gofmt-bin.sh")"
describe_gofmt() {
local bin="$1" version="" go_bin=""
if [[ -n "${TEST_SRCDIR:-}" ]]; then
# Under `bazel test` a bare `go` on PATH can be the farm's exit-127
# mask for the host toolchain, so only call a go binary the test
# explicitly declared as data: BEADS_TEST_GO, set the same way
# scripts/prlintmake:prlintmake_test wires in the registered SDK's go
# ($(rlocationpath @go_sdk//:bin/go)). A caller that did not wire it
# up (e.g. scripts/repochecks:fmt_test) just gets the version-less
# fallback below, never a PATH `go`.
if [[ -n "${BEADS_TEST_GO:-}" ]]; then
local candidate="$BEADS_TEST_GO"
if [[ "$candidate" != /* ]]; then
candidate="$TEST_SRCDIR/$candidate"
fi
if [[ -x "$candidate" ]]; then
go_bin="$candidate"
fi
fi
elif command -v go >/dev/null 2>&1; then
go_bin="go"
fi
if [[ -n "$go_bin" ]]; then
version="$("$go_bin" version "$bin" 2>/dev/null | awk '{ print $NF }')"
fi
if [[ -n "$version" ]]; then
printf '%s (%s)' "$version" "$bin"
else
printf '%s' "$bin"
fi
}
printf 'Checking Go formatting...\n'
printf 'Using gofmt %s\n' "$(describe_gofmt "$GOFMT_BIN")"
if UNFORMATTED="$("$GOFMT_BIN" -l .)"; then
:
else
status=$?
printf 'gofmt failed while checking formatting\n' >&2
exit "$status"
fi
if [[ -n "$UNFORMATTED" ]]; then
printf 'The following files are not properly formatted:\n'
printf '%s\n' "$UNFORMATTED"
printf '\n'
printf "Run 'make fmt' to fix formatting\n"
exit 1
fi
printf 'All Go files are properly formatted\n'