@vibescope/mcp-server 0.2.9 → 0.3.0

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 (95) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/api-client.d.ts +36 -0
  4. package/dist/api-client.js +34 -0
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.js +30 -38
  7. package/dist/handlers/discovery.js +2 -0
  8. package/dist/handlers/session.d.ts +11 -0
  9. package/dist/handlers/session.js +101 -0
  10. package/dist/handlers/tasks.d.ts +8 -0
  11. package/dist/handlers/tasks.js +163 -3
  12. package/dist/handlers/tool-docs.js +840 -828
  13. package/dist/handlers/validation.js +45 -2
  14. package/dist/index.js +73 -73
  15. package/dist/setup.js +6 -6
  16. package/dist/templates/agent-guidelines.js +185 -185
  17. package/dist/templates/help-content.js +1622 -1544
  18. package/dist/tools.js +126 -74
  19. package/dist/utils.d.ts +15 -11
  20. package/dist/utils.js +53 -28
  21. package/docs/TOOLS.md +2406 -2053
  22. package/package.json +51 -51
  23. package/scripts/generate-docs.ts +212 -212
  24. package/scripts/version-bump.ts +203 -203
  25. package/src/api-client.test.ts +723 -723
  26. package/src/api-client.ts +2561 -2499
  27. package/src/cli.test.ts +24 -8
  28. package/src/cli.ts +204 -212
  29. package/src/handlers/__test-setup__.ts +236 -236
  30. package/src/handlers/__test-utils__.ts +87 -87
  31. package/src/handlers/blockers.test.ts +468 -468
  32. package/src/handlers/blockers.ts +163 -163
  33. package/src/handlers/bodies-of-work.test.ts +704 -704
  34. package/src/handlers/bodies-of-work.ts +526 -526
  35. package/src/handlers/connectors.test.ts +834 -834
  36. package/src/handlers/connectors.ts +229 -229
  37. package/src/handlers/cost.test.ts +462 -462
  38. package/src/handlers/cost.ts +285 -285
  39. package/src/handlers/decisions.test.ts +382 -382
  40. package/src/handlers/decisions.ts +153 -153
  41. package/src/handlers/deployment.test.ts +551 -551
  42. package/src/handlers/deployment.ts +541 -541
  43. package/src/handlers/discovery.test.ts +206 -206
  44. package/src/handlers/discovery.ts +392 -390
  45. package/src/handlers/fallback.test.ts +537 -537
  46. package/src/handlers/fallback.ts +194 -194
  47. package/src/handlers/file-checkouts.test.ts +750 -750
  48. package/src/handlers/file-checkouts.ts +185 -185
  49. package/src/handlers/findings.test.ts +633 -633
  50. package/src/handlers/findings.ts +239 -239
  51. package/src/handlers/git-issues.test.ts +631 -631
  52. package/src/handlers/git-issues.ts +136 -136
  53. package/src/handlers/ideas.test.ts +644 -644
  54. package/src/handlers/ideas.ts +207 -207
  55. package/src/handlers/index.ts +84 -84
  56. package/src/handlers/milestones.test.ts +475 -475
  57. package/src/handlers/milestones.ts +180 -180
  58. package/src/handlers/organizations.test.ts +826 -826
  59. package/src/handlers/organizations.ts +315 -315
  60. package/src/handlers/progress.test.ts +269 -269
  61. package/src/handlers/progress.ts +77 -77
  62. package/src/handlers/project.test.ts +546 -546
  63. package/src/handlers/project.ts +239 -239
  64. package/src/handlers/requests.test.ts +303 -303
  65. package/src/handlers/requests.ts +99 -99
  66. package/src/handlers/roles.test.ts +305 -305
  67. package/src/handlers/roles.ts +219 -219
  68. package/src/handlers/session.test.ts +998 -875
  69. package/src/handlers/session.ts +839 -730
  70. package/src/handlers/sprints.test.ts +732 -732
  71. package/src/handlers/sprints.ts +537 -537
  72. package/src/handlers/tasks.test.ts +931 -907
  73. package/src/handlers/tasks.ts +1121 -945
  74. package/src/handlers/tool-categories.test.ts +66 -66
  75. package/src/handlers/tool-docs.ts +1109 -1096
  76. package/src/handlers/types.test.ts +259 -259
  77. package/src/handlers/types.ts +175 -175
  78. package/src/handlers/validation.test.ts +582 -582
  79. package/src/handlers/validation.ts +159 -113
  80. package/src/index.test.ts +674 -0
  81. package/src/index.ts +792 -792
  82. package/src/setup.test.ts +233 -233
  83. package/src/setup.ts +404 -403
  84. package/src/templates/agent-guidelines.ts +210 -210
  85. package/src/templates/help-content.ts +1751 -1673
  86. package/src/token-tracking.test.ts +463 -463
  87. package/src/token-tracking.ts +166 -166
  88. package/src/tools.test.ts +416 -0
  89. package/src/tools.ts +3607 -3555
  90. package/src/utils.test.ts +785 -683
  91. package/src/utils.ts +469 -436
  92. package/src/validators.test.ts +223 -223
  93. package/src/validators.ts +249 -249
  94. package/tsconfig.json +16 -16
  95. 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
+ });