Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/__tests__/main/cue/cue-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ vi.mock('../../../main/parsers', () => ({

// Mock child_process.spawn
class MockChildProcess extends EventEmitter {
pid = 12345;
stdin = {
write: vi.fn(),
end: vi.fn(),
Expand Down Expand Up @@ -151,6 +152,7 @@ import {
executeCuePrompt,
stopCueRun,
getActiveProcesses,
getCueProcessList,
recordCueHistoryEntry,
type CueExecutionConfig,
} from '../../../main/cue/cue-executor';
Expand Down Expand Up @@ -1304,4 +1306,49 @@ describe('cue-executor', () => {
expect(result.stdout).toBe(rawOutput);
});
});

describe('getCueProcessList', () => {
it('should return empty array when no active processes', () => {
expect(getCueProcessList()).toEqual([]);
});

it('should return process info during active run', async () => {
const config = createExecutionConfig({ runId: 'list-test-run', toolType: 'claude-code' });

const resultPromise = executeCuePrompt(config);
await vi.advanceTimersByTimeAsync(0);

const list = getCueProcessList();
expect(list).toHaveLength(1);
expect(list[0].runId).toBe('list-test-run');
expect(list[0].pid).toBe(12345);
expect(list[0].toolType).toBe('claude-code');
expect(list[0].cwd).toBe('/projects/test');
expect(list[0].command).toBe('claude');
expect(Array.isArray(list[0].args)).toBe(true);
expect(typeof list[0].startTime).toBe('number');

mockChild.emit('close', 0);
await resultPromise;
});

it('should exclude completed processes', async () => {
const config = createExecutionConfig({ runId: 'completed-run' });

const resultPromise = executeCuePrompt(config);
await vi.advanceTimersByTimeAsync(0);

// Process is active — should appear in list
const activeEntry = getActiveProcesses().get('completed-run');
expect(activeEntry).toBeDefined();
expect(getCueProcessList().some((p) => p.runId === 'completed-run')).toBe(true);

mockChild.emit('close', 0);
await resultPromise;

// Process completed — should be removed
expect(getActiveProcesses().has('completed-run')).toBe(false);
expect(getCueProcessList().some((p) => p.runId === 'completed-run')).toBe(false);
});
});
});
Loading