Add tests for cmd/bd CLI to improve coverage (bd-llfl)

Added tests for:
- daemon_config.go: ensureBeadsDir, getPIDFilePath, getLogFilePath,
  getSocketPathForPID
- daemon_autostart.go: determineSocketPath, isDaemonRunningQuiet
- activity.go: printEvent
- cleanup.go: showCleanupDeprecationHint
- upgrade.go: pluralize
- wisp.go: formatTimeAgo
- list.go: pinIndicator, sortIssues
- hooks.go: FormatHookWarnings, isRebaseInProgress, hasBeadsJSONL
- template.go: extractIDSuffix
- thanks.go: getContributorsSorted

Coverage improved from 22.5% to 23.1% for cmd/bd package.
Most remaining untested code requires daemon/RPC operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-23 22:45:33 -08:00
parent bbb08d6d8d
commit 2069f0a3d7
3 changed files with 683 additions and 0 deletions

View File

@@ -245,3 +245,58 @@ func TestGetSocketPath(t *testing.T) {
}
})
}
func TestDetermineSocketPath(t *testing.T) {
t.Run("returns same path passed in", func(t *testing.T) {
testPath := "/tmp/.beads/bd.sock"
result := determineSocketPath(testPath)
if result != testPath {
t.Errorf("determineSocketPath(%q) = %q, want %q", testPath, result, testPath)
}
})
t.Run("preserves empty path", func(t *testing.T) {
result := determineSocketPath("")
if result != "" {
t.Errorf("determineSocketPath(\"\") = %q, want empty string", result)
}
})
}
func TestIsDaemonRunningQuiet(t *testing.T) {
tmpDir := t.TempDir()
pidFile := filepath.Join(tmpDir, "daemon.pid")
t.Run("returns false when PID file does not exist", func(t *testing.T) {
os.Remove(pidFile)
if isDaemonRunningQuiet(pidFile) {
t.Error("expected false when PID file does not exist")
}
})
t.Run("returns false when PID file is invalid", func(t *testing.T) {
if err := os.WriteFile(pidFile, []byte("not-a-number"), 0644); err != nil {
t.Fatalf("failed to create PID file: %v", err)
}
defer os.Remove(pidFile)
if isDaemonRunningQuiet(pidFile) {
t.Error("expected false when PID file contains invalid content")
}
})
t.Run("returns false for non-existent PID", func(t *testing.T) {
// Use a PID that's very unlikely to exist
if err := os.WriteFile(pidFile, []byte("999999999"), 0644); err != nil {
t.Fatalf("failed to create PID file: %v", err)
}
defer os.Remove(pidFile)
if isDaemonRunningQuiet(pidFile) {
t.Error("expected false for non-existent PID")
}
})
}
// Note: TestGetPIDFileForSocket, TestReadPIDFromFile, and TestIsPIDAlive
// are already defined in daemon_basics_test.go