fix(test): Complete rootCtx initialization fix for all hanging tests (issue #355)

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 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-21 23:09:47 -08:00
parent 89aa83a8d9
commit b8db5ab6fc
2 changed files with 28 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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 {