beads/scripts/internal/testbash/BUILD.bazel
ecuthiell 4183fa0509
test(scripts): resolve Git Bash explicitly on Windows (#5727) (#5730)
* test(scripts): resolve Git Bash explicitly on Windows

Add one test-only resolver that positively identifies Git Bash on Windows and use it in the doc-freshness and PR-preflight fixtures. Preserve ordinary PATH resolution on non-Windows hosts and leave the remaining #5727 callers for follow-up.

Part of #5727.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* docs(testbash): state exact probe completion requirements

Document that capability scripts must be silent on both streams and reach
the sentinel epilogue without exiting the shell. Remove redundant startup
environment entries already stripped by the shared resolver.

Bead: saa-cgh.13
Agent-Signature: unknown-model/unknown-reasoning

* chore(bazel): sync BUILD files for scripts/internal/testbash

`make bazel-sync` output for the new `scripts/internal/testbash` package,
regenerated with `bazel run //:gazelle`:

- add the generated `scripts/internal/testbash/BUILD.bazel`
  (`go_library testbash` + `go_test testbash_test`)
- add `//scripts/internal/testbash` to `//scripts:scripts_test` deps

Without this, `bazel.yml` fails two ways:

1. `bazel test //... --config=integration` (bazel.yml:592) is a hard compile
   failure — `compilepkg: missing strict dependencies` for the
   `scripts/internal/testbash` import in both `check_doc_freshness_test.go`
   and `pr_preflight_test.go`. The default config builds clean because both
   files are `//go:build integration`, so only the integration lane sees it.
2. The `BUILD files in sync` step (bazel.yml:310) exits 1 on the
   `make bazel-sync` drift.

`make bazel-sync-check` (go_srcs globs only) and the repo's own
`TestBazel*` policy tests are both blind to this and pass either way.

* fix(testbash): pin the sanitization contract and split probe diagnostics

Maintainer review fixups for the adopt-pr review of PR #5730 (iteration 1,
synthesis approve / no blocker or major; all items were non-gating).

Finding 1 (minor, Test Evidence Quality) — the sanitization test's oracle was
the predicate under test. TestSanitizedEnvironmentRemovesBashAuthorityControls
validated the sanitized result by calling isBashAuthorityControl, the very
predicate sanitizedEnvironment filters with, so filter and oracle weakened in
lockstep and the assertion could not fail for any definition of the predicate.
It now asserts against the test's own controls literal and checks the
BASH_FUNC_ prefix class separately, pinning both the filter plumbing and the
key list. Proven with a three-arm control: fixed test + real predicate passes;
fixed test + a full `return false` neuter of isBashAuthorityControl now FAILS
(it previously passed); the original test + the same neuter still passes, so the
new failure is caused by this change and not by the mutation itself.

Finding 4 (nit, Debuggability) — a chatty-but-successful probe reported the
sentinel as unreached while its own quoted payload contained it. runProbe now
branches on strings.HasSuffix and emits a distinct "completed but wrote
unexpected output before the execution sentinel" message quoting only the stray
payload. The three existing assertions on "without the exact execution
sentinel" all cover cases whose output is empty (early exit, noexec), so none
of them can take the new branch; verified by execution.

Finding 3 (nit, Debuggability) — Probe's doc comment named only the three Bash
control classes while the implementation also strips GIT_EXEC_PATH. The comment
now documents Bash and Git authority controls explicitly.

Finding 2 (minor, Test Evidence Quality) is deliberately NOT taken here and
remains a non-gating follow-up. Its primary remedy — adding
./scripts/internal/testbash to the windows-latest leg — would execute four
//go:build windows tests that have never run on any lane, and the synthesis's
own Unresolved Uncertainty concerns MSYS2 PATH handling in exactly this
package's validateCandidate, which is not verifiable from Linux; a first-ever
execution that reds pr-preflight-platforms is not the "nearby, cheap, low-risk"
cleanup the operator contract allows. Its fallback arm only typechecks and
would edit repo-wide CI outside this PR's payload. Note that finding 1 reduces
finding 2's severity: the sanitization contract is now pinned on every Linux
lane instead of only incidentally on Windows.

Validation: go test ./scripts/internal/testbash ok; go test -run
'^TestDocFreshness|^TestPRPreflight' ./scripts ok, and ok again with
-tags=integration,gms_pure_go; gofmt clean; go vet clean; CGO_ENABLED=0
GOOS=windows go vet ./scripts/... and go build ./scripts/... both rc=0;
git diff --check clean. No files added or removed, so the generated
BUILD.bazel srcs are unchanged.

Contributor commits are untouched.

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 15:50:28 -07:00

22 lines
503 B
Python

load("@rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "testbash",
srcs = [
"resolver.go",
"resolver_other.go",
"resolver_windows.go",
],
importpath = "github.com/steveyegge/beads/scripts/internal/testbash",
visibility = ["//scripts:__subpackages__"],
)
go_test(
name = "testbash_test",
srcs = [
"resolver_other_test.go",
"resolver_test.go",
"resolver_windows_test.go",
],
embed = [":testbash"],
)