Elffuss BraidHub

kikocis/continue public

1db4eaf4c0a7 · 2.2 KiBRawPermalink
1import {
2 markProcessAsBackgrounded,
3 isProcessBackgrounded,
4 removeBackgroundedProcess
5} from './processTerminalBackgroundStates';
6
7describe('processTerminalBackgroundStates', () => {
8 beforeEach(() => {
9 // Clear any backgrounded processes before each test
10 const backgroundedProcesses = Array.from(
11 Object.getOwnPropertySymbols(global)
12 ).find(symbol => String(symbol) === 'Symbol(processTerminalBackgroundStates)');
13
14 if (backgroundedProcesses) {
15 // Reset the map by reimporting the module
16 jest.resetModules();
17 }
18 });
19
20 test('should mark a process as backgrounded', () => {
21 const toolCallId = 'test-123';
22 markProcessAsBackgrounded(toolCallId);
23 expect(isProcessBackgrounded(toolCallId)).toBe(true);
24 });
25
26 test('should correctly identify non-backgrounded processes', () => {
27 const toolCallId = 'test-123';
28 const anotherToolCallId = 'test-456';
29
30 markProcessAsBackgrounded(toolCallId);
31
32 expect(isProcessBackgrounded(toolCallId)).toBe(true);
33 expect(isProcessBackgrounded(anotherToolCallId)).toBe(false);
34 });
35
36 test('should remove a process from backgrounded state', () => {
37 const toolCallId = 'test-123';
38
39 markProcessAsBackgrounded(toolCallId);
40 expect(isProcessBackgrounded(toolCallId)).toBe(true);
41
42 removeBackgroundedProcess(toolCallId);
43 expect(isProcessBackgrounded(toolCallId)).toBe(false);
44 });
45
46 test('should handle removing non-existent processes', () => {
47 const toolCallId = 'test-123';
48
49 // Should not throw an error
50 removeBackgroundedProcess(toolCallId);
51 expect(isProcessBackgrounded(toolCallId)).toBe(false);
52 });
53
54 test('should handle multiple processes', () => {
55 const toolCallId1 = 'test-123';
56 const toolCallId2 = 'test-456';
57 const toolCallId3 = 'test-789';
58
59 markProcessAsBackgrounded(toolCallId1);
60 markProcessAsBackgrounded(toolCallId2);
61
62 expect(isProcessBackgrounded(toolCallId1)).toBe(true);
63 expect(isProcessBackgrounded(toolCallId2)).toBe(true);
64 expect(isProcessBackgrounded(toolCallId3)).toBe(false);
65
66 removeBackgroundedProcess(toolCallId1);
67
68 expect(isProcessBackgrounded(toolCallId1)).toBe(false);
69 expect(isProcessBackgrounded(toolCallId2)).toBe(true);
70 });
71});