* 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>
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
//go:build windows
|
|
|
|
package testbash
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func resolve() (string, error) {
|
|
if override := os.Getenv(OverrideEnv); override != "" {
|
|
if !filepath.IsAbs(override) {
|
|
return "", configurationErrorf("%s must be an absolute path: %q", OverrideEnv, override)
|
|
}
|
|
override = filepath.Clean(override)
|
|
if err := validateCandidate(override); err != nil {
|
|
return "", configurationErrorf("%s=%s: %v", OverrideEnv, override, err)
|
|
}
|
|
return override, nil
|
|
}
|
|
|
|
git, err := exec.LookPath("git.exe")
|
|
if err != nil {
|
|
return "", fmt.Errorf("Git for Windows is required: %w", err)
|
|
}
|
|
gitInfo, err := os.Stat(git)
|
|
if err != nil {
|
|
return "", fmt.Errorf("inspect Git for Windows executable %s: %w", git, err)
|
|
}
|
|
if !gitInfo.Mode().IsRegular() {
|
|
return "", fmt.Errorf("Git for Windows executable %s is not an ordinary file", git)
|
|
}
|
|
|
|
execPathCommand := exec.Command(git, "--exec-path")
|
|
execPathCommand.Env = sanitizedEnvironment(os.Environ())
|
|
execPathOutput, err := execPathCommand.CombinedOutput()
|
|
if err != nil {
|
|
return "", fmt.Errorf(
|
|
"locate the Git for Windows installation through %s: %w: %s",
|
|
git,
|
|
err,
|
|
strings.TrimSpace(string(execPathOutput)),
|
|
)
|
|
}
|
|
execPath := filepath.Clean(strings.TrimSpace(string(execPathOutput)))
|
|
if !filepath.IsAbs(execPath) {
|
|
return "", fmt.Errorf("Git for Windows returned a non-absolute exec path: %q", execPath)
|
|
}
|
|
|
|
gitRoot := filepath.Clean(filepath.Join(execPath, "..", "..", ".."))
|
|
candidates := []string{
|
|
filepath.Join(gitRoot, "bin", "bash.exe"),
|
|
filepath.Join(gitRoot, "usr", "bin", "bash.exe"),
|
|
}
|
|
diagnostics := make([]string, 0, len(candidates))
|
|
for _, candidate := range candidates {
|
|
if candidateErr := validateCandidate(candidate); candidateErr != nil {
|
|
diagnostics = append(diagnostics, fmt.Sprintf("%s: %v", candidate, candidateErr))
|
|
continue
|
|
}
|
|
return candidate, nil
|
|
}
|
|
|
|
return "", fmt.Errorf("no working Git Bash candidate: %s", strings.Join(diagnostics, "; "))
|
|
}
|
|
|
|
func validateCandidate(candidate string) error {
|
|
info, err := os.Stat(candidate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !info.Mode().IsRegular() {
|
|
return errors.New("is not an ordinary file")
|
|
}
|
|
|
|
return runProbe(
|
|
candidate,
|
|
"Git Bash identity",
|
|
`set -eu
|
|
test -n "${BASH_VERSION:-}"
|
|
case "$(uname -s)" in
|
|
MINGW*|MSYS*) ;;
|
|
*) printf 'expected Git Bash, found %s\n' "$(uname -s)" >&2; exit 69 ;;
|
|
esac
|
|
pwd -W >/dev/null
|
|
`,
|
|
sanitizedEnvironment(os.Environ(), "PATH=/usr/bin:/bin", "LC_ALL=C", "LANG=C"),
|
|
)
|
|
}
|