Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

  • 23 tests for locking functionality
  • Tests acquireDaemonLock, releaseDaemonLock, isProcessAlive, isDaemonAlive
  • 2 failing tests identify real bugs:
    • isProcessAlive doesn't validate negative PIDs
    • releaseDaemonLock clears instead of unlinking

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Contributes to #56

This was referenced Jan 23, 2026
Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Implements comprehensive test suite for daemon locking module with 23 tests covering process liveness, lock acquisition/release, and stale lock handling
  • Follows strict TDD RED phase approach by writing failing tests first to document expected behavior before implementation
  • Tests intentionally identify 2 real implementation bugs: negative PID validation and improper lock file deletion

Important Files Changed

Filename Overview
packages/daemon/src/tests/locking.test.ts New comprehensive test suite for daemon locking functionality; includes 2 intentionally failing tests to document bugs

Confidence score: 4/5

  • This PR is safe to merge as it only adds tests without modifying production code
  • Score reflects high-quality TDD approach with comprehensive test coverage, though intentional failing tests lower confidence slightly
  • Pay close attention to the test file to understand documented bugs that need fixing in implementation

Sequence Diagram

sequenceDiagram
    participant User
    participant Test as "Test Suite"
    participant Locking as "Locking Module"
    participant FS as "File System"
    participant OS as "Operating System"

    User->>Test: "Run locking tests"
    Test->>Locking: "isProcessAlive(alivePid)"
    Locking->>OS: "Check process exists"
    OS-->>Locking: "Process exists"
    Locking-->>Test: "true"

    Test->>Locking: "isProcessAlive(deadPid)"
    Locking->>OS: "Check process exists"
    OS-->>Locking: "Process not found"
    Locking-->>Test: "false"

    Test->>FS: "Create lock file with PID"
    FS-->>Test: "Lock file created"
    Test->>Locking: "isDaemonAlive(lockPath)"
    Locking->>FS: "Read lock file"
    FS-->>Locking: "PID content"
    Locking->>OS: "Check PID alive"
    OS-->>Locking: "Process status"
    Locking-->>Test: "true/false"

    Test->>Locking: "acquireDaemonLock(lockPath)"
    Locking->>FS: "Check lock file exists"
    FS-->>Locking: "File not found"
    Locking->>FS: "Write PID to lock file"
    FS-->>Locking: "Lock file written"
    Locking-->>Test: "LockHandle"

    Test->>Locking: "releaseDaemonLock(handle)"
    Locking->>FS: "Read current lock PID"
    FS-->>Locking: "Lock PID"
    Locking->>Locking: "Verify PID matches handle"
    Locking->>FS: "Delete lock file"
    FS-->>Locking: "File deleted"
    Locking-->>Test: "Lock released"

    Test->>Locking: "readLockPid(lockPath)"
    Locking->>FS: "Read lock file content"
    FS-->>Locking: "PID string"
    Locking->>Locking: "Parse PID number"
    Locking-->>Test: "PID number"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 54 to 67
function getDeadPid(): number {
// PIDs are typically limited to values less than 2^22 on most systems
// Use a very high value that's almost certainly not in use
return 999999;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more reliable method to get a guaranteed non-existent PID. High PIDs might still exist on some systems

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/daemon/src/__tests__/locking.test.ts
Line: 54:58

Comment:
**style:** Consider using a more reliable method to get a guaranteed non-existent PID. High PIDs might still exist on some systems

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@galligan galligan changed the base branch from p5/daemon/scaffold to graphite-base/88 January 23, 2026 22:10
@galligan galligan changed the base branch from graphite-base/88 to p5/daemon/scaffold January 23, 2026 22:11
@galligan
Copy link
Contributor Author

Restacked and re-submitted this RED-phase test PR. Pre-push hook skipped tests as expected for RED phase.

@galligan galligan changed the base branch from p5/daemon/scaffold to graphite-base/88 January 23, 2026 23:00
@galligan galligan changed the base branch from graphite-base/88 to p5/daemon/scaffold January 23, 2026 23:02
@galligan
Copy link
Contributor Author

Tweaked locking tests to derive a dead PID via ESRCH scan instead of hardcoding a high PID.

@galligan
Copy link
Contributor Author

Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR.

@galligan galligan changed the base branch from p5/daemon/scaffold to graphite-base/88 January 24, 2026 03:16
galligan and others added 2 commits January 23, 2026 22:17
- 23 tests for locking functionality
- Tests acquireDaemonLock, releaseDaemonLock, isProcessAlive, isDaemonAlive
- 2 failing tests identify real bugs:
  - isProcessAlive doesn't validate negative PIDs
  - releaseDaemonLock clears instead of unlinking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan changed the base branch from graphite-base/88 to p5/daemon/scaffold January 24, 2026 03:26
@galligan
Copy link
Contributor Author

Greptile note: getDeadPid already probes for an ESRCH candidate (scan loop) instead of assuming a high PID, so we should be safe here. Restacked and resubmitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants