mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-15 04:18:19 +00:00
fix(cursor): add resolve guard, port validation, and daemon tests
- Add double-resolve guard in startDaemon with safeResolve wrapper - Add port validation (1-65535) before Node.js script interpolation - Fix misleading comment in stopDaemon (no PID file handling) - Add getDaemonStatus test for no daemon running case - Add stopDaemon tests for graceful non-existent PID handling
This commit is contained in:
1 parent
afb5e746b3
commit
7d4e6d6b65
2 files changed
+63
-13
No files matched your search
@@ -11,6 +11,8 @@ import {
|
||||
writePidToFile,
|
||||
removePidFile,
|
||||
isDaemonRunning,
|
||||
getDaemonStatus,
|
||||
stopDaemon,
|
||||
} from '../../../src/cursor/cursor-daemon';
|
||||
|
||||
// Test isolation
|
||||
@@ -121,3 +123,40 @@ describe('isDaemonRunning', () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDaemonStatus', () => {
|
||||
it('returns status with running=false when no daemon running', async () => {
|
||||
const status = await getDaemonStatus(19999);
|
||||
expect(status.running).toBe(false);
|
||||
expect(status.port).toBe(19999);
|
||||
expect(status.pid).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns status with pid when PID file exists but daemon not running', async () => {
|
||||
writePidToFile(99999);
|
||||
const status = await getDaemonStatus(19999);
|
||||
expect(status.running).toBe(false);
|
||||
expect(status.port).toBe(19999);
|
||||
expect(status.pid).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('stopDaemon', () => {
|
||||
it('returns success when no PID file exists', async () => {
|
||||
const result = await stopDaemon();
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns success when PID refers to non-existent process', async () => {
|
||||
// Write a PID that doesn't exist
|
||||
writePidToFile(999999);
|
||||
const result = await stopDaemon();
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.error).toBeUndefined();
|
||||
|
||||
// PID file should be removed
|
||||
const pidFile = path.join(ccsDir(), 'cursor', 'daemon.pid');
|
||||
expect(fs.existsSync(pidFile)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user