From b8db5ab6fc6706e1adf5e7cbe362dfe168633a17 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 21 Nov 2025 23:09:47 -0800 Subject: [PATCH] fix(test): Complete rootCtx initialization fix for all hanging tests (issue #355) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - TestFallbackToDirectModeEnablesFlush hung with database deadlock - TestIdempotentImportNoTimestampChurn and TestImportMultipleUnchangedIssues also hung - All three tests call flushToJSONL() or autoImportIfNewer() which require rootCtx Solution: Applied the same rootCtx initialization pattern from v0.24.1 (commit 822baa0) to the remaining hanging tests: - TestFallbackToDirectModeEnablesFlush in direct_mode_test.go - TestIdempotentImportNoTimestampChurn in import_idempotent_test.go - TestImportMultipleUnchangedIssues in import_idempotent_test.go Results: - Before: Tests hung for 5+ minutes with database deadlock - After: All tests pass in ~0.1s each Fixes #355 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cmd/bd/direct_mode_test.go | 15 ++++++++++++--- cmd/bd/import_idempotent_test.go | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cmd/bd/direct_mode_test.go b/cmd/bd/direct_mode_test.go index 4b1758a4..b7fa3c1b 100644 --- a/cmd/bd/direct_mode_test.go +++ b/cmd/bd/direct_mode_test.go @@ -6,12 +6,21 @@ import ( "os" "path/filepath" "testing" + "time" "github.com/steveyegge/beads/internal/rpc" "github.com/steveyegge/beads/internal/types" ) func TestFallbackToDirectModeEnablesFlush(t *testing.T) { + // FIX: Initialize rootCtx for flush operations (issue #355) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + oldRootCtx := rootCtx + rootCtx = ctx + defer func() { rootCtx = oldRootCtx }() + origDaemonClient := daemonClient origDaemonStatus := daemonStatus origStore := store @@ -68,14 +77,14 @@ func TestFallbackToDirectModeEnablesFlush(t *testing.T) { // Seed database with issues setupStore := newTestStore(t, testDBPath) - ctx := context.Background() + setupCtx := context.Background() target := &types.Issue{ Title: "Issue to delete", IssueType: types.TypeTask, Priority: 2, Status: types.StatusOpen, } - if err := setupStore.CreateIssue(ctx, target, "test"); err != nil { + if err := setupStore.CreateIssue(setupCtx, target, "test"); err != nil { t.Fatalf("failed to create target issue: %v", err) } @@ -86,7 +95,7 @@ func TestFallbackToDirectModeEnablesFlush(t *testing.T) { Priority: 2, Status: types.StatusOpen, } - if err := setupStore.CreateIssue(ctx, neighbor, "test"); err != nil { + if err := setupStore.CreateIssue(setupCtx, neighbor, "test"); err != nil { t.Fatalf("failed to create neighbor issue: %v", err) } if err := setupStore.Close(); err != nil { diff --git a/cmd/bd/import_idempotent_test.go b/cmd/bd/import_idempotent_test.go index 7518158a..cc72e7d1 100644 --- a/cmd/bd/import_idempotent_test.go +++ b/cmd/bd/import_idempotent_test.go @@ -218,6 +218,14 @@ func strPtr(s string) *string { // TestIdempotentImportNoTimestampChurn verifies that importing unchanged issues // does not update their timestamps (bd-84) func TestIdempotentImportNoTimestampChurn(t *testing.T) { + // FIX: Initialize rootCtx for autoImportIfNewer (issue #355) + testRootCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + oldRootCtx := rootCtx + rootCtx = testRootCtx + defer func() { rootCtx = oldRootCtx }() + // Create temp directory tmpDir, err := os.MkdirTemp("", "bd-test-idempotent-*") if err != nil { @@ -300,6 +308,14 @@ func TestIdempotentImportNoTimestampChurn(t *testing.T) { // TestImportMultipleUnchangedIssues verifies that importing multiple unchanged issues // does not update any of their timestamps (bd-84) func TestImportMultipleUnchangedIssues(t *testing.T) { + // FIX: Initialize rootCtx for autoImportIfNewer (issue #355) + testRootCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + oldRootCtx := rootCtx + rootCtx = testRootCtx + defer func() { rootCtx = oldRootCtx }() + // Create temp directory tmpDir, err := os.MkdirTemp("", "bd-test-changed-*") if err != nil {