feat(daemon): add BD_SOCKET env var for test isolation (#914)

Add BD_SOCKET environment variable support to override daemon socket path,
enabling parallel test isolation via t.TempDir() + t.Setenv().

Changes:
- getSocketPath() checks BD_SOCKET first, falls back to dbPath-derived path
- getSocketPathForPID() checks BD_SOCKET first (for consistency)
- Add daemon_socket_test.go with isolation pattern examples

This is a minimal tracer bullet to validate the approach before
expanding to full test isolation infrastructure.

Backward compatible: default behavior unchanged without env var set.
This commit is contained in:
Peter Chanthamynavong
2026-01-06 19:13:49 -08:00
committed by GitHub
parent 5dfb838d60
commit e9e0d7f1e5
4 changed files with 92 additions and 4 deletions

View File

@@ -455,9 +455,14 @@ func recordDaemonStartFailure() {
// No cap needed - backoff is capped at 120s in canRetryDaemonStart
}
// getSocketPath returns the daemon socket path based on the database location
// getSocketPath returns the daemon socket path based on the database location.
// If BD_SOCKET env var is set, uses that value instead (enables test isolation).
// Returns local socket path (.beads/bd.sock relative to database)
func getSocketPath() string {
// Check environment variable first (enables test isolation)
if socketPath := os.Getenv("BD_SOCKET"); socketPath != "" {
return socketPath
}
return filepath.Join(filepath.Dir(dbPath), "bd.sock")
}