-
Notifications
You must be signed in to change notification settings - Fork 0
test(daemon): add locking module tests (RED phase) #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: p5/daemon/scaffold
Are you sure you want to change the base?
Conversation
15c0b24 to
ade7527
Compare
Greptile Summary
|
| 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"
There was a problem hiding this 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
| 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; | ||
| } |
There was a problem hiding this comment.
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.ade7527 to
c779d8d
Compare
6a060dd to
43ba5e1
Compare
|
Restacked and re-submitted this RED-phase test PR. Pre-push hook skipped tests as expected for RED phase. |
43ba5e1 to
ec39151
Compare
c779d8d to
3f4f73c
Compare
|
Tweaked locking tests to derive a dead PID via ESRCH scan instead of hardcoding a high PID. |
ec39151 to
8c0c488
Compare
3f4f73c to
7c38924
Compare
|
Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR. |
- 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>
8c0c488 to
e3558b0
Compare
7c38924 to
41b71e7
Compare
|
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. |

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
Contributes to #56