fix: guard pid <= 0 in killProcessTree on all platforms#215
fix: guard pid <= 0 in killProcessTree on all platforms#215
Conversation
📝 WalkthroughWalkthroughThe changes add a platform-agnostic guard to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/server/src/__tests__/process-kill.test.ts (1)
111-121: Consider adding a test for negative pid on Windows for symmetry.For completeness and explicit documentation, you could add a test verifying
killProcessTree(-1)on Windows also results in noexecFilecall. This would make the test coverage symmetric across platforms for bothpid = 0andpid < 0cases.💡 Optional test to add
it("does nothing when pid is negative on Windows", async () => { const originalPlatform = process.platform; Object.defineProperty(process, "platform", { value: "win32" }); try { await killProcessTree(-1); expect(mockExecFile).not.toHaveBeenCalled(); } finally { Object.defineProperty(process, "platform", { value: originalPlatform }); } });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/server/src/__tests__/process-kill.test.ts` around lines 111 - 121, Add a symmetric test case in process-kill.test.ts that verifies killProcessTree(-1) on Windows does nothing: mirror the existing "does nothing when pid is 0 on Windows" test by temporarily setting process.platform to "win32", calling killProcessTree with -1, and asserting mockExecFile was not called; ensure you restore the original platform in the finally block and reference the same mocks used by the existing test (killProcessTree, mockExecFile).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/server/src/__tests__/process-kill.test.ts`:
- Around line 111-121: Add a symmetric test case in process-kill.test.ts that
verifies killProcessTree(-1) on Windows does nothing: mirror the existing "does
nothing when pid is 0 on Windows" test by temporarily setting process.platform
to "win32", calling killProcessTree with -1, and asserting mockExecFile was not
called; ensure you restore the original platform in the finally block and
reference the same mocks used by the existing test (killProcessTree,
mockExecFile).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a0f63d19-e57b-438a-ac35-e2cd87990678
📒 Files selected for processing (2)
apps/server/src/__tests__/process-kill.test.tsapps/server/src/services/process-kill.ts
What
Guards against
pid <= 0at the top ofkillProcessTreebefore the platform check, and moveskillSpy.mockRestore()intofinallyblocks in the tests.Why
The original guard was Unix-only (
if (pid > 0)inside theelsebranch). On Windows,killProcessTree(0)would calltaskkill /T /F /PID 0, which targets the System Idle Process. This was caught by thetry/catchand logged, but it was noisy and technically wrong. Consolidating the guard at the function entry covers both platforms with a single check.The
mockRestore()placement intrymeant a failing assertion would leave the spy active and potentially affect later tests.Key Changes
process-kill.ts: Singleif (pid <= 0) returnguard before the platform branchprocess-kill.test.ts:killSpy.mockRestore()moved tofinallyin all three affected tests; addedpid=0on Windows andpid=-1on Unix coverage testsRelated to #206
Summary by CodeRabbit
Bug Fixes
Tests