@vibescope/mcp-server 0.2.1 → 0.2.3

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 (93) hide show
  1. package/README.md +63 -38
  2. package/dist/api-client.d.ts +187 -0
  3. package/dist/api-client.js +53 -1
  4. package/dist/handlers/blockers.js +9 -8
  5. package/dist/handlers/bodies-of-work.js +14 -14
  6. package/dist/handlers/connectors.d.ts +45 -0
  7. package/dist/handlers/connectors.js +183 -0
  8. package/dist/handlers/cost.d.ts +10 -0
  9. package/dist/handlers/cost.js +54 -0
  10. package/dist/handlers/decisions.js +3 -3
  11. package/dist/handlers/deployment.js +35 -19
  12. package/dist/handlers/discovery.d.ts +7 -0
  13. package/dist/handlers/discovery.js +61 -2
  14. package/dist/handlers/fallback.js +5 -4
  15. package/dist/handlers/file-checkouts.d.ts +2 -0
  16. package/dist/handlers/file-checkouts.js +38 -6
  17. package/dist/handlers/findings.js +13 -12
  18. package/dist/handlers/git-issues.js +4 -4
  19. package/dist/handlers/ideas.js +5 -5
  20. package/dist/handlers/index.d.ts +1 -0
  21. package/dist/handlers/index.js +3 -0
  22. package/dist/handlers/milestones.js +5 -5
  23. package/dist/handlers/organizations.js +13 -13
  24. package/dist/handlers/progress.js +2 -2
  25. package/dist/handlers/project.js +6 -6
  26. package/dist/handlers/requests.js +3 -3
  27. package/dist/handlers/session.js +28 -9
  28. package/dist/handlers/sprints.js +17 -17
  29. package/dist/handlers/tasks.d.ts +2 -0
  30. package/dist/handlers/tasks.js +78 -20
  31. package/dist/handlers/types.d.ts +64 -2
  32. package/dist/handlers/types.js +48 -1
  33. package/dist/handlers/validation.js +3 -3
  34. package/dist/index.js +7 -2716
  35. package/dist/token-tracking.d.ts +74 -0
  36. package/dist/token-tracking.js +122 -0
  37. package/dist/tools.js +298 -9
  38. package/dist/utils.d.ts +5 -0
  39. package/dist/utils.js +17 -0
  40. package/docs/TOOLS.md +2053 -0
  41. package/package.json +4 -1
  42. package/scripts/generate-docs.ts +212 -0
  43. package/src/api-client.test.ts +723 -0
  44. package/src/api-client.ts +236 -1
  45. package/src/handlers/__test-setup__.ts +9 -0
  46. package/src/handlers/blockers.test.ts +31 -19
  47. package/src/handlers/blockers.ts +9 -8
  48. package/src/handlers/bodies-of-work.test.ts +55 -32
  49. package/src/handlers/bodies-of-work.ts +14 -14
  50. package/src/handlers/connectors.test.ts +834 -0
  51. package/src/handlers/connectors.ts +229 -0
  52. package/src/handlers/cost.ts +66 -0
  53. package/src/handlers/decisions.test.ts +34 -25
  54. package/src/handlers/decisions.ts +3 -3
  55. package/src/handlers/deployment.ts +39 -19
  56. package/src/handlers/discovery.ts +61 -2
  57. package/src/handlers/fallback.test.ts +26 -22
  58. package/src/handlers/fallback.ts +5 -4
  59. package/src/handlers/file-checkouts.test.ts +242 -49
  60. package/src/handlers/file-checkouts.ts +44 -6
  61. package/src/handlers/findings.test.ts +38 -24
  62. package/src/handlers/findings.ts +13 -12
  63. package/src/handlers/git-issues.test.ts +51 -43
  64. package/src/handlers/git-issues.ts +4 -4
  65. package/src/handlers/ideas.test.ts +28 -23
  66. package/src/handlers/ideas.ts +5 -5
  67. package/src/handlers/index.ts +3 -0
  68. package/src/handlers/milestones.test.ts +33 -28
  69. package/src/handlers/milestones.ts +5 -5
  70. package/src/handlers/organizations.test.ts +104 -83
  71. package/src/handlers/organizations.ts +13 -13
  72. package/src/handlers/progress.test.ts +20 -14
  73. package/src/handlers/progress.ts +2 -2
  74. package/src/handlers/project.test.ts +34 -27
  75. package/src/handlers/project.ts +6 -6
  76. package/src/handlers/requests.test.ts +27 -18
  77. package/src/handlers/requests.ts +3 -3
  78. package/src/handlers/session.test.ts +47 -0
  79. package/src/handlers/session.ts +26 -9
  80. package/src/handlers/sprints.test.ts +71 -50
  81. package/src/handlers/sprints.ts +17 -17
  82. package/src/handlers/tasks.test.ts +77 -15
  83. package/src/handlers/tasks.ts +90 -21
  84. package/src/handlers/tool-categories.test.ts +66 -0
  85. package/src/handlers/types.ts +81 -2
  86. package/src/handlers/validation.test.ts +78 -45
  87. package/src/handlers/validation.ts +3 -3
  88. package/src/index.ts +12 -2732
  89. package/src/token-tracking.test.ts +453 -0
  90. package/src/token-tracking.ts +164 -0
  91. package/src/tools.ts +298 -9
  92. package/src/utils.test.ts +2 -2
  93. package/src/utils.ts +17 -0
@@ -0,0 +1,723 @@
1
+ /**
2
+ * API Client Tests
3
+ *
4
+ * Tests for the VibescopeApiClient class that handles all HTTP communication
5
+ * with the Vibescope API.
6
+ */
7
+
8
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
9
+
10
+ // Unmock the api-client module so we test the real implementation
11
+ vi.unmock('./api-client.js');
12
+ vi.unmock('../api-client.js');
13
+
14
+ // Import after unmocking
15
+ import { VibescopeApiClient } from './api-client.js';
16
+
17
+ // ============================================================================
18
+ // Test Setup
19
+ // ============================================================================
20
+
21
+ // Mock fetch globally
22
+ const mockFetch = vi.fn();
23
+ global.fetch = mockFetch;
24
+
25
+ // Helper to create mock response
26
+ function createMockResponse(data: unknown, ok = true, status = 200) {
27
+ return {
28
+ ok,
29
+ status,
30
+ json: vi.fn().mockResolvedValue(data),
31
+ };
32
+ }
33
+
34
+ // Helper to create network error
35
+ function createNetworkError(message: string) {
36
+ return new Error(message);
37
+ }
38
+
39
+ describe('VibescopeApiClient', () => {
40
+ let client: VibescopeApiClient;
41
+
42
+ beforeEach(() => {
43
+ vi.clearAllMocks();
44
+ client = new VibescopeApiClient({ apiKey: 'test-api-key' });
45
+ });
46
+
47
+ afterEach(() => {
48
+ vi.resetAllMocks();
49
+ });
50
+
51
+ // ============================================================================
52
+ // Constructor Tests
53
+ // ============================================================================
54
+
55
+ describe('constructor', () => {
56
+ it('should use default API URL when not provided', () => {
57
+ const c = new VibescopeApiClient({ apiKey: 'test-key' });
58
+ mockFetch.mockResolvedValue(createMockResponse({ valid: true }));
59
+
60
+ // Trigger a request to verify the URL
61
+ c.validateAuth();
62
+
63
+ expect(mockFetch).toHaveBeenCalledWith(
64
+ expect.stringContaining('https://vibescope.dev'),
65
+ expect.any(Object)
66
+ );
67
+ });
68
+
69
+ it('should use custom baseUrl when provided', () => {
70
+ const c = new VibescopeApiClient({
71
+ apiKey: 'test-key',
72
+ baseUrl: 'https://custom.api.com',
73
+ });
74
+ mockFetch.mockResolvedValue(createMockResponse({ valid: true }));
75
+
76
+ c.validateAuth();
77
+
78
+ expect(mockFetch).toHaveBeenCalledWith(
79
+ expect.stringContaining('https://custom.api.com'),
80
+ expect.any(Object)
81
+ );
82
+ });
83
+
84
+ it('should use VIBESCOPE_API_URL env var when set', () => {
85
+ const originalEnv = process.env.VIBESCOPE_API_URL;
86
+ process.env.VIBESCOPE_API_URL = 'https://env-api.com';
87
+
88
+ const c = new VibescopeApiClient({ apiKey: 'test-key' });
89
+ mockFetch.mockResolvedValue(createMockResponse({ valid: true }));
90
+
91
+ c.validateAuth();
92
+
93
+ expect(mockFetch).toHaveBeenCalledWith(
94
+ expect.stringContaining('https://env-api.com'),
95
+ expect.any(Object)
96
+ );
97
+
98
+ // Restore
99
+ if (originalEnv !== undefined) {
100
+ process.env.VIBESCOPE_API_URL = originalEnv;
101
+ } else {
102
+ delete process.env.VIBESCOPE_API_URL;
103
+ }
104
+ });
105
+ });
106
+
107
+ // ============================================================================
108
+ // Request Method Tests (via validateAuth)
109
+ // ============================================================================
110
+
111
+ describe('request method', () => {
112
+ it('should send correct headers', async () => {
113
+ mockFetch.mockResolvedValue(createMockResponse({ valid: true }));
114
+
115
+ await client.validateAuth();
116
+
117
+ expect(mockFetch).toHaveBeenCalledWith(
118
+ expect.any(String),
119
+ expect.objectContaining({
120
+ method: 'POST',
121
+ headers: {
122
+ 'Content-Type': 'application/json',
123
+ 'X-API-Key': 'test-api-key',
124
+ },
125
+ })
126
+ );
127
+ });
128
+
129
+ it('should return success response on 2xx status', async () => {
130
+ const responseData = { valid: true, user_id: 'user-123' };
131
+ mockFetch.mockResolvedValue(createMockResponse(responseData, true, 200));
132
+
133
+ const result = await client.validateAuth();
134
+
135
+ expect(result).toEqual({
136
+ ok: true,
137
+ status: 200,
138
+ data: responseData,
139
+ });
140
+ });
141
+
142
+ it('should return error response on 4xx status', async () => {
143
+ const errorData = { error: 'Invalid API key' };
144
+ mockFetch.mockResolvedValue(createMockResponse(errorData, false, 401));
145
+
146
+ const result = await client.validateAuth();
147
+
148
+ expect(result).toEqual({
149
+ ok: false,
150
+ status: 401,
151
+ error: 'Invalid API key',
152
+ data: errorData,
153
+ });
154
+ });
155
+
156
+ it('should return error response on 5xx status', async () => {
157
+ const errorData = { error: 'Internal server error' };
158
+ mockFetch.mockResolvedValue(createMockResponse(errorData, false, 500));
159
+
160
+ const result = await client.validateAuth();
161
+
162
+ expect(result).toEqual({
163
+ ok: false,
164
+ status: 500,
165
+ error: 'Internal server error',
166
+ data: errorData,
167
+ });
168
+ });
169
+
170
+ it('should handle missing error field in error response', async () => {
171
+ const errorData = { message: 'Something went wrong' };
172
+ mockFetch.mockResolvedValue(createMockResponse(errorData, false, 400));
173
+
174
+ const result = await client.validateAuth();
175
+
176
+ expect(result).toEqual({
177
+ ok: false,
178
+ status: 400,
179
+ error: 'HTTP 400',
180
+ data: errorData,
181
+ });
182
+ });
183
+
184
+ it('should handle network errors', async () => {
185
+ mockFetch.mockRejectedValue(createNetworkError('Network request failed'));
186
+
187
+ const result = await client.validateAuth();
188
+
189
+ expect(result).toEqual({
190
+ ok: false,
191
+ status: 0,
192
+ error: 'Network request failed',
193
+ });
194
+ });
195
+
196
+ it('should handle non-Error exceptions', async () => {
197
+ mockFetch.mockRejectedValue('String error');
198
+
199
+ const result = await client.validateAuth();
200
+
201
+ expect(result).toEqual({
202
+ ok: false,
203
+ status: 0,
204
+ error: 'Network error',
205
+ });
206
+ });
207
+ });
208
+
209
+ // ============================================================================
210
+ // Auth Endpoints
211
+ // ============================================================================
212
+
213
+ describe('validateAuth', () => {
214
+ it('should call correct endpoint', async () => {
215
+ mockFetch.mockResolvedValue(createMockResponse({ valid: true }));
216
+
217
+ await client.validateAuth();
218
+
219
+ expect(mockFetch).toHaveBeenCalledWith(
220
+ expect.stringContaining('/api/mcp/auth/validate'),
221
+ expect.objectContaining({
222
+ method: 'POST',
223
+ body: JSON.stringify({ api_key: 'test-api-key' }),
224
+ })
225
+ );
226
+ });
227
+ });
228
+
229
+ // ============================================================================
230
+ // Session Endpoints
231
+ // ============================================================================
232
+
233
+ describe('startSession', () => {
234
+ it('should call correct endpoint with params', async () => {
235
+ mockFetch.mockResolvedValue(
236
+ createMockResponse({ session_started: true, session_id: 'session-123' })
237
+ );
238
+
239
+ await client.startSession({
240
+ project_id: 'proj-123',
241
+ mode: 'lite',
242
+ model: 'opus',
243
+ });
244
+
245
+ expect(mockFetch).toHaveBeenCalledWith(
246
+ expect.stringContaining('/api/mcp/sessions/start'),
247
+ expect.objectContaining({
248
+ method: 'POST',
249
+ body: JSON.stringify({
250
+ project_id: 'proj-123',
251
+ mode: 'lite',
252
+ model: 'opus',
253
+ }),
254
+ })
255
+ );
256
+ });
257
+
258
+ it('should support git_url param', async () => {
259
+ mockFetch.mockResolvedValue(
260
+ createMockResponse({ session_started: true })
261
+ );
262
+
263
+ await client.startSession({
264
+ git_url: 'https://github.com/org/repo',
265
+ });
266
+
267
+ expect(mockFetch).toHaveBeenCalledWith(
268
+ expect.any(String),
269
+ expect.objectContaining({
270
+ body: JSON.stringify({
271
+ git_url: 'https://github.com/org/repo',
272
+ }),
273
+ })
274
+ );
275
+ });
276
+ });
277
+
278
+ describe('heartbeat', () => {
279
+ it('should call correct endpoint', async () => {
280
+ mockFetch.mockResolvedValue(
281
+ createMockResponse({ timestamp: '2026-01-14T10:00:00Z' })
282
+ );
283
+
284
+ await client.heartbeat('session-123');
285
+
286
+ expect(mockFetch).toHaveBeenCalledWith(
287
+ expect.stringContaining('/api/mcp/sessions/heartbeat'),
288
+ expect.objectContaining({
289
+ method: 'POST',
290
+ body: JSON.stringify({ session_id: 'session-123' }),
291
+ })
292
+ );
293
+ });
294
+
295
+ it('should pass worktree path option', async () => {
296
+ mockFetch.mockResolvedValue(
297
+ createMockResponse({ timestamp: '2026-01-14T10:00:00Z' })
298
+ );
299
+
300
+ await client.heartbeat('session-123', {
301
+ current_worktree_path: '../project-task-abc',
302
+ });
303
+
304
+ expect(mockFetch).toHaveBeenCalledWith(
305
+ expect.any(String),
306
+ expect.objectContaining({
307
+ body: JSON.stringify({
308
+ session_id: 'session-123',
309
+ current_worktree_path: '../project-task-abc',
310
+ }),
311
+ })
312
+ );
313
+ });
314
+ });
315
+
316
+ describe('endSession', () => {
317
+ it('should call correct endpoint', async () => {
318
+ mockFetch.mockResolvedValue(
319
+ createMockResponse({ success: true })
320
+ );
321
+
322
+ await client.endSession('session-123');
323
+
324
+ expect(mockFetch).toHaveBeenCalledWith(
325
+ expect.stringContaining('/api/mcp/sessions/end'),
326
+ expect.objectContaining({
327
+ method: 'POST',
328
+ body: JSON.stringify({ session_id: 'session-123' }),
329
+ })
330
+ );
331
+ });
332
+ });
333
+
334
+ // ============================================================================
335
+ // Project Endpoints
336
+ // ============================================================================
337
+
338
+ describe('listProjects', () => {
339
+ it('should call correct endpoint', async () => {
340
+ mockFetch.mockResolvedValue(
341
+ createMockResponse({ projects: [] })
342
+ );
343
+
344
+ await client.listProjects();
345
+
346
+ expect(mockFetch).toHaveBeenCalledWith(
347
+ expect.stringContaining('/api/mcp/projects'),
348
+ expect.objectContaining({ method: 'GET' })
349
+ );
350
+ });
351
+ });
352
+
353
+ describe('getProject', () => {
354
+ it('should call correct endpoint with project ID', async () => {
355
+ mockFetch.mockResolvedValue(
356
+ createMockResponse({ project: { id: 'proj-123', name: 'Test' } })
357
+ );
358
+
359
+ await client.getProject('proj-123');
360
+
361
+ expect(mockFetch).toHaveBeenCalledWith(
362
+ expect.stringContaining('/api/mcp/projects/proj-123'),
363
+ expect.objectContaining({ method: 'GET' })
364
+ );
365
+ });
366
+
367
+ it('should include git_url param when provided', async () => {
368
+ mockFetch.mockResolvedValue(
369
+ createMockResponse({ project: { id: 'proj-123' } })
370
+ );
371
+
372
+ await client.getProject('proj-123', 'https://github.com/org/repo');
373
+
374
+ expect(mockFetch).toHaveBeenCalledWith(
375
+ expect.stringContaining('git_url=https'),
376
+ expect.any(Object)
377
+ );
378
+ });
379
+ });
380
+
381
+ describe('createProject', () => {
382
+ it('should call correct endpoint', async () => {
383
+ mockFetch.mockResolvedValue(
384
+ createMockResponse({ project: { id: 'new-proj' } })
385
+ );
386
+
387
+ await client.createProject({
388
+ name: 'New Project',
389
+ description: 'Test description',
390
+ });
391
+
392
+ expect(mockFetch).toHaveBeenCalledWith(
393
+ expect.stringContaining('/api/mcp/projects'),
394
+ expect.objectContaining({
395
+ method: 'POST',
396
+ body: JSON.stringify({
397
+ name: 'New Project',
398
+ description: 'Test description',
399
+ }),
400
+ })
401
+ );
402
+ });
403
+ });
404
+
405
+ describe('updateProject', () => {
406
+ it('should call correct endpoint', async () => {
407
+ mockFetch.mockResolvedValue(
408
+ createMockResponse({ success: true })
409
+ );
410
+
411
+ await client.updateProject('proj-123', {
412
+ name: 'Updated Name',
413
+ status: 'active',
414
+ });
415
+
416
+ expect(mockFetch).toHaveBeenCalledWith(
417
+ expect.stringContaining('/api/mcp/projects/proj-123'),
418
+ expect.objectContaining({
419
+ method: 'PATCH',
420
+ body: JSON.stringify({
421
+ name: 'Updated Name',
422
+ status: 'active',
423
+ }),
424
+ })
425
+ );
426
+ });
427
+ });
428
+
429
+ // ============================================================================
430
+ // Task Endpoints
431
+ // ============================================================================
432
+
433
+ describe('getTasks', () => {
434
+ it('should call correct endpoint', async () => {
435
+ mockFetch.mockResolvedValue(
436
+ createMockResponse({ tasks: [] })
437
+ );
438
+
439
+ await client.getTasks('proj-123');
440
+
441
+ expect(mockFetch).toHaveBeenCalledWith(
442
+ expect.stringContaining('/api/mcp/projects/proj-123/tasks'),
443
+ expect.objectContaining({ method: 'GET' })
444
+ );
445
+ });
446
+
447
+ it('should include filter params', async () => {
448
+ mockFetch.mockResolvedValue(
449
+ createMockResponse({ tasks: [] })
450
+ );
451
+
452
+ await client.getTasks('proj-123', {
453
+ status: 'in_progress',
454
+ limit: 10,
455
+ });
456
+
457
+ const url = mockFetch.mock.calls[0][0] as string;
458
+ expect(url).toContain('status=in_progress');
459
+ expect(url).toContain('limit=10');
460
+ });
461
+ });
462
+
463
+ describe('createTask', () => {
464
+ it('should call correct endpoint', async () => {
465
+ mockFetch.mockResolvedValue(
466
+ createMockResponse({ task: { id: 'task-123' } })
467
+ );
468
+
469
+ await client.createTask('proj-123', {
470
+ title: 'New Task',
471
+ priority: 2,
472
+ });
473
+
474
+ expect(mockFetch).toHaveBeenCalledWith(
475
+ expect.stringContaining('/api/mcp/projects/proj-123/tasks'),
476
+ expect.objectContaining({
477
+ method: 'POST',
478
+ body: JSON.stringify({
479
+ title: 'New Task',
480
+ priority: 2,
481
+ }),
482
+ })
483
+ );
484
+ });
485
+ });
486
+
487
+ describe('updateTask', () => {
488
+ it('should call correct endpoint', async () => {
489
+ mockFetch.mockResolvedValue(
490
+ createMockResponse({ success: true })
491
+ );
492
+
493
+ await client.updateTask('task-123', {
494
+ status: 'in_progress',
495
+ progress_percentage: 50,
496
+ });
497
+
498
+ expect(mockFetch).toHaveBeenCalledWith(
499
+ expect.stringContaining('/api/mcp/tasks/task-123'),
500
+ expect.objectContaining({
501
+ method: 'PATCH',
502
+ body: JSON.stringify({
503
+ status: 'in_progress',
504
+ progress_percentage: 50,
505
+ }),
506
+ })
507
+ );
508
+ });
509
+ });
510
+
511
+ describe('completeTask', () => {
512
+ it('should call proxy endpoint', async () => {
513
+ mockFetch.mockResolvedValue(
514
+ createMockResponse({ success: true })
515
+ );
516
+
517
+ await client.completeTask('task-123', {
518
+ summary: 'Task completed successfully',
519
+ });
520
+
521
+ // completeTask uses proxy endpoint for consistency (direct endpoint had Vercel routing issues)
522
+ expect(mockFetch).toHaveBeenCalledWith(
523
+ expect.stringContaining('/api/mcp/proxy'),
524
+ expect.objectContaining({
525
+ method: 'POST',
526
+ body: JSON.stringify({
527
+ operation: 'complete_task',
528
+ args: {
529
+ task_id: 'task-123',
530
+ summary: 'Task completed successfully',
531
+ },
532
+ }),
533
+ })
534
+ );
535
+ });
536
+ });
537
+
538
+ describe('deleteTask', () => {
539
+ it('should call correct endpoint', async () => {
540
+ mockFetch.mockResolvedValue(
541
+ createMockResponse({ success: true })
542
+ );
543
+
544
+ await client.deleteTask('task-123');
545
+
546
+ expect(mockFetch).toHaveBeenCalledWith(
547
+ expect.stringContaining('/api/mcp/tasks/task-123'),
548
+ expect.objectContaining({ method: 'DELETE' })
549
+ );
550
+ });
551
+ });
552
+
553
+ describe('getNextTask', () => {
554
+ it('should call correct endpoint', async () => {
555
+ mockFetch.mockResolvedValue(
556
+ createMockResponse({ task: { id: 'task-123', title: 'Next task' } })
557
+ );
558
+
559
+ await client.getNextTask('proj-123');
560
+
561
+ expect(mockFetch).toHaveBeenCalledWith(
562
+ expect.stringContaining('/api/mcp/projects/proj-123/next-task'),
563
+ expect.objectContaining({ method: 'GET' })
564
+ );
565
+ });
566
+
567
+ it('should include session_id when provided', async () => {
568
+ mockFetch.mockResolvedValue(
569
+ createMockResponse({ task: null })
570
+ );
571
+
572
+ await client.getNextTask('proj-123', 'session-456');
573
+
574
+ const url = mockFetch.mock.calls[0][0] as string;
575
+ expect(url).toContain('session_id=session-456');
576
+ });
577
+ });
578
+
579
+ // ============================================================================
580
+ // Blocker Endpoints
581
+ // ============================================================================
582
+
583
+ describe('getBlockers', () => {
584
+ it('should call correct endpoint', async () => {
585
+ mockFetch.mockResolvedValue(
586
+ createMockResponse({ blockers: [] })
587
+ );
588
+
589
+ await client.getBlockers('proj-123');
590
+
591
+ expect(mockFetch).toHaveBeenCalledWith(
592
+ expect.stringContaining('/api/mcp/proxy'),
593
+ expect.objectContaining({ method: 'POST' })
594
+ );
595
+ });
596
+ });
597
+
598
+ describe('addBlocker', () => {
599
+ it('should call correct endpoint', async () => {
600
+ mockFetch.mockResolvedValue(
601
+ createMockResponse({ blocker_id: 'blocker-123' })
602
+ );
603
+
604
+ await client.addBlocker('proj-123', 'Blocked by dependency');
605
+
606
+ expect(mockFetch).toHaveBeenCalledWith(
607
+ expect.stringContaining('/api/mcp/proxy'),
608
+ expect.objectContaining({ method: 'POST' })
609
+ );
610
+ });
611
+ });
612
+
613
+ // ============================================================================
614
+ // Validation Endpoints
615
+ // ============================================================================
616
+
617
+ describe('getTasksAwaitingValidation', () => {
618
+ it('should call correct endpoint', async () => {
619
+ mockFetch.mockResolvedValue(
620
+ createMockResponse({ tasks: [] })
621
+ );
622
+
623
+ await client.getTasksAwaitingValidation('proj-123');
624
+
625
+ expect(mockFetch).toHaveBeenCalledWith(
626
+ expect.stringContaining('/api/mcp/proxy'),
627
+ expect.objectContaining({ method: 'POST' })
628
+ );
629
+ });
630
+ });
631
+
632
+ describe('validateTask', () => {
633
+ it('should call correct endpoint', async () => {
634
+ mockFetch.mockResolvedValue(
635
+ createMockResponse({ success: true })
636
+ );
637
+
638
+ await client.validateTask('task-123', {
639
+ approved: true,
640
+ validation_notes: 'All tests pass',
641
+ });
642
+
643
+ expect(mockFetch).toHaveBeenCalledWith(
644
+ expect.stringContaining('/api/mcp/proxy'),
645
+ expect.objectContaining({ method: 'POST' })
646
+ );
647
+ });
648
+ });
649
+
650
+ // ============================================================================
651
+ // Proxy Endpoint
652
+ // ============================================================================
653
+
654
+ describe('proxy', () => {
655
+ it('should call proxy endpoint with operation', async () => {
656
+ mockFetch.mockResolvedValue(
657
+ createMockResponse({ result: 'success' })
658
+ );
659
+
660
+ await client.proxy('custom_operation', { param1: 'value1' });
661
+
662
+ expect(mockFetch).toHaveBeenCalledWith(
663
+ expect.stringContaining('/api/mcp/proxy'),
664
+ expect.objectContaining({
665
+ method: 'POST',
666
+ body: expect.stringContaining('custom_operation'),
667
+ })
668
+ );
669
+ });
670
+
671
+ it('should pass session context when provided', async () => {
672
+ mockFetch.mockResolvedValue(
673
+ createMockResponse({ result: 'success' })
674
+ );
675
+
676
+ await client.proxy(
677
+ 'operation',
678
+ { arg: 'value' },
679
+ { sessionId: 'session-123', persona: 'Wave' }
680
+ );
681
+
682
+ expect(mockFetch).toHaveBeenCalledWith(
683
+ expect.any(String),
684
+ expect.objectContaining({
685
+ body: expect.stringContaining('session-123'),
686
+ })
687
+ );
688
+ });
689
+ });
690
+
691
+ // ============================================================================
692
+ // Error Handling Edge Cases
693
+ // ============================================================================
694
+
695
+ describe('error handling edge cases', () => {
696
+ it('should handle JSON parse error in response', async () => {
697
+ mockFetch.mockResolvedValue({
698
+ ok: true,
699
+ status: 200,
700
+ json: vi.fn().mockRejectedValue(new SyntaxError('Invalid JSON')),
701
+ });
702
+
703
+ const result = await client.validateAuth();
704
+
705
+ expect(result.ok).toBe(false);
706
+ expect(result.error).toContain('Invalid JSON');
707
+ });
708
+
709
+ it('should handle timeout errors', async () => {
710
+ const timeoutError = new Error('Request timeout');
711
+ timeoutError.name = 'AbortError';
712
+ mockFetch.mockRejectedValue(timeoutError);
713
+
714
+ const result = await client.validateAuth();
715
+
716
+ expect(result).toEqual({
717
+ ok: false,
718
+ status: 0,
719
+ error: 'Request timeout',
720
+ });
721
+ });
722
+ });
723
+ });