diff --git a/cmd/bd/daemon_autostart.go b/cmd/bd/daemon_autostart.go index aff399fd..011dc02c 100644 --- a/cmd/bd/daemon_autostart.go +++ b/cmd/bd/daemon_autostart.go @@ -398,9 +398,10 @@ func setupDaemonIO(cmd *exec.Cmd) { } } -// getPIDFileForSocket returns the PID file path for a given socket path -func getPIDFileForSocket(socketPath string) string { - // PID file is in .beads directory, not socket directory (socket may be in /tmp for short paths) +// getPIDFileForSocket returns the PID file path. +// Note: socketPath parameter is unused - PID file is always in .beads directory +// (not socket directory, which may be in /tmp for short paths). +func getPIDFileForSocket(_ string) string { dir := filepath.Dir(dbPath) return filepath.Join(dir, "daemon.pid") } diff --git a/cmd/bd/daemon_basics_test.go b/cmd/bd/daemon_basics_test.go index ca3d60fc..17dafa39 100644 --- a/cmd/bd/daemon_basics_test.go +++ b/cmd/bd/daemon_basics_test.go @@ -120,35 +120,41 @@ func TestCheckParentProcessAlive_InvalidPID(t *testing.T) { } } -// TestGetPIDFileForSocket tests socket to PID file path conversion +// TestGetPIDFileForSocket tests PID file path derivation from dbPath +// Note: The socketPath parameter is ignored; PID file is always in .beads directory func TestGetPIDFileForSocket(t *testing.T) { tests := []struct { - name string - socketPath string - expected string + name string + dbPath string + expected string }{ { - name: "typical beads socket", - socketPath: "/home/user/.beads/bd.sock", - expected: "/home/user/.beads/daemon.pid", + name: "typical beads directory", + dbPath: "/home/user/.beads/issues.db", + expected: "/home/user/.beads/daemon.pid", }, { - name: "root .beads directory", - socketPath: "/root/.beads/bd.sock", - expected: "/root/.beads/daemon.pid", + name: "root beads directory", + dbPath: "/root/.beads/issues.db", + expected: "/root/.beads/daemon.pid", }, { - name: "temporary directory", - socketPath: "/tmp/test.sock", - expected: "/tmp/daemon.pid", + name: "nested project beads", + dbPath: "/home/user/projects/myapp/.beads/issues.db", + expected: "/home/user/projects/myapp/.beads/daemon.pid", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := getPIDFileForSocket(tt.socketPath) + // Save and restore global dbPath + oldDbPath := dbPath + defer func() { dbPath = oldDbPath }() + + dbPath = tt.dbPath + result := getPIDFileForSocket("ignored") if result != tt.expected { - t.Errorf("getPIDFileForSocket(%q) = %q, want %q", tt.socketPath, result, tt.expected) + t.Errorf("getPIDFileForSocket() with dbPath=%q = %q, want %q", tt.dbPath, result, tt.expected) } }) } diff --git a/cmd/bd/sync_git_test.go b/cmd/bd/sync_git_test.go index 2bbecce9..40f1f5dd 100644 --- a/cmd/bd/sync_git_test.go +++ b/cmd/bd/sync_git_test.go @@ -607,10 +607,7 @@ func TestGetCurrentBranchOrHEAD(t *testing.T) { // Test 1: Normal branch returns branch name t.Run("returns branch name when on branch", func(t *testing.T) { - branch, err := getCurrentBranchOrHEAD(ctx) - if err != nil { - t.Errorf("getCurrentBranchOrHEAD() error = %v", err) - } + branch := getCurrentBranchOrHEAD(ctx) if branch != "main" { t.Errorf("getCurrentBranchOrHEAD() = %q, want %q", branch, "main") } @@ -625,10 +622,7 @@ func TestGetCurrentBranchOrHEAD(t *testing.T) { t.Fatalf("Failed to detach HEAD: %v\n%s", err, out) } - branch, err := getCurrentBranchOrHEAD(ctx) - if err != nil { - t.Errorf("getCurrentBranchOrHEAD() error = %v", err) - } + branch := getCurrentBranchOrHEAD(ctx) if branch != "HEAD" { t.Errorf("getCurrentBranchOrHEAD() = %q, want %q", branch, "HEAD") }