diff --git a/.github/scripts/embedded-cmd-test-shards.txt b/.github/scripts/embedded-cmd-test-shards.txt index c3bfa552f..535bf8d06 100644 --- a/.github/scripts/embedded-cmd-test-shards.txt +++ b/.github/scripts/embedded-cmd-test-shards.txt @@ -290,6 +290,7 @@ 50 15 TestEmbeddedVersionConcurrent 50 16 TestEmbeddedBlockedLabelFilters +50 16 TestEmbeddedGateInheritsDownParentChain 50 16 TestEmbeddedKV 50 16 TestEmbeddedMaxRowsReady 50 16 TestEmbeddedOpen_EmptyDatabaseRejected diff --git a/cmd/bd/BUILD.bazel b/cmd/bd/BUILD.bazel index 10f006ac9..4305927a5 100644 --- a/cmd/bd/BUILD.bazel +++ b/cmd/bd/BUILD.bazel @@ -770,6 +770,7 @@ go_test( "gate_discover_test.go", "gate_embedded_test.go", "gate_frontdoor_parity_integration_test.go", + "gate_inherit_embedded_test.go", "gate_lifecycle_proxied_integration_test.go", "gate_routing_test.go", "gate_test.go", diff --git a/cmd/bd/gate_inherit_embedded_test.go b/cmd/bd/gate_inherit_embedded_test.go new file mode 100644 index 000000000..b3f18d8b0 --- /dev/null +++ b/cmd/bd/gate_inherit_embedded_test.go @@ -0,0 +1,99 @@ +//go:build cgo + +package main + +import ( + "os" + "os/exec" + "slices" + "strings" + "testing" + + "github.com/steveyegge/beads/internal/types" +) + +// TestEmbeddedGateInheritsDownParentChain pins the property that a gate on a +// parent hides the parent AND every child from `bd ready` — children that +// existed when the gate was created and children created afterwards alike — +// and that resolving the gate frees all of them. The wyvern rig's operator +// tooling relies on this (its own gate labels are a snapshot; the bd ready +// fence is not), so a regression here would silently put shelved work back +// on agent fronts. Mechanism under test: a gate is a blocks-dependency onto +// the gate issue, and the parent-child leg of the blocked-consistency +// recompute cascades a parent's blockedness to its children. +func TestEmbeddedGateInheritsDownParentChain(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, beadsDir, _ := bdInit(t, bd, "--prefix", "gi") + store := openStore(t, beadsDir, "gi") + if err := store.SetConfig(t.Context(), "types.custom", `["gate"]`); err != nil { + t.Fatalf("SetConfig types.custom: %v", err) + } + store.Close() + + ready := func() string { + t.Helper() + cmd := exec.Command(bd, "ready", "--limit", "0") + cmd.Dir = dir + cmd.Env = bdEnv(dir) + stdout, stderr, err := runCommandBuffers(t, cmd) + if err != nil { + t.Fatalf("bd ready failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String()) + } + return stdout.String() + } + // An issue counts as listed only when its ID is a whole token of the + // output. Neither its title nor a substring of its ID will do: every + // ready child of an epic carries a "← " annotation, and a + // child's hierarchical ID (.N) contains the epic's ID, so either + // looser match would let a child row stand in for the epic. + wantReady := func(out string, issue *types.Issue, want bool, when string) { + t.Helper() + if got := slices.Contains(strings.Fields(out), issue.ID); got != want { + t.Errorf("%s: %s (%q) in ready = %v, want %v\n%s", when, issue.ID, issue.Title, got, want, out) + } + } + + epic := bdCreate(t, bd, dir, "Inherit epic", "--type", "epic") + one := bdCreate(t, bd, dir, "Inherit child one", "--type", "task", "--parent", epic.ID) + two := bdCreate(t, bd, dir, "Inherit child two", "--type", "task", "--parent", epic.ID) + + out := ready() + wantReady(out, epic, true, "before gate") + wantReady(out, one, true, "before gate") + wantReady(out, two, true, "before gate") + + gateOut := bdGate(t, bd, dir, "create", "--blocks", epic.ID, "--reason", "hold the whole tree") + var gateID string + for _, word := range strings.Fields(gateOut) { + if strings.HasPrefix(word, "gi-") { + gateID = word + break + } + } + if gateID == "" { + t.Fatalf("could not extract gate ID from output: %s", gateOut) + } + + out = ready() + wantReady(out, epic, false, "gate open, existing children") + wantReady(out, one, false, "gate open, existing children") + wantReady(out, two, false, "gate open, existing children") + + // A child filed AFTER the gate must be born hidden too: the fence is a + // property of the tree at read time, not a snapshot at gate time. + late := bdCreate(t, bd, dir, "Inherit child late", "--type", "task", "--parent", epic.ID) + out = ready() + wantReady(out, late, false, "gate open, later-born child") + + bdGate(t, bd, dir, "resolve", gateID, "--reason", "released") + out = ready() + wantReady(out, epic, true, "after resolve") + wantReady(out, one, true, "after resolve") + wantReady(out, two, true, "after resolve") + wantReady(out, late, true, "after resolve") +}