BREAKING CHANGE(daemon): Refactor daemon and service management: remove IPC auto-spawn, add TspmServiceManager, tighten IPC/client/CLI behavior and tests

This commit is contained in:
2025-08-28 15:52:29 +00:00
parent 8e3cfb624b
commit e73f4acd63
38 changed files with 810 additions and 580 deletions

View File

@@ -13,18 +13,18 @@ tap.test('TspmDaemon creation', async () => {
tap.test('Daemon PID file management', async (tools) => {
const testDir = path.join(process.cwd(), '.nogit');
const testPidFile = path.join(testDir, 'test-daemon.pid');
// Create directory if it doesn't exist
await fs.mkdir(testDir, { recursive: true });
// Clean up any existing test file
await fs.unlink(testPidFile).catch(() => {});
// Test writing PID file
await fs.writeFile(testPidFile, process.pid.toString());
const pidContent = await fs.readFile(testPidFile, 'utf-8');
expect(parseInt(pidContent)).toEqual(process.pid);
// Clean up
await fs.unlink(testPidFile);
});
@@ -38,11 +38,11 @@ tap.test('Daemon socket path generation', async () => {
tap.test('Daemon shutdown handlers', async (tools) => {
const daemon = new TspmDaemon();
// Test that shutdown handlers are registered
const sigintListeners = process.listeners('SIGINT');
const sigtermListeners = process.listeners('SIGTERM');
// We expect at least one listener for each signal
// (Note: in actual test we won't start the daemon to avoid side effects)
expect(sigintListeners.length).toBeGreaterThanOrEqual(0);
@@ -52,7 +52,7 @@ tap.test('Daemon shutdown handlers', async (tools) => {
tap.test('Daemon process info tracking', async () => {
const daemon = new TspmDaemon();
const tspmInstance = (daemon as any).tspmInstance;
expect(tspmInstance).toBeDefined();
expect(tspmInstance.processes).toBeInstanceOf(Map);
expect(tspmInstance.processConfigs).toBeInstanceOf(Map);
@@ -61,7 +61,7 @@ tap.test('Daemon process info tracking', async () => {
tap.test('Daemon heartbeat monitoring setup', async (tools) => {
const daemon = new TspmDaemon();
// Test heartbeat interval property exists
const heartbeatInterval = (daemon as any).heartbeatInterval;
expect(heartbeatInterval).toEqual(null); // Should be null before start
@@ -70,13 +70,13 @@ tap.test('Daemon heartbeat monitoring setup', async (tools) => {
tap.test('Daemon shutdown state management', async () => {
const daemon = new TspmDaemon();
const isShuttingDown = (daemon as any).isShuttingDown;
expect(isShuttingDown).toEqual(false);
});
tap.test('Daemon memory usage reporting', async () => {
const memUsage = process.memoryUsage();
expect(memUsage.heapUsed).toBeGreaterThan(0);
expect(memUsage.heapTotal).toBeGreaterThan(0);
expect(memUsage.rss).toBeGreaterThan(0);
@@ -84,10 +84,10 @@ tap.test('Daemon memory usage reporting', async () => {
tap.test('Daemon CPU usage calculation', async () => {
const cpuUsage = process.cpuUsage();
expect(cpuUsage.user).toBeGreaterThanOrEqual(0);
expect(cpuUsage.system).toBeGreaterThanOrEqual(0);
// Test conversion to seconds
const cpuSeconds = cpuUsage.user / 1000000;
expect(cpuSeconds).toBeGreaterThanOrEqual(0);
@@ -95,13 +95,13 @@ tap.test('Daemon CPU usage calculation', async () => {
tap.test('Daemon uptime calculation', async () => {
const startTime = Date.now();
// Wait a bit
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
const uptime = Date.now() - startTime;
expect(uptime).toBeGreaterThanOrEqual(100);
expect(uptime).toBeLessThan(200);
});
export default tap.start();
export default tap.start();