beads/scripts/managed_local_lane_test.go
Julian Knutsen c292964571
ci(bazel): run the managed-local proxied lifecycle lane under Bazel; retire proxied-local-smoke.yml (#7326)
proxied-local-smoke.yml built bd and the cmd/bd test binary on a GitHub
runner, installed the pinned dolt, and ran `-test.run ^TestManagedLocalProxied`
under `sudo unshare --net` with only loopback up, to prove the managed-local
lifecycle (bd -> loopback proxy -> dolt sql-server) needs no outbound network.

//cmd/bd:bd_managed_local_test runs the same tests (BEADS_TEST_PROXIED_LOCAL=1,
BEADS_TEST_SKIP=dolt, the non-race bd_for_tests as the bd under test, the
pinned dolt from the test wrapper's PATH) through tools/bazel/go_test_offline.sh,
which enters an unprivileged user + network namespace with only loopback up
and fails if outbound network is reachable: the job's netns, without sudo,
on the rbe-west workers. Tagged dolt-server-proxied, so bazel.yml's
bazel-proxied lane (remote-only, required by pr.yml's gate) runs it; test
result caching replaces the workflow's path filter. The job's "tests are
compiled in" assertion becomes scripts/managed_local_lane_test.go, which
evaluates cmd/bd's build constraints for a linux cgo build and requires each
of the 17 pinned tests.

The target joins the pinned retired-lane targets in
TestBazelRetiredLanesCannotBeNarrowed. proxied-local-smoke.yml and the policy
tests that pinned its job and its dolt version are removed (the Bazel dolt
pin is already enforced against install-dolt.sh).

Refs: ga-96smfk.19

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 00:59:14 +00:00

81 lines
2.8 KiB
Go

package scripts_test
import (
"go/build"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// managedLocalLaneTests are the managed-local proxied lifecycle tests the
// retired proxied-local-smoke.yml asserted were compiled into its test binary
// before it ran `-test.run ^TestManagedLocalProxied`. They now run in
// //cmd/bd:bd_managed_local_test, whose -test.run would silently match fewer
// tests if a build constraint dropped one.
var managedLocalLaneTests = []string{
"TestManagedLocalProxiedLifecycleSmoke",
"TestManagedLocalProxiedForeignListenerNotAdopted",
"TestManagedLocalProxiedReusedPidNeverKilled",
"TestManagedLocalProxiedLegacyRecordFailClosed",
"TestManagedLocalProxiedOrphanBackendReaped",
"TestManagedLocalProxiedNProcessColdStartConvergence",
"TestManagedLocalProxiedStopStartInterleave",
"TestManagedLocalProxiedDoltStatusReportsLiveTopology",
"TestManagedLocalProxiedDoltStartRefusesOverLiveProxy",
"TestManagedLocalProxiedDoltStartRefusesWithProxyDown",
"TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone",
"TestManagedLocalProxiedTrackerUOWConformance",
"TestManagedLocalProxiedBackupRoundTrip",
"TestManagedLocalProxiedAutoBackup",
"TestManagedLocalProxiedBackupRestoreRefusedWhileAttached",
"TestManagedLocalProxiedPurgeWispsPlaneRetention",
"TestManagedLocalProxiedBackendCleanExitRetiresProxy",
}
// TestManagedLocalLaneTestsCompileIntoBdTest is the job's "Assert the
// managed-local lifecycle tests are compiled in" step: each pinned test is
// defined in a cmd/bd _test.go file that a linux/amd64 cgo build with
// bd_test's tags (gms_pure_go, no integration) compiles.
func TestManagedLocalLaneTestsCompileIntoBdTest(t *testing.T) {
dir := filepath.Join(sourceRepoRoot(t), "cmd", "bd")
ctx := build.Default
ctx.GOOS, ctx.GOARCH, ctx.CgoEnabled = "linux", "amd64", true
ctx.BuildTags = []string{"gms_pure_go"}
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
defined := map[string]string{}
funcRe := regexp.MustCompile(`(?m)^func (TestManagedLocalProxied\w*)\(`)
for _, e := range entries {
name := e.Name()
if e.IsDir() || !strings.HasSuffix(name, "_test.go") {
continue
}
match, err := ctx.MatchFile(dir, name)
if err != nil {
t.Fatalf("%s: %v", name, err)
}
if !match {
continue
}
data, err := os.ReadFile(filepath.Join(dir, name))
if err != nil {
t.Fatal(err)
}
for _, m := range funcRe.FindAllStringSubmatch(string(data), -1) {
defined[m[1]] = name
}
}
for _, name := range managedLocalLaneTests {
if _, ok := defined[name]; !ok {
t.Errorf("%s is not defined in any cmd/bd test file a linux cgo build of bd_test compiles", name)
}
}
if len(defined) < len(managedLocalLaneTests) {
t.Errorf("found %d TestManagedLocalProxied* tests, want at least %d: %v", len(defined), len(managedLocalLaneTests), defined)
}
}