vibecodingmachine-core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +13 -13
- package/README.md +28 -28
- package/__tests__/applescript-manager-claude-fix.test.js +286 -286
- package/__tests__/requirement-2-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-3-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-4-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-6-auto-start-looping.test.js +73 -73
- package/__tests__/requirement-7-status-tracking.test.js +332 -332
- package/jest.config.js +18 -18
- package/jest.setup.js +12 -12
- package/package.json +47 -45
- package/src/auth/access-denied.html +119 -119
- package/src/auth/shared-auth-storage.js +230 -230
- package/src/autonomous-mode/feature-implementer.cjs +70 -70
- package/src/autonomous-mode/feature-implementer.js +425 -425
- package/src/chat-management/chat-manager.cjs +71 -71
- package/src/chat-management/chat-manager.js +342 -342
- package/src/ide-integration/__tests__/applescript-manager-thread-closure.test.js +227 -227
- package/src/ide-integration/aider-cli-manager.cjs +850 -850
- package/src/ide-integration/applescript-manager.cjs +1088 -1088
- package/src/ide-integration/applescript-manager.js +2802 -2802
- package/src/ide-integration/applescript-utils.js +306 -306
- package/src/ide-integration/cdp-manager.cjs +221 -221
- package/src/ide-integration/cdp-manager.js +321 -321
- package/src/ide-integration/claude-code-cli-manager.cjs +301 -301
- package/src/ide-integration/cline-cli-manager.cjs +2252 -2252
- package/src/ide-integration/continue-cli-manager.js +431 -431
- package/src/ide-integration/provider-manager.cjs +354 -354
- package/src/ide-integration/quota-detector.cjs +34 -34
- package/src/ide-integration/quota-detector.js +349 -349
- package/src/ide-integration/windows-automation-manager.js +262 -262
- package/src/index.cjs +43 -43
- package/src/index.js +17 -17
- package/src/llm/direct-llm-manager.cjs +609 -609
- package/src/ui/ButtonComponents.js +247 -247
- package/src/ui/ChatInterface.js +499 -499
- package/src/ui/StateManager.js +259 -259
- package/src/utils/audit-logger.cjs +116 -116
- package/src/utils/config-helpers.cjs +94 -94
- package/src/utils/config-helpers.js +94 -94
- package/src/utils/electron-update-checker.js +85 -78
- package/src/utils/gcloud-auth.cjs +394 -394
- package/src/utils/logger.cjs +193 -193
- package/src/utils/logger.js +191 -191
- package/src/utils/repo-helpers.cjs +120 -120
- package/src/utils/repo-helpers.js +120 -120
- package/src/utils/requirement-helpers.js +432 -432
- package/src/utils/update-checker.js +167 -167
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Jest tests for AppleScript Manager thread closure functionality
|
|
3
|
-
* Tests the ability to close previous chat threads when starting new ones
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { AppleScriptManager } from '../applescript-manager.js';
|
|
7
|
-
import { execSync } from 'child_process';
|
|
8
|
-
|
|
9
|
-
// Mock child_process
|
|
10
|
-
jest.mock('child_process', () => ({
|
|
11
|
-
execSync: jest.fn()
|
|
12
|
-
}));Windsurf: Open Chat
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// Mock fs
|
|
19
|
-
jest.mock('fs', () => ({
|
|
20
|
-
writeFileSync: jest.fn(),
|
|
21
|
-
unlinkSync: jest.fn()
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
// Mock os
|
|
25
|
-
jest.mock('os', () => ({
|
|
26
|
-
tmpdir: () => '/tmp'
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
describe('AppleScriptManager - Thread Closure', () => {
|
|
30
|
-
let appleScriptManager;
|
|
31
|
-
let mockExecSync;
|
|
32
|
-
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
appleScriptManager = new AppleScriptManager();
|
|
35
|
-
mockExecSync = execSync;
|
|
36
|
-
mockExecSync.mockClear();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
afterEach(() => {
|
|
40
|
-
jest.clearAllMocks();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('closePreviousChatThread', () => {
|
|
44
|
-
it('should close previous chat thread in Cursor', async () => {
|
|
45
|
-
// Mock successful execution
|
|
46
|
-
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
47
|
-
|
|
48
|
-
const result = await appleScriptManager.closePreviousChatThread('cursor');
|
|
49
|
-
|
|
50
|
-
expect(result.success).toBe(true);
|
|
51
|
-
expect(result.message).toContain('Previous chat thread closed');
|
|
52
|
-
expect(result.method).toBe('applescript');
|
|
53
|
-
expect(mockExecSync).toHaveBeenCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should close previous chat thread in VS Code', async () => {
|
|
57
|
-
// Mock successful execution
|
|
58
|
-
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
59
|
-
|
|
60
|
-
const result = await appleScriptManager.closePreviousChatThread('vscode');
|
|
61
|
-
|
|
62
|
-
expect(result.success).toBe(true);
|
|
63
|
-
expect(result.message).toContain('Previous chat thread closed');
|
|
64
|
-
expect(result.method).toBe('applescript');
|
|
65
|
-
expect(mockExecSync).toHaveBeenCalled();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should close previous chat thread in Windsurf', async () => {
|
|
69
|
-
// Mock successful execution
|
|
70
|
-
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
71
|
-
|
|
72
|
-
const result = await appleScriptManager.closePreviousChatThread('windsurf');
|
|
73
|
-
|
|
74
|
-
expect(result.success).toBe(true);
|
|
75
|
-
expect(result.message).toContain('Previous chat thread closed');
|
|
76
|
-
expect(result.method).toBe('applescript');
|
|
77
|
-
expect(mockExecSync).toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should handle errors gracefully when closing threads', async () => {
|
|
81
|
-
// Mock execution error
|
|
82
|
-
mockExecSync.mockImplementation(() => {
|
|
83
|
-
throw new Error('Failed to close thread');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const result = await appleScriptManager.closePreviousChatThread('cursor');
|
|
87
|
-
|
|
88
|
-
expect(result.success).toBe(false);
|
|
89
|
-
expect(result.error).toContain('Failed to close thread');
|
|
90
|
-
expect(result.method).toBe('applescript');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should return error for unsupported IDE', async () => {
|
|
94
|
-
const result = await appleScriptManager.closePreviousChatThread('unsupported');
|
|
95
|
-
|
|
96
|
-
expect(result.success).toBe(false);
|
|
97
|
-
expect(result.error).toContain('Unsupported IDE');
|
|
98
|
-
expect(mockExecSync).not.toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('sendTextWithThreadClosure', () => {
|
|
103
|
-
it('should close previous thread before sending new message to Cursor', async () => {
|
|
104
|
-
// Mock successful executions
|
|
105
|
-
mockExecSync
|
|
106
|
-
.mockReturnValueOnce('Previous chat thread closed')
|
|
107
|
-
.mockReturnValueOnce('Message sent to Cursor: Test message')
|
|
108
|
-
.mockReturnValueOnce('Message sent to Cursor: Test message');
|
|
109
|
-
|
|
110
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
111
|
-
|
|
112
|
-
expect(result.success).toBe(true);
|
|
113
|
-
expect(result.message).toContain('Test message');
|
|
114
|
-
expect(mockExecSync).toHaveBeenCalledTimes(3); // Once for close, twice for send (sendText calls execSync twice)
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should close previous thread before sending new message to VS Code', async () => {
|
|
118
|
-
// Mock successful executions
|
|
119
|
-
mockExecSync
|
|
120
|
-
.mockReturnValueOnce('Previous chat thread closed')
|
|
121
|
-
.mockImplementationOnce(() => {
|
|
122
|
-
// Simulate successful AppleScript execution for text sending
|
|
123
|
-
return 'Message sent via AppleScript to VS Code GitHub Copilot Chat';
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'vscode');
|
|
127
|
-
|
|
128
|
-
expect(result.success).toBe(true); // VS Code is now supported by AppleScript manager
|
|
129
|
-
expect(result.method).toBe('applescript');
|
|
130
|
-
expect(result.threadClosure).toContain('Previous thread closed');
|
|
131
|
-
expect(mockExecSync).toHaveBeenCalledTimes(2); // Once for thread closure, once for sending
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should close previous thread before sending new message to Windsurf', async () => {
|
|
135
|
-
// Mock successful executions
|
|
136
|
-
mockExecSync
|
|
137
|
-
.mockReturnValueOnce('Previous chat thread closed')
|
|
138
|
-
.mockImplementationOnce(() => {
|
|
139
|
-
throw new Error('AppleScript failed');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'windsurf');
|
|
143
|
-
|
|
144
|
-
expect(result.success).toBe(true);
|
|
145
|
-
expect(result.message).toContain('Test message');
|
|
146
|
-
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once for thread closure
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should handle thread closure failure gracefully', async () => {
|
|
150
|
-
// Mock thread closure failure but successful message send
|
|
151
|
-
mockExecSync
|
|
152
|
-
.mockImplementationOnce(() => {
|
|
153
|
-
throw new Error('Failed to close thread');
|
|
154
|
-
})
|
|
155
|
-
.mockImplementationOnce(() => {
|
|
156
|
-
throw new Error('AppleScript failed');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
160
|
-
|
|
161
|
-
expect(result.success).toBe(true);
|
|
162
|
-
expect(result.message).toContain('Test message');
|
|
163
|
-
expect(result.warning).toContain('Failed to close previous thread');
|
|
164
|
-
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should handle both thread closure and message send failures', async () => {
|
|
168
|
-
// Mock both failures
|
|
169
|
-
mockExecSync
|
|
170
|
-
.mockImplementationOnce(() => {
|
|
171
|
-
throw new Error('Failed to close thread');
|
|
172
|
-
})
|
|
173
|
-
.mockImplementationOnce(() => {
|
|
174
|
-
throw new Error('AppleScript failed');
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
178
|
-
|
|
179
|
-
expect(result.success).toBe(true); // Should still succeed due to simulated fallback
|
|
180
|
-
expect(result.message).toContain('Test message');
|
|
181
|
-
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should validate input parameters', async () => {
|
|
185
|
-
const result = await appleScriptManager.sendTextWithThreadClosure('', 'cursor');
|
|
186
|
-
|
|
187
|
-
expect(result.success).toBe(false);
|
|
188
|
-
expect(result.error).toContain('Invalid text');
|
|
189
|
-
expect(mockExecSync).not.toHaveBeenCalled();
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('AppleScript Content Validation', () => {
|
|
194
|
-
it('should generate correct AppleScript for Cursor thread closure', async () => {
|
|
195
|
-
mockExecSync.mockReturnValue('Success');
|
|
196
|
-
|
|
197
|
-
await appleScriptManager.closePreviousChatThread('cursor');
|
|
198
|
-
|
|
199
|
-
const callArgs = mockExecSync.mock.calls[0][0];
|
|
200
|
-
expect(callArgs).toContain('osascript');
|
|
201
|
-
// The script content is written to a temp file, so we check the osascript call
|
|
202
|
-
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('should generate correct AppleScript for VS Code thread closure', async () => {
|
|
206
|
-
mockExecSync.mockReturnValue('Success');
|
|
207
|
-
|
|
208
|
-
await appleScriptManager.closePreviousChatThread('vscode');
|
|
209
|
-
|
|
210
|
-
const callArgs = mockExecSync.mock.calls[0][0];
|
|
211
|
-
expect(callArgs).toContain('osascript');
|
|
212
|
-
// The script content is written to a temp file, so we check the osascript call
|
|
213
|
-
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should generate correct AppleScript for Windsurf thread closure', async () => {
|
|
217
|
-
mockExecSync.mockReturnValue('Success');
|
|
218
|
-
|
|
219
|
-
await appleScriptManager.closePreviousChatThread('windsurf');
|
|
220
|
-
|
|
221
|
-
const callArgs = mockExecSync.mock.calls[0][0];
|
|
222
|
-
expect(callArgs).toContain('osascript');
|
|
223
|
-
// The script content is written to a temp file, so we check the osascript call
|
|
224
|
-
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Jest tests for AppleScript Manager thread closure functionality
|
|
3
|
+
* Tests the ability to close previous chat threads when starting new ones
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AppleScriptManager } from '../applescript-manager.js';
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
|
|
9
|
+
// Mock child_process
|
|
10
|
+
jest.mock('child_process', () => ({
|
|
11
|
+
execSync: jest.fn()
|
|
12
|
+
}));Windsurf: Open Chat
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// Mock fs
|
|
19
|
+
jest.mock('fs', () => ({
|
|
20
|
+
writeFileSync: jest.fn(),
|
|
21
|
+
unlinkSync: jest.fn()
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
// Mock os
|
|
25
|
+
jest.mock('os', () => ({
|
|
26
|
+
tmpdir: () => '/tmp'
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
describe('AppleScriptManager - Thread Closure', () => {
|
|
30
|
+
let appleScriptManager;
|
|
31
|
+
let mockExecSync;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
appleScriptManager = new AppleScriptManager();
|
|
35
|
+
mockExecSync = execSync;
|
|
36
|
+
mockExecSync.mockClear();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
jest.clearAllMocks();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('closePreviousChatThread', () => {
|
|
44
|
+
it('should close previous chat thread in Cursor', async () => {
|
|
45
|
+
// Mock successful execution
|
|
46
|
+
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
47
|
+
|
|
48
|
+
const result = await appleScriptManager.closePreviousChatThread('cursor');
|
|
49
|
+
|
|
50
|
+
expect(result.success).toBe(true);
|
|
51
|
+
expect(result.message).toContain('Previous chat thread closed');
|
|
52
|
+
expect(result.method).toBe('applescript');
|
|
53
|
+
expect(mockExecSync).toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should close previous chat thread in VS Code', async () => {
|
|
57
|
+
// Mock successful execution
|
|
58
|
+
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
59
|
+
|
|
60
|
+
const result = await appleScriptManager.closePreviousChatThread('vscode');
|
|
61
|
+
|
|
62
|
+
expect(result.success).toBe(true);
|
|
63
|
+
expect(result.message).toContain('Previous chat thread closed');
|
|
64
|
+
expect(result.method).toBe('applescript');
|
|
65
|
+
expect(mockExecSync).toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should close previous chat thread in Windsurf', async () => {
|
|
69
|
+
// Mock successful execution
|
|
70
|
+
mockExecSync.mockReturnValue('Previous chat thread closed');
|
|
71
|
+
|
|
72
|
+
const result = await appleScriptManager.closePreviousChatThread('windsurf');
|
|
73
|
+
|
|
74
|
+
expect(result.success).toBe(true);
|
|
75
|
+
expect(result.message).toContain('Previous chat thread closed');
|
|
76
|
+
expect(result.method).toBe('applescript');
|
|
77
|
+
expect(mockExecSync).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should handle errors gracefully when closing threads', async () => {
|
|
81
|
+
// Mock execution error
|
|
82
|
+
mockExecSync.mockImplementation(() => {
|
|
83
|
+
throw new Error('Failed to close thread');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const result = await appleScriptManager.closePreviousChatThread('cursor');
|
|
87
|
+
|
|
88
|
+
expect(result.success).toBe(false);
|
|
89
|
+
expect(result.error).toContain('Failed to close thread');
|
|
90
|
+
expect(result.method).toBe('applescript');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should return error for unsupported IDE', async () => {
|
|
94
|
+
const result = await appleScriptManager.closePreviousChatThread('unsupported');
|
|
95
|
+
|
|
96
|
+
expect(result.success).toBe(false);
|
|
97
|
+
expect(result.error).toContain('Unsupported IDE');
|
|
98
|
+
expect(mockExecSync).not.toHaveBeenCalled();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('sendTextWithThreadClosure', () => {
|
|
103
|
+
it('should close previous thread before sending new message to Cursor', async () => {
|
|
104
|
+
// Mock successful executions
|
|
105
|
+
mockExecSync
|
|
106
|
+
.mockReturnValueOnce('Previous chat thread closed')
|
|
107
|
+
.mockReturnValueOnce('Message sent to Cursor: Test message')
|
|
108
|
+
.mockReturnValueOnce('Message sent to Cursor: Test message');
|
|
109
|
+
|
|
110
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
111
|
+
|
|
112
|
+
expect(result.success).toBe(true);
|
|
113
|
+
expect(result.message).toContain('Test message');
|
|
114
|
+
expect(mockExecSync).toHaveBeenCalledTimes(3); // Once for close, twice for send (sendText calls execSync twice)
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should close previous thread before sending new message to VS Code', async () => {
|
|
118
|
+
// Mock successful executions
|
|
119
|
+
mockExecSync
|
|
120
|
+
.mockReturnValueOnce('Previous chat thread closed')
|
|
121
|
+
.mockImplementationOnce(() => {
|
|
122
|
+
// Simulate successful AppleScript execution for text sending
|
|
123
|
+
return 'Message sent via AppleScript to VS Code GitHub Copilot Chat';
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'vscode');
|
|
127
|
+
|
|
128
|
+
expect(result.success).toBe(true); // VS Code is now supported by AppleScript manager
|
|
129
|
+
expect(result.method).toBe('applescript');
|
|
130
|
+
expect(result.threadClosure).toContain('Previous thread closed');
|
|
131
|
+
expect(mockExecSync).toHaveBeenCalledTimes(2); // Once for thread closure, once for sending
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should close previous thread before sending new message to Windsurf', async () => {
|
|
135
|
+
// Mock successful executions
|
|
136
|
+
mockExecSync
|
|
137
|
+
.mockReturnValueOnce('Previous chat thread closed')
|
|
138
|
+
.mockImplementationOnce(() => {
|
|
139
|
+
throw new Error('AppleScript failed');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'windsurf');
|
|
143
|
+
|
|
144
|
+
expect(result.success).toBe(true);
|
|
145
|
+
expect(result.message).toContain('Test message');
|
|
146
|
+
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once for thread closure
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should handle thread closure failure gracefully', async () => {
|
|
150
|
+
// Mock thread closure failure but successful message send
|
|
151
|
+
mockExecSync
|
|
152
|
+
.mockImplementationOnce(() => {
|
|
153
|
+
throw new Error('Failed to close thread');
|
|
154
|
+
})
|
|
155
|
+
.mockImplementationOnce(() => {
|
|
156
|
+
throw new Error('AppleScript failed');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
160
|
+
|
|
161
|
+
expect(result.success).toBe(true);
|
|
162
|
+
expect(result.message).toContain('Test message');
|
|
163
|
+
expect(result.warning).toContain('Failed to close previous thread');
|
|
164
|
+
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should handle both thread closure and message send failures', async () => {
|
|
168
|
+
// Mock both failures
|
|
169
|
+
mockExecSync
|
|
170
|
+
.mockImplementationOnce(() => {
|
|
171
|
+
throw new Error('Failed to close thread');
|
|
172
|
+
})
|
|
173
|
+
.mockImplementationOnce(() => {
|
|
174
|
+
throw new Error('AppleScript failed');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('Test message', 'cursor');
|
|
178
|
+
|
|
179
|
+
expect(result.success).toBe(true); // Should still succeed due to simulated fallback
|
|
180
|
+
expect(result.message).toContain('Test message');
|
|
181
|
+
expect(mockExecSync).toHaveBeenCalled(); // Should be called at least once
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should validate input parameters', async () => {
|
|
185
|
+
const result = await appleScriptManager.sendTextWithThreadClosure('', 'cursor');
|
|
186
|
+
|
|
187
|
+
expect(result.success).toBe(false);
|
|
188
|
+
expect(result.error).toContain('Invalid text');
|
|
189
|
+
expect(mockExecSync).not.toHaveBeenCalled();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('AppleScript Content Validation', () => {
|
|
194
|
+
it('should generate correct AppleScript for Cursor thread closure', async () => {
|
|
195
|
+
mockExecSync.mockReturnValue('Success');
|
|
196
|
+
|
|
197
|
+
await appleScriptManager.closePreviousChatThread('cursor');
|
|
198
|
+
|
|
199
|
+
const callArgs = mockExecSync.mock.calls[0][0];
|
|
200
|
+
expect(callArgs).toContain('osascript');
|
|
201
|
+
// The script content is written to a temp file, so we check the osascript call
|
|
202
|
+
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should generate correct AppleScript for VS Code thread closure', async () => {
|
|
206
|
+
mockExecSync.mockReturnValue('Success');
|
|
207
|
+
|
|
208
|
+
await appleScriptManager.closePreviousChatThread('vscode');
|
|
209
|
+
|
|
210
|
+
const callArgs = mockExecSync.mock.calls[0][0];
|
|
211
|
+
expect(callArgs).toContain('osascript');
|
|
212
|
+
// The script content is written to a temp file, so we check the osascript call
|
|
213
|
+
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should generate correct AppleScript for Windsurf thread closure', async () => {
|
|
217
|
+
mockExecSync.mockReturnValue('Success');
|
|
218
|
+
|
|
219
|
+
await appleScriptManager.closePreviousChatThread('windsurf');
|
|
220
|
+
|
|
221
|
+
const callArgs = mockExecSync.mock.calls[0][0];
|
|
222
|
+
expect(callArgs).toContain('osascript');
|
|
223
|
+
// The script content is written to a temp file, so we check the osascript call
|
|
224
|
+
expect(mockExecSync).toHaveBeenCalledWith(expect.stringContaining('osascript'), expect.any(Object));
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|