* test(cmd/bd): repair the embedded-gated tests that rotted while no lane ran them These tests skip unless BEADS_TEST_EMBEDDED_DOLT=1 but no CI lane selected them, so they rotted unseen. Running them shows: - TestEventsTailFollowReportsTruncationOnTheStream raced on a plain bytes.Buffer that os/exec's copy goroutine writes while the test polls it. Use the package's syncBuffer. - TestCorruptMetadataDiagnosticsRunAndDataFailsLoud still asserted that doctor and init run on a corrupt metadata.json. #4857 deliberately made every workspace command refuse instead (pinned for doctor by TestDoctorRejectsCorruptMetadataBeforeSharedServerChecks). Rewrite it to the shipped contract as TestEmbeddedCorruptMetadataFailsLoudUntilRestored: version warns, doctor/list/init refuse naming the file without touching it, and restoring the file brings the data back. - dolt_remote_origin_guard_embedded_test.go was tagged `embeddeddolt && cgo`, a tag no lane sets, so it never compiled in CI (gazelle left it out of bd_test srcs). Retag it `cgo`, as #4153 did for its dolt_local_only sibling, and add it to srcs. Drop its four bd doctor git-origin tests: bd doctor runs no checks on an embedded workspace (GH#3794), so two could never pass and two passed vacuously on empty output. Rename the surviving tests into the TestEmbedded* prefix. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane The embedded-Dolt cmd lane selected tests with grep '^func TestEmbedded' cmd/bd/*_embedded_test.go, and only its two Bazel targets set BEADS_TEST_EMBEDDED_DOLT. A test that skips without the variable but missed the name prefix or the file suffix skipped in every lane and reported green: 92 of them, including #7203's --if-revision CLI coverage (TestIfRevisionMatchAndMismatch, TestReassignFenceCLI, ...). - embedded-test-shard.sh and gen_embedded_cmd_shard_manifest.py select TestEmbedded* by name across cmd/bd/*_test.go, as proxied-test-shard.sh does, leaving authors one rule. - Rename the gated tests into the TestEmbedded* prefix (TestDoctorEmbedded<X> -> TestEmbeddedDoctor<X>) and update every reference. - Place the new names with gen_embedded_cmd_shard_manifest.py 100 --weights=duration --write (incremental). - Add TestEmbeddedGatedTestsRunInTheEmbeddedLane: it walks cmd/bd's tests for any that reach os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" and fails if a shard of the lane never lists one. The proxied guard's helpers now take the variable and the script; a fixture test pins the walk. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
108 lines
3.6 KiB
Go
108 lines
3.6 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// embeddedDoltEnv is the variable only //cmd/bd:bd_embedded_test and
|
|
// //cmd/bd:bd_embedded_part2_test set for cmd/bd: a cmd/bd test that skips
|
|
// without it runs in that lane or in none.
|
|
const embeddedDoltEnv = "BEADS_TEST_EMBEDDED_DOLT"
|
|
|
|
// TestEmbeddedGatedTestsRunInTheEmbeddedLane is
|
|
// TestProxiedGatedTestsRunInTheProxiedLane for the embedded-Dolt lane: every
|
|
// top-level cmd/bd test that skips unless BEADS_TEST_EMBEDDED_DOLT=1 —
|
|
// directly or through any chain of helpers — must be selected by
|
|
// .github/scripts/embedded-test-shard.sh, the lane's only test selection. The
|
|
// script selects by the TestEmbedded* name prefix alone, so a gated test named
|
|
// otherwise skips in every CI lane and its pass means nothing: 92 did,
|
|
// including #7203's --if-revision CLI coverage, until they were renamed into
|
|
// the prefix.
|
|
func TestEmbeddedGatedTestsRunInTheEmbeddedLane(t *testing.T) {
|
|
requireAutofixBash(t)
|
|
root := sourceRepoRoot(t)
|
|
|
|
gated, err := gatedTests(filepath.Join(root, "cmd/bd"), embeddedDoltEnv)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(gated) < 300 {
|
|
t.Fatalf("found only %d cmd/bd tests gated on %s; did the gate helpers change shape?", len(gated), embeddedDoltEnv)
|
|
}
|
|
|
|
listed := laneListedTests(t, root, ".github/scripts/embedded-test-shard.sh", bazelEmbeddedCmdShardCount(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/embedded-test-shard.sh never selects them, so no CI lane runs them; rename them into the TestEmbedded* prefix and place them with scripts/ci/gen_embedded_cmd_shard_manifest.py --write:\n %s",
|
|
len(missing), embeddedDoltEnv, strings.Join(missing, "\n "))
|
|
}
|
|
}
|
|
|
|
// TestEmbeddedGatedTestsDetector pins gatedTests for the embedded variable
|
|
// against a fixture, so a regression in the walk cannot silently turn the
|
|
// guard above into a no-op, and a test gated on another lane's variable is not
|
|
// demanded here.
|
|
func TestEmbeddedGatedTestsDetector(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 requireEmbedded(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("gated")
|
|
}
|
|
}
|
|
|
|
func requireProxied(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" {
|
|
t.Skip("another lane")
|
|
}
|
|
}
|
|
|
|
func buildBD(t *testing.T) string { requireEmbedded(t); return "bd" }
|
|
|
|
type harness struct{}
|
|
|
|
func (harness) start(t *testing.T) { buildBD(t) }
|
|
|
|
func TestDirect(t *testing.T) { requireEmbedded(t) }
|
|
func TestTransitive(t *testing.T) { _ = buildBD(t) }
|
|
func TestMethod(t *testing.T) { harness{}.start(t) }
|
|
func TestInSubtest(t *testing.T) {
|
|
t.Run("x", func(t *testing.T) { _ = buildBD(t) })
|
|
}
|
|
func TestInline(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("gated")
|
|
}
|
|
}
|
|
func TestOtherLane(t *testing.T) { requireProxied(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 := gatedTests(dir, embeddedDoltEnv)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []string{"TestDirect", "TestInSubtest", "TestInline", "TestMethod", "TestTransitive"}
|
|
if strings.Join(got, ",") != strings.Join(want, ",") {
|
|
t.Errorf("gatedTests(%s) = %v, want %v", embeddedDoltEnv, got, want)
|
|
}
|
|
}
|