@vibescope/mcp-server 0.2.5 → 0.2.6

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 (82) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/cli.js +26 -26
  4. package/dist/handlers/tool-docs.js +828 -828
  5. package/dist/index.js +73 -73
  6. package/dist/templates/agent-guidelines.js +185 -185
  7. package/dist/token-tracking.js +4 -2
  8. package/dist/tools.js +65 -65
  9. package/dist/utils.js +11 -11
  10. package/docs/TOOLS.md +2053 -2053
  11. package/package.json +1 -1
  12. package/scripts/generate-docs.ts +212 -212
  13. package/scripts/version-bump.ts +203 -203
  14. package/src/api-client.test.ts +723 -723
  15. package/src/api-client.ts +2499 -2499
  16. package/src/cli.ts +212 -212
  17. package/src/handlers/__test-setup__.ts +236 -236
  18. package/src/handlers/__test-utils__.ts +87 -87
  19. package/src/handlers/blockers.test.ts +468 -468
  20. package/src/handlers/blockers.ts +163 -163
  21. package/src/handlers/bodies-of-work.test.ts +704 -704
  22. package/src/handlers/bodies-of-work.ts +526 -526
  23. package/src/handlers/connectors.test.ts +834 -834
  24. package/src/handlers/connectors.ts +229 -229
  25. package/src/handlers/cost.test.ts +462 -462
  26. package/src/handlers/cost.ts +285 -285
  27. package/src/handlers/decisions.test.ts +382 -382
  28. package/src/handlers/decisions.ts +153 -153
  29. package/src/handlers/deployment.test.ts +551 -551
  30. package/src/handlers/deployment.ts +541 -541
  31. package/src/handlers/discovery.test.ts +206 -206
  32. package/src/handlers/discovery.ts +390 -390
  33. package/src/handlers/fallback.test.ts +537 -537
  34. package/src/handlers/fallback.ts +194 -194
  35. package/src/handlers/file-checkouts.test.ts +750 -750
  36. package/src/handlers/file-checkouts.ts +185 -185
  37. package/src/handlers/findings.test.ts +633 -633
  38. package/src/handlers/findings.ts +239 -239
  39. package/src/handlers/git-issues.test.ts +631 -631
  40. package/src/handlers/git-issues.ts +136 -136
  41. package/src/handlers/ideas.test.ts +644 -644
  42. package/src/handlers/ideas.ts +207 -207
  43. package/src/handlers/index.ts +84 -84
  44. package/src/handlers/milestones.test.ts +475 -475
  45. package/src/handlers/milestones.ts +180 -180
  46. package/src/handlers/organizations.test.ts +826 -826
  47. package/src/handlers/organizations.ts +315 -315
  48. package/src/handlers/progress.test.ts +269 -269
  49. package/src/handlers/progress.ts +77 -77
  50. package/src/handlers/project.test.ts +546 -546
  51. package/src/handlers/project.ts +239 -239
  52. package/src/handlers/requests.test.ts +303 -303
  53. package/src/handlers/requests.ts +99 -99
  54. package/src/handlers/roles.test.ts +303 -303
  55. package/src/handlers/roles.ts +226 -226
  56. package/src/handlers/session.test.ts +875 -875
  57. package/src/handlers/session.ts +738 -738
  58. package/src/handlers/sprints.test.ts +732 -732
  59. package/src/handlers/sprints.ts +537 -537
  60. package/src/handlers/tasks.test.ts +907 -907
  61. package/src/handlers/tasks.ts +945 -945
  62. package/src/handlers/tool-categories.test.ts +66 -66
  63. package/src/handlers/tool-docs.ts +1096 -1096
  64. package/src/handlers/types.test.ts +259 -259
  65. package/src/handlers/types.ts +175 -175
  66. package/src/handlers/validation.test.ts +582 -582
  67. package/src/handlers/validation.ts +97 -97
  68. package/src/index.ts +792 -792
  69. package/src/setup.test.ts +233 -231
  70. package/src/setup.ts +370 -370
  71. package/src/templates/agent-guidelines.ts +210 -210
  72. package/src/token-tracking.test.ts +463 -453
  73. package/src/token-tracking.ts +166 -164
  74. package/src/tools.ts +3562 -3562
  75. package/src/utils.test.ts +683 -683
  76. package/src/utils.ts +436 -436
  77. package/src/validators.test.ts +223 -223
  78. package/src/validators.ts +249 -249
  79. package/tsconfig.json +16 -16
  80. package/vitest.config.ts +14 -14
  81. package/dist/knowledge.d.ts +0 -6
  82. package/dist/knowledge.js +0 -218
@@ -1,723 +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
- });
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
+ });