@mrpatronz/nexusflow 0.2.13 → 0.2.17

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.
Files changed (186) hide show
  1. package/.github/dependabot.yml +52 -52
  2. package/.github/workflows/dependabot-merge.yml +53 -0
  3. package/.github/workflows/release.yml +112 -100
  4. package/.vscode/launch.json +17 -17
  5. package/.vscode/tasks.json +17 -17
  6. package/GETTING_STARTED.md +114 -109
  7. package/README.md +336 -311
  8. package/desktop/build-installer.js +228 -0
  9. package/desktop/build.js +118 -0
  10. package/desktop/installer/nexusflow.iss +35 -0
  11. package/desktop/neutralino.config.json +39 -0
  12. package/desktop/package-lock.json +1060 -0
  13. package/desktop/package.json +14 -0
  14. package/dist/commands/desktop.d.ts +12 -0
  15. package/dist/commands/desktop.d.ts.map +1 -0
  16. package/dist/commands/desktop.js +119 -0
  17. package/dist/commands/desktop.js.map +1 -0
  18. package/dist/commands/sync.d.ts.map +1 -1
  19. package/dist/commands/sync.js +1 -3
  20. package/dist/commands/sync.js.map +1 -1
  21. package/dist/commands/tui.d.ts +8 -0
  22. package/dist/commands/tui.d.ts.map +1 -0
  23. package/dist/commands/tui.js +386 -0
  24. package/dist/commands/tui.js.map +1 -0
  25. package/dist/commands/ui.d.ts +3 -1
  26. package/dist/commands/ui.d.ts.map +1 -1
  27. package/dist/commands/ui.js +76 -19
  28. package/dist/commands/ui.js.map +1 -1
  29. package/dist/generators/base.d.ts.map +1 -1
  30. package/dist/generators/base.js +78 -66
  31. package/dist/generators/base.js.map +1 -1
  32. package/dist/generators/codex.js +11 -11
  33. package/dist/generators/copilot.js +17 -17
  34. package/dist/generators/cursor.js +5 -5
  35. package/dist/generators/index.js +50 -50
  36. package/dist/generators/map-generator.js +14 -14
  37. package/dist/generators/skills-generator.js +28 -28
  38. package/dist/gui/app_logo.png +0 -0
  39. package/dist/gui/assets/index-Ct3qq-X4.js +25 -0
  40. package/dist/gui/assets/index-P_ZrgHXg.css +1 -0
  41. package/dist/gui/icons.svg +24 -24
  42. package/dist/gui/index.html +18 -18
  43. package/dist/index.js +43 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/server.d.ts.map +1 -1
  46. package/dist/server.js +182 -1
  47. package/dist/server.js.map +1 -1
  48. package/dist/server.test.js +78 -0
  49. package/dist/server.test.js.map +1 -1
  50. package/dist/types.d.ts +4 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/git.d.ts +16 -0
  53. package/dist/utils/git.d.ts.map +1 -1
  54. package/dist/utils/git.js +52 -0
  55. package/dist/utils/git.js.map +1 -1
  56. package/dist/utils/multi-git.d.ts +2 -0
  57. package/dist/utils/multi-git.d.ts.map +1 -1
  58. package/dist/utils/multi-git.js +5 -2
  59. package/dist/utils/multi-git.js.map +1 -1
  60. package/dist/utils/update-check.d.ts +3 -1
  61. package/dist/utils/update-check.d.ts.map +1 -1
  62. package/dist/utils/update-check.js +23 -6
  63. package/dist/utils/update-check.js.map +1 -1
  64. package/dist/utils/workflows.d.ts +11 -0
  65. package/dist/utils/workflows.d.ts.map +1 -0
  66. package/dist/utils/workflows.js +156 -0
  67. package/dist/utils/workflows.js.map +1 -0
  68. package/dist/utils/workflows.test.d.ts +2 -0
  69. package/dist/utils/workflows.test.d.ts.map +1 -0
  70. package/dist/utils/workflows.test.js +86 -0
  71. package/dist/utils/workflows.test.js.map +1 -0
  72. package/extension/media/icon.svg +1 -0
  73. package/extension/package-lock.json +2673 -2811
  74. package/extension/package.json +108 -70
  75. package/extension/src/extension.ts +631 -204
  76. package/extension/tsconfig.json +21 -19
  77. package/gui/README.md +73 -73
  78. package/gui/e2e/wizard.spec.ts +346 -327
  79. package/gui/eslint.config.js +26 -26
  80. package/gui/index.html +17 -17
  81. package/gui/package-lock.json +3079 -3118
  82. package/gui/package.json +36 -36
  83. package/gui/playwright.config.ts +41 -41
  84. package/gui/public/app_logo.png +0 -0
  85. package/gui/public/icons.svg +24 -24
  86. package/gui/src/App.css +1 -1
  87. package/gui/src/App.tsx +3407 -2722
  88. package/gui/src/assets/vite.svg +1 -1
  89. package/gui/src/features/changes/ChangesViewer.tsx +388 -388
  90. package/gui/src/features/knowledge/KnowledgeBase.tsx +84 -84
  91. package/gui/src/features/onboarding/OnboardingWizard.tsx +230 -230
  92. package/gui/src/features/plan/ImplementationPlan.tsx +32 -32
  93. package/gui/src/features/services/ServiceConsole.tsx +250 -250
  94. package/gui/src/features/sessions/SessionHistory.tsx +195 -195
  95. package/gui/src/features/workspace/WorkspaceList.tsx +666 -666
  96. package/gui/src/index.css +152 -110
  97. package/gui/src/main.tsx +94 -10
  98. package/gui/src/types.ts +62 -62
  99. package/gui/tsconfig.app.json +25 -25
  100. package/gui/tsconfig.json +7 -7
  101. package/gui/tsconfig.node.json +24 -24
  102. package/gui/vite.config.ts +12 -12
  103. package/package.json +56 -56
  104. package/resources/workflows/plan-implement-review.md +8 -0
  105. package/resources/workflows/research-verify.md +6 -0
  106. package/resources/workflows/solo-developer.md +3 -0
  107. package/scripts/simulate-workspaces.ts +55 -55
  108. package/src/analyzers/detect-apis.ts +290 -290
  109. package/src/analyzers/detect-deps.ts +315 -315
  110. package/src/analyzers/detect-existing.ts +74 -74
  111. package/src/analyzers/detect-ports.ts +110 -110
  112. package/src/analyzers/index.ts +97 -97
  113. package/src/analyzers/messaging-analyzer.ts +254 -254
  114. package/src/analyzers/readme-summarizer.ts +102 -102
  115. package/src/analyzers/run-analyzer.ts +269 -269
  116. package/src/analyzers/tech-stack.ts +283 -283
  117. package/src/commands/add-repo.ts +157 -157
  118. package/src/commands/commands.test.ts +155 -155
  119. package/src/commands/commit.ts +131 -131
  120. package/src/commands/create.ts +207 -207
  121. package/src/commands/desktop.ts +128 -0
  122. package/src/commands/diff.ts +125 -125
  123. package/src/commands/doctor.ts +357 -357
  124. package/src/commands/handoff.ts +266 -266
  125. package/src/commands/init.ts +134 -134
  126. package/src/commands/list.ts +46 -46
  127. package/src/commands/logs.ts +63 -63
  128. package/src/commands/mcp.ts +92 -92
  129. package/src/commands/open.ts +129 -129
  130. package/src/commands/pack.ts +73 -73
  131. package/src/commands/refresh.ts +147 -147
  132. package/src/commands/remove.ts +98 -98
  133. package/src/commands/start.ts +117 -117
  134. package/src/commands/status.ts +54 -54
  135. package/src/commands/stop.ts +55 -55
  136. package/src/commands/sync.ts +151 -153
  137. package/src/commands/tui.ts +424 -0
  138. package/src/commands/ui.ts +111 -47
  139. package/src/core/config.test.ts +96 -96
  140. package/src/core/config.ts +115 -115
  141. package/src/core/graph.ts +344 -344
  142. package/src/core/packer.test.ts +99 -99
  143. package/src/core/packer.ts +107 -107
  144. package/src/core/scanner.test.ts +61 -61
  145. package/src/core/scanner.ts +91 -91
  146. package/src/core/workspace.ts +380 -380
  147. package/src/core/worktree.ts +120 -120
  148. package/src/generators/antigravity.ts +32 -32
  149. package/src/generators/base.ts +240 -227
  150. package/src/generators/claude.ts +34 -34
  151. package/src/generators/codex.ts +48 -48
  152. package/src/generators/copilot.ts +56 -56
  153. package/src/generators/cursor.ts +44 -44
  154. package/src/generators/index.ts +250 -250
  155. package/src/generators/map-generator.test.ts +159 -159
  156. package/src/generators/map-generator.ts +542 -542
  157. package/src/generators/plan-generator.ts +481 -481
  158. package/src/generators/skills-generator.ts +259 -259
  159. package/src/index.ts +426 -382
  160. package/src/mcp/server.ts +294 -294
  161. package/src/orchestration/detect.ts +313 -313
  162. package/src/orchestration/index.ts +7 -7
  163. package/src/orchestration/runner.ts +283 -283
  164. package/src/server.test.ts +555 -464
  165. package/src/server.ts +1308 -1104
  166. package/src/types.ts +408 -403
  167. package/src/utils/detect-ai.test.ts +44 -44
  168. package/src/utils/detect-ai.ts +84 -84
  169. package/src/utils/detect-editors.test.ts +48 -48
  170. package/src/utils/detect-editors.ts +57 -57
  171. package/src/utils/git.test.ts +74 -74
  172. package/src/utils/git.ts +117 -61
  173. package/src/utils/local-ai.test.ts +130 -130
  174. package/src/utils/local-ai.ts +111 -111
  175. package/src/utils/multi-git.ts +313 -306
  176. package/src/utils/prompts.ts +209 -209
  177. package/src/utils/session-finder.ts +483 -483
  178. package/src/utils/system-scanner.test.ts +89 -89
  179. package/src/utils/system-scanner.ts +96 -96
  180. package/src/utils/update-check.ts +309 -275
  181. package/src/utils/workflows.test.ts +114 -0
  182. package/src/utils/workflows.ts +178 -0
  183. package/tsconfig.json +19 -19
  184. package/vitest.config.ts +14 -14
  185. package/dist/gui/assets/index-CFWwqFux.js +0 -23
  186. package/dist/gui/assets/index-Dvc9QMvl.css +0 -2
@@ -1,464 +1,555 @@
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
- });
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
+ import * as workflows from './utils/workflows.js';
14
+ import * as detectAi from './utils/detect-ai.js';
15
+
16
+ // Mock dependencies
17
+ vi.mock('node:fs/promises');
18
+ vi.mock('execa');
19
+ vi.mock('./core/workspace.js');
20
+ vi.mock('./core/config.js');
21
+ vi.mock('./utils/system-scanner.js');
22
+ vi.mock('./utils/local-ai.js');
23
+ vi.mock('./utils/update-check.js');
24
+ vi.mock('./analyzers/index.js');
25
+ vi.mock('./generators/index.js');
26
+ vi.mock('./core/packer.js');
27
+ vi.mock('./utils/workflows.js');
28
+ vi.mock('./utils/detect-ai.js', () => ({
29
+ detectAIAssistants: vi.fn().mockResolvedValue([])
30
+ }));
31
+
32
+ describe('Server API Endpoints Unit Tests', () => {
33
+ beforeEach(() => {
34
+ vi.clearAllMocks();
35
+ });
36
+
37
+ describe('POST /api/open-editor', () => {
38
+ it('should return 400 for forbidden editor commands', async () => {
39
+ const response = await app.request('/api/open-editor', {
40
+ method: 'POST',
41
+ headers: { 'Content-Type': 'application/json' },
42
+ body: JSON.stringify({
43
+ workspacePath: '/mock/workspace/path',
44
+ command: 'rm -rf /'
45
+ })
46
+ });
47
+
48
+ expect(response.status).toBe(400);
49
+ const data = await response.json();
50
+ expect(data.error).toBe('Forbidden editor command');
51
+ });
52
+
53
+ it('should return 400 if workspace path does not exist', async () => {
54
+ vi.spyOn(fs, 'stat').mockRejectedValue(new Error('File not found'));
55
+
56
+ const response = await app.request('/api/open-editor', {
57
+ method: 'POST',
58
+ headers: { 'Content-Type': 'application/json' },
59
+ body: JSON.stringify({
60
+ workspacePath: '/non-existent/path',
61
+ command: 'code-insiders'
62
+ })
63
+ });
64
+
65
+ expect(response.status).toBe(400);
66
+ const data = await response.json();
67
+ expect(data.error).toBe('Workspace path does not exist');
68
+ });
69
+
70
+ it('should return 400 if workspace path is not a directory', async () => {
71
+ vi.spyOn(fs, 'stat').mockResolvedValue({
72
+ isDirectory: () => false
73
+ } as any);
74
+
75
+ const response = await app.request('/api/open-editor', {
76
+ method: 'POST',
77
+ headers: { 'Content-Type': 'application/json' },
78
+ body: JSON.stringify({
79
+ workspacePath: '/mock/file.txt',
80
+ command: 'code-insiders'
81
+ })
82
+ });
83
+
84
+ expect(response.status).toBe(400);
85
+ const data = await response.json();
86
+ expect(data.error).toBe('Workspace path is not a directory');
87
+ });
88
+
89
+ it('should call execa with detached, stdio, shell, and cleanup options and return success', async () => {
90
+ vi.spyOn(fs, 'stat').mockResolvedValue({
91
+ isDirectory: () => true
92
+ } as any);
93
+
94
+ // Mock execa to return a dummy child process with a catch method
95
+ const dummyChild = {
96
+ unref: vi.fn(),
97
+ catch: vi.fn().mockReturnThis()
98
+ };
99
+ vi.mocked(execa).mockReturnValue(dummyChild as any);
100
+
101
+ const response = await app.request('/api/open-editor', {
102
+ method: 'POST',
103
+ headers: { 'Content-Type': 'application/json' },
104
+ body: JSON.stringify({
105
+ workspacePath: '/mock/workspace/dir',
106
+ command: 'code-insiders'
107
+ })
108
+ });
109
+
110
+ expect(response.status).toBe(200);
111
+ const data = await response.json();
112
+ expect(data.success).toBe(true);
113
+
114
+ const isWin = process.platform === 'win32';
115
+ expect(execa).toHaveBeenCalledWith('code-insiders', ['/mock/workspace/dir'], {
116
+ detached: true,
117
+ stdio: 'ignore',
118
+ shell: isWin,
119
+ cleanup: false
120
+ });
121
+ expect(dummyChild.unref).toHaveBeenCalled();
122
+ expect(dummyChild.catch).toHaveBeenCalled();
123
+ });
124
+ });
125
+
126
+ describe('POST /api/workspace/:id/resume', () => {
127
+ it('should fail with 400 if command is forbidden', async () => {
128
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
129
+ workspacesDir: '/mock/workspaces'
130
+ } as any);
131
+ vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
132
+ id: 'test-ws',
133
+ repos: [],
134
+ assistants: ['antigravity']
135
+ } as any);
136
+
137
+ const response = await app.request('/api/workspace/test-ws/resume', {
138
+ method: 'POST',
139
+ headers: { 'Content-Type': 'application/json' },
140
+ body: JSON.stringify({
141
+ command: 'malicious-editor',
142
+ assistant: 'antigravity'
143
+ })
144
+ });
145
+
146
+ expect(response.status).toBe(400);
147
+ const data = await response.json();
148
+ expect(data.error).toBe('Forbidden editor command');
149
+ });
150
+
151
+ it('should spawn the editor with proper options when resuming', async () => {
152
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
153
+ workspacesDir: '/mock/workspaces'
154
+ } as any);
155
+ vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
156
+ id: 'test-ws',
157
+ repos: [],
158
+ assistants: ['antigravity']
159
+ } as any);
160
+
161
+ const dummyChild = {
162
+ unref: vi.fn(),
163
+ catch: vi.fn().mockReturnThis()
164
+ };
165
+ vi.mocked(execa).mockReturnValue(dummyChild as any);
166
+
167
+ const response = await app.request('/api/workspace/test-ws/resume', {
168
+ method: 'POST',
169
+ headers: { 'Content-Type': 'application/json' },
170
+ body: JSON.stringify({
171
+ command: 'code',
172
+ assistant: 'antigravity'
173
+ })
174
+ });
175
+
176
+ expect(response.status).toBe(200);
177
+ const data = await response.json();
178
+ expect(data.success).toBe(true);
179
+
180
+ const isWin = process.platform === 'win32';
181
+ expect(execa).toHaveBeenCalledWith('code', [expect.any(String)], {
182
+ detached: true,
183
+ stdio: 'ignore',
184
+ shell: isWin,
185
+ cleanup: false
186
+ });
187
+ expect(dummyChild.unref).toHaveBeenCalled();
188
+ expect(dummyChild.catch).toHaveBeenCalled();
189
+ });
190
+ });
191
+
192
+ describe('GET /api/config', () => {
193
+ it('should load configuration successfully', async () => {
194
+ vi.spyOn(config, 'getConfigDir').mockReturnValue('/mock/config-dir');
195
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
196
+ devDir: '/mock/dev',
197
+ scanDepth: 2
198
+ } as any);
199
+ vi.spyOn(fs, 'access').mockResolvedValue();
200
+
201
+ const response = await app.request('/api/config');
202
+ expect(response.status).toBe(200);
203
+ const data = await response.json();
204
+ expect(data.config.devDir).toBe('/mock/dev');
205
+ expect(data.exists).toBe(true);
206
+ });
207
+ });
208
+
209
+ describe('POST /api/config', () => {
210
+ it('should validate endpoint domain safety', async () => {
211
+ const response = await app.request('/api/config', {
212
+ method: 'POST',
213
+ headers: { 'Content-Type': 'application/json' },
214
+ body: JSON.stringify({
215
+ localLlm: {
216
+ enabled: true,
217
+ endpoint: 'http://malicious-external-domain.com'
218
+ }
219
+ })
220
+ });
221
+
222
+ expect(response.status).toBe(400);
223
+ const data = await response.json();
224
+ expect(data.error).toContain('Local AI endpoint must be localhost, 127.0.0.1, or a private LAN IP.');
225
+ });
226
+
227
+ it('should save safe endpoint and config', async () => {
228
+ vi.spyOn(config, 'saveConfig').mockResolvedValue();
229
+
230
+ const response = await app.request('/api/config', {
231
+ method: 'POST',
232
+ headers: { 'Content-Type': 'application/json' },
233
+ body: JSON.stringify({
234
+ localLlm: {
235
+ enabled: true,
236
+ endpoint: 'http://127.0.0.1:11434'
237
+ }
238
+ })
239
+ });
240
+
241
+ expect(response.status).toBe(200);
242
+ const data = await response.json();
243
+ expect(data.success).toBe(true);
244
+ });
245
+ });
246
+
247
+ describe('POST /api/local-llm/test', () => {
248
+ it('should reject unsafe endpoints', async () => {
249
+ const response = await app.request('/api/local-llm/test', {
250
+ method: 'POST',
251
+ headers: { 'Content-Type': 'application/json' },
252
+ body: JSON.stringify({
253
+ endpoint: 'http://unsafe-domain.com',
254
+ provider: 'ollama',
255
+ model: 'qwen2.5-coder:1.5b'
256
+ })
257
+ });
258
+
259
+ expect(response.status).toBe(400);
260
+ const data = await response.json();
261
+ expect(data.success).toBe(false);
262
+ expect(data.error).toContain('Local AI endpoint must be');
263
+ });
264
+
265
+ it('should perform inference shoot test if shoot = true', async () => {
266
+ vi.spyOn(localAi, 'callLocalLlm').mockResolvedValue('OK\n');
267
+
268
+ const response = await app.request('/api/local-llm/test', {
269
+ method: 'POST',
270
+ headers: { 'Content-Type': 'application/json' },
271
+ body: JSON.stringify({
272
+ endpoint: 'http://localhost:11434',
273
+ provider: 'ollama',
274
+ model: 'qwen2.5-coder:1.5b',
275
+ shoot: true
276
+ })
277
+ });
278
+
279
+ expect(response.status).toBe(200);
280
+ const data = await response.json();
281
+ expect(data.success).toBe(true);
282
+ expect(data.modelReady).toBe(true);
283
+ expect(data.message).toContain('Inference test succeeded');
284
+ });
285
+ });
286
+
287
+ describe('GET /api/local-llm/recommend', () => {
288
+ it('should fetch system specs and return them', async () => {
289
+ vi.spyOn(systemScanner, 'scanSystemSpecs').mockResolvedValue({
290
+ totalRamGb: 16,
291
+ gpuName: 'Nvidia RTX 4080',
292
+ hasHardwareAcceleration: true,
293
+ recommendedModel: 'qwen2.5-coder:7b'
294
+ });
295
+
296
+ const response = await app.request('/api/local-llm/recommend');
297
+ expect(response.status).toBe(200);
298
+ const data = await response.json();
299
+ expect(data.totalRamGb).toBe(16);
300
+ expect(data.gpuName).toBe('Nvidia RTX 4080');
301
+ expect(data.recommendedModel).toBe('qwen2.5-coder:7b');
302
+ });
303
+ });
304
+
305
+ describe('GET and PUT /api/workspace/:id/knowledge', () => {
306
+ it('should get workspace knowledge content', async () => {
307
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
308
+ workspacesDir: '/mock/workspaces'
309
+ } as any);
310
+ vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Knowledge File content');
311
+
312
+ const response = await app.request('/api/workspace/test-ws/knowledge');
313
+ expect(response.status).toBe(200);
314
+ const data = await response.json();
315
+ expect(data.content).toBe('# Mock Knowledge File content');
316
+ });
317
+
318
+ it('should write workspace knowledge content', async () => {
319
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
320
+ workspacesDir: '/mock/workspaces'
321
+ } as any);
322
+ vi.spyOn(fs, 'writeFile').mockResolvedValue();
323
+
324
+ const response = await app.request('/api/workspace/test-ws/knowledge', {
325
+ method: 'PUT',
326
+ headers: { 'Content-Type': 'application/json' },
327
+ body: JSON.stringify({ content: '# Updated Content' })
328
+ });
329
+
330
+ expect(response.status).toBe(200);
331
+ const data = await response.json();
332
+ expect(data.success).toBe(true);
333
+ });
334
+ });
335
+
336
+ describe('GET /api/workspace/:id/plan', () => {
337
+ it('should get workspace plan content', async () => {
338
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
339
+ workspacesDir: '/mock/workspaces'
340
+ } as any);
341
+ vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Plan content');
342
+
343
+ const response = await app.request('/api/workspace/test-ws/plan');
344
+ expect(response.status).toBe(200);
345
+ const data = await response.json();
346
+ expect(data.content).toBe('# Mock Plan content');
347
+ });
348
+ });
349
+
350
+ describe('POST /api/updates/install', () => {
351
+ it('should fail if tool not found', async () => {
352
+ const response = await app.request('/api/updates/install', {
353
+ method: 'POST',
354
+ headers: { 'Content-Type': 'application/json' },
355
+ body: JSON.stringify({ toolId: 'invalid-tool' })
356
+ });
357
+
358
+ expect(response.status).toBe(404);
359
+ const data = await response.json();
360
+ expect(data.error).toBe('Tool not found');
361
+ });
362
+
363
+ it('should install tool successfully if execa exits with 0', async () => {
364
+ vi.mocked(execa).mockResolvedValue({ exitCode: 0, stdout: 'Successfully updated' } as any);
365
+
366
+ const response = await app.request('/api/updates/install', {
367
+ method: 'POST',
368
+ headers: { 'Content-Type': 'application/json' },
369
+ body: JSON.stringify({ toolId: 'repomix' })
370
+ });
371
+
372
+ expect(response.status).toBe(200);
373
+ const data = await response.json();
374
+ expect(data.success).toBe(true);
375
+ expect(data.output).toBe('Successfully updated');
376
+ expect(execa).toHaveBeenCalledWith('npm', ['install', '-g', 'repomix'], expect.any(Object));
377
+ });
378
+ });
379
+
380
+ describe('POST /api/workspace', () => {
381
+ it('should complete workspace creation successfully when packContextXml is false', async () => {
382
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
383
+ workspacesDir: '/mock/workspaces',
384
+ packContextXml: false
385
+ } as any);
386
+
387
+ vi.spyOn(workspace, 'createWorkspace').mockResolvedValue('/mock/workspaces/test-ws-creation-no-pack');
388
+ vi.spyOn(analyzers, 'analyzeAllRepos').mockResolvedValue(new Map());
389
+ vi.spyOn(generators, 'generateContextFiles').mockResolvedValue(undefined);
390
+
391
+ const response = await app.request('/api/workspace', {
392
+ method: 'POST',
393
+ headers: { 'Content-Type': 'application/json' },
394
+ body: JSON.stringify({
395
+ branchName: 'test-ws-creation-no-pack',
396
+ description: 'A test workspace',
397
+ repos: [{ name: 'repo-1', path: '/mock/repo-1' }],
398
+ assistants: ['antigravity']
399
+ })
400
+ });
401
+
402
+ expect(response.status).toBe(200);
403
+ const data = await response.json();
404
+ expect(data.success).toBe(true);
405
+ expect(data.jobId).toBe('test-ws-creation-no-pack');
406
+
407
+ // Wait a brief tick for the background job to execute
408
+ await new Promise((resolve) => setTimeout(resolve, 50));
409
+
410
+ expect(workspace.createWorkspace).toHaveBeenCalled();
411
+ expect(analyzers.analyzeAllRepos).toHaveBeenCalled();
412
+ expect(generators.generateContextFiles).toHaveBeenCalled();
413
+
414
+ // Read status via SSE stream route
415
+ const streamResponse = await app.request('/api/workspace/create-stream/test-ws-creation-no-pack');
416
+ expect(streamResponse.status).toBe(200);
417
+ const text = await streamResponse.text();
418
+ expect(text).toContain('"status":"completed"');
419
+ expect(text).toContain('"progress":100');
420
+ });
421
+
422
+ it('should complete workspace creation successfully when packContextXml is true', async () => {
423
+ vi.spyOn(config, 'loadConfig').mockResolvedValue({
424
+ workspacesDir: '/mock/workspaces',
425
+ packContextXml: true
426
+ } as any);
427
+
428
+ vi.spyOn(workspace, 'createWorkspace').mockResolvedValue('/mock/workspaces/test-ws-creation-with-pack');
429
+ vi.spyOn(analyzers, 'analyzeAllRepos').mockResolvedValue(new Map());
430
+ vi.spyOn(generators, 'generateContextFiles').mockResolvedValue(undefined);
431
+ vi.spyOn(packer, 'packWorkspace').mockResolvedValue({
432
+ outputPath: '/mock/workspace/nexusflow-context.xml',
433
+ totalFiles: 5,
434
+ totalCharacters: 1000,
435
+ fileSize: 5120
436
+ });
437
+
438
+ const response = await app.request('/api/workspace', {
439
+ method: 'POST',
440
+ headers: { 'Content-Type': 'application/json' },
441
+ body: JSON.stringify({
442
+ branchName: 'test-ws-creation-with-pack',
443
+ description: 'A test workspace',
444
+ repos: [{ name: 'repo-1', path: '/mock/repo-1' }],
445
+ assistants: ['antigravity']
446
+ })
447
+ });
448
+
449
+ expect(response.status).toBe(200);
450
+ const data = await response.json();
451
+ expect(data.success).toBe(true);
452
+ expect(data.jobId).toBe('test-ws-creation-with-pack');
453
+
454
+ // Wait a brief tick for the background job to execute
455
+ await new Promise((resolve) => setTimeout(resolve, 50));
456
+
457
+ expect(workspace.createWorkspace).toHaveBeenCalled();
458
+ expect(analyzers.analyzeAllRepos).toHaveBeenCalled();
459
+ expect(generators.generateContextFiles).toHaveBeenCalled();
460
+ expect(packer.packWorkspace).toHaveBeenCalled();
461
+
462
+ // Read status via SSE stream route
463
+ const streamResponse = await app.request('/api/workspace/create-stream/test-ws-creation-with-pack');
464
+ expect(streamResponse.status).toBe(200);
465
+ const text = await streamResponse.text();
466
+ expect(text).toContain('"status":"completed"');
467
+ expect(text).toContain('"progress":100');
468
+ });
469
+ });
470
+
471
+ describe('Workflows Templates API', () => {
472
+ it('GET /api/workflows/templates should return list of templates', async () => {
473
+ vi.spyOn(workflows, 'getWorkflowTemplates').mockResolvedValue([
474
+ { id: 'test-id', name: 'Test Name', description: 'Test Desc', content: 'Test Content', custom: false }
475
+ ]);
476
+
477
+ const response = await app.request('/api/workflows/templates');
478
+ expect(response.status).toBe(200);
479
+ const data = await response.json();
480
+ expect(data).toEqual({
481
+ templates: [
482
+ { id: 'test-id', name: 'Test Name', description: 'Test Desc', content: 'Test Content', custom: false }
483
+ ]
484
+ });
485
+ });
486
+
487
+ it('POST /api/workflows/templates should create or update template', async () => {
488
+ vi.spyOn(workflows, 'saveWorkflowTemplate').mockResolvedValue({
489
+ id: 'test-id',
490
+ name: 'Test Name',
491
+ description: 'Test Desc',
492
+ content: 'Test Content',
493
+ custom: true
494
+ });
495
+
496
+ const response = await app.request('/api/workflows/templates', {
497
+ method: 'POST',
498
+ headers: { 'Content-Type': 'application/json' },
499
+ body: JSON.stringify({ id: 'old-id', name: 'Test Name', content: 'Test Content' })
500
+ });
501
+
502
+ expect(response.status).toBe(200);
503
+ const data = await response.json();
504
+ expect(data.success).toBe(true);
505
+ expect(data.template.id).toBe('test-id');
506
+ expect(workflows.saveWorkflowTemplate).toHaveBeenCalledWith('Test Name', 'Test Content', 'old-id');
507
+ });
508
+
509
+ it('DELETE /api/workflows/templates/:id should delete template', async () => {
510
+ vi.spyOn(workflows, 'getWorkflowTemplates').mockResolvedValue([
511
+ { id: 'test-id', name: 'Test Name', description: 'Test Desc', content: 'Test Content', custom: true }
512
+ ]);
513
+ vi.spyOn(workflows, 'deleteWorkflowTemplate').mockResolvedValue(undefined);
514
+
515
+ const response = await app.request('/api/workflows/templates/test-id', {
516
+ method: 'DELETE'
517
+ });
518
+
519
+ expect(response.status).toBe(200);
520
+ const data = await response.json();
521
+ expect(data.success).toBe(true);
522
+ expect(workflows.deleteWorkflowTemplate).toHaveBeenCalledWith('test-id');
523
+ });
524
+
525
+ it('POST /api/workflows/templates/:id/analyze should run inspection with comment', async () => {
526
+ vi.mocked(detectAi.detectAIAssistants).mockResolvedValue([
527
+ { name: 'antigravity', displayName: 'Antigravity', detected: true, command: 'agy' }
528
+ ]);
529
+
530
+ vi.mocked(execa).mockResolvedValue({
531
+ exitCode: 0,
532
+ stdout: 'Review result: Success\n=== SUGGESTED IMPROVEMENT START ===\n# Refined Strategy\n=== SUGGESTED IMPROVEMENT END ==='
533
+ } as any);
534
+
535
+ const response = await app.request('/api/workflows/templates/test-id/analyze', {
536
+ method: 'POST',
537
+ headers: { 'Content-Type': 'application/json' },
538
+ body: JSON.stringify({
539
+ content: 'My Strategy guidelines',
540
+ assistant: 'antigravity',
541
+ comment: 'Check for timeouts'
542
+ })
543
+ });
544
+
545
+ expect(response.status).toBe(200);
546
+ const data = await response.json();
547
+ expect(data.analysis).toContain('Review result: Success');
548
+ expect(data.suggestedImprovement).toBe('# Refined Strategy');
549
+ expect(execa).toHaveBeenCalled();
550
+
551
+ const calledArgs = vi.mocked(execa).mock.calls[0][1];
552
+ expect(JSON.stringify(calledArgs)).toContain('Check for timeouts');
553
+ });
554
+ });
555
+ });