@vibescope/mcp-server 0.2.1 → 0.2.2
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.
- package/README.md +60 -7
- package/dist/api-client.d.ts +187 -0
- package/dist/api-client.js +48 -0
- package/dist/handlers/blockers.js +9 -8
- package/dist/handlers/bodies-of-work.js +14 -14
- package/dist/handlers/connectors.d.ts +45 -0
- package/dist/handlers/connectors.js +183 -0
- package/dist/handlers/cost.d.ts +10 -0
- package/dist/handlers/cost.js +54 -0
- package/dist/handlers/decisions.js +3 -3
- package/dist/handlers/deployment.js +35 -19
- package/dist/handlers/discovery.d.ts +7 -0
- package/dist/handlers/discovery.js +61 -2
- package/dist/handlers/fallback.js +5 -4
- package/dist/handlers/file-checkouts.d.ts +2 -0
- package/dist/handlers/file-checkouts.js +38 -6
- package/dist/handlers/findings.js +13 -12
- package/dist/handlers/git-issues.js +4 -4
- package/dist/handlers/ideas.js +5 -5
- package/dist/handlers/index.d.ts +1 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/milestones.js +5 -5
- package/dist/handlers/organizations.js +13 -13
- package/dist/handlers/progress.js +2 -2
- package/dist/handlers/project.js +6 -6
- package/dist/handlers/requests.js +3 -3
- package/dist/handlers/session.js +28 -9
- package/dist/handlers/sprints.js +17 -17
- package/dist/handlers/tasks.d.ts +2 -0
- package/dist/handlers/tasks.js +78 -20
- package/dist/handlers/types.d.ts +64 -2
- package/dist/handlers/types.js +48 -1
- package/dist/handlers/validation.js +3 -3
- package/dist/index.js +7 -2716
- package/dist/token-tracking.d.ts +74 -0
- package/dist/token-tracking.js +122 -0
- package/dist/tools.js +298 -9
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +17 -0
- package/docs/TOOLS.md +2053 -0
- package/package.json +4 -1
- package/scripts/generate-docs.ts +212 -0
- package/src/api-client.test.ts +718 -0
- package/src/api-client.ts +231 -0
- package/src/handlers/__test-setup__.ts +9 -0
- package/src/handlers/blockers.test.ts +31 -19
- package/src/handlers/blockers.ts +9 -8
- package/src/handlers/bodies-of-work.test.ts +55 -32
- package/src/handlers/bodies-of-work.ts +14 -14
- package/src/handlers/connectors.test.ts +834 -0
- package/src/handlers/connectors.ts +229 -0
- package/src/handlers/cost.ts +66 -0
- package/src/handlers/decisions.test.ts +34 -25
- package/src/handlers/decisions.ts +3 -3
- package/src/handlers/deployment.ts +39 -19
- package/src/handlers/discovery.ts +61 -2
- package/src/handlers/fallback.test.ts +26 -22
- package/src/handlers/fallback.ts +5 -4
- package/src/handlers/file-checkouts.test.ts +242 -49
- package/src/handlers/file-checkouts.ts +44 -6
- package/src/handlers/findings.test.ts +38 -24
- package/src/handlers/findings.ts +13 -12
- package/src/handlers/git-issues.test.ts +51 -43
- package/src/handlers/git-issues.ts +4 -4
- package/src/handlers/ideas.test.ts +28 -23
- package/src/handlers/ideas.ts +5 -5
- package/src/handlers/index.ts +3 -0
- package/src/handlers/milestones.test.ts +33 -28
- package/src/handlers/milestones.ts +5 -5
- package/src/handlers/organizations.test.ts +104 -83
- package/src/handlers/organizations.ts +13 -13
- package/src/handlers/progress.test.ts +20 -14
- package/src/handlers/progress.ts +2 -2
- package/src/handlers/project.test.ts +34 -27
- package/src/handlers/project.ts +6 -6
- package/src/handlers/requests.test.ts +27 -18
- package/src/handlers/requests.ts +3 -3
- package/src/handlers/session.test.ts +47 -0
- package/src/handlers/session.ts +32 -9
- package/src/handlers/sprints.test.ts +71 -50
- package/src/handlers/sprints.ts +17 -17
- package/src/handlers/tasks.test.ts +77 -15
- package/src/handlers/tasks.ts +90 -21
- package/src/handlers/tool-categories.test.ts +66 -0
- package/src/handlers/types.ts +81 -2
- package/src/handlers/validation.test.ts +78 -45
- package/src/handlers/validation.ts +3 -3
- package/src/index.ts +12 -2732
- package/src/token-tracking.test.ts +453 -0
- package/src/token-tracking.ts +164 -0
- package/src/tools.ts +298 -9
- package/src/utils.test.ts +2 -2
- package/src/utils.ts +17 -0
|
@@ -0,0 +1,718 @@
|
|
|
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 correct 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
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
522
|
+
expect.stringContaining('/api/mcp/tasks/task-123/complete'),
|
|
523
|
+
expect.objectContaining({
|
|
524
|
+
method: 'POST',
|
|
525
|
+
body: JSON.stringify({
|
|
526
|
+
summary: 'Task completed successfully',
|
|
527
|
+
}),
|
|
528
|
+
})
|
|
529
|
+
);
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
describe('deleteTask', () => {
|
|
534
|
+
it('should call correct endpoint', async () => {
|
|
535
|
+
mockFetch.mockResolvedValue(
|
|
536
|
+
createMockResponse({ success: true })
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
await client.deleteTask('task-123');
|
|
540
|
+
|
|
541
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
542
|
+
expect.stringContaining('/api/mcp/tasks/task-123'),
|
|
543
|
+
expect.objectContaining({ method: 'DELETE' })
|
|
544
|
+
);
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
describe('getNextTask', () => {
|
|
549
|
+
it('should call correct endpoint', async () => {
|
|
550
|
+
mockFetch.mockResolvedValue(
|
|
551
|
+
createMockResponse({ task: { id: 'task-123', title: 'Next task' } })
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
await client.getNextTask('proj-123');
|
|
555
|
+
|
|
556
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
557
|
+
expect.stringContaining('/api/mcp/projects/proj-123/next-task'),
|
|
558
|
+
expect.objectContaining({ method: 'GET' })
|
|
559
|
+
);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it('should include session_id when provided', async () => {
|
|
563
|
+
mockFetch.mockResolvedValue(
|
|
564
|
+
createMockResponse({ task: null })
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
await client.getNextTask('proj-123', 'session-456');
|
|
568
|
+
|
|
569
|
+
const url = mockFetch.mock.calls[0][0] as string;
|
|
570
|
+
expect(url).toContain('session_id=session-456');
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// ============================================================================
|
|
575
|
+
// Blocker Endpoints
|
|
576
|
+
// ============================================================================
|
|
577
|
+
|
|
578
|
+
describe('getBlockers', () => {
|
|
579
|
+
it('should call correct endpoint', async () => {
|
|
580
|
+
mockFetch.mockResolvedValue(
|
|
581
|
+
createMockResponse({ blockers: [] })
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
await client.getBlockers('proj-123');
|
|
585
|
+
|
|
586
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
587
|
+
expect.stringContaining('/api/mcp/proxy'),
|
|
588
|
+
expect.objectContaining({ method: 'POST' })
|
|
589
|
+
);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
describe('addBlocker', () => {
|
|
594
|
+
it('should call correct endpoint', async () => {
|
|
595
|
+
mockFetch.mockResolvedValue(
|
|
596
|
+
createMockResponse({ blocker_id: 'blocker-123' })
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
await client.addBlocker('proj-123', 'Blocked by dependency');
|
|
600
|
+
|
|
601
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
602
|
+
expect.stringContaining('/api/mcp/proxy'),
|
|
603
|
+
expect.objectContaining({ method: 'POST' })
|
|
604
|
+
);
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// ============================================================================
|
|
609
|
+
// Validation Endpoints
|
|
610
|
+
// ============================================================================
|
|
611
|
+
|
|
612
|
+
describe('getTasksAwaitingValidation', () => {
|
|
613
|
+
it('should call correct endpoint', async () => {
|
|
614
|
+
mockFetch.mockResolvedValue(
|
|
615
|
+
createMockResponse({ tasks: [] })
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
await client.getTasksAwaitingValidation('proj-123');
|
|
619
|
+
|
|
620
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
621
|
+
expect.stringContaining('/api/mcp/proxy'),
|
|
622
|
+
expect.objectContaining({ method: 'POST' })
|
|
623
|
+
);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
describe('validateTask', () => {
|
|
628
|
+
it('should call correct endpoint', async () => {
|
|
629
|
+
mockFetch.mockResolvedValue(
|
|
630
|
+
createMockResponse({ success: true })
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
await client.validateTask('task-123', {
|
|
634
|
+
approved: true,
|
|
635
|
+
validation_notes: 'All tests pass',
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
639
|
+
expect.stringContaining('/api/mcp/proxy'),
|
|
640
|
+
expect.objectContaining({ method: 'POST' })
|
|
641
|
+
);
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
// ============================================================================
|
|
646
|
+
// Proxy Endpoint
|
|
647
|
+
// ============================================================================
|
|
648
|
+
|
|
649
|
+
describe('proxy', () => {
|
|
650
|
+
it('should call proxy endpoint with operation', async () => {
|
|
651
|
+
mockFetch.mockResolvedValue(
|
|
652
|
+
createMockResponse({ result: 'success' })
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
await client.proxy('custom_operation', { param1: 'value1' });
|
|
656
|
+
|
|
657
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
658
|
+
expect.stringContaining('/api/mcp/proxy'),
|
|
659
|
+
expect.objectContaining({
|
|
660
|
+
method: 'POST',
|
|
661
|
+
body: expect.stringContaining('custom_operation'),
|
|
662
|
+
})
|
|
663
|
+
);
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it('should pass session context when provided', async () => {
|
|
667
|
+
mockFetch.mockResolvedValue(
|
|
668
|
+
createMockResponse({ result: 'success' })
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
await client.proxy(
|
|
672
|
+
'operation',
|
|
673
|
+
{ arg: 'value' },
|
|
674
|
+
{ sessionId: 'session-123', persona: 'Wave' }
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
678
|
+
expect.any(String),
|
|
679
|
+
expect.objectContaining({
|
|
680
|
+
body: expect.stringContaining('session-123'),
|
|
681
|
+
})
|
|
682
|
+
);
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
// ============================================================================
|
|
687
|
+
// Error Handling Edge Cases
|
|
688
|
+
// ============================================================================
|
|
689
|
+
|
|
690
|
+
describe('error handling edge cases', () => {
|
|
691
|
+
it('should handle JSON parse error in response', async () => {
|
|
692
|
+
mockFetch.mockResolvedValue({
|
|
693
|
+
ok: true,
|
|
694
|
+
status: 200,
|
|
695
|
+
json: vi.fn().mockRejectedValue(new SyntaxError('Invalid JSON')),
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
const result = await client.validateAuth();
|
|
699
|
+
|
|
700
|
+
expect(result.ok).toBe(false);
|
|
701
|
+
expect(result.error).toContain('Invalid JSON');
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it('should handle timeout errors', async () => {
|
|
705
|
+
const timeoutError = new Error('Request timeout');
|
|
706
|
+
timeoutError.name = 'AbortError';
|
|
707
|
+
mockFetch.mockRejectedValue(timeoutError);
|
|
708
|
+
|
|
709
|
+
const result = await client.validateAuth();
|
|
710
|
+
|
|
711
|
+
expect(result).toEqual({
|
|
712
|
+
ok: false,
|
|
713
|
+
status: 0,
|
|
714
|
+
error: 'Request timeout',
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
});
|