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:
@@ -14,7 +14,7 @@ tap.test('TspmIpcClient creation', async () => {
|
||||
tap.test('IPC client socket path', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
const socketPath = (client as any).socketPath;
|
||||
|
||||
|
||||
expect(socketPath).toInclude('.tspm');
|
||||
expect(socketPath).toInclude('tspm.sock');
|
||||
});
|
||||
@@ -22,7 +22,7 @@ tap.test('IPC client socket path', async () => {
|
||||
tap.test('IPC client daemon PID file path', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
const daemonPidFile = (client as any).daemonPidFile;
|
||||
|
||||
|
||||
expect(daemonPidFile).toInclude('.tspm');
|
||||
expect(daemonPidFile).toInclude('daemon.pid');
|
||||
});
|
||||
@@ -30,7 +30,7 @@ tap.test('IPC client daemon PID file path', async () => {
|
||||
tap.test('IPC client connection state', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
const isConnected = (client as any).isConnected;
|
||||
|
||||
|
||||
expect(isConnected).toEqual(false); // Should be false initially
|
||||
});
|
||||
|
||||
@@ -38,10 +38,10 @@ tap.test('IPC client daemon running check - no daemon', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
const tspmDir = path.join(os.homedir(), '.tspm');
|
||||
const pidFile = path.join(tspmDir, 'daemon.pid');
|
||||
|
||||
|
||||
// Ensure no PID file exists for this test
|
||||
await fs.unlink(pidFile).catch(() => {});
|
||||
|
||||
|
||||
const isRunning = await (client as any).isDaemonRunning();
|
||||
expect(isRunning).toEqual(false);
|
||||
});
|
||||
@@ -50,18 +50,21 @@ tap.test('IPC client daemon running check - stale PID', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
const tspmDir = path.join(os.homedir(), '.tspm');
|
||||
const pidFile = path.join(tspmDir, 'daemon.pid');
|
||||
|
||||
|
||||
// Create directory if it doesn't exist
|
||||
await fs.mkdir(tspmDir, { recursive: true });
|
||||
|
||||
|
||||
// Write a fake PID that doesn't exist
|
||||
await fs.writeFile(pidFile, '99999999');
|
||||
|
||||
|
||||
const isRunning = await (client as any).isDaemonRunning();
|
||||
expect(isRunning).toEqual(false);
|
||||
|
||||
|
||||
// Clean up - the stale PID should be removed
|
||||
const fileExists = await fs.access(pidFile).then(() => true).catch(() => false);
|
||||
const fileExists = await fs
|
||||
.access(pidFile)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
expect(fileExists).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -70,19 +73,19 @@ tap.test('IPC client daemon running check - current process', async () => {
|
||||
const tspmDir = path.join(os.homedir(), '.tspm');
|
||||
const pidFile = path.join(tspmDir, 'daemon.pid');
|
||||
const socketFile = path.join(tspmDir, 'tspm.sock');
|
||||
|
||||
|
||||
// Create directory if it doesn't exist
|
||||
await fs.mkdir(tspmDir, { recursive: true });
|
||||
|
||||
|
||||
// Write current process PID (simulating daemon is this process)
|
||||
await fs.writeFile(pidFile, process.pid.toString());
|
||||
|
||||
|
||||
// Create a fake socket file
|
||||
await fs.writeFile(socketFile, '');
|
||||
|
||||
|
||||
const isRunning = await (client as any).isDaemonRunning();
|
||||
expect(isRunning).toEqual(true);
|
||||
|
||||
|
||||
// Clean up
|
||||
await fs.unlink(pidFile).catch(() => {});
|
||||
await fs.unlink(socketFile).catch(() => {});
|
||||
@@ -91,17 +94,19 @@ tap.test('IPC client daemon running check - current process', async () => {
|
||||
tap.test('IPC client singleton instance', async () => {
|
||||
// Import the singleton
|
||||
const { tspmIpcClient } = await import('../ts/classes.ipcclient.js');
|
||||
|
||||
|
||||
expect(tspmIpcClient).toBeInstanceOf(TspmIpcClient);
|
||||
|
||||
|
||||
// Test that it's the same instance
|
||||
const { tspmIpcClient: secondImport } = await import('../ts/classes.ipcclient.js');
|
||||
const { tspmIpcClient: secondImport } = await import(
|
||||
'../ts/classes.ipcclient.js'
|
||||
);
|
||||
expect(tspmIpcClient).toBe(secondImport);
|
||||
});
|
||||
|
||||
tap.test('IPC client request method type safety', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
|
||||
|
||||
// Test that request method exists
|
||||
expect(client.request).toBeInstanceOf(Function);
|
||||
expect(client.connect).toBeInstanceOf(Function);
|
||||
@@ -111,17 +116,18 @@ tap.test('IPC client request method type safety', async () => {
|
||||
});
|
||||
|
||||
tap.test('IPC client error message formatting', async () => {
|
||||
const errorMessage = 'Could not connect to TSPM daemon. Please try running "tspm daemon start" manually.';
|
||||
const errorMessage =
|
||||
'Could not connect to TSPM daemon. Please try running "tspm daemon start" manually.';
|
||||
expect(errorMessage).toInclude('tspm daemon start');
|
||||
});
|
||||
|
||||
tap.test('IPC client reconnection logic', async () => {
|
||||
const client = new TspmIpcClient();
|
||||
|
||||
|
||||
// Test reconnection error conditions
|
||||
const econnrefusedError = new Error('ECONNREFUSED');
|
||||
expect(econnrefusedError.message).toInclude('ECONNREFUSED');
|
||||
|
||||
|
||||
const enoentError = new Error('ENOENT');
|
||||
expect(enoentError.message).toInclude('ENOENT');
|
||||
});
|
||||
@@ -129,7 +135,7 @@ tap.test('IPC client reconnection logic', async () => {
|
||||
tap.test('IPC client daemon start timeout', async () => {
|
||||
const maxWaitTime = 10000; // 10 seconds
|
||||
const checkInterval = 500; // 500ms
|
||||
|
||||
|
||||
const maxChecks = maxWaitTime / checkInterval;
|
||||
expect(maxChecks).toEqual(20);
|
||||
});
|
||||
@@ -137,9 +143,9 @@ tap.test('IPC client daemon start timeout', async () => {
|
||||
tap.test('IPC client daemon stop timeout', async () => {
|
||||
const maxWaitTime = 15000; // 15 seconds
|
||||
const checkInterval = 500; // 500ms
|
||||
|
||||
|
||||
const maxChecks = maxWaitTime / checkInterval;
|
||||
expect(maxChecks).toEqual(30);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
Reference in New Issue
Block a user