Implement stricter daemon lock file validation (bd-161)

- Add JSON format to daemon.lock with database path, version, PID, and timestamp
- Validate database path on client connection (fail if mismatch)
- Backward compatible with old plain-PID lock files
- Add comprehensive tests for JSON format and validation
- Update all lock acquisition callsites to pass database path

Amp-Thread-ID: https://ampcode.com/threads/T-137e6a9c-b690-4ade-9bec-13fcd7d0e4ed
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-26 18:37:17 -07:00
parent 50623f8be1
commit 7549bd86bc
5 changed files with 212 additions and 43 deletions

View File

@@ -132,7 +132,8 @@ func TestIsDaemonRunning_CurrentProcess(t *testing.T) {
// Acquire the daemon lock to simulate a running daemon
beadsDir := filepath.Dir(pidFile)
lock, err := acquireDaemonLock(beadsDir, false)
dbPath := filepath.Join(beadsDir, "beads.db")
lock, err := acquireDaemonLock(beadsDir, dbPath)
if err != nil {
t.Fatalf("Failed to acquire daemon lock: %v", err)
}