diff --git a/cmd/bd/mol_squash.go b/cmd/bd/mol_squash.go index 355ae9b04..8a00b0724 100644 --- a/cmd/bd/mol_squash.go +++ b/cmd/bd/mol_squash.go @@ -282,6 +282,10 @@ func squashMolecule(ctx context.Context, s storage.DoltStorage, root *types.Issu if err := tx.CloseIssue(ctx, root.ID, reason, actorName, ""); err != nil { return fmt.Errorf("failed to close wisp root %s: %w", root.ID, err) } + // Clear ephemeral so the closed root stops being re-emitted by every wisp-table export cycle. + if err := tx.UpdateIssue(ctx, root.ID, map[string]interface{}{"wisp": false}, actorName); err != nil { + return fmt.Errorf("failed to clear ephemeral flag on root %s: %w", root.ID, err) + } result.WispSquash = true } diff --git a/cmd/bd/mol_squash_embedded_test.go b/cmd/bd/mol_squash_embedded_test.go new file mode 100644 index 000000000..53b12f453 --- /dev/null +++ b/cmd/bd/mol_squash_embedded_test.go @@ -0,0 +1,83 @@ +//go:build cgo + +package main + +import ( + "context" + "os" + "testing" + + "github.com/steveyegge/beads/internal/storage/embeddeddolt" + "github.com/steveyegge/beads/internal/types" +) + +// TestEmbeddedSquashWispMoleculeClearsRootEphemeral mirrors +// TestSquashWispMoleculeClearsRootEphemeral but runs against the embedded +// Dolt backend used by CI. Without this, the standalone-Dolt regression test +// skips in the Embedded Dolt CI tier and the fix's lines stay uncovered. +func TestEmbeddedSquashWispMoleculeClearsRootEphemeral(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") + } + + ctx := context.Background() + beadsDir := t.TempDir() + + s, err := embeddeddolt.Open(ctx, beadsDir, "moltest", "main") + if err != nil { + t.Fatalf("embeddeddolt.Open: %v", err) + } + defer s.Close() + + if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { + t.Fatalf("SetConfig: %v", err) + } + + root := &types.Issue{ + Title: "Wisp Molecule Root", + Status: types.StatusOpen, + Priority: 1, + IssueType: types.TypeEpic, + Ephemeral: true, + } + if err := s.CreateIssue(ctx, root, "test"); err != nil { + t.Fatalf("CreateIssue root: %v", err) + } + + child := &types.Issue{ + Title: "Wisp Step", + Status: types.StatusClosed, + Priority: 2, + IssueType: types.TypeTask, + Ephemeral: true, + } + if err := s.CreateIssue(ctx, child, "test"); err != nil { + t.Fatalf("CreateIssue child: %v", err) + } + if err := s.AddDependency(ctx, &types.Dependency{ + IssueID: child.ID, + DependsOnID: root.ID, + Type: types.DepParentChild, + }, "test"); err != nil { + t.Fatalf("AddDependency: %v", err) + } + + result, err := squashMolecule(ctx, s, root, []*types.Issue{child}, false, "", "test") + if err != nil { + t.Fatalf("squashMolecule: %v", err) + } + if !result.WispSquash { + t.Error("expected WispSquash=true for ephemeral root") + } + + closed, err := s.GetIssue(ctx, root.ID) + if err != nil { + t.Fatalf("GetIssue root after squash: %v", err) + } + if closed.Status != types.StatusClosed { + t.Errorf("root status = %v, want closed", closed.Status) + } + if closed.Ephemeral { + t.Error("root Ephemeral should be false after squash; closed wisp roots otherwise leak as duplicate JSONL rows on every export cycle") + } +} diff --git a/cmd/bd/mol_test.go b/cmd/bd/mol_test.go index da3d922a2..3a0b46665 100644 --- a/cmd/bd/mol_test.go +++ b/cmd/bd/mol_test.go @@ -746,6 +746,73 @@ func TestSquashMoleculeWithAgentSummary(t *testing.T) { } } +// TestSquashWispMoleculeClearsRootEphemeral verifies that squashing a wisp +// molecule (root with Ephemeral=true) clears the root's Ephemeral flag in +// addition to auto-closing it. Without this, auto-export keeps re-emitting +// the closed root as ephemeral=true on every export cycle, accumulating +// duplicate JSONL rows. +func TestSquashWispMoleculeClearsRootEphemeral(t *testing.T) { + ctx := context.Background() + dbPath := t.TempDir() + "/test.db" + s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) + if err != nil { + t.Skipf("skipping: Dolt server not available: %v", err) + } + defer s.Close() + if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { + t.Fatalf("Failed to set config: %v", err) + } + + // Wisp molecule: root is ephemeral too (created via `bd mol wisp`). + root := &types.Issue{ + Title: "Wisp Molecule Root", + Status: types.StatusOpen, + Priority: 1, + IssueType: types.TypeEpic, + Ephemeral: true, + } + if err := s.CreateIssue(ctx, root, "test"); err != nil { + t.Fatalf("Failed to create ephemeral root: %v", err) + } + + child := &types.Issue{ + Title: "Wisp Step", + Status: types.StatusClosed, + Priority: 2, + IssueType: types.TypeTask, + Ephemeral: true, + } + if err := s.CreateIssue(ctx, child, "test"); err != nil { + t.Fatalf("Failed to create child: %v", err) + } + if err := s.AddDependency(ctx, &types.Dependency{ + IssueID: child.ID, + DependsOnID: root.ID, + Type: types.DepParentChild, + }, "test"); err != nil { + t.Fatalf("Failed to add dependency: %v", err) + } + + result, err := squashMolecule(ctx, s, root, []*types.Issue{child}, false, "", "test") + if err != nil { + t.Fatalf("squashMolecule failed: %v", err) + } + if !result.WispSquash { + t.Error("expected WispSquash=true for ephemeral root") + } + + closed, err := s.GetIssue(ctx, root.ID) + if err != nil { + t.Fatalf("Failed to get root after squash: %v", err) + } + if closed.Status != types.StatusClosed { + t.Errorf("root status = %v, want closed", closed.Status) + } + if closed.Ephemeral { + t.Errorf("root Ephemeral should be false after squash, got true (issue: closed wisp roots leak as duplicate JSONL rows on every export)") + } +} + // ============================================================================= // Spawn --attach Tests (bd-f7p1) // =============================================================================