fix: update tests for getCurrentBranchOrHEAD and getPIDFileForSocket
- sync_git_test.go: getCurrentBranchOrHEAD now returns 1 value (not 2) - daemon_basics_test.go: getPIDFileForSocket uses dbPath not socketPath - daemon_autostart.go: mark unused socketPath param with underscore These tests were broken by recent refactors that changed function signatures but didn't update the corresponding test files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -398,9 +398,10 @@ func setupDaemonIO(cmd *exec.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPIDFileForSocket returns the PID file path for a given socket path
|
// getPIDFileForSocket returns the PID file path.
|
||||||
func getPIDFileForSocket(socketPath string) string {
|
// Note: socketPath parameter is unused - PID file is always in .beads directory
|
||||||
// PID file is in .beads directory, not socket directory (socket may be in /tmp for short paths)
|
// (not socket directory, which may be in /tmp for short paths).
|
||||||
|
func getPIDFileForSocket(_ string) string {
|
||||||
dir := filepath.Dir(dbPath)
|
dir := filepath.Dir(dbPath)
|
||||||
return filepath.Join(dir, "daemon.pid")
|
return filepath.Join(dir, "daemon.pid")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
func TestGetPIDFileForSocket(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
socketPath string
|
dbPath string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "typical beads socket",
|
name: "typical beads directory",
|
||||||
socketPath: "/home/user/.beads/bd.sock",
|
dbPath: "/home/user/.beads/issues.db",
|
||||||
expected: "/home/user/.beads/daemon.pid",
|
expected: "/home/user/.beads/daemon.pid",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "root .beads directory",
|
name: "root beads directory",
|
||||||
socketPath: "/root/.beads/bd.sock",
|
dbPath: "/root/.beads/issues.db",
|
||||||
expected: "/root/.beads/daemon.pid",
|
expected: "/root/.beads/daemon.pid",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "temporary directory",
|
name: "nested project beads",
|
||||||
socketPath: "/tmp/test.sock",
|
dbPath: "/home/user/projects/myapp/.beads/issues.db",
|
||||||
expected: "/tmp/daemon.pid",
|
expected: "/home/user/projects/myapp/.beads/daemon.pid",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -607,10 +607,7 @@ func TestGetCurrentBranchOrHEAD(t *testing.T) {
|
|||||||
|
|
||||||
// Test 1: Normal branch returns branch name
|
// Test 1: Normal branch returns branch name
|
||||||
t.Run("returns branch name when on branch", func(t *testing.T) {
|
t.Run("returns branch name when on branch", func(t *testing.T) {
|
||||||
branch, err := getCurrentBranchOrHEAD(ctx)
|
branch := getCurrentBranchOrHEAD(ctx)
|
||||||
if err != nil {
|
|
||||||
t.Errorf("getCurrentBranchOrHEAD() error = %v", err)
|
|
||||||
}
|
|
||||||
if branch != "main" {
|
if branch != "main" {
|
||||||
t.Errorf("getCurrentBranchOrHEAD() = %q, want %q", 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)
|
t.Fatalf("Failed to detach HEAD: %v\n%s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
branch, err := getCurrentBranchOrHEAD(ctx)
|
branch := getCurrentBranchOrHEAD(ctx)
|
||||||
if err != nil {
|
|
||||||
t.Errorf("getCurrentBranchOrHEAD() error = %v", err)
|
|
||||||
}
|
|
||||||
if branch != "HEAD" {
|
if branch != "HEAD" {
|
||||||
t.Errorf("getCurrentBranchOrHEAD() = %q, want %q", branch, "HEAD")
|
t.Errorf("getCurrentBranchOrHEAD() = %q, want %q", branch, "HEAD")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user