* 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>
122 lines
5.5 KiB
Go
122 lines
5.5 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// THE NAME IS LOAD-BEARING: it must keep the TestEmbedded prefix, because
|
|
// .github/scripts/embedded-test-shard.sh selects what runs with
|
|
// `grep -rh '^func TestEmbedded' cmd/bd/*_test.go` and validates each
|
|
// manifest entry against `^TestEmbedded[A-Za-z0-9_]+$`. As
|
|
// TestVersionedHistorySwitchRoundTrip_Embedded this test matched neither, so
|
|
// the only job that sets BEADS_TEST_EMBEDDED_DOLT=1 for cmd/bd never selected
|
|
// it, and the generic Test jobs run without that env so its own guard skipped
|
|
// it there. The one test that can see the two planes disagree therefore ran
|
|
// only on the author's machine. Renaming it is the whole fix -- a test absent
|
|
// from the manifest still gets a shard from the fallback distribution.
|
|
// (bee-ghosttrack, #6661 third review, blocking finding 2.)
|
|
//
|
|
// TestEmbeddedVersionedHistorySwitchRoundTrip drives the REAL
|
|
// `bd config set versioned-history.enabled true` through to a real
|
|
// `bd versions`, against a real store.
|
|
//
|
|
// This exists because the two ends disagreed and no unit test could see it.
|
|
// `bd config set` routes a key that is not yaml-only to the workspace
|
|
// DATABASE; the readers called config.GetBool, which is viper (yaml + env)
|
|
// only. So the command the help text and the off-refusal both named wrote one
|
|
// plane while the reader read the other: the user ran exactly what they were
|
|
// told, was told it worked, and recording stayed off. A fake-backed unit test
|
|
// cannot catch that, because the bug IS the difference between the two real
|
|
// planes. (bee-ghosttrack, #6661 review, finding 1: "a test that drives the
|
|
// real bd config set -> reader round trip would have caught this and would
|
|
// keep it caught.")
|
|
//
|
|
// The env var is explicitly cleared for the write and read below, so a
|
|
// passing run proves the STORE setting alone carried it.
|
|
func TestEmbeddedVersionedHistorySwitchRoundTrip(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
|
|
}
|
|
// No t.Parallel: t.Setenv below is incompatible with it, and clearing the
|
|
// env var is the whole point — a pass has to prove the STORE setting
|
|
// carried the switch on its own.
|
|
t.Setenv("BD_VERSIONED_HISTORY_ENABLED", "")
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "vsw")
|
|
|
|
created := bdRunOK(t, bd, dir, "create", "switch round trip")
|
|
id := extractFirstID(created, "vsw-")
|
|
if id == "" {
|
|
t.Fatalf("could not find a vsw- id in create output: %s", created)
|
|
}
|
|
|
|
// Off by default: a bead with no recorded versions must refuse, not
|
|
// report an empty history.
|
|
if out, code := bdRunFailCode(t, bd, dir, "versions", id); code == 0 {
|
|
t.Errorf("bd versions succeeded with recording off and nothing recorded; want a refusal. out=%s", out)
|
|
} else if !strings.Contains(out, "bd config set versioned-history.enabled true") {
|
|
t.Errorf("the refusal must name the command that actually turns it on; got: %s", out)
|
|
}
|
|
|
|
// The advertised command. If this writes a plane the reader does not
|
|
// consult, everything below fails.
|
|
bdConfig(t, bd, dir, "set", "versioned-history.enabled", "true")
|
|
|
|
// A bead that existed before the switch was turned on never participated in
|
|
// history (design §16.2b: the write fence skips a legacy record), so writing
|
|
// to it versions nothing. That is the fence, pinned at the command level.
|
|
legacyID := id
|
|
bdRunOK(t, bd, dir, "update", legacyID, "--title", "switch round trip, edited while legacy")
|
|
if legacy := bdRunOK(t, bd, dir, "versions", legacyID); !strings.Contains(legacy, "No versions recorded for "+legacyID) {
|
|
t.Errorf("a bead created before the switch was turned on gained a version from an ordinary write; the fence must skip it. out=%s", legacy)
|
|
}
|
|
|
|
// The round trip itself is asserted on a bead created AFTER the switch, which
|
|
// participates, so its writes are versioned.
|
|
created = bdRunOK(t, bd, dir, "create", "switch round trip, created with history on")
|
|
id = extractFirstID(created, "vsw-")
|
|
if id == "" {
|
|
t.Fatalf("could not find a vsw- id in create output: %s", created)
|
|
}
|
|
|
|
bdRunOK(t, bd, dir, "update", id, "--title", "switch round trip, edited")
|
|
|
|
out := bdRunOK(t, bd, dir, "versions", id)
|
|
if !strings.Contains(out, "Versions of "+id) {
|
|
t.Fatalf("no versions listed after enabling via bd config set — the write and read planes have diverged again. out=%s", out)
|
|
}
|
|
if strings.Contains(out, "Recording is currently OFF") {
|
|
t.Errorf("recording reported OFF immediately after bd config set enabled it: %s", out)
|
|
}
|
|
|
|
// Turning it back off must not hide what was already recorded: that is a
|
|
// claim about the store made from a fact about this invocation's config
|
|
// (same review, finding 3).
|
|
bdConfig(t, bd, dir, "set", "versioned-history.enabled", "false")
|
|
|
|
off := bdRunOK(t, bd, dir, "versions", id)
|
|
if !strings.Contains(off, "Versions of "+id) {
|
|
t.Errorf("recorded versions vanished when recording was switched off; they are still real. out=%s", off)
|
|
}
|
|
if !strings.Contains(off, "Recording is currently OFF") {
|
|
t.Errorf("a listing taken while recording is off must say so, or it reads as current: %s", off)
|
|
}
|
|
}
|
|
|
|
// extractFirstID pulls the first whitespace-delimited token carrying prefix
|
|
// out of command output.
|
|
func extractFirstID(out, prefix string) string {
|
|
for _, f := range strings.FieldsFunc(out, func(r rune) bool {
|
|
return r == ' ' || r == '\n' || r == '\t' || r == ':' || r == '\r'
|
|
}) {
|
|
if strings.HasPrefix(f, prefix) {
|
|
return strings.TrimRight(f, ".,")
|
|
}
|
|
}
|
|
return ""
|
|
}
|