diff --git a/.github/scripts/proxied-cmd-test-shards.txt b/.github/scripts/proxied-cmd-test-shards.txt index aaec871fd..4e05f0649 100644 --- a/.github/scripts/proxied-cmd-test-shards.txt +++ b/.github/scripts/proxied-cmd-test-shards.txt @@ -276,6 +276,7 @@ 34 3 TestProxiedServerAutoPrune 34 3 TestProxiedServerClose2B 34 3 TestProxiedServerEventsJournalOffByDefault +34 3 TestProxiedServerIfRevisionCloseMismatchRefuses 34 3 TestProxiedServerMolLastActivity 34 3 TestProxiedServerPurgeWispsPlaneRetention 34 3 TestProxiedServerServeLifecycle @@ -304,6 +305,7 @@ 34 7 TestProxiedServerCloseConcurrent 34 7 TestProxiedServerCreateInfraTypeRoutesToWisps +34 7 TestProxiedServerDeleteIfRevisionSingleWinner 34 7 TestProxiedServerExternalCreate 34 7 TestProxiedServerIfRevisionGuardDelete 34 7 TestProxiedServerLabelC @@ -320,6 +322,7 @@ 34 9 TestProxiedServerGateLifecycle 34 9 TestProxiedServerHistoryRemoteSupportedFrontDoorParity 34 9 TestProxiedServerIfRevisionGuardReopen +34 9 TestProxiedServerIfRevisionOutranksReassignFence 34 9 TestProxiedServerServeRefusesTheJournalWhenItIsDisabled 34 9 TestProxiedServerUpdate 34 9 TestServerModeServe @@ -350,6 +353,7 @@ 34 13 TestProxiedServerCompactDolt 34 13 TestProxiedServerCreate2 34 13 TestProxiedServerGraph +34 13 TestProxiedServerHistoryRemoteSupportedDirectParity 34 13 TestProxiedServerMolSquash 34 13 TestProxiedServerPromote 34 13 TestProxiedServerServeRefusesAStaleCheckpointWithGone @@ -358,6 +362,7 @@ 34 14 TestProxiedServerCloseB 34 14 TestProxiedServerDuplicates 34 14 TestProxiedServerHeartbeat +34 14 TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose 34 14 TestProxiedServerInitIfMissing 34 14 TestProxiedServerMolReadyGated @@ -429,6 +434,7 @@ 34 24 TestProxiedServerDeleteBlockedJSONSingleDoc 34 24 TestProxiedServerDeleteForceOrphans 34 24 TestProxiedServerHuman +34 24 TestProxiedServerIfRevisionDeleteMatchAndMismatch 34 24 TestProxiedServerIfRevisionGuardAssign 34 24 TestProxiedServerListComments 34 24 TestProxiedServerListSortRetiresTheWalk @@ -458,6 +464,7 @@ 34 28 TestProxiedServerDep2C 34 28 TestProxiedServerDoltLifecycle +34 28 TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren 34 28 TestProxiedServerReady2 34 28 TestProxiedServerReassignFence 34 28 TestProxiedServerSQLStatementRouting diff --git a/cmd/bd/close_if_revision_proxied_test.go b/cmd/bd/close_if_revision_proxied_test.go index 07b234489..0657424ac 100644 --- a/cmd/bd/close_if_revision_proxied_test.go +++ b/cmd/bd/close_if_revision_proxied_test.go @@ -9,14 +9,14 @@ import ( "github.com/steveyegge/beads/internal/types" ) -// TestProxiedIfRevisionCloseReplaysMoleculeAutoClose is +// TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose is // TestIfRevisionCloseReplaysMoleculeAutoClose's proxied-server twin, pinning // mc-zndi7.75 item 1 on the route `bd serve` actually runs: // runCloseProxiedIfRevision bypasses the batch entirely (A8, beads#4682), so // it must re-drive molecule auto-close itself via its own post-close unit of // work, exactly as closeProxiedRunPostClose does for the unguarded batch // route. -func TestProxiedIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) { +func TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) @@ -50,10 +50,10 @@ func TestProxiedIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) { } } -// TestProxiedIfRevisionCloseWarnsOnForcedOpenChildren is +// TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren is // TestIfRevisionCloseWarnsOnForcedOpenChildren's proxied-server twin, pinning // mc-zndi7.75 item 3 on the proxied route. -func TestProxiedIfRevisionCloseWarnsOnForcedOpenChildren(t *testing.T) { +func TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) diff --git a/cmd/bd/delete_if_revision_proxied_concurrency_test.go b/cmd/bd/delete_if_revision_proxied_concurrency_test.go index 6333ba6d1..005397d80 100644 --- a/cmd/bd/delete_if_revision_proxied_concurrency_test.go +++ b/cmd/bd/delete_if_revision_proxied_concurrency_test.go @@ -18,20 +18,20 @@ import ( // connecting to the one shared Dolt server (requireSharedProxiedServer). const proxiedDeleteIfRevisionRacers = 10 -// TestProxiedDeleteIfRevisionSingleWinner pins mc-zndi7.73 on the proxied +// TestProxiedServerDeleteIfRevisionSingleWinner pins mc-zndi7.73 on the proxied // route — the topology every shared-dolt-server clone actually writes // through. It is the proxied-tier companion to // TestSharedServerDeleteIfRevisionSingleWinner (same three pairings: a // same-token delete race, delete vs close, delete vs update), proved here // against real `bd` subprocesses each going through their own local dbproxy // instance rather than connecting to the shared Dolt server directly. Every -// existing proxied --if-revision test (TestProxiedIfRevisionDeleteMatchAndMismatch, -// TestProxiedIfRevisionOutranksReassignFence) races sequentially — set up a +// existing proxied --if-revision test (TestProxiedServerIfRevisionDeleteMatchAndMismatch, +// TestProxiedServerIfRevisionOutranksReassignFence) races sequentially — set up a // "holder", then try a stale "thief" afterward — which can never observe two // writes actually overlapping at the storage layer. This test launches all // racers concurrently via goroutines, the way // TestSharedServerIfRevisionSingleWinner's race helper does. -func TestProxiedDeleteIfRevisionSingleWinner(t *testing.T) { +func TestProxiedServerDeleteIfRevisionSingleWinner(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) diff --git a/cmd/bd/history_remote_frontdoor_matrix_test.go b/cmd/bd/history_remote_frontdoor_matrix_test.go index 2a6f33ea2..b227b62a3 100644 --- a/cmd/bd/history_remote_frontdoor_matrix_test.go +++ b/cmd/bd/history_remote_frontdoor_matrix_test.go @@ -387,13 +387,16 @@ func TestProxiedServerHistoryRemoteSupportedFrontDoorParity(t *testing.T) { } } -func TestHistoryRemoteSupportedDirectAndProxiedParity(t *testing.T) { +func TestProxiedServerHistoryRemoteSupportedDirectParity(t *testing.T) { if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" { t.Skip("set BEADS_TEST_PROXIED_SERVER=1 to run direct/server parity") } bd := buildEmbeddedBD(t) direct := newDirectHistoryProject(t, bd, "hp_direct") - proxied := newSharedProxiedProject(t, bd, "hp_proxy") + // Root, not the database-scoped user: exerciseHistoryParity's `bd dolt + // remote remove` needs DOLT_REMOTE, a server-wide privilege (#7436 moved + // the other remote-removing tests to root; this one ran in no lane then). + proxied := newSharedProxiedRootProject(t, bd, "hp_proxy") directIssue := createDirectHistoryIssue(t, bd, direct) proxyIssue := bdProxiedCreate(t, bd, proxied.dir, "history parity") diff --git a/cmd/bd/if_revision_proxied_close_delete_test.go b/cmd/bd/if_revision_proxied_close_delete_test.go index aa867aa0a..4836c38cd 100644 --- a/cmd/bd/if_revision_proxied_close_delete_test.go +++ b/cmd/bd/if_revision_proxied_close_delete_test.go @@ -11,15 +11,15 @@ import ( "github.com/steveyegge/beads/internal/types" ) -// TestProxiedIfRevisionCloseMismatchRefuses pins mc-zndi7.76 (gap 4 / mutant +// TestProxiedServerIfRevisionCloseMismatchRefuses pins mc-zndi7.76 (gap 4 / mutant // MD2): close_if_revision.go's proxied route wires ExpectedVersion into both // of its SingleIssueUpdate calls (the plain close and the --force one), but // until now nothing on the proxied route ever gave it a STALE token -- -// TestProxiedIfRevisionCloseReplaysMoleculeAutoClose and -// TestProxiedIfRevisionCloseWarnsOnForcedOpenChildren only ever close with the +// TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose and +// TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren only ever close with the // current revision. A stale guard must refuse the close outright, before any // write, on the real shared Dolt server. -func TestProxiedIfRevisionCloseMismatchRefuses(t *testing.T) { +func TestProxiedServerIfRevisionCloseMismatchRefuses(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) @@ -50,12 +50,12 @@ func TestProxiedIfRevisionCloseMismatchRefuses(t *testing.T) { } } -// TestProxiedIfRevisionDeleteMatchAndMismatch pins mc-zndi7.76 (gap 4 / mutant +// TestProxiedServerIfRevisionDeleteMatchAndMismatch pins mc-zndi7.76 (gap 4 / mutant // MD4): delete_proxied_server.go wires ExpectedVersion: ifRevision into the // issueops.DeleteRequest it sends to the real Deleter, but no proxied test // gave --if-revision to delete at all before now. A matching guard deletes // the row; a stale guard refuses, and the row survives. -func TestProxiedIfRevisionDeleteMatchAndMismatch(t *testing.T) { +func TestProxiedServerIfRevisionDeleteMatchAndMismatch(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) diff --git a/cmd/bd/if_revision_reassign_fence_proxied_test.go b/cmd/bd/if_revision_reassign_fence_proxied_test.go index cc1893452..ad4a0c748 100644 --- a/cmd/bd/if_revision_reassign_fence_proxied_test.go +++ b/cmd/bd/if_revision_reassign_fence_proxied_test.go @@ -45,13 +45,13 @@ func bdProxiedShowRevision(t *testing.T, bd, dir, id string) int64 { func proxiedRevStr(rev int64) string { return strconv.FormatInt(rev, 10) } -// TestProxiedIfRevisionOutranksReassignFence pins mc-zndi7.74 on the +// TestProxiedServerIfRevisionOutranksReassignFence pins mc-zndi7.74 on the // proxied-server route, the topology where this race actually happens: every // shared-dolt-server clone writes through it. See // TestIfRevisionOutranksReassignFenceCLI's doc for the full race shape — // this is the same scenario, proved against the real shared Dolt server // instead of embedded Dolt. -func TestProxiedIfRevisionOutranksReassignFence(t *testing.T) { +func TestProxiedServerIfRevisionOutranksReassignFence(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) diff --git a/scripts/BUILD.bazel b/scripts/BUILD.bazel index b5664d7a6..3da5a9629 100644 --- a/scripts/BUILD.bazel +++ b/scripts/BUILD.bazel @@ -139,6 +139,7 @@ go_test( "managed_local_lane_test.go", "pinned_shards_helpers_test.go", "pinned_shards_sources_test.go", + "proxied_lane_coverage_test.go", "repo_helpers_test.go", "scripts_targets_test.go", "shard_manifest_test.go", diff --git a/scripts/proxied_lane_coverage_test.go b/scripts/proxied_lane_coverage_test.go new file mode 100644 index 000000000..4e3cf4f2d --- /dev/null +++ b/scripts/proxied_lane_coverage_test.go @@ -0,0 +1,247 @@ +package scripts_test + +import ( + "go/ast" + "go/parser" + "go/token" + "os" + "os/exec" + "path/filepath" + "sort" + "strconv" + "strings" + "sync" + "testing" +) + +// proxiedServerEnv is the variable only //cmd/bd:bd_proxied_test sets: a +// cmd/bd test that skips without it runs in that lane or in none. +const proxiedServerEnv = "BEADS_TEST_PROXIED_SERVER" + +// TestProxiedGatedTestsRunInTheProxiedLane pins ga-vnycm2.43: every top-level +// cmd/bd test that skips unless BEADS_TEST_PROXIED_SERVER=1 — directly, or +// through any chain of helpers (requireSharedProxiedServer, +// requireProxiedServerEnv, newSharedProxiedProject, ...) — must be selected +// by .github/scripts/proxied-test-shard.sh, the proxied lane's only test +// selection. The script discovers tests by name prefix +// (TestProxiedServer*/TestServerMode*) alone, so a gated test named otherwise +// skips in every CI lane and its pass means nothing: seven did, until they +// were renamed into the prefix (TestProxiedIfRevision* and +// TestProxiedDeleteIfRevisionSingleWinner became TestProxiedServer*). +// +// The gate is recognized structurally: an `if os.Getenv("BEADS_TEST_PROXIED_SERVER") +// != "1" { ... }` statement. A compound condition (one that also accepts a +// second lane's variable, e.g. the managed-local lane's) is not a proxied-only +// gate and is not followed. +func TestProxiedGatedTestsRunInTheProxiedLane(t *testing.T) { + requireAutofixBash(t) + root := sourceRepoRoot(t) + + gated, err := proxiedGatedTests(filepath.Join(root, "cmd/bd")) + if err != nil { + t.Fatal(err) + } + if len(gated) < 50 { + t.Fatalf("found only %d cmd/bd tests gated on %s; did the gate helpers change shape?", len(gated), proxiedServerEnv) + } + + listed := proxiedLaneListedTests(t, root, bazelProxiedShardCount(t)) + var missing []string + for _, name := range gated { + if !listed[name] { + missing = append(missing, name) + } + } + if len(missing) > 0 { + t.Errorf("%d cmd/bd test(s) skip unless %s=1 but .github/scripts/proxied-test-shard.sh never selects them, so no CI lane runs them; widen its discovery (and gen_proxied_shard_manifest.py's) or rename the test:\n %s", + len(missing), proxiedServerEnv, strings.Join(missing, "\n ")) + } +} + +// TestProxiedGatedTestsDetector pins the call-graph walk above against a +// fixture, so a regression in the detector cannot silently turn the guard +// into a no-op. +func TestProxiedGatedTestsDetector(t *testing.T) { + dir := t.TempDir() + // Every fixture line is indented one tab, so repo scanners that find + // tests by a line-anchored `^func TestX(t *testing.T)` (equivalence.py) + // do not mistake the fixture's functions for this package's tests. + const src = `package main + + import ( + "os" + "testing" + ) + + func requireGate(t *testing.T) { + if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" { + t.Skip("gated") + } + } + + func newProject(t *testing.T) { requireGate(t) } + + func requireEither(t *testing.T) { + if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" && os.Getenv("OTHER") != "1" { + t.Skip("either lane") + } + } + + type harness struct{} + + func (harness) start(t *testing.T) { newProject(t) } + + func TestDirect(t *testing.T) { requireGate(t) } + func TestTransitive(t *testing.T) { newProject(t) } + func TestMethod(t *testing.T) { harness{}.start(t) } + func TestInSubtest(t *testing.T) { + t.Run("x", func(t *testing.T) { newProject(t) }) + } + func TestInline(t *testing.T) { + if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" { + t.Skip("gated") + } + } + func TestEitherLane(t *testing.T) { requireEither(t) } + func TestUngated(t *testing.T) {} +` + if err := os.WriteFile(filepath.Join(dir, "fixture_test.go"), []byte(src), 0o644); err != nil { + t.Fatal(err) + } + got, err := proxiedGatedTests(dir) + if err != nil { + t.Fatal(err) + } + want := []string{"TestDirect", "TestInSubtest", "TestInline", "TestMethod", "TestTransitive"} + if strings.Join(got, ",") != strings.Join(want, ",") { + t.Errorf("proxiedGatedTests = %v, want %v", got, want) + } +} + +// proxiedGatedTests returns, sorted, the top-level `func TestX(t *testing.T)` +// declarations in dir's _test.go files that reach a proxied-only gate through +// calls (functions and methods alike, by name, closures included). Matching +// callees by bare name over-approximates, which errs toward demanding the +// lane run a test rather than missing one. +func proxiedGatedTests(dir string) ([]string, error) { + files, err := filepath.Glob(filepath.Join(dir, "*_test.go")) + if err != nil { + return nil, err + } + fset := token.NewFileSet() + calls := map[string]map[string]bool{} + gated := map[string]bool{} + var tests []string + for _, f := range files { + file, err := parser.ParseFile(fset, f, nil, parser.SkipObjectResolution) + if err != nil { + return nil, err + } + for _, decl := range file.Decls { + fn, ok := decl.(*ast.FuncDecl) + if !ok || fn.Body == nil { + continue + } + name := fn.Name.Name + if fn.Recv == nil && strings.HasPrefix(name, "Test") && takesTestingT(fn) { + tests = append(tests, name) + } + if calls[name] == nil { + calls[name] = map[string]bool{} + } + ast.Inspect(fn.Body, func(n ast.Node) bool { + switch n := n.(type) { + case *ast.IfStmt: + if isProxiedOnlyGate(n.Cond) { + gated[name] = true + } + case *ast.CallExpr: + switch fun := n.Fun.(type) { + case *ast.Ident: + calls[name][fun.Name] = true + case *ast.SelectorExpr: + calls[name][fun.Sel.Name] = true + } + } + return true + }) + } + } + for changed := true; changed; { + changed = false + for caller, callees := range calls { + if gated[caller] { + continue + } + for callee := range callees { + if gated[callee] { + gated[caller] = true + changed = true + break + } + } + } + } + var out []string + for _, name := range tests { + if gated[name] { + out = append(out, name) + } + } + sort.Strings(out) + return out, nil +} + +// isProxiedOnlyGate reports whether cond is exactly +// os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1". +func isProxiedOnlyGate(cond ast.Expr) bool { + be, ok := cond.(*ast.BinaryExpr) + if !ok || be.Op != token.NEQ { + return false + } + if lit, ok := be.Y.(*ast.BasicLit); !ok || lit.Value != `"1"` { + return false + } + call, ok := be.X.(*ast.CallExpr) + if !ok || len(call.Args) != 1 { + return false + } + sel, ok := call.Fun.(*ast.SelectorExpr) + if !ok || sel.Sel.Name != "Getenv" { + return false + } + arg, ok := call.Args[0].(*ast.BasicLit) + return ok && arg.Value == strconv.Quote(proxiedServerEnv) +} + +// proxiedLaneListedTests runs proxied-test-shard.sh list-only for every shard +// of the Bazel lane's split and returns every test name any shard selects. +func proxiedLaneListedTests(t *testing.T, root string, shards int) map[string]bool { + t.Helper() + outs, errs := make([][]byte, shards+1), make([]error, shards+1) + var wg sync.WaitGroup + for k := 1; k <= shards; k++ { + wg.Add(1) + go func(k int) { + defer wg.Done() + cmd := exec.Command("bash", ".github/scripts/proxied-test-shard.sh", strconv.Itoa(k), strconv.Itoa(shards)) + cmd.Dir = root + cmd.Env = append(os.Environ(), "BEADS_TEST_SHARD_LIST_ONLY=1") + outs[k], errs[k] = cmd.Output() + }(k) + } + wg.Wait() + listed := map[string]bool{} + for k := 1; k <= shards; k++ { + if errs[k] != nil { + t.Fatalf("proxied-test-shard.sh %d %d: %v\n%s", k, shards, errs[k], outs[k]) + } + for _, line := range strings.Split(string(outs[k]), "\n") { + name, ok := strings.CutPrefix(line, " ") + if ok && strings.HasPrefix(name, "Test") && !strings.ContainsAny(name, " :") { + listed[name] = true + } + } + } + return listed +}