//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>
117 lines
4.7 KiB
Go
117 lines
4.7 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Built via concatenation so this file's own source never contains the
|
|
// literal substring check-testing-short.sh scans for — otherwise this test
|
|
// file would flag itself when TestCheckTestingShortPassesOnCleanRepoTree
|
|
// runs the checker against the real repo tree.
|
|
const shortCall = "testing" + ".Short()"
|
|
|
|
func TestCheckTestingShortIgnoresCommentOnlyMention(t *testing.T) {
|
|
out, err := runCheckTestingShort(t, map[string]string{
|
|
"pkg_test.go": "package pkg\n\nimport \"testing\"\n\nfunc TestFoo(t *testing.T) {\n\t// this comment mentions " + shortCall + " and should not fail the gate\n}\n",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("comment-only mention of %s should not fail the gate; err=%v output=%s", shortCall, err, out)
|
|
}
|
|
}
|
|
|
|
func TestCheckTestingShortStillFlagsRealCallAndNamesFunc(t *testing.T) {
|
|
out, err := runCheckTestingShort(t, map[string]string{
|
|
"pkg_test.go": "package pkg\n\nimport \"testing\"\n\nfunc TestBar(t *testing.T) {\n\tif " + shortCall + " {\n\t\tt.Skip(\"slow\")\n\t}\n}\n",
|
|
})
|
|
if err == nil {
|
|
t.Fatalf("real %s call should still fail the gate; output=%s", shortCall, out)
|
|
}
|
|
if !strings.Contains(out, "TestBar") {
|
|
t.Errorf("expected offending function TestBar named in output, got: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestCheckTestingShortReportsUnknownAboveFirstFunc(t *testing.T) {
|
|
out, err := runCheckTestingShort(t, map[string]string{
|
|
"pkg_test.go": "package pkg\n\nimport \"testing\"\n\nvar shortMode = " + shortCall + "\n\nfunc TestBaz(t *testing.T) {}\n",
|
|
})
|
|
if err == nil {
|
|
t.Fatalf("real %s call above any func should still fail the gate; output=%s", shortCall, out)
|
|
}
|
|
if !strings.Contains(out, "unknown") {
|
|
t.Errorf("expected 'unknown' function name for a hit above the first func, got: %s", out)
|
|
}
|
|
if strings.Contains(out, "TestBaz") {
|
|
t.Errorf("hit above the first func must not be attributed to a later func TestBaz: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestCheckTestingShortReportsUnknownBetweenFunctions(t *testing.T) {
|
|
out, err := runCheckTestingShort(t, map[string]string{
|
|
"pkg_test.go": "package pkg\n\nimport \"testing\"\n\nfunc TestA(t *testing.T) {\n\tt.Log(\"a\")\n}\n\nvar shortAgain = " + shortCall + "\n\nfunc TestB(t *testing.T) {}\n",
|
|
})
|
|
if err == nil {
|
|
t.Fatalf("real %s call between two functions should still fail the gate; output=%s", shortCall, out)
|
|
}
|
|
if !strings.Contains(out, "unknown") {
|
|
t.Errorf("expected 'unknown' function name for a hit between two functions (not truly inside either body), got: %s", out)
|
|
}
|
|
if strings.Contains(out, "TestA") {
|
|
t.Errorf("hit between two functions must not be attributed to the preceding func TestA: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestCheckTestingShortPassesOnCleanRepoTree(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("checker is a Bash boundary")
|
|
}
|
|
repo := sourceRepoRoot(t)
|
|
// Under Bazel the tree is //:repo_files; a tree missing the allowlisted
|
|
// call sites would let the scan pass vacuously.
|
|
for _, rel := range []string{"internal/hooks/hooks_test.go", "internal/storage/dolt/concurrent_test.go", "internal/workapi/sweep_test.go"} {
|
|
if _, err := os.Stat(filepath.Join(repo, filepath.FromSlash(rel))); err != nil {
|
|
t.Fatalf("the scanned tree lacks %s, which holds an allowlisted call: %v", rel, err)
|
|
}
|
|
}
|
|
cmd := exec.Command("bash", filepath.Join(repo, "scripts", "check-testing-short.sh"))
|
|
cmd.Dir = repo
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("check-testing-short.sh failed on clean repo tree (all 9 allowlist entries must still be recognized): %v\noutput: %s", err, out)
|
|
}
|
|
}
|
|
|
|
func runCheckTestingShort(t *testing.T, files map[string]string) (string, error) {
|
|
t.Helper()
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("checker is a Bash boundary")
|
|
}
|
|
dir := t.TempDir()
|
|
// A second, innocuous .go file keeps find+grep invoked with 2+ filenames,
|
|
// matching real usage (repo root always has many .go files): grep only
|
|
// prefixes matches with the filename when given more than one file, so a
|
|
// single-fixture temp dir would silently corrupt the file:line parse in
|
|
// check-testing-short.sh's read loop.
|
|
if err := os.WriteFile(filepath.Join(dir, "companion.go"), []byte("package pkg\n"), 0600); err != nil {
|
|
t.Fatalf("write companion.go: %v", err)
|
|
}
|
|
for rel, content := range files {
|
|
full := filepath.Join(dir, rel)
|
|
if err := os.MkdirAll(filepath.Dir(full), 0700); err != nil {
|
|
t.Fatalf("mkdir %s: %v", filepath.Dir(full), err)
|
|
}
|
|
if err := os.WriteFile(full, []byte(content), 0600); err != nil {
|
|
t.Fatalf("write %s: %v", rel, err)
|
|
}
|
|
}
|
|
script := filepath.Join(sourceRepoRoot(t), "scripts", "check-testing-short.sh")
|
|
cmd := exec.Command("bash", script)
|
|
cmd.Dir = dir
|
|
out, err := cmd.CombinedOutput()
|
|
return string(out), err
|
|
}
|