fix(daemon): Improve daemon log delivery and process monitor memory accounting; gate debug output and update tests to numeric ProcessId
This commit is contained in:
@@ -5,6 +5,7 @@ import * as fs from 'fs/promises';
|
||||
import * as os from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import { tspmIpcClient, TspmIpcClient } from '../ts/client/tspm.ipcclient.js';
|
||||
import { toProcessId } from '../ts/shared/protocol/id.js';
|
||||
|
||||
// Helper to ensure daemon is stopped before tests
|
||||
async function ensureDaemonStopped() {
|
||||
@@ -160,7 +161,7 @@ tap.test('Process management through daemon', async (tools) => {
|
||||
|
||||
// Test 2: Start a test process
|
||||
const testConfig: tspm.IProcessConfig = {
|
||||
id: 'test-echo',
|
||||
id: toProcessId(1001),
|
||||
name: 'Test Echo Process',
|
||||
command: 'echo "Test process"',
|
||||
projectDir: process.cwd(),
|
||||
@@ -172,7 +173,7 @@ tap.test('Process management through daemon', async (tools) => {
|
||||
config: testConfig,
|
||||
});
|
||||
console.log('Start response:', startResponse);
|
||||
expect(startResponse.processId).toEqual('test-echo');
|
||||
expect(startResponse.processId).toEqual(1001);
|
||||
expect(startResponse.status).toBeDefined();
|
||||
|
||||
// Test 3: List processes (should have one process)
|
||||
@@ -180,27 +181,27 @@ tap.test('Process management through daemon', async (tools) => {
|
||||
console.log('List after start:', listResponse);
|
||||
expect(listResponse.processes.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const procInfo = listResponse.processes.find((p) => p.id === 'test-echo');
|
||||
const procInfo = listResponse.processes.find((p) => p.id === toProcessId(1001));
|
||||
expect(procInfo).toBeDefined();
|
||||
expect(procInfo?.id).toEqual('test-echo');
|
||||
expect(procInfo?.id).toEqual(1001);
|
||||
|
||||
// Test 4: Describe the process
|
||||
const describeResponse = await tspmIpcClient.request('describe', {
|
||||
id: 'test-echo',
|
||||
id: toProcessId(1001),
|
||||
});
|
||||
console.log('Describe:', describeResponse);
|
||||
expect(describeResponse.processInfo).toBeDefined();
|
||||
expect(describeResponse.config).toBeDefined();
|
||||
expect(describeResponse.config.id).toEqual('test-echo');
|
||||
expect(describeResponse.config.id).toEqual(1001);
|
||||
|
||||
// Test 5: Stop the process
|
||||
const stopResponse = await tspmIpcClient.request('stop', { id: 'test-echo' });
|
||||
const stopResponse = await tspmIpcClient.request('stop', { id: toProcessId(1001) });
|
||||
console.log('Stop response:', stopResponse);
|
||||
expect(stopResponse.success).toEqual(true);
|
||||
|
||||
// Test 6: Delete the process
|
||||
const deleteResponse = await tspmIpcClient.request('delete', {
|
||||
id: 'test-echo',
|
||||
id: toProcessId(1001),
|
||||
});
|
||||
console.log('Delete response:', deleteResponse);
|
||||
expect(deleteResponse.success).toEqual(true);
|
||||
@@ -208,9 +209,7 @@ tap.test('Process management through daemon', async (tools) => {
|
||||
// Test 7: Verify process is gone
|
||||
listResponse = await tspmIpcClient.request('list', {});
|
||||
console.log('List after delete:', listResponse);
|
||||
const deletedProcess = listResponse.processes.find(
|
||||
(p) => p.id === 'test-echo',
|
||||
);
|
||||
const deletedProcess = listResponse.processes.find((p) => p.id === toProcessId(1001));
|
||||
expect(deletedProcess).toBeUndefined();
|
||||
|
||||
// Cleanup: stop daemon
|
||||
@@ -241,7 +240,7 @@ tap.test('Batch operations through daemon', async (tools) => {
|
||||
// Add multiple test processes
|
||||
const testConfigs: tspm.IProcessConfig[] = [
|
||||
{
|
||||
id: 'batch-test-1',
|
||||
id: toProcessId(1101),
|
||||
name: 'Batch Test 1',
|
||||
command: 'echo "Process 1"',
|
||||
projectDir: process.cwd(),
|
||||
@@ -249,7 +248,7 @@ tap.test('Batch operations through daemon', async (tools) => {
|
||||
autorestart: false,
|
||||
},
|
||||
{
|
||||
id: 'batch-test-2',
|
||||
id: toProcessId(1102),
|
||||
name: 'Batch Test 2',
|
||||
command: 'echo "Process 2"',
|
||||
projectDir: process.cwd(),
|
||||
@@ -308,7 +307,7 @@ tap.test('Daemon error handling', async (tools) => {
|
||||
|
||||
// Test 1: Try to stop non-existent process
|
||||
try {
|
||||
await tspmIpcClient.request('stop', { id: 'non-existent-process' });
|
||||
await tspmIpcClient.request('stop', { id: toProcessId(99999) });
|
||||
expect(false).toEqual(true); // Should not reach here
|
||||
} catch (error) {
|
||||
expect(error.message).toInclude('Failed to stop process');
|
||||
@@ -316,7 +315,7 @@ tap.test('Daemon error handling', async (tools) => {
|
||||
|
||||
// Test 2: Try to describe non-existent process
|
||||
try {
|
||||
await tspmIpcClient.request('describe', { id: 'non-existent-process' });
|
||||
await tspmIpcClient.request('describe', { id: toProcessId(99999) });
|
||||
expect(false).toEqual(true); // Should not reach here
|
||||
} catch (error) {
|
||||
expect(error.message).toInclude('not found');
|
||||
@@ -324,7 +323,7 @@ tap.test('Daemon error handling', async (tools) => {
|
||||
|
||||
// Test 3: Try to restart non-existent process
|
||||
try {
|
||||
await tspmIpcClient.request('restart', { id: 'non-existent-process' });
|
||||
await tspmIpcClient.request('restart', { id: toProcessId(99999) });
|
||||
expect(false).toEqual(true); // Should not reach here
|
||||
} catch (error) {
|
||||
expect(error.message).toInclude('Failed to restart process');
|
||||
|
Reference in New Issue
Block a user