@vibescope/mcp-server 0.4.9 → 0.5.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/api-client/tasks.d.ts +1 -0
  4. package/dist/cli-init.js +21 -21
  5. package/dist/cli.js +26 -26
  6. package/dist/handlers/tasks.js +7 -1
  7. package/dist/handlers/tool-docs.js +1216 -1216
  8. package/dist/index.js +73 -73
  9. package/dist/templates/agent-guidelines.d.ts +1 -1
  10. package/dist/templates/agent-guidelines.js +205 -205
  11. package/dist/templates/help-content.js +1621 -1621
  12. package/dist/tools/bodies-of-work.js +6 -6
  13. package/dist/tools/cloud-agents.js +22 -22
  14. package/dist/tools/milestones.js +2 -2
  15. package/dist/tools/requests.js +1 -1
  16. package/dist/tools/session.js +11 -11
  17. package/dist/tools/sprints.js +9 -9
  18. package/dist/tools/tasks.js +43 -35
  19. package/dist/tools/worktrees.js +14 -14
  20. package/dist/utils.js +11 -11
  21. package/docs/TOOLS.md +2687 -2685
  22. package/package.json +53 -53
  23. package/scripts/generate-docs.ts +212 -212
  24. package/scripts/version-bump.ts +203 -203
  25. package/src/api-client/blockers.ts +86 -86
  26. package/src/api-client/bodies-of-work.ts +194 -194
  27. package/src/api-client/chat.ts +50 -50
  28. package/src/api-client/connectors.ts +152 -152
  29. package/src/api-client/cost.ts +185 -185
  30. package/src/api-client/decisions.ts +87 -87
  31. package/src/api-client/deployment.ts +313 -313
  32. package/src/api-client/discovery.ts +81 -81
  33. package/src/api-client/fallback.ts +52 -52
  34. package/src/api-client/file-checkouts.ts +115 -115
  35. package/src/api-client/findings.ts +100 -100
  36. package/src/api-client/git-issues.ts +88 -88
  37. package/src/api-client/ideas.ts +112 -112
  38. package/src/api-client/index.ts +592 -592
  39. package/src/api-client/milestones.ts +83 -83
  40. package/src/api-client/organizations.ts +185 -185
  41. package/src/api-client/progress.ts +94 -94
  42. package/src/api-client/project.ts +181 -181
  43. package/src/api-client/requests.ts +54 -54
  44. package/src/api-client/session.ts +220 -220
  45. package/src/api-client/sprints.ts +227 -227
  46. package/src/api-client/subtasks.ts +57 -57
  47. package/src/api-client/tasks.ts +451 -450
  48. package/src/api-client/types.ts +32 -32
  49. package/src/api-client/validation.ts +60 -60
  50. package/src/api-client/worktrees.ts +53 -53
  51. package/src/api-client.test.ts +847 -847
  52. package/src/api-client.ts +2728 -2728
  53. package/src/cli-init.ts +558 -558
  54. package/src/cli.test.ts +284 -284
  55. package/src/cli.ts +204 -204
  56. package/src/handlers/__test-setup__.ts +240 -240
  57. package/src/handlers/__test-utils__.ts +89 -89
  58. package/src/handlers/blockers.test.ts +468 -468
  59. package/src/handlers/blockers.ts +172 -172
  60. package/src/handlers/bodies-of-work.test.ts +704 -704
  61. package/src/handlers/bodies-of-work.ts +526 -526
  62. package/src/handlers/chat.test.ts +185 -185
  63. package/src/handlers/chat.ts +101 -101
  64. package/src/handlers/cloud-agents.test.ts +438 -438
  65. package/src/handlers/cloud-agents.ts +156 -156
  66. package/src/handlers/connectors.test.ts +834 -834
  67. package/src/handlers/connectors.ts +229 -229
  68. package/src/handlers/cost.test.ts +462 -462
  69. package/src/handlers/cost.ts +285 -285
  70. package/src/handlers/decisions.test.ts +382 -382
  71. package/src/handlers/decisions.ts +153 -153
  72. package/src/handlers/deployment.test.ts +551 -551
  73. package/src/handlers/deployment.ts +570 -570
  74. package/src/handlers/discovery.test.ts +206 -206
  75. package/src/handlers/discovery.ts +433 -433
  76. package/src/handlers/fallback.test.ts +537 -537
  77. package/src/handlers/fallback.ts +194 -194
  78. package/src/handlers/file-checkouts.test.ts +750 -750
  79. package/src/handlers/file-checkouts.ts +185 -185
  80. package/src/handlers/findings.test.ts +633 -633
  81. package/src/handlers/findings.ts +239 -239
  82. package/src/handlers/git-issues.test.ts +631 -631
  83. package/src/handlers/git-issues.ts +136 -136
  84. package/src/handlers/ideas.test.ts +644 -644
  85. package/src/handlers/ideas.ts +207 -207
  86. package/src/handlers/index.ts +93 -93
  87. package/src/handlers/milestones.test.ts +475 -475
  88. package/src/handlers/milestones.ts +180 -180
  89. package/src/handlers/organizations.test.ts +826 -826
  90. package/src/handlers/organizations.ts +315 -315
  91. package/src/handlers/progress.test.ts +269 -269
  92. package/src/handlers/progress.ts +77 -77
  93. package/src/handlers/project.test.ts +546 -546
  94. package/src/handlers/project.ts +245 -245
  95. package/src/handlers/requests.test.ts +303 -303
  96. package/src/handlers/requests.ts +99 -99
  97. package/src/handlers/roles.test.ts +305 -305
  98. package/src/handlers/roles.ts +219 -219
  99. package/src/handlers/session.test.ts +998 -998
  100. package/src/handlers/session.ts +1105 -1105
  101. package/src/handlers/sprints.test.ts +732 -732
  102. package/src/handlers/sprints.ts +537 -537
  103. package/src/handlers/tasks.test.ts +931 -931
  104. package/src/handlers/tasks.ts +1144 -1137
  105. package/src/handlers/tool-categories.test.ts +66 -66
  106. package/src/handlers/tool-docs.test.ts +511 -511
  107. package/src/handlers/tool-docs.ts +1595 -1595
  108. package/src/handlers/types.test.ts +259 -259
  109. package/src/handlers/types.ts +176 -176
  110. package/src/handlers/validation.test.ts +582 -582
  111. package/src/handlers/validation.ts +164 -164
  112. package/src/handlers/version.ts +63 -63
  113. package/src/index.test.ts +674 -674
  114. package/src/index.ts +884 -884
  115. package/src/setup.test.ts +243 -243
  116. package/src/setup.ts +410 -410
  117. package/src/templates/agent-guidelines.ts +233 -233
  118. package/src/templates/help-content.ts +1751 -1751
  119. package/src/token-tracking.test.ts +463 -463
  120. package/src/token-tracking.ts +167 -167
  121. package/src/tools/blockers.ts +122 -122
  122. package/src/tools/bodies-of-work.ts +283 -283
  123. package/src/tools/chat.ts +72 -72
  124. package/src/tools/cloud-agents.ts +101 -101
  125. package/src/tools/connectors.ts +191 -191
  126. package/src/tools/cost.ts +111 -111
  127. package/src/tools/decisions.ts +111 -111
  128. package/src/tools/deployment.ts +455 -455
  129. package/src/tools/discovery.ts +76 -76
  130. package/src/tools/fallback.ts +111 -111
  131. package/src/tools/features.ts +154 -154
  132. package/src/tools/file-checkouts.ts +145 -145
  133. package/src/tools/findings.ts +101 -101
  134. package/src/tools/git-issues.ts +130 -130
  135. package/src/tools/ideas.ts +162 -162
  136. package/src/tools/index.ts +145 -145
  137. package/src/tools/milestones.ts +118 -118
  138. package/src/tools/organizations.ts +224 -224
  139. package/src/tools/persona-templates.ts +25 -25
  140. package/src/tools/progress.ts +73 -73
  141. package/src/tools/project.ts +210 -210
  142. package/src/tools/requests.ts +68 -68
  143. package/src/tools/roles.ts +112 -112
  144. package/src/tools/session.ts +181 -181
  145. package/src/tools/sprints.ts +298 -298
  146. package/src/tools/tasks.ts +583 -575
  147. package/src/tools/tools.test.ts +222 -222
  148. package/src/tools/types.ts +9 -9
  149. package/src/tools/validation.ts +75 -75
  150. package/src/tools/version.ts +34 -34
  151. package/src/tools/worktrees.ts +66 -66
  152. package/src/tools.test.ts +416 -416
  153. package/src/utils.test.ts +1014 -1014
  154. package/src/utils.ts +586 -586
  155. package/src/validators.test.ts +223 -223
  156. package/src/validators.ts +249 -249
  157. package/src/version.ts +162 -162
  158. package/tsconfig.json +16 -16
  159. package/vitest.config.ts +14 -14
@@ -1,633 +1,633 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import {
3
- addFinding,
4
- getFindings,
5
- getFindingsStats,
6
- updateFinding,
7
- deleteFinding,
8
- queryKnowledgeBase,
9
- } from './findings.js';
10
- import { ValidationError } from '../validators.js';
11
- import { createMockContext } from './__test-utils__.js';
12
- import { mockApiClient } from './__test-setup__.js';
13
-
14
- const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
15
- const VALID_UUID_2 = '223e4567-e89b-12d3-a456-426614174001';
16
-
17
- // ============================================================================
18
- // addFinding Tests
19
- // ============================================================================
20
-
21
- describe('addFinding', () => {
22
- beforeEach(() => vi.clearAllMocks());
23
-
24
- it('should throw error for missing project_id', async () => {
25
- const ctx = createMockContext();
26
-
27
- await expect(addFinding({ title: 'Test Finding' }, ctx)).rejects.toThrow(ValidationError);
28
- });
29
-
30
- it('should throw error for invalid project_id UUID', async () => {
31
- const ctx = createMockContext();
32
-
33
- await expect(
34
- addFinding({ project_id: 'invalid', title: 'Test' }, ctx)
35
- ).rejects.toThrow(ValidationError);
36
- });
37
-
38
- it('should throw error for missing title', async () => {
39
- const ctx = createMockContext();
40
-
41
- await expect(
42
- addFinding({ project_id: VALID_UUID }, ctx)
43
- ).rejects.toThrow(ValidationError);
44
- });
45
-
46
- it('should throw error for invalid related_task_id UUID', async () => {
47
- const ctx = createMockContext();
48
-
49
- await expect(
50
- addFinding({ project_id: VALID_UUID, title: 'Test', related_task_id: 'invalid' }, ctx)
51
- ).rejects.toThrow(ValidationError);
52
- });
53
-
54
- it('should create finding with required fields', async () => {
55
- mockApiClient.addFinding.mockResolvedValue({
56
- ok: true,
57
- data: { success: true, finding_id: 'finding-1', title: 'Performance issue' },
58
- });
59
- const ctx = createMockContext();
60
-
61
- const result = await addFinding(
62
- { project_id: VALID_UUID, title: 'Performance issue' },
63
- ctx
64
- );
65
-
66
- expect(result.result).toMatchObject({
67
- success: true,
68
- finding_id: 'finding-1',
69
- title: 'Performance issue',
70
- });
71
- });
72
-
73
- it('should call API client with all parameters', async () => {
74
- mockApiClient.addFinding.mockResolvedValue({
75
- ok: true,
76
- data: { success: true, finding_id: 'finding-2' },
77
- });
78
- const ctx = createMockContext({ sessionId: 'my-session' });
79
-
80
- await addFinding(
81
- {
82
- project_id: VALID_UUID,
83
- title: 'SQL Injection vulnerability',
84
- description: 'User input not sanitized',
85
- category: 'security',
86
- severity: 'critical',
87
- file_path: 'src/api/users.ts',
88
- line_number: 42,
89
- related_task_id: VALID_UUID_2,
90
- },
91
- ctx
92
- );
93
-
94
- expect(mockApiClient.addFinding).toHaveBeenCalledWith(
95
- VALID_UUID,
96
- {
97
- title: 'SQL Injection vulnerability',
98
- description: 'User input not sanitized',
99
- category: 'security',
100
- severity: 'critical',
101
- file_path: 'src/api/users.ts',
102
- line_number: 42,
103
- related_task_id: VALID_UUID_2,
104
- },
105
- 'my-session'
106
- );
107
- });
108
-
109
- it('should return error when API call fails', async () => {
110
- mockApiClient.addFinding.mockResolvedValue({
111
- ok: false,
112
- error: 'Insert failed',
113
- });
114
- const ctx = createMockContext();
115
-
116
- const result = await addFinding({ project_id: VALID_UUID, title: 'Test' }, ctx);
117
-
118
- expect(result.isError).toBe(true);
119
- expect(result.result).toMatchObject({ error: 'Insert failed' });
120
- });
121
- });
122
-
123
- // ============================================================================
124
- // getFindings Tests
125
- // ============================================================================
126
-
127
- describe('getFindings', () => {
128
- beforeEach(() => vi.clearAllMocks());
129
-
130
- it('should throw error for missing project_id', async () => {
131
- const ctx = createMockContext();
132
-
133
- await expect(getFindings({}, ctx)).rejects.toThrow(ValidationError);
134
- });
135
-
136
- it('should throw error for invalid project_id UUID', async () => {
137
- const ctx = createMockContext();
138
-
139
- await expect(
140
- getFindings({ project_id: 'invalid' }, ctx)
141
- ).rejects.toThrow(ValidationError);
142
- });
143
-
144
- it('should return findings for project', async () => {
145
- const mockFindings = [
146
- { id: 'f1', title: 'Finding 1', category: 'security', severity: 'high', status: 'open', file_path: null, created_at: '2026-01-14' },
147
- { id: 'f2', title: 'Finding 2', category: 'performance', severity: 'medium', status: 'addressed', file_path: 'src/app.ts', created_at: '2026-01-13' },
148
- ];
149
- mockApiClient.getFindings.mockResolvedValue({
150
- ok: true,
151
- data: { findings: mockFindings },
152
- });
153
- const ctx = createMockContext();
154
-
155
- const result = await getFindings({ project_id: VALID_UUID }, ctx);
156
-
157
- expect(result.result).toMatchObject({ findings: mockFindings });
158
- });
159
-
160
- it('should pass filters to API client', async () => {
161
- mockApiClient.getFindings.mockResolvedValue({
162
- ok: true,
163
- data: { findings: [] },
164
- });
165
- const ctx = createMockContext();
166
-
167
- await getFindings({
168
- project_id: VALID_UUID,
169
- category: 'security',
170
- severity: 'critical',
171
- status: 'open',
172
- limit: 10
173
- }, ctx);
174
-
175
- expect(mockApiClient.getFindings).toHaveBeenCalledWith(
176
- VALID_UUID,
177
- expect.objectContaining({
178
- category: 'security',
179
- severity: 'critical',
180
- status: 'open',
181
- limit: 10,
182
- })
183
- );
184
- });
185
-
186
- it('should pass summary_only parameter to API client', async () => {
187
- mockApiClient.getFindings.mockResolvedValue({
188
- ok: true,
189
- data: { findings: [], total_count: 0, has_more: false },
190
- });
191
- const ctx = createMockContext();
192
-
193
- await getFindings({
194
- project_id: VALID_UUID,
195
- summary_only: true
196
- }, ctx);
197
-
198
- expect(mockApiClient.getFindings).toHaveBeenCalledWith(
199
- VALID_UUID,
200
- expect.objectContaining({
201
- summary_only: true,
202
- })
203
- );
204
- });
205
-
206
- it('should pass search_query parameter to API client', async () => {
207
- mockApiClient.getFindings.mockResolvedValue({
208
- ok: true,
209
- data: { findings: [], total_count: 0, has_more: false },
210
- });
211
- const ctx = createMockContext();
212
-
213
- await getFindings({
214
- project_id: VALID_UUID,
215
- search_query: 'security'
216
- }, ctx);
217
-
218
- expect(mockApiClient.getFindings).toHaveBeenCalledWith(
219
- VALID_UUID,
220
- expect.objectContaining({
221
- search_query: 'security',
222
- })
223
- );
224
- });
225
-
226
- it('should pass offset parameter to API client', async () => {
227
- mockApiClient.getFindings.mockResolvedValue({
228
- ok: true,
229
- data: { findings: [], total_count: 100, has_more: true },
230
- });
231
- const ctx = createMockContext();
232
-
233
- await getFindings({
234
- project_id: VALID_UUID,
235
- offset: 50,
236
- limit: 25
237
- }, ctx);
238
-
239
- expect(mockApiClient.getFindings).toHaveBeenCalledWith(
240
- VALID_UUID,
241
- expect.objectContaining({
242
- offset: 50,
243
- limit: 25,
244
- })
245
- );
246
- });
247
-
248
- it('should use default limit of 10 and summary_only true', async () => {
249
- mockApiClient.getFindings.mockResolvedValue({
250
- ok: true,
251
- data: { findings: [] },
252
- });
253
- const ctx = createMockContext();
254
-
255
- await getFindings({ project_id: VALID_UUID }, ctx);
256
-
257
- expect(mockApiClient.getFindings).toHaveBeenCalledWith(
258
- VALID_UUID,
259
- expect.objectContaining({ limit: 10, summary_only: true })
260
- );
261
- });
262
-
263
- it('should return error when API call fails', async () => {
264
- mockApiClient.getFindings.mockResolvedValue({
265
- ok: false,
266
- error: 'Query failed',
267
- });
268
- const ctx = createMockContext();
269
-
270
- const result = await getFindings({ project_id: VALID_UUID }, ctx);
271
-
272
- expect(result.isError).toBe(true);
273
- expect(result.result).toMatchObject({ error: 'Query failed' });
274
- });
275
- });
276
-
277
- // ============================================================================
278
- // updateFinding Tests
279
- // ============================================================================
280
-
281
- describe('updateFinding', () => {
282
- beforeEach(() => vi.clearAllMocks());
283
-
284
- it('should throw error for missing finding_id', async () => {
285
- const ctx = createMockContext();
286
-
287
- await expect(updateFinding({}, ctx)).rejects.toThrow(ValidationError);
288
- });
289
-
290
- it('should throw error for invalid finding_id UUID', async () => {
291
- const ctx = createMockContext();
292
-
293
- await expect(
294
- updateFinding({ finding_id: 'invalid' }, ctx)
295
- ).rejects.toThrow(ValidationError);
296
- });
297
-
298
- it('should update title', async () => {
299
- mockApiClient.updateFinding.mockResolvedValue({
300
- ok: true,
301
- data: { success: true, finding_id: VALID_UUID },
302
- });
303
- const ctx = createMockContext();
304
-
305
- const result = await updateFinding(
306
- { finding_id: VALID_UUID, title: 'Updated Title' },
307
- ctx
308
- );
309
-
310
- expect(result.result).toMatchObject({ success: true, finding_id: VALID_UUID });
311
- });
312
-
313
- it('should call API client with all update fields', async () => {
314
- mockApiClient.updateFinding.mockResolvedValue({
315
- ok: true,
316
- data: { success: true },
317
- });
318
- const ctx = createMockContext();
319
-
320
- await updateFinding(
321
- {
322
- finding_id: VALID_UUID,
323
- title: 'New Title',
324
- description: 'New description',
325
- severity: 'high',
326
- status: 'addressed',
327
- resolution_note: 'Fixed by sanitizing input'
328
- },
329
- ctx
330
- );
331
-
332
- expect(mockApiClient.updateFinding).toHaveBeenCalledWith(
333
- VALID_UUID,
334
- {
335
- title: 'New Title',
336
- description: 'New description',
337
- severity: 'high',
338
- status: 'addressed',
339
- resolution_note: 'Fixed by sanitizing input',
340
- }
341
- );
342
- });
343
-
344
- it('should return error when API call fails', async () => {
345
- mockApiClient.updateFinding.mockResolvedValue({
346
- ok: false,
347
- error: 'Update failed',
348
- });
349
- const ctx = createMockContext();
350
-
351
- const result = await updateFinding({ finding_id: VALID_UUID, title: 'Test' }, ctx);
352
-
353
- expect(result.isError).toBe(true);
354
- expect(result.result).toMatchObject({ error: 'Update failed' });
355
- });
356
- });
357
-
358
- // ============================================================================
359
- // deleteFinding Tests
360
- // ============================================================================
361
-
362
- describe('deleteFinding', () => {
363
- beforeEach(() => vi.clearAllMocks());
364
-
365
- it('should throw error for missing finding_id', async () => {
366
- const ctx = createMockContext();
367
-
368
- await expect(deleteFinding({}, ctx)).rejects.toThrow(ValidationError);
369
- });
370
-
371
- it('should throw error for invalid finding_id UUID', async () => {
372
- const ctx = createMockContext();
373
-
374
- await expect(
375
- deleteFinding({ finding_id: 'invalid' }, ctx)
376
- ).rejects.toThrow(ValidationError);
377
- });
378
-
379
- it('should delete finding successfully', async () => {
380
- mockApiClient.deleteFinding.mockResolvedValue({
381
- ok: true,
382
- data: { success: true },
383
- });
384
- const ctx = createMockContext();
385
-
386
- const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
387
-
388
- expect(result.result).toMatchObject({ success: true });
389
- });
390
-
391
- it('should call API client deleteFinding', async () => {
392
- mockApiClient.deleteFinding.mockResolvedValue({
393
- ok: true,
394
- data: { success: true },
395
- });
396
- const ctx = createMockContext();
397
-
398
- await deleteFinding({ finding_id: VALID_UUID }, ctx);
399
-
400
- expect(mockApiClient.deleteFinding).toHaveBeenCalledWith(VALID_UUID);
401
- });
402
-
403
- it('should return error when API call fails', async () => {
404
- mockApiClient.deleteFinding.mockResolvedValue({
405
- ok: false,
406
- error: 'Delete failed',
407
- });
408
- const ctx = createMockContext();
409
-
410
- const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
411
-
412
- expect(result.isError).toBe(true);
413
- expect(result.result).toMatchObject({ error: 'Delete failed' });
414
- });
415
- });
416
-
417
- // ============================================================================
418
- // getFindingsStats Tests
419
- // ============================================================================
420
-
421
- describe('getFindingsStats', () => {
422
- beforeEach(() => vi.clearAllMocks());
423
-
424
- it('should throw error for missing project_id', async () => {
425
- const ctx = createMockContext();
426
-
427
- await expect(getFindingsStats({}, ctx)).rejects.toThrow(ValidationError);
428
- });
429
-
430
- it('should throw error for invalid project_id UUID', async () => {
431
- const ctx = createMockContext();
432
-
433
- await expect(
434
- getFindingsStats({ project_id: 'invalid' }, ctx)
435
- ).rejects.toThrow(ValidationError);
436
- });
437
-
438
- it('should return findings stats for project', async () => {
439
- const mockStats = {
440
- total: 10,
441
- by_status: { open: 5, addressed: 3, dismissed: 2 },
442
- by_severity: { critical: 1, high: 3, medium: 4, low: 2 },
443
- by_category: { security: 3, performance: 4, code_quality: 3 },
444
- };
445
- mockApiClient.getFindingsStats.mockResolvedValue({
446
- ok: true,
447
- data: mockStats,
448
- });
449
- const ctx = createMockContext();
450
-
451
- const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
452
-
453
- expect(result.result).toMatchObject(mockStats);
454
- });
455
-
456
- it('should call API client getFindingsStats with project_id', async () => {
457
- mockApiClient.getFindingsStats.mockResolvedValue({
458
- ok: true,
459
- data: { total: 0, by_status: {}, by_severity: {}, by_category: {} },
460
- });
461
- const ctx = createMockContext();
462
-
463
- await getFindingsStats({ project_id: VALID_UUID }, ctx);
464
-
465
- expect(mockApiClient.getFindingsStats).toHaveBeenCalledWith(VALID_UUID);
466
- });
467
-
468
- it('should return error when API call fails', async () => {
469
- mockApiClient.getFindingsStats.mockResolvedValue({
470
- ok: false,
471
- error: 'Query failed',
472
- });
473
- const ctx = createMockContext();
474
-
475
- const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
476
-
477
- expect(result.isError).toBe(true);
478
- expect(result.result).toMatchObject({ error: 'Query failed' });
479
- });
480
- });
481
-
482
- // ============================================================================
483
- // queryKnowledgeBase Tests
484
- // ============================================================================
485
-
486
- describe('queryKnowledgeBase', () => {
487
- beforeEach(() => vi.clearAllMocks());
488
-
489
- it('should throw error for missing project_id', async () => {
490
- const ctx = createMockContext();
491
-
492
- await expect(queryKnowledgeBase({}, ctx)).rejects.toThrow(ValidationError);
493
- });
494
-
495
- it('should throw error for invalid project_id UUID', async () => {
496
- const ctx = createMockContext();
497
-
498
- await expect(
499
- queryKnowledgeBase({ project_id: 'invalid' }, ctx)
500
- ).rejects.toThrow(ValidationError);
501
- });
502
-
503
- it('should throw error for invalid scope value', async () => {
504
- const ctx = createMockContext();
505
-
506
- await expect(
507
- queryKnowledgeBase({ project_id: VALID_UUID, scope: 'invalid_scope' }, ctx)
508
- ).rejects.toThrow(ValidationError);
509
- });
510
-
511
- it('should query with default parameters', async () => {
512
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
513
- ok: true,
514
- data: {
515
- findings: [],
516
- decisions: [],
517
- completed_tasks: [],
518
- resolved_blockers: [],
519
- },
520
- });
521
- const ctx = createMockContext();
522
-
523
- const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
524
-
525
- expect(result.result).toMatchObject({
526
- findings: [],
527
- decisions: [],
528
- });
529
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
530
- VALID_UUID,
531
- expect.objectContaining({
532
- scope: 'summary',
533
- limit: 5,
534
- })
535
- );
536
- });
537
-
538
- it('should pass scope parameter', async () => {
539
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
540
- ok: true,
541
- data: { findings: [] },
542
- });
543
- const ctx = createMockContext();
544
-
545
- await queryKnowledgeBase({ project_id: VALID_UUID, scope: 'detailed' }, ctx);
546
-
547
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
548
- VALID_UUID,
549
- expect.objectContaining({ scope: 'detailed' })
550
- );
551
- });
552
-
553
- it('should pass categories filter', async () => {
554
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
555
- ok: true,
556
- data: { findings: [], decisions: [] },
557
- });
558
- const ctx = createMockContext();
559
-
560
- await queryKnowledgeBase({
561
- project_id: VALID_UUID,
562
- categories: ['findings', 'decisions']
563
- }, ctx);
564
-
565
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
566
- VALID_UUID,
567
- expect.objectContaining({
568
- categories: ['findings', 'decisions']
569
- })
570
- );
571
- });
572
-
573
- it('should cap limit at 20', async () => {
574
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
575
- ok: true,
576
- data: { findings: [] },
577
- });
578
- const ctx = createMockContext();
579
-
580
- await queryKnowledgeBase({ project_id: VALID_UUID, limit: 100 }, ctx);
581
-
582
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
583
- VALID_UUID,
584
- expect.objectContaining({ limit: 20 })
585
- );
586
- });
587
-
588
- it('should enforce minimum limit of 1', async () => {
589
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
590
- ok: true,
591
- data: { findings: [] },
592
- });
593
- const ctx = createMockContext();
594
-
595
- await queryKnowledgeBase({ project_id: VALID_UUID, limit: -5 }, ctx);
596
-
597
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
598
- VALID_UUID,
599
- expect.objectContaining({ limit: 1 })
600
- );
601
- });
602
-
603
- it('should pass search_query', async () => {
604
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
605
- ok: true,
606
- data: { findings: [] },
607
- });
608
- const ctx = createMockContext();
609
-
610
- await queryKnowledgeBase({
611
- project_id: VALID_UUID,
612
- search_query: 'security'
613
- }, ctx);
614
-
615
- expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
616
- VALID_UUID,
617
- expect.objectContaining({ search_query: 'security' })
618
- );
619
- });
620
-
621
- it('should return error when API call fails', async () => {
622
- mockApiClient.queryKnowledgeBase.mockResolvedValue({
623
- ok: false,
624
- error: 'Query failed',
625
- });
626
- const ctx = createMockContext();
627
-
628
- const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
629
-
630
- expect(result.isError).toBe(true);
631
- expect(result.result).toMatchObject({ error: 'Query failed' });
632
- });
633
- });
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import {
3
+ addFinding,
4
+ getFindings,
5
+ getFindingsStats,
6
+ updateFinding,
7
+ deleteFinding,
8
+ queryKnowledgeBase,
9
+ } from './findings.js';
10
+ import { ValidationError } from '../validators.js';
11
+ import { createMockContext } from './__test-utils__.js';
12
+ import { mockApiClient } from './__test-setup__.js';
13
+
14
+ const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
15
+ const VALID_UUID_2 = '223e4567-e89b-12d3-a456-426614174001';
16
+
17
+ // ============================================================================
18
+ // addFinding Tests
19
+ // ============================================================================
20
+
21
+ describe('addFinding', () => {
22
+ beforeEach(() => vi.clearAllMocks());
23
+
24
+ it('should throw error for missing project_id', async () => {
25
+ const ctx = createMockContext();
26
+
27
+ await expect(addFinding({ title: 'Test Finding' }, ctx)).rejects.toThrow(ValidationError);
28
+ });
29
+
30
+ it('should throw error for invalid project_id UUID', async () => {
31
+ const ctx = createMockContext();
32
+
33
+ await expect(
34
+ addFinding({ project_id: 'invalid', title: 'Test' }, ctx)
35
+ ).rejects.toThrow(ValidationError);
36
+ });
37
+
38
+ it('should throw error for missing title', async () => {
39
+ const ctx = createMockContext();
40
+
41
+ await expect(
42
+ addFinding({ project_id: VALID_UUID }, ctx)
43
+ ).rejects.toThrow(ValidationError);
44
+ });
45
+
46
+ it('should throw error for invalid related_task_id UUID', async () => {
47
+ const ctx = createMockContext();
48
+
49
+ await expect(
50
+ addFinding({ project_id: VALID_UUID, title: 'Test', related_task_id: 'invalid' }, ctx)
51
+ ).rejects.toThrow(ValidationError);
52
+ });
53
+
54
+ it('should create finding with required fields', async () => {
55
+ mockApiClient.addFinding.mockResolvedValue({
56
+ ok: true,
57
+ data: { success: true, finding_id: 'finding-1', title: 'Performance issue' },
58
+ });
59
+ const ctx = createMockContext();
60
+
61
+ const result = await addFinding(
62
+ { project_id: VALID_UUID, title: 'Performance issue' },
63
+ ctx
64
+ );
65
+
66
+ expect(result.result).toMatchObject({
67
+ success: true,
68
+ finding_id: 'finding-1',
69
+ title: 'Performance issue',
70
+ });
71
+ });
72
+
73
+ it('should call API client with all parameters', async () => {
74
+ mockApiClient.addFinding.mockResolvedValue({
75
+ ok: true,
76
+ data: { success: true, finding_id: 'finding-2' },
77
+ });
78
+ const ctx = createMockContext({ sessionId: 'my-session' });
79
+
80
+ await addFinding(
81
+ {
82
+ project_id: VALID_UUID,
83
+ title: 'SQL Injection vulnerability',
84
+ description: 'User input not sanitized',
85
+ category: 'security',
86
+ severity: 'critical',
87
+ file_path: 'src/api/users.ts',
88
+ line_number: 42,
89
+ related_task_id: VALID_UUID_2,
90
+ },
91
+ ctx
92
+ );
93
+
94
+ expect(mockApiClient.addFinding).toHaveBeenCalledWith(
95
+ VALID_UUID,
96
+ {
97
+ title: 'SQL Injection vulnerability',
98
+ description: 'User input not sanitized',
99
+ category: 'security',
100
+ severity: 'critical',
101
+ file_path: 'src/api/users.ts',
102
+ line_number: 42,
103
+ related_task_id: VALID_UUID_2,
104
+ },
105
+ 'my-session'
106
+ );
107
+ });
108
+
109
+ it('should return error when API call fails', async () => {
110
+ mockApiClient.addFinding.mockResolvedValue({
111
+ ok: false,
112
+ error: 'Insert failed',
113
+ });
114
+ const ctx = createMockContext();
115
+
116
+ const result = await addFinding({ project_id: VALID_UUID, title: 'Test' }, ctx);
117
+
118
+ expect(result.isError).toBe(true);
119
+ expect(result.result).toMatchObject({ error: 'Insert failed' });
120
+ });
121
+ });
122
+
123
+ // ============================================================================
124
+ // getFindings Tests
125
+ // ============================================================================
126
+
127
+ describe('getFindings', () => {
128
+ beforeEach(() => vi.clearAllMocks());
129
+
130
+ it('should throw error for missing project_id', async () => {
131
+ const ctx = createMockContext();
132
+
133
+ await expect(getFindings({}, ctx)).rejects.toThrow(ValidationError);
134
+ });
135
+
136
+ it('should throw error for invalid project_id UUID', async () => {
137
+ const ctx = createMockContext();
138
+
139
+ await expect(
140
+ getFindings({ project_id: 'invalid' }, ctx)
141
+ ).rejects.toThrow(ValidationError);
142
+ });
143
+
144
+ it('should return findings for project', async () => {
145
+ const mockFindings = [
146
+ { id: 'f1', title: 'Finding 1', category: 'security', severity: 'high', status: 'open', file_path: null, created_at: '2026-01-14' },
147
+ { id: 'f2', title: 'Finding 2', category: 'performance', severity: 'medium', status: 'addressed', file_path: 'src/app.ts', created_at: '2026-01-13' },
148
+ ];
149
+ mockApiClient.getFindings.mockResolvedValue({
150
+ ok: true,
151
+ data: { findings: mockFindings },
152
+ });
153
+ const ctx = createMockContext();
154
+
155
+ const result = await getFindings({ project_id: VALID_UUID }, ctx);
156
+
157
+ expect(result.result).toMatchObject({ findings: mockFindings });
158
+ });
159
+
160
+ it('should pass filters to API client', async () => {
161
+ mockApiClient.getFindings.mockResolvedValue({
162
+ ok: true,
163
+ data: { findings: [] },
164
+ });
165
+ const ctx = createMockContext();
166
+
167
+ await getFindings({
168
+ project_id: VALID_UUID,
169
+ category: 'security',
170
+ severity: 'critical',
171
+ status: 'open',
172
+ limit: 10
173
+ }, ctx);
174
+
175
+ expect(mockApiClient.getFindings).toHaveBeenCalledWith(
176
+ VALID_UUID,
177
+ expect.objectContaining({
178
+ category: 'security',
179
+ severity: 'critical',
180
+ status: 'open',
181
+ limit: 10,
182
+ })
183
+ );
184
+ });
185
+
186
+ it('should pass summary_only parameter to API client', async () => {
187
+ mockApiClient.getFindings.mockResolvedValue({
188
+ ok: true,
189
+ data: { findings: [], total_count: 0, has_more: false },
190
+ });
191
+ const ctx = createMockContext();
192
+
193
+ await getFindings({
194
+ project_id: VALID_UUID,
195
+ summary_only: true
196
+ }, ctx);
197
+
198
+ expect(mockApiClient.getFindings).toHaveBeenCalledWith(
199
+ VALID_UUID,
200
+ expect.objectContaining({
201
+ summary_only: true,
202
+ })
203
+ );
204
+ });
205
+
206
+ it('should pass search_query parameter to API client', async () => {
207
+ mockApiClient.getFindings.mockResolvedValue({
208
+ ok: true,
209
+ data: { findings: [], total_count: 0, has_more: false },
210
+ });
211
+ const ctx = createMockContext();
212
+
213
+ await getFindings({
214
+ project_id: VALID_UUID,
215
+ search_query: 'security'
216
+ }, ctx);
217
+
218
+ expect(mockApiClient.getFindings).toHaveBeenCalledWith(
219
+ VALID_UUID,
220
+ expect.objectContaining({
221
+ search_query: 'security',
222
+ })
223
+ );
224
+ });
225
+
226
+ it('should pass offset parameter to API client', async () => {
227
+ mockApiClient.getFindings.mockResolvedValue({
228
+ ok: true,
229
+ data: { findings: [], total_count: 100, has_more: true },
230
+ });
231
+ const ctx = createMockContext();
232
+
233
+ await getFindings({
234
+ project_id: VALID_UUID,
235
+ offset: 50,
236
+ limit: 25
237
+ }, ctx);
238
+
239
+ expect(mockApiClient.getFindings).toHaveBeenCalledWith(
240
+ VALID_UUID,
241
+ expect.objectContaining({
242
+ offset: 50,
243
+ limit: 25,
244
+ })
245
+ );
246
+ });
247
+
248
+ it('should use default limit of 10 and summary_only true', async () => {
249
+ mockApiClient.getFindings.mockResolvedValue({
250
+ ok: true,
251
+ data: { findings: [] },
252
+ });
253
+ const ctx = createMockContext();
254
+
255
+ await getFindings({ project_id: VALID_UUID }, ctx);
256
+
257
+ expect(mockApiClient.getFindings).toHaveBeenCalledWith(
258
+ VALID_UUID,
259
+ expect.objectContaining({ limit: 10, summary_only: true })
260
+ );
261
+ });
262
+
263
+ it('should return error when API call fails', async () => {
264
+ mockApiClient.getFindings.mockResolvedValue({
265
+ ok: false,
266
+ error: 'Query failed',
267
+ });
268
+ const ctx = createMockContext();
269
+
270
+ const result = await getFindings({ project_id: VALID_UUID }, ctx);
271
+
272
+ expect(result.isError).toBe(true);
273
+ expect(result.result).toMatchObject({ error: 'Query failed' });
274
+ });
275
+ });
276
+
277
+ // ============================================================================
278
+ // updateFinding Tests
279
+ // ============================================================================
280
+
281
+ describe('updateFinding', () => {
282
+ beforeEach(() => vi.clearAllMocks());
283
+
284
+ it('should throw error for missing finding_id', async () => {
285
+ const ctx = createMockContext();
286
+
287
+ await expect(updateFinding({}, ctx)).rejects.toThrow(ValidationError);
288
+ });
289
+
290
+ it('should throw error for invalid finding_id UUID', async () => {
291
+ const ctx = createMockContext();
292
+
293
+ await expect(
294
+ updateFinding({ finding_id: 'invalid' }, ctx)
295
+ ).rejects.toThrow(ValidationError);
296
+ });
297
+
298
+ it('should update title', async () => {
299
+ mockApiClient.updateFinding.mockResolvedValue({
300
+ ok: true,
301
+ data: { success: true, finding_id: VALID_UUID },
302
+ });
303
+ const ctx = createMockContext();
304
+
305
+ const result = await updateFinding(
306
+ { finding_id: VALID_UUID, title: 'Updated Title' },
307
+ ctx
308
+ );
309
+
310
+ expect(result.result).toMatchObject({ success: true, finding_id: VALID_UUID });
311
+ });
312
+
313
+ it('should call API client with all update fields', async () => {
314
+ mockApiClient.updateFinding.mockResolvedValue({
315
+ ok: true,
316
+ data: { success: true },
317
+ });
318
+ const ctx = createMockContext();
319
+
320
+ await updateFinding(
321
+ {
322
+ finding_id: VALID_UUID,
323
+ title: 'New Title',
324
+ description: 'New description',
325
+ severity: 'high',
326
+ status: 'addressed',
327
+ resolution_note: 'Fixed by sanitizing input'
328
+ },
329
+ ctx
330
+ );
331
+
332
+ expect(mockApiClient.updateFinding).toHaveBeenCalledWith(
333
+ VALID_UUID,
334
+ {
335
+ title: 'New Title',
336
+ description: 'New description',
337
+ severity: 'high',
338
+ status: 'addressed',
339
+ resolution_note: 'Fixed by sanitizing input',
340
+ }
341
+ );
342
+ });
343
+
344
+ it('should return error when API call fails', async () => {
345
+ mockApiClient.updateFinding.mockResolvedValue({
346
+ ok: false,
347
+ error: 'Update failed',
348
+ });
349
+ const ctx = createMockContext();
350
+
351
+ const result = await updateFinding({ finding_id: VALID_UUID, title: 'Test' }, ctx);
352
+
353
+ expect(result.isError).toBe(true);
354
+ expect(result.result).toMatchObject({ error: 'Update failed' });
355
+ });
356
+ });
357
+
358
+ // ============================================================================
359
+ // deleteFinding Tests
360
+ // ============================================================================
361
+
362
+ describe('deleteFinding', () => {
363
+ beforeEach(() => vi.clearAllMocks());
364
+
365
+ it('should throw error for missing finding_id', async () => {
366
+ const ctx = createMockContext();
367
+
368
+ await expect(deleteFinding({}, ctx)).rejects.toThrow(ValidationError);
369
+ });
370
+
371
+ it('should throw error for invalid finding_id UUID', async () => {
372
+ const ctx = createMockContext();
373
+
374
+ await expect(
375
+ deleteFinding({ finding_id: 'invalid' }, ctx)
376
+ ).rejects.toThrow(ValidationError);
377
+ });
378
+
379
+ it('should delete finding successfully', async () => {
380
+ mockApiClient.deleteFinding.mockResolvedValue({
381
+ ok: true,
382
+ data: { success: true },
383
+ });
384
+ const ctx = createMockContext();
385
+
386
+ const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
387
+
388
+ expect(result.result).toMatchObject({ success: true });
389
+ });
390
+
391
+ it('should call API client deleteFinding', async () => {
392
+ mockApiClient.deleteFinding.mockResolvedValue({
393
+ ok: true,
394
+ data: { success: true },
395
+ });
396
+ const ctx = createMockContext();
397
+
398
+ await deleteFinding({ finding_id: VALID_UUID }, ctx);
399
+
400
+ expect(mockApiClient.deleteFinding).toHaveBeenCalledWith(VALID_UUID);
401
+ });
402
+
403
+ it('should return error when API call fails', async () => {
404
+ mockApiClient.deleteFinding.mockResolvedValue({
405
+ ok: false,
406
+ error: 'Delete failed',
407
+ });
408
+ const ctx = createMockContext();
409
+
410
+ const result = await deleteFinding({ finding_id: VALID_UUID }, ctx);
411
+
412
+ expect(result.isError).toBe(true);
413
+ expect(result.result).toMatchObject({ error: 'Delete failed' });
414
+ });
415
+ });
416
+
417
+ // ============================================================================
418
+ // getFindingsStats Tests
419
+ // ============================================================================
420
+
421
+ describe('getFindingsStats', () => {
422
+ beforeEach(() => vi.clearAllMocks());
423
+
424
+ it('should throw error for missing project_id', async () => {
425
+ const ctx = createMockContext();
426
+
427
+ await expect(getFindingsStats({}, ctx)).rejects.toThrow(ValidationError);
428
+ });
429
+
430
+ it('should throw error for invalid project_id UUID', async () => {
431
+ const ctx = createMockContext();
432
+
433
+ await expect(
434
+ getFindingsStats({ project_id: 'invalid' }, ctx)
435
+ ).rejects.toThrow(ValidationError);
436
+ });
437
+
438
+ it('should return findings stats for project', async () => {
439
+ const mockStats = {
440
+ total: 10,
441
+ by_status: { open: 5, addressed: 3, dismissed: 2 },
442
+ by_severity: { critical: 1, high: 3, medium: 4, low: 2 },
443
+ by_category: { security: 3, performance: 4, code_quality: 3 },
444
+ };
445
+ mockApiClient.getFindingsStats.mockResolvedValue({
446
+ ok: true,
447
+ data: mockStats,
448
+ });
449
+ const ctx = createMockContext();
450
+
451
+ const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
452
+
453
+ expect(result.result).toMatchObject(mockStats);
454
+ });
455
+
456
+ it('should call API client getFindingsStats with project_id', async () => {
457
+ mockApiClient.getFindingsStats.mockResolvedValue({
458
+ ok: true,
459
+ data: { total: 0, by_status: {}, by_severity: {}, by_category: {} },
460
+ });
461
+ const ctx = createMockContext();
462
+
463
+ await getFindingsStats({ project_id: VALID_UUID }, ctx);
464
+
465
+ expect(mockApiClient.getFindingsStats).toHaveBeenCalledWith(VALID_UUID);
466
+ });
467
+
468
+ it('should return error when API call fails', async () => {
469
+ mockApiClient.getFindingsStats.mockResolvedValue({
470
+ ok: false,
471
+ error: 'Query failed',
472
+ });
473
+ const ctx = createMockContext();
474
+
475
+ const result = await getFindingsStats({ project_id: VALID_UUID }, ctx);
476
+
477
+ expect(result.isError).toBe(true);
478
+ expect(result.result).toMatchObject({ error: 'Query failed' });
479
+ });
480
+ });
481
+
482
+ // ============================================================================
483
+ // queryKnowledgeBase Tests
484
+ // ============================================================================
485
+
486
+ describe('queryKnowledgeBase', () => {
487
+ beforeEach(() => vi.clearAllMocks());
488
+
489
+ it('should throw error for missing project_id', async () => {
490
+ const ctx = createMockContext();
491
+
492
+ await expect(queryKnowledgeBase({}, ctx)).rejects.toThrow(ValidationError);
493
+ });
494
+
495
+ it('should throw error for invalid project_id UUID', async () => {
496
+ const ctx = createMockContext();
497
+
498
+ await expect(
499
+ queryKnowledgeBase({ project_id: 'invalid' }, ctx)
500
+ ).rejects.toThrow(ValidationError);
501
+ });
502
+
503
+ it('should throw error for invalid scope value', async () => {
504
+ const ctx = createMockContext();
505
+
506
+ await expect(
507
+ queryKnowledgeBase({ project_id: VALID_UUID, scope: 'invalid_scope' }, ctx)
508
+ ).rejects.toThrow(ValidationError);
509
+ });
510
+
511
+ it('should query with default parameters', async () => {
512
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
513
+ ok: true,
514
+ data: {
515
+ findings: [],
516
+ decisions: [],
517
+ completed_tasks: [],
518
+ resolved_blockers: [],
519
+ },
520
+ });
521
+ const ctx = createMockContext();
522
+
523
+ const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
524
+
525
+ expect(result.result).toMatchObject({
526
+ findings: [],
527
+ decisions: [],
528
+ });
529
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
530
+ VALID_UUID,
531
+ expect.objectContaining({
532
+ scope: 'summary',
533
+ limit: 5,
534
+ })
535
+ );
536
+ });
537
+
538
+ it('should pass scope parameter', async () => {
539
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
540
+ ok: true,
541
+ data: { findings: [] },
542
+ });
543
+ const ctx = createMockContext();
544
+
545
+ await queryKnowledgeBase({ project_id: VALID_UUID, scope: 'detailed' }, ctx);
546
+
547
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
548
+ VALID_UUID,
549
+ expect.objectContaining({ scope: 'detailed' })
550
+ );
551
+ });
552
+
553
+ it('should pass categories filter', async () => {
554
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
555
+ ok: true,
556
+ data: { findings: [], decisions: [] },
557
+ });
558
+ const ctx = createMockContext();
559
+
560
+ await queryKnowledgeBase({
561
+ project_id: VALID_UUID,
562
+ categories: ['findings', 'decisions']
563
+ }, ctx);
564
+
565
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
566
+ VALID_UUID,
567
+ expect.objectContaining({
568
+ categories: ['findings', 'decisions']
569
+ })
570
+ );
571
+ });
572
+
573
+ it('should cap limit at 20', async () => {
574
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
575
+ ok: true,
576
+ data: { findings: [] },
577
+ });
578
+ const ctx = createMockContext();
579
+
580
+ await queryKnowledgeBase({ project_id: VALID_UUID, limit: 100 }, ctx);
581
+
582
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
583
+ VALID_UUID,
584
+ expect.objectContaining({ limit: 20 })
585
+ );
586
+ });
587
+
588
+ it('should enforce minimum limit of 1', async () => {
589
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
590
+ ok: true,
591
+ data: { findings: [] },
592
+ });
593
+ const ctx = createMockContext();
594
+
595
+ await queryKnowledgeBase({ project_id: VALID_UUID, limit: -5 }, ctx);
596
+
597
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
598
+ VALID_UUID,
599
+ expect.objectContaining({ limit: 1 })
600
+ );
601
+ });
602
+
603
+ it('should pass search_query', async () => {
604
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
605
+ ok: true,
606
+ data: { findings: [] },
607
+ });
608
+ const ctx = createMockContext();
609
+
610
+ await queryKnowledgeBase({
611
+ project_id: VALID_UUID,
612
+ search_query: 'security'
613
+ }, ctx);
614
+
615
+ expect(mockApiClient.queryKnowledgeBase).toHaveBeenCalledWith(
616
+ VALID_UUID,
617
+ expect.objectContaining({ search_query: 'security' })
618
+ );
619
+ });
620
+
621
+ it('should return error when API call fails', async () => {
622
+ mockApiClient.queryKnowledgeBase.mockResolvedValue({
623
+ ok: false,
624
+ error: 'Query failed',
625
+ });
626
+ const ctx = createMockContext();
627
+
628
+ const result = await queryKnowledgeBase({ project_id: VALID_UUID }, ctx);
629
+
630
+ expect(result.isError).toBe(true);
631
+ expect(result.result).toMatchObject({ error: 'Query failed' });
632
+ });
633
+ });