* 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>
126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
// bdShowSucceeds reports whether "bd show <id> --json" succeeds. Non-fatal
|
|
// so a cascade sweep reports every deleted step instead of aborting on the
|
|
// first one.
|
|
func bdShowSucceeds(t *testing.T, bd, dir, id string) bool {
|
|
t.Helper()
|
|
cmd := exec.Command(bd, "show", id, "--json")
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Logf("bd show %s failed (expected for deleted): %v\n%s", id, err, out)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// TestEmbeddedWispGCPurgeClosedDoesNotCascadeIntoLiveSteps is the regression test for
|
|
// the patrol self-destruct bug: `bd mol wisp gc --closed --force` on a
|
|
// molecule that has closed its first step deleted the ENTIRE molecule.
|
|
//
|
|
// purgeClosed handed cascade=true to deleteBatch, and deleteMany(Cascade)
|
|
// expands every closed wisp to ALL transitive dependents. In a linear
|
|
// molecule DAG, step 1's dependents are every other step, so the first
|
|
// closed step dragged all 26 open steps of mol-deacon-patrol into deletion
|
|
// (plus its dependency links and events). Wisps live in an ignored
|
|
// (non-versioned) table, so the deletion was permanent.
|
|
//
|
|
// The closed set is complete: every closed, non-pinned, non-infra wisp is
|
|
// already a GC candidate. Cascade can only ever add NON-closed dependents to
|
|
// the batch — exactly the live steps it must not touch.
|
|
func TestEmbeddedWispGCPurgeClosedDoesNotCascadeIntoLiveSteps(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")
|
|
}
|
|
t.Parallel()
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "pc")
|
|
|
|
// Deacon patrol shape: an open mol root (the husk that survives) plus a
|
|
// linear chain of 26 steps. Each step depends on its predecessor (the
|
|
// first step is dependency-free — the patrol closes it, so it cannot be
|
|
// blocked on an open root), and step 1's transitive dependents are every
|
|
// other step.
|
|
root := bdCreate(t, bd, dir, "patrol molecule", "--ephemeral", "--type", "molecule")
|
|
|
|
const steps = 26
|
|
stepIDs := make([]string, steps)
|
|
prev := ""
|
|
for i := 0; i < steps; i++ {
|
|
id := bdCreate(t, bd, dir, fmt.Sprintf("patrol step %d", i+1), "--ephemeral").ID
|
|
stepIDs[i] = id
|
|
if prev != "" {
|
|
bdDepAdd(t, bd, dir, id, prev) // step N depends on step N-1
|
|
}
|
|
prev = id
|
|
}
|
|
|
|
// Patrol cycle: the completed first step is closed, then the formula's GC
|
|
// step purges closed wisps. The other 25 steps are live work (open) and
|
|
// must survive the purge.
|
|
bdClose(t, bd, dir, stepIDs[0])
|
|
bdCommand(t, bd, dir, "mol", "wisp", "gc", "--closed", "--force")
|
|
|
|
// The closed step itself is gone.
|
|
bdShowFail(t, bd, dir, stepIDs[0])
|
|
|
|
// Every live step survives.
|
|
for i := 1; i < steps; i++ {
|
|
if bdShowSucceeds(t, bd, dir, stepIDs[i]) {
|
|
continue
|
|
}
|
|
t.Errorf("live step %s (index %d) was cascade-deleted by purgeClosed; only the first closed step should be removed", stepIDs[i], i)
|
|
}
|
|
|
|
// The open molecule root survives too (the husk must keep its steps).
|
|
if bdShowSucceeds(t, bd, dir, root.ID) {
|
|
return
|
|
}
|
|
t.Error("open molecule root was deleted by purgeClosed")
|
|
}
|
|
|
|
// TestEmbeddedWispGCPurgeClosedStillPurgesFullyClosedMolecules guards the other side
|
|
// of the fix: when EVERY step is closed, gc --closed --force must still remove
|
|
// the whole molecule. Restricting cascade must not break complete cleanup.
|
|
func TestEmbeddedWispGCPurgeClosedStillPurgesFullyClosedMolecules(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")
|
|
}
|
|
t.Parallel()
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "pc2")
|
|
|
|
const steps = 5
|
|
stepIDs := make([]string, steps)
|
|
prev := ""
|
|
for i := 0; i < steps; i++ {
|
|
id := bdCreate(t, bd, dir, fmt.Sprintf("finished step %d", i+1), "--ephemeral").ID
|
|
stepIDs[i] = id
|
|
if prev != "" {
|
|
bdDepAdd(t, bd, dir, id, prev)
|
|
}
|
|
prev = id
|
|
}
|
|
for _, id := range stepIDs {
|
|
bdClose(t, bd, dir, id)
|
|
}
|
|
|
|
bdCommand(t, bd, dir, "mol", "wisp", "gc", "--closed", "--force")
|
|
|
|
for _, id := range stepIDs {
|
|
bdShowFail(t, bd, dir, id)
|
|
}
|
|
}
|