beads/scripts/embedded_shard_count_test.go
Julian Knutsen 4f924fc161
ci(bazel): retire PR Risk's legacy Dolt tiers, pr.yml's legacy Go jobs and the D2 coverage flags (#7353)
Every pull_request and merge group already took the Bazel lanes for the
retired tiers (BAZEL_RETIRES_LEGACY_* and BAZEL_COVERS_FORKS all "true",
and pr.yml/pr-risk.yml run on no other event), so the legacy jobs those
flags stood down could never run again. Remove them with their decision:

- pr-risk.yml: build-embedded, test-embedded-{storage,conformance,cmd},
  test-proxied-cmd, test-server-storage{,-full}, detect-ci-tier (and its
  ci-embedded-tier.sh / ci-capability-selector.sh scripts) and
  bazel-coverage. PR Risk keeps the Nix packaging check (test-nix) and its
  gate, PR Risk Gate / Required.
- pr.yml: build-artifacts, check-cmd-bd-puregeo-tests, pr-core-wrapper and
  bazel-coverage; the BAZEL_RETIRES_LEGACY_* and BAZEL_COVERS_FORKS flags.
  The three BAZEL_*_RETIRED gate ids become one, BAZEL_REMOTE: the Bazel
  call must have run remotely (remote, fork-ro or fork-rw) on every PR and
  merge group, each lane's own id still required. Gate names unchanged.

Policy tests: the D2 decision matrix becomes
TestPRGateRequiresRemoteBazelLanes (bazel.yml's actual rbe step and
pr.yml's actual gate over every event/variable/secret/fork/actor/mint
fact); the parity tests that read the legacy jobs now pin the Bazel lanes
against those jobs' frozen commands.

ga-96smfk.22

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

119 lines
5.4 KiB
Go

package scripts_test
import (
"os/exec"
"regexp"
"strconv"
"testing"
)
// shardCountPattern matches a rule block's ` shard_count = N,` line, the
// same pattern bazelProxiedShardCount (scripts/ci_workflow_test.go) inlines
// for its own single use; shared here since both embedded accessors below
// need it.
var shardCountPattern = regexp.MustCompile(`(?m)^ shard_count = (\d+),$`)
// bazelEmbeddedCmdShardCount returns cmd/bd:bd_embedded_test's own
// shard_count from cmd/bd/BUILD.bazel: the single source of truth for the
// Bazel-only bazel-embedded lane's cmd/bd shard split (slice F1), which no
// longer has to equal PR Risk's/main.yml's legacy "Test (Embedded Dolt Cmd
// N/20)" fork/push jobs' matrix size — mirrors bazelProxiedShardCount (F2;
// see that function's doc comment in scripts/ci_workflow_test.go for the
// shared rationale, not repeated here).
func bazelEmbeddedCmdShardCount(t *testing.T) int {
t.Helper()
root := sourceRepoRoot(t)
rule := bazelRuleBlock(readPolicyFile(t, root, "cmd/bd/BUILD.bazel"), "bd_embedded_test")
m := shardCountPattern.FindStringSubmatch(rule)
if m == nil {
t.Fatalf("cmd/bd:bd_embedded_test has no `shard_count = N,` in cmd/bd/BUILD.bazel:\n%s", rule)
}
n, err := strconv.Atoi(m[1])
if err != nil {
t.Fatalf("cmd/bd:bd_embedded_test shard_count: %v", err)
}
return n
}
// bazelEmbeddedStorageShardCount returns
// embeddeddolt:embeddeddolt_embedded_test's own shard_count from
// internal/storage/embeddeddolt/BUILD.bazel: the single source of truth for
// the Bazel-only bazel-embedded lane's storage shard split (slice F1), which
// no longer has to equal PR Risk's/main.yml's legacy "Test (Embedded Dolt
// Storage N/5)" fork/push jobs' matrix size. Mirrors
// bazelEmbeddedCmdShardCount above; see its doc comment.
func bazelEmbeddedStorageShardCount(t *testing.T) int {
t.Helper()
root := sourceRepoRoot(t)
rule := bazelRuleBlock(readPolicyFile(t, root, "internal/storage/embeddeddolt/BUILD.bazel"), "embeddeddolt_embedded_test")
m := shardCountPattern.FindStringSubmatch(rule)
if m == nil {
t.Fatalf("embeddeddolt:embeddeddolt_embedded_test has no `shard_count = N,` in internal/storage/embeddeddolt/BUILD.bazel:\n%s", rule)
}
n, err := strconv.Atoi(m[1])
if err != nil {
t.Fatalf("embeddeddolt:embeddeddolt_embedded_test shard_count: %v", err)
}
return n
}
// S3 (F1, mirroring F2's TestProxiedShardManifestGeneratorNotStale in
// scripts/pr_risk_bazel_coverage_test.go — see that test's doc comment for
// the full --check rationale, not repeated here): the Bazel-only 50-shard
// cmd block and 15-shard storage block are not frozen like their files'
// legacy 20- and 5-shard blocks. gen_embedded_{cmd,storage}_shard_manifest.py
// --check verifies only that the committed block names every discovered
// test exactly once, failing with the exact command to fix it when a name
// is missing, stale, or duplicated — run here so a drifted block fails `go
// test ./scripts/...` (//scripts:scripts_test under Bazel) instead of only
// surfacing as a test silently never running in any shard. The legacy
// blocks are deliberately excluded: both files document that their 20- and
// 5-shard blocks are frozen (see .github/scripts/embedded-{cmd,storage}-
// test-shards.txt and engdocs/TESTING.md), so a --check against them is
// expected to report "missing" entries by design (see those generators'
// module docstrings) and is not what this test runs.
func TestCmdEmbeddedShardManifestGeneratorNotStale(t *testing.T) {
python := requireHostTool(t, "python3")
root := sourceRepoRoot(t)
shards := strconv.Itoa(bazelEmbeddedCmdShardCount(t))
cmd := exec.Command(python, "scripts/ci/gen_embedded_cmd_shard_manifest.py", shards, "--weights=duration", "--check")
cmd.Dir = root
if out, err := cmd.CombinedOutput(); err != nil {
t.Errorf("gen_embedded_cmd_shard_manifest.py %s --weights=duration --check: %v\n%s", shards, err, out)
}
}
// TestStorageEmbeddedShardManifestGeneratorNotStale mirrors
// TestCmdEmbeddedShardManifestGeneratorNotStale above for the storage tier's
// Bazel-only 15-shard block; see that test's doc comment.
func TestStorageEmbeddedShardManifestGeneratorNotStale(t *testing.T) {
python := requireHostTool(t, "python3")
root := sourceRepoRoot(t)
shards := strconv.Itoa(bazelEmbeddedStorageShardCount(t))
cmd := exec.Command(python, "scripts/ci/gen_embedded_storage_shard_manifest.py", shards, "--weights=duration", "--check")
cmd.Dir = root
if out, err := cmd.CombinedOutput(); err != nil {
t.Errorf("gen_embedded_storage_shard_manifest.py %s --weights=duration --check: %v\n%s", shards, err, out)
}
}
// bazelServerFullShardCount returns dolt:dolt_server_full_test's own
// shard_count from internal/storage/dolt/BUILD.bazel: the single source of
// truth for the bazel-server-storage lane's full-suite shard split, now that
// PR Risk's legacy "Test (Server Dolt Full Suite N/16)" job, whose matrix it
// used to mirror, is retired (ga-96smfk.22). Mirrors
// bazelEmbeddedCmdShardCount above.
func bazelServerFullShardCount(t *testing.T) int {
t.Helper()
root := sourceRepoRoot(t)
rule := bazelRuleBlock(readPolicyFile(t, root, "internal/storage/dolt/BUILD.bazel"), "dolt_server_full_test")
m := shardCountPattern.FindStringSubmatch(rule)
if m == nil {
t.Fatalf("dolt:dolt_server_full_test has no `shard_count = N,` in internal/storage/dolt/BUILD.bazel:\n%s", rule)
}
n, err := strconv.Atoi(m[1])
if err != nil {
t.Fatalf("dolt:dolt_server_full_test shard_count: %v", err)
}
return n
}