@mrpatronz/nexusflow 0.2.7 → 0.2.11
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/.github/workflows/release.yml +7 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +6 -1
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +58 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +73 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +11 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/config.test.d.ts +2 -0
- package/dist/core/config.test.d.ts.map +1 -0
- package/dist/core/config.test.js +75 -0
- package/dist/core/config.test.js.map +1 -0
- package/dist/core/scanner.test.d.ts +2 -0
- package/dist/core/scanner.test.d.ts.map +1 -0
- package/dist/core/scanner.test.js +53 -0
- package/dist/core/scanner.test.js.map +1 -0
- package/dist/generators/base.d.ts.map +1 -1
- package/dist/generators/base.js +8 -2
- package/dist/generators/base.js.map +1 -1
- package/dist/generators/skills-generator.js +1 -1
- package/dist/generators/skills-generator.js.map +1 -1
- package/dist/gui/assets/index-Ca2VRMrQ.js +22 -0
- package/dist/gui/assets/index-fj0RJiOb.css +2 -0
- package/dist/gui/index.html +2 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +132 -93
- package/dist/mcp/server.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +134 -12
- package/dist/server.js.map +1 -1
- package/dist/server.test.d.ts +2 -0
- package/dist/server.test.d.ts.map +1 -0
- package/dist/server.test.js +401 -0
- package/dist/server.test.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/detect-ai.test.d.ts +2 -0
- package/dist/utils/detect-ai.test.d.ts.map +1 -0
- package/dist/utils/detect-ai.test.js +37 -0
- package/dist/utils/detect-ai.test.js.map +1 -0
- package/dist/utils/detect-editors.test.d.ts +2 -0
- package/dist/utils/detect-editors.test.d.ts.map +1 -0
- package/dist/utils/detect-editors.test.js +39 -0
- package/dist/utils/detect-editors.test.js.map +1 -0
- package/dist/utils/git.test.d.ts +2 -0
- package/dist/utils/git.test.d.ts.map +1 -0
- package/dist/utils/git.test.js +55 -0
- package/dist/utils/git.test.js.map +1 -0
- package/dist/utils/local-ai.d.ts +27 -0
- package/dist/utils/local-ai.d.ts.map +1 -0
- package/dist/utils/local-ai.js +96 -0
- package/dist/utils/local-ai.js.map +1 -0
- package/dist/utils/local-ai.test.d.ts +2 -0
- package/dist/utils/local-ai.test.d.ts.map +1 -0
- package/dist/utils/local-ai.test.js +108 -0
- package/dist/utils/local-ai.test.js.map +1 -0
- package/dist/utils/system-scanner.d.ts +16 -0
- package/dist/utils/system-scanner.d.ts.map +1 -0
- package/dist/utils/system-scanner.js +85 -0
- package/dist/utils/system-scanner.js.map +1 -0
- package/dist/utils/system-scanner.test.d.ts +2 -0
- package/dist/utils/system-scanner.test.d.ts.map +1 -0
- package/dist/utils/system-scanner.test.js +73 -0
- package/dist/utils/system-scanner.test.js.map +1 -0
- package/gui/e2e/wizard.spec.ts +327 -0
- package/gui/package-lock.json +64 -0
- package/gui/package.json +4 -1
- package/gui/playwright.config.ts +41 -0
- package/gui/src/App.tsx +376 -786
- package/gui/src/index.css +16 -0
- package/package.json +3 -1
- package/scripts/simulate-workspaces.ts +55 -0
- package/src/commands/create.ts +7 -1
- package/src/commands/doctor.ts +56 -0
- package/src/commands/init.ts +77 -1
- package/src/core/config.test.ts +96 -0
- package/src/core/config.ts +11 -1
- package/src/core/scanner.test.ts +61 -0
- package/src/generators/base.ts +13 -2
- package/src/generators/skills-generator.ts +1 -1
- package/src/mcp/server.ts +144 -95
- package/src/server.test.ts +464 -0
- package/src/server.ts +141 -11
- package/src/types.ts +16 -0
- package/src/utils/detect-ai.test.ts +44 -0
- package/src/utils/detect-editors.test.ts +47 -0
- package/src/utils/git.test.ts +74 -0
- package/src/utils/local-ai.test.ts +130 -0
- package/src/utils/local-ai.ts +111 -0
- package/src/utils/system-scanner.test.ts +89 -0
- package/src/utils/system-scanner.ts +96 -0
- package/vitest.config.ts +2 -1
- package/dist/gui/assets/index-BgEo5w2Q.js +0 -22
- package/dist/gui/assets/index-D-VigurY.css +0 -2
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
import { app } from './server.js';
|
|
5
|
+
import * as workspace from './core/workspace.js';
|
|
6
|
+
import * as config from './core/config.js';
|
|
7
|
+
import * as systemScanner from './utils/system-scanner.js';
|
|
8
|
+
import * as localAi from './utils/local-ai.js';
|
|
9
|
+
import * as updateCheck from './utils/update-check.js';
|
|
10
|
+
import * as analyzers from './analyzers/index.js';
|
|
11
|
+
import * as generators from './generators/index.js';
|
|
12
|
+
import * as packer from './core/packer.js';
|
|
13
|
+
|
|
14
|
+
// Mock dependencies
|
|
15
|
+
vi.mock('node:fs/promises');
|
|
16
|
+
vi.mock('execa');
|
|
17
|
+
vi.mock('./core/workspace.js');
|
|
18
|
+
vi.mock('./core/config.js');
|
|
19
|
+
vi.mock('./utils/system-scanner.js');
|
|
20
|
+
vi.mock('./utils/local-ai.js');
|
|
21
|
+
vi.mock('./utils/update-check.js');
|
|
22
|
+
vi.mock('./analyzers/index.js');
|
|
23
|
+
vi.mock('./generators/index.js');
|
|
24
|
+
vi.mock('./core/packer.js');
|
|
25
|
+
|
|
26
|
+
describe('Server API Endpoints Unit Tests', () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
vi.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('POST /api/open-editor', () => {
|
|
32
|
+
it('should return 400 for forbidden editor commands', async () => {
|
|
33
|
+
const response = await app.request('/api/open-editor', {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
workspacePath: '/mock/workspace/path',
|
|
38
|
+
command: 'rm -rf /'
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(response.status).toBe(400);
|
|
43
|
+
const data = await response.json();
|
|
44
|
+
expect(data.error).toBe('Forbidden editor command');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should return 400 if workspace path does not exist', async () => {
|
|
48
|
+
vi.spyOn(fs, 'stat').mockRejectedValue(new Error('File not found'));
|
|
49
|
+
|
|
50
|
+
const response = await app.request('/api/open-editor', {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
workspacePath: '/non-existent/path',
|
|
55
|
+
command: 'code-insiders'
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(response.status).toBe(400);
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
expect(data.error).toBe('Workspace path does not exist');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should return 400 if workspace path is not a directory', async () => {
|
|
65
|
+
vi.spyOn(fs, 'stat').mockResolvedValue({
|
|
66
|
+
isDirectory: () => false
|
|
67
|
+
} as any);
|
|
68
|
+
|
|
69
|
+
const response = await app.request('/api/open-editor', {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'Content-Type': 'application/json' },
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
workspacePath: '/mock/file.txt',
|
|
74
|
+
command: 'code-insiders'
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(response.status).toBe(400);
|
|
79
|
+
const data = await response.json();
|
|
80
|
+
expect(data.error).toBe('Workspace path is not a directory');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should call execa with detached, stdio, shell, and cleanup options and return success', async () => {
|
|
84
|
+
vi.spyOn(fs, 'stat').mockResolvedValue({
|
|
85
|
+
isDirectory: () => true
|
|
86
|
+
} as any);
|
|
87
|
+
|
|
88
|
+
// Mock execa to return a dummy child process with a catch method
|
|
89
|
+
const dummyChild = {
|
|
90
|
+
unref: vi.fn(),
|
|
91
|
+
catch: vi.fn().mockReturnThis()
|
|
92
|
+
};
|
|
93
|
+
vi.mocked(execa).mockReturnValue(dummyChild as any);
|
|
94
|
+
|
|
95
|
+
const response = await app.request('/api/open-editor', {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: { 'Content-Type': 'application/json' },
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
workspacePath: '/mock/workspace/dir',
|
|
100
|
+
command: 'code-insiders'
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(response.status).toBe(200);
|
|
105
|
+
const data = await response.json();
|
|
106
|
+
expect(data.success).toBe(true);
|
|
107
|
+
|
|
108
|
+
const isWin = process.platform === 'win32';
|
|
109
|
+
expect(execa).toHaveBeenCalledWith('code-insiders', ['/mock/workspace/dir'], {
|
|
110
|
+
detached: true,
|
|
111
|
+
stdio: 'ignore',
|
|
112
|
+
shell: isWin,
|
|
113
|
+
cleanup: false
|
|
114
|
+
});
|
|
115
|
+
expect(dummyChild.unref).toHaveBeenCalled();
|
|
116
|
+
expect(dummyChild.catch).toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('POST /api/workspace/:id/resume', () => {
|
|
121
|
+
it('should fail with 400 if command is forbidden', async () => {
|
|
122
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
123
|
+
workspacesDir: '/mock/workspaces'
|
|
124
|
+
} as any);
|
|
125
|
+
vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
|
|
126
|
+
id: 'test-ws',
|
|
127
|
+
repos: [],
|
|
128
|
+
assistants: ['antigravity']
|
|
129
|
+
} as any);
|
|
130
|
+
|
|
131
|
+
const response = await app.request('/api/workspace/test-ws/resume', {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers: { 'Content-Type': 'application/json' },
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
command: 'malicious-editor',
|
|
136
|
+
assistant: 'antigravity'
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(response.status).toBe(400);
|
|
141
|
+
const data = await response.json();
|
|
142
|
+
expect(data.error).toBe('Forbidden editor command');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should spawn the editor with proper options when resuming', async () => {
|
|
146
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
147
|
+
workspacesDir: '/mock/workspaces'
|
|
148
|
+
} as any);
|
|
149
|
+
vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
|
|
150
|
+
id: 'test-ws',
|
|
151
|
+
repos: [],
|
|
152
|
+
assistants: ['antigravity']
|
|
153
|
+
} as any);
|
|
154
|
+
|
|
155
|
+
const dummyChild = {
|
|
156
|
+
unref: vi.fn(),
|
|
157
|
+
catch: vi.fn().mockReturnThis()
|
|
158
|
+
};
|
|
159
|
+
vi.mocked(execa).mockReturnValue(dummyChild as any);
|
|
160
|
+
|
|
161
|
+
const response = await app.request('/api/workspace/test-ws/resume', {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: { 'Content-Type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
command: 'code',
|
|
166
|
+
assistant: 'antigravity'
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(response.status).toBe(200);
|
|
171
|
+
const data = await response.json();
|
|
172
|
+
expect(data.success).toBe(true);
|
|
173
|
+
|
|
174
|
+
const isWin = process.platform === 'win32';
|
|
175
|
+
expect(execa).toHaveBeenCalledWith('code', [expect.any(String)], {
|
|
176
|
+
detached: true,
|
|
177
|
+
stdio: 'ignore',
|
|
178
|
+
shell: isWin,
|
|
179
|
+
cleanup: false
|
|
180
|
+
});
|
|
181
|
+
expect(dummyChild.unref).toHaveBeenCalled();
|
|
182
|
+
expect(dummyChild.catch).toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('GET /api/config', () => {
|
|
187
|
+
it('should load configuration successfully', async () => {
|
|
188
|
+
vi.spyOn(config, 'getConfigDir').mockReturnValue('/mock/config-dir');
|
|
189
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
190
|
+
devDir: '/mock/dev',
|
|
191
|
+
scanDepth: 2
|
|
192
|
+
} as any);
|
|
193
|
+
vi.spyOn(fs, 'access').mockResolvedValue();
|
|
194
|
+
|
|
195
|
+
const response = await app.request('/api/config');
|
|
196
|
+
expect(response.status).toBe(200);
|
|
197
|
+
const data = await response.json();
|
|
198
|
+
expect(data.config.devDir).toBe('/mock/dev');
|
|
199
|
+
expect(data.exists).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('POST /api/config', () => {
|
|
204
|
+
it('should validate endpoint domain safety', async () => {
|
|
205
|
+
const response = await app.request('/api/config', {
|
|
206
|
+
method: 'POST',
|
|
207
|
+
headers: { 'Content-Type': 'application/json' },
|
|
208
|
+
body: JSON.stringify({
|
|
209
|
+
localLlm: {
|
|
210
|
+
enabled: true,
|
|
211
|
+
endpoint: 'http://malicious-external-domain.com'
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(response.status).toBe(400);
|
|
217
|
+
const data = await response.json();
|
|
218
|
+
expect(data.error).toContain('Local AI endpoint must be localhost, 127.0.0.1, or a private LAN IP.');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should save safe endpoint and config', async () => {
|
|
222
|
+
vi.spyOn(config, 'saveConfig').mockResolvedValue();
|
|
223
|
+
|
|
224
|
+
const response = await app.request('/api/config', {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
headers: { 'Content-Type': 'application/json' },
|
|
227
|
+
body: JSON.stringify({
|
|
228
|
+
localLlm: {
|
|
229
|
+
enabled: true,
|
|
230
|
+
endpoint: 'http://127.0.0.1:11434'
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(response.status).toBe(200);
|
|
236
|
+
const data = await response.json();
|
|
237
|
+
expect(data.success).toBe(true);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('POST /api/local-llm/test', () => {
|
|
242
|
+
it('should reject unsafe endpoints', async () => {
|
|
243
|
+
const response = await app.request('/api/local-llm/test', {
|
|
244
|
+
method: 'POST',
|
|
245
|
+
headers: { 'Content-Type': 'application/json' },
|
|
246
|
+
body: JSON.stringify({
|
|
247
|
+
endpoint: 'http://unsafe-domain.com',
|
|
248
|
+
provider: 'ollama',
|
|
249
|
+
model: 'qwen2.5-coder:1.5b'
|
|
250
|
+
})
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expect(response.status).toBe(400);
|
|
254
|
+
const data = await response.json();
|
|
255
|
+
expect(data.success).toBe(false);
|
|
256
|
+
expect(data.error).toContain('Local AI endpoint must be');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should perform inference shoot test if shoot = true', async () => {
|
|
260
|
+
vi.spyOn(localAi, 'callLocalLlm').mockResolvedValue('OK\n');
|
|
261
|
+
|
|
262
|
+
const response = await app.request('/api/local-llm/test', {
|
|
263
|
+
method: 'POST',
|
|
264
|
+
headers: { 'Content-Type': 'application/json' },
|
|
265
|
+
body: JSON.stringify({
|
|
266
|
+
endpoint: 'http://localhost:11434',
|
|
267
|
+
provider: 'ollama',
|
|
268
|
+
model: 'qwen2.5-coder:1.5b',
|
|
269
|
+
shoot: true
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
expect(response.status).toBe(200);
|
|
274
|
+
const data = await response.json();
|
|
275
|
+
expect(data.success).toBe(true);
|
|
276
|
+
expect(data.modelReady).toBe(true);
|
|
277
|
+
expect(data.message).toContain('Inference test succeeded');
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('GET /api/local-llm/recommend', () => {
|
|
282
|
+
it('should fetch system specs and return them', async () => {
|
|
283
|
+
vi.spyOn(systemScanner, 'scanSystemSpecs').mockResolvedValue({
|
|
284
|
+
totalRamGb: 16,
|
|
285
|
+
gpuName: 'Nvidia RTX 4080',
|
|
286
|
+
hasHardwareAcceleration: true,
|
|
287
|
+
recommendedModel: 'qwen2.5-coder:7b'
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const response = await app.request('/api/local-llm/recommend');
|
|
291
|
+
expect(response.status).toBe(200);
|
|
292
|
+
const data = await response.json();
|
|
293
|
+
expect(data.totalRamGb).toBe(16);
|
|
294
|
+
expect(data.gpuName).toBe('Nvidia RTX 4080');
|
|
295
|
+
expect(data.recommendedModel).toBe('qwen2.5-coder:7b');
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('GET and PUT /api/workspace/:id/knowledge', () => {
|
|
300
|
+
it('should get workspace knowledge content', async () => {
|
|
301
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
302
|
+
workspacesDir: '/mock/workspaces'
|
|
303
|
+
} as any);
|
|
304
|
+
vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Knowledge File content');
|
|
305
|
+
|
|
306
|
+
const response = await app.request('/api/workspace/test-ws/knowledge');
|
|
307
|
+
expect(response.status).toBe(200);
|
|
308
|
+
const data = await response.json();
|
|
309
|
+
expect(data.content).toBe('# Mock Knowledge File content');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should write workspace knowledge content', async () => {
|
|
313
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
314
|
+
workspacesDir: '/mock/workspaces'
|
|
315
|
+
} as any);
|
|
316
|
+
vi.spyOn(fs, 'writeFile').mockResolvedValue();
|
|
317
|
+
|
|
318
|
+
const response = await app.request('/api/workspace/test-ws/knowledge', {
|
|
319
|
+
method: 'PUT',
|
|
320
|
+
headers: { 'Content-Type': 'application/json' },
|
|
321
|
+
body: JSON.stringify({ content: '# Updated Content' })
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(response.status).toBe(200);
|
|
325
|
+
const data = await response.json();
|
|
326
|
+
expect(data.success).toBe(true);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('GET /api/workspace/:id/plan', () => {
|
|
331
|
+
it('should get workspace plan content', async () => {
|
|
332
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
333
|
+
workspacesDir: '/mock/workspaces'
|
|
334
|
+
} as any);
|
|
335
|
+
vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Plan content');
|
|
336
|
+
|
|
337
|
+
const response = await app.request('/api/workspace/test-ws/plan');
|
|
338
|
+
expect(response.status).toBe(200);
|
|
339
|
+
const data = await response.json();
|
|
340
|
+
expect(data.content).toBe('# Mock Plan content');
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe('POST /api/updates/install', () => {
|
|
345
|
+
it('should fail if tool not found', async () => {
|
|
346
|
+
const response = await app.request('/api/updates/install', {
|
|
347
|
+
method: 'POST',
|
|
348
|
+
headers: { 'Content-Type': 'application/json' },
|
|
349
|
+
body: JSON.stringify({ toolId: 'invalid-tool' })
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
expect(response.status).toBe(404);
|
|
353
|
+
const data = await response.json();
|
|
354
|
+
expect(data.error).toBe('Tool not found');
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('should install tool successfully if execa exits with 0', async () => {
|
|
358
|
+
vi.mocked(execa).mockResolvedValue({ exitCode: 0, stdout: 'Successfully updated' } as any);
|
|
359
|
+
|
|
360
|
+
const response = await app.request('/api/updates/install', {
|
|
361
|
+
method: 'POST',
|
|
362
|
+
headers: { 'Content-Type': 'application/json' },
|
|
363
|
+
body: JSON.stringify({ toolId: 'repomix' })
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
expect(response.status).toBe(200);
|
|
367
|
+
const data = await response.json();
|
|
368
|
+
expect(data.success).toBe(true);
|
|
369
|
+
expect(data.output).toBe('Successfully updated');
|
|
370
|
+
expect(execa).toHaveBeenCalledWith('npm', ['install', '-g', 'repomix'], expect.any(Object));
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
describe('POST /api/workspace', () => {
|
|
375
|
+
it('should complete workspace creation successfully when packContextXml is false', async () => {
|
|
376
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
377
|
+
workspacesDir: '/mock/workspaces',
|
|
378
|
+
packContextXml: false
|
|
379
|
+
} as any);
|
|
380
|
+
|
|
381
|
+
vi.spyOn(workspace, 'createWorkspace').mockResolvedValue('/mock/workspaces/test-ws-creation-no-pack');
|
|
382
|
+
vi.spyOn(analyzers, 'analyzeAllRepos').mockResolvedValue(new Map());
|
|
383
|
+
vi.spyOn(generators, 'generateContextFiles').mockResolvedValue(undefined);
|
|
384
|
+
|
|
385
|
+
const response = await app.request('/api/workspace', {
|
|
386
|
+
method: 'POST',
|
|
387
|
+
headers: { 'Content-Type': 'application/json' },
|
|
388
|
+
body: JSON.stringify({
|
|
389
|
+
branchName: 'test-ws-creation-no-pack',
|
|
390
|
+
description: 'A test workspace',
|
|
391
|
+
repos: [{ name: 'repo-1', path: '/mock/repo-1' }],
|
|
392
|
+
assistants: ['antigravity']
|
|
393
|
+
})
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
expect(response.status).toBe(200);
|
|
397
|
+
const data = await response.json();
|
|
398
|
+
expect(data.success).toBe(true);
|
|
399
|
+
expect(data.jobId).toBe('test-ws-creation-no-pack');
|
|
400
|
+
|
|
401
|
+
// Wait a brief tick for the background job to execute
|
|
402
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
403
|
+
|
|
404
|
+
expect(workspace.createWorkspace).toHaveBeenCalled();
|
|
405
|
+
expect(analyzers.analyzeAllRepos).toHaveBeenCalled();
|
|
406
|
+
expect(generators.generateContextFiles).toHaveBeenCalled();
|
|
407
|
+
|
|
408
|
+
// Read status via SSE stream route
|
|
409
|
+
const streamResponse = await app.request('/api/workspace/create-stream/test-ws-creation-no-pack');
|
|
410
|
+
expect(streamResponse.status).toBe(200);
|
|
411
|
+
const text = await streamResponse.text();
|
|
412
|
+
expect(text).toContain('"status":"completed"');
|
|
413
|
+
expect(text).toContain('"progress":100');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('should complete workspace creation successfully when packContextXml is true', async () => {
|
|
417
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
418
|
+
workspacesDir: '/mock/workspaces',
|
|
419
|
+
packContextXml: true
|
|
420
|
+
} as any);
|
|
421
|
+
|
|
422
|
+
vi.spyOn(workspace, 'createWorkspace').mockResolvedValue('/mock/workspaces/test-ws-creation-with-pack');
|
|
423
|
+
vi.spyOn(analyzers, 'analyzeAllRepos').mockResolvedValue(new Map());
|
|
424
|
+
vi.spyOn(generators, 'generateContextFiles').mockResolvedValue(undefined);
|
|
425
|
+
vi.spyOn(packer, 'packWorkspace').mockResolvedValue({
|
|
426
|
+
outputPath: '/mock/workspace/nexusflow-context.xml',
|
|
427
|
+
totalFiles: 5,
|
|
428
|
+
totalCharacters: 1000,
|
|
429
|
+
fileSize: 5120
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
const response = await app.request('/api/workspace', {
|
|
433
|
+
method: 'POST',
|
|
434
|
+
headers: { 'Content-Type': 'application/json' },
|
|
435
|
+
body: JSON.stringify({
|
|
436
|
+
branchName: 'test-ws-creation-with-pack',
|
|
437
|
+
description: 'A test workspace',
|
|
438
|
+
repos: [{ name: 'repo-1', path: '/mock/repo-1' }],
|
|
439
|
+
assistants: ['antigravity']
|
|
440
|
+
})
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
expect(response.status).toBe(200);
|
|
444
|
+
const data = await response.json();
|
|
445
|
+
expect(data.success).toBe(true);
|
|
446
|
+
expect(data.jobId).toBe('test-ws-creation-with-pack');
|
|
447
|
+
|
|
448
|
+
// Wait a brief tick for the background job to execute
|
|
449
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
450
|
+
|
|
451
|
+
expect(workspace.createWorkspace).toHaveBeenCalled();
|
|
452
|
+
expect(analyzers.analyzeAllRepos).toHaveBeenCalled();
|
|
453
|
+
expect(generators.generateContextFiles).toHaveBeenCalled();
|
|
454
|
+
expect(packer.packWorkspace).toHaveBeenCalled();
|
|
455
|
+
|
|
456
|
+
// Read status via SSE stream route
|
|
457
|
+
const streamResponse = await app.request('/api/workspace/create-stream/test-ws-creation-with-pack');
|
|
458
|
+
expect(streamResponse.status).toBe(200);
|
|
459
|
+
const text = await streamResponse.text();
|
|
460
|
+
expect(text).toContain('"status":"completed"');
|
|
461
|
+
expect(text).toContain('"progress":100');
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
});
|