@vibescope/mcp-server 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/api-client.d.ts +36 -0
  4. package/dist/api-client.js +34 -0
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.js +30 -38
  7. package/dist/handlers/discovery.js +2 -0
  8. package/dist/handlers/session.d.ts +11 -0
  9. package/dist/handlers/session.js +101 -0
  10. package/dist/handlers/tasks.d.ts +8 -0
  11. package/dist/handlers/tasks.js +163 -3
  12. package/dist/handlers/tool-docs.js +840 -828
  13. package/dist/handlers/validation.js +49 -2
  14. package/dist/index.js +73 -73
  15. package/dist/setup.js +6 -6
  16. package/dist/templates/agent-guidelines.js +185 -185
  17. package/dist/templates/help-content.js +1622 -1544
  18. package/dist/tools.js +130 -74
  19. package/dist/utils.d.ts +15 -11
  20. package/dist/utils.js +53 -28
  21. package/docs/TOOLS.md +2407 -2053
  22. package/package.json +51 -51
  23. package/scripts/generate-docs.ts +212 -212
  24. package/scripts/version-bump.ts +203 -203
  25. package/src/api-client.test.ts +723 -723
  26. package/src/api-client.ts +2561 -2499
  27. package/src/cli.test.ts +24 -8
  28. package/src/cli.ts +204 -212
  29. package/src/handlers/__test-setup__.ts +236 -236
  30. package/src/handlers/__test-utils__.ts +87 -87
  31. package/src/handlers/blockers.test.ts +468 -468
  32. package/src/handlers/blockers.ts +163 -163
  33. package/src/handlers/bodies-of-work.test.ts +704 -704
  34. package/src/handlers/bodies-of-work.ts +526 -526
  35. package/src/handlers/connectors.test.ts +834 -834
  36. package/src/handlers/connectors.ts +229 -229
  37. package/src/handlers/cost.test.ts +462 -462
  38. package/src/handlers/cost.ts +285 -285
  39. package/src/handlers/decisions.test.ts +382 -382
  40. package/src/handlers/decisions.ts +153 -153
  41. package/src/handlers/deployment.test.ts +551 -551
  42. package/src/handlers/deployment.ts +541 -541
  43. package/src/handlers/discovery.test.ts +206 -206
  44. package/src/handlers/discovery.ts +392 -390
  45. package/src/handlers/fallback.test.ts +537 -537
  46. package/src/handlers/fallback.ts +194 -194
  47. package/src/handlers/file-checkouts.test.ts +750 -750
  48. package/src/handlers/file-checkouts.ts +185 -185
  49. package/src/handlers/findings.test.ts +633 -633
  50. package/src/handlers/findings.ts +239 -239
  51. package/src/handlers/git-issues.test.ts +631 -631
  52. package/src/handlers/git-issues.ts +136 -136
  53. package/src/handlers/ideas.test.ts +644 -644
  54. package/src/handlers/ideas.ts +207 -207
  55. package/src/handlers/index.ts +84 -84
  56. package/src/handlers/milestones.test.ts +475 -475
  57. package/src/handlers/milestones.ts +180 -180
  58. package/src/handlers/organizations.test.ts +826 -826
  59. package/src/handlers/organizations.ts +315 -315
  60. package/src/handlers/progress.test.ts +269 -269
  61. package/src/handlers/progress.ts +77 -77
  62. package/src/handlers/project.test.ts +546 -546
  63. package/src/handlers/project.ts +239 -239
  64. package/src/handlers/requests.test.ts +303 -303
  65. package/src/handlers/requests.ts +99 -99
  66. package/src/handlers/roles.test.ts +305 -305
  67. package/src/handlers/roles.ts +219 -219
  68. package/src/handlers/session.test.ts +998 -875
  69. package/src/handlers/session.ts +839 -730
  70. package/src/handlers/sprints.test.ts +732 -732
  71. package/src/handlers/sprints.ts +537 -537
  72. package/src/handlers/tasks.test.ts +931 -907
  73. package/src/handlers/tasks.ts +1121 -945
  74. package/src/handlers/tool-categories.test.ts +66 -66
  75. package/src/handlers/tool-docs.ts +1109 -1096
  76. package/src/handlers/types.test.ts +259 -259
  77. package/src/handlers/types.ts +175 -175
  78. package/src/handlers/validation.test.ts +582 -582
  79. package/src/handlers/validation.ts +164 -113
  80. package/src/index.test.ts +674 -0
  81. package/src/index.ts +792 -792
  82. package/src/setup.test.ts +233 -233
  83. package/src/setup.ts +404 -403
  84. package/src/templates/agent-guidelines.ts +210 -210
  85. package/src/templates/help-content.ts +1751 -1673
  86. package/src/token-tracking.test.ts +463 -463
  87. package/src/token-tracking.ts +166 -166
  88. package/src/tools.test.ts +416 -0
  89. package/src/tools.ts +3611 -3555
  90. package/src/utils.test.ts +785 -683
  91. package/src/utils.ts +469 -436
  92. package/src/validators.test.ts +223 -223
  93. package/src/validators.ts +249 -249
  94. package/tsconfig.json +16 -16
  95. package/vitest.config.ts +14 -14
@@ -1,551 +1,551 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import {
3
- claimDeploymentValidation,
4
- reportValidation,
5
- checkDeploymentStatus,
6
- startDeployment,
7
- completeDeployment,
8
- cancelDeployment,
9
- addDeploymentRequirement,
10
- getDeploymentRequirements,
11
- getDeploymentRequirementsStats,
12
- } from './deployment.js';
13
- import { ValidationError } from '../validators.js';
14
- import { createMockContext } from './__test-utils__.js';
15
- import { mockApiClient } from './__test-setup__.js';
16
-
17
- // ============================================================================
18
- // Test Utilities
19
- // ============================================================================
20
-
21
- const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
22
-
23
- // ============================================================================
24
- // claimDeploymentValidation Tests
25
- // ============================================================================
26
-
27
- describe('claimDeploymentValidation', () => {
28
- beforeEach(() => vi.clearAllMocks());
29
-
30
- it('should throw error for missing project_id', async () => {
31
- const ctx = createMockContext();
32
- await expect(claimDeploymentValidation({}, ctx)).rejects.toThrow(ValidationError);
33
- });
34
-
35
- it('should throw error for invalid project_id UUID', async () => {
36
- const ctx = createMockContext();
37
- await expect(
38
- claimDeploymentValidation({ project_id: 'invalid' }, ctx)
39
- ).rejects.toThrow(ValidationError);
40
- });
41
-
42
- it('should return error when no pending deployment', async () => {
43
- mockApiClient.claimDeploymentValidation.mockResolvedValue({
44
- ok: true,
45
- data: { success: false, error: 'No pending deployment found' },
46
- });
47
- const ctx = createMockContext();
48
-
49
- const result = await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
50
-
51
- expect(result.result).toMatchObject({
52
- success: false,
53
- error: 'No pending deployment found',
54
- });
55
- });
56
-
57
- it('should claim deployment successfully', async () => {
58
- mockApiClient.claimDeploymentValidation.mockResolvedValue({
59
- ok: true,
60
- data: { success: true, deployment_id: 'deploy-1' },
61
- });
62
- const ctx = createMockContext();
63
-
64
- const result = await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
65
-
66
- expect(result.result).toMatchObject({
67
- success: true,
68
- deployment_id: 'deploy-1',
69
- });
70
- });
71
-
72
- it('should pass session_id to API client', async () => {
73
- mockApiClient.claimDeploymentValidation.mockResolvedValue({
74
- ok: true,
75
- data: { success: true },
76
- });
77
- const ctx = createMockContext({ sessionId: 'my-session' });
78
-
79
- await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
80
-
81
- expect(mockApiClient.claimDeploymentValidation).toHaveBeenCalledWith(VALID_UUID, 'my-session');
82
- });
83
- });
84
-
85
- // ============================================================================
86
- // reportValidation Tests
87
- // ============================================================================
88
-
89
- describe('reportValidation', () => {
90
- beforeEach(() => vi.clearAllMocks());
91
-
92
- it('should throw error for missing project_id', async () => {
93
- const ctx = createMockContext();
94
- await expect(
95
- reportValidation({ build_passed: true }, ctx)
96
- ).rejects.toThrow(ValidationError);
97
- });
98
-
99
- it('should throw error for missing build_passed', async () => {
100
- const ctx = createMockContext();
101
- await expect(
102
- reportValidation({ project_id: VALID_UUID }, ctx)
103
- ).rejects.toThrow(ValidationError);
104
- });
105
-
106
- it('should return error when no deployment being validated', async () => {
107
- mockApiClient.reportValidation.mockResolvedValue({
108
- ok: true,
109
- data: { success: false, error: 'No deployment being validated. Use claim_deployment_validation first.' },
110
- });
111
- const ctx = createMockContext();
112
-
113
- const result = await reportValidation(
114
- { project_id: VALID_UUID, build_passed: true },
115
- ctx
116
- );
117
-
118
- expect(result.result).toMatchObject({
119
- success: false,
120
- error: 'No deployment being validated. Use claim_deployment_validation first.',
121
- });
122
- });
123
-
124
- it('should report validation successfully', async () => {
125
- mockApiClient.reportValidation.mockResolvedValue({
126
- ok: true,
127
- data: { success: true, status: 'ready' },
128
- });
129
- const ctx = createMockContext();
130
-
131
- const result = await reportValidation(
132
- { project_id: VALID_UUID, build_passed: true, tests_passed: true },
133
- ctx
134
- );
135
-
136
- expect(result.result).toMatchObject({
137
- success: true,
138
- status: 'ready',
139
- });
140
- });
141
- });
142
-
143
- // ============================================================================
144
- // checkDeploymentStatus Tests
145
- // ============================================================================
146
-
147
- describe('checkDeploymentStatus', () => {
148
- beforeEach(() => vi.clearAllMocks());
149
-
150
- it('should throw error for missing project_id', async () => {
151
- const ctx = createMockContext();
152
- await expect(checkDeploymentStatus({}, ctx)).rejects.toThrow(ValidationError);
153
- });
154
-
155
- it('should return no deployment when none found', async () => {
156
- mockApiClient.checkDeploymentStatus.mockResolvedValue({
157
- ok: true,
158
- data: { has_deployment: false, message: 'No deployments found for this project' },
159
- });
160
- const ctx = createMockContext();
161
-
162
- const result = await checkDeploymentStatus({ project_id: VALID_UUID }, ctx);
163
-
164
- expect(result.result).toMatchObject({
165
- has_deployment: false,
166
- message: 'No deployments found for this project',
167
- });
168
- });
169
-
170
- it('should return deployment details when found', async () => {
171
- const mockDeployment = {
172
- id: 'deploy-1',
173
- status: 'deployed',
174
- environment: 'production',
175
- };
176
- mockApiClient.checkDeploymentStatus.mockResolvedValue({
177
- ok: true,
178
- data: { has_deployment: true, deployment: mockDeployment },
179
- });
180
- const ctx = createMockContext();
181
-
182
- const result = await checkDeploymentStatus({ project_id: VALID_UUID }, ctx);
183
-
184
- expect(result.result).toMatchObject({
185
- has_deployment: true,
186
- });
187
- expect((result.result as { deployment: { id: string } }).deployment.id).toBe('deploy-1');
188
- });
189
- });
190
-
191
- // ============================================================================
192
- // startDeployment Tests
193
- // ============================================================================
194
-
195
- describe('startDeployment', () => {
196
- beforeEach(() => vi.clearAllMocks());
197
-
198
- it('should throw error for missing project_id', async () => {
199
- const ctx = createMockContext();
200
- await expect(startDeployment({}, ctx)).rejects.toThrow(ValidationError);
201
- });
202
-
203
- it('should return error when no deployment ready', async () => {
204
- mockApiClient.startDeployment.mockResolvedValue({
205
- ok: true,
206
- data: { success: false, error: 'No deployment ready. Must pass validation first.' },
207
- });
208
- const ctx = createMockContext();
209
-
210
- const result = await startDeployment({ project_id: VALID_UUID }, ctx);
211
-
212
- expect(result.result).toMatchObject({
213
- success: false,
214
- error: 'No deployment ready. Must pass validation first.',
215
- });
216
- });
217
-
218
- it('should start deployment successfully', async () => {
219
- mockApiClient.startDeployment.mockResolvedValue({
220
- ok: true,
221
- data: { success: true, status: 'deploying' },
222
- });
223
- const ctx = createMockContext();
224
-
225
- const result = await startDeployment({ project_id: VALID_UUID }, ctx);
226
-
227
- expect(result.result).toMatchObject({
228
- success: true,
229
- status: 'deploying',
230
- });
231
- });
232
- });
233
-
234
- // ============================================================================
235
- // completeDeployment Tests
236
- // ============================================================================
237
-
238
- describe('completeDeployment', () => {
239
- beforeEach(() => vi.clearAllMocks());
240
-
241
- it('should throw error for missing project_id', async () => {
242
- const ctx = createMockContext();
243
- await expect(
244
- completeDeployment({ success: true }, ctx)
245
- ).rejects.toThrow(ValidationError);
246
- });
247
-
248
- it('should throw error for missing success', async () => {
249
- const ctx = createMockContext();
250
- await expect(
251
- completeDeployment({ project_id: VALID_UUID }, ctx)
252
- ).rejects.toThrow(ValidationError);
253
- });
254
-
255
- it('should return error when no deployment in progress', async () => {
256
- mockApiClient.completeDeployment.mockResolvedValue({
257
- ok: true,
258
- data: { success: false, error: 'No deployment in progress. Use start_deployment first.' },
259
- });
260
- const ctx = createMockContext();
261
-
262
- const result = await completeDeployment(
263
- { project_id: VALID_UUID, success: true },
264
- ctx
265
- );
266
-
267
- expect(result.result).toMatchObject({
268
- success: false,
269
- error: 'No deployment in progress. Use start_deployment first.',
270
- });
271
- });
272
-
273
- it('should complete deployment successfully', async () => {
274
- mockApiClient.completeDeployment.mockResolvedValue({
275
- ok: true,
276
- data: { success: true, status: 'deployed' },
277
- });
278
- const ctx = createMockContext();
279
-
280
- const result = await completeDeployment(
281
- { project_id: VALID_UUID, success: true, summary: 'Deployed v1.2.0' },
282
- ctx
283
- );
284
-
285
- expect(result.result).toMatchObject({
286
- success: true,
287
- status: 'deployed',
288
- });
289
- });
290
- });
291
-
292
- // ============================================================================
293
- // cancelDeployment Tests
294
- // ============================================================================
295
-
296
- describe('cancelDeployment', () => {
297
- beforeEach(() => vi.clearAllMocks());
298
-
299
- it('should throw error for missing project_id', async () => {
300
- const ctx = createMockContext();
301
- await expect(cancelDeployment({}, ctx)).rejects.toThrow(ValidationError);
302
- });
303
-
304
- it('should return error when no active deployment', async () => {
305
- mockApiClient.cancelDeployment.mockResolvedValue({
306
- ok: true,
307
- data: { success: false, error: 'No active deployment' },
308
- });
309
- const ctx = createMockContext();
310
-
311
- const result = await cancelDeployment({ project_id: VALID_UUID }, ctx);
312
-
313
- expect(result.result).toMatchObject({
314
- success: false,
315
- error: 'No active deployment',
316
- });
317
- });
318
-
319
- it('should cancel deployment successfully', async () => {
320
- mockApiClient.cancelDeployment.mockResolvedValue({
321
- ok: true,
322
- data: { success: true, status: 'failed' },
323
- });
324
- const ctx = createMockContext();
325
-
326
- const result = await cancelDeployment(
327
- { project_id: VALID_UUID, reason: 'Found critical bug' },
328
- ctx
329
- );
330
-
331
- expect(result.result).toMatchObject({
332
- success: true,
333
- status: 'failed',
334
- });
335
- });
336
- });
337
-
338
- // ============================================================================
339
- // addDeploymentRequirement Tests
340
- // ============================================================================
341
-
342
- describe('addDeploymentRequirement', () => {
343
- beforeEach(() => vi.clearAllMocks());
344
-
345
- it('should throw error for missing project_id', async () => {
346
- const ctx = createMockContext();
347
- await expect(
348
- addDeploymentRequirement({ type: 'migration', title: 'Test' }, ctx)
349
- ).rejects.toThrow(ValidationError);
350
- });
351
-
352
- it('should throw error for missing type', async () => {
353
- const ctx = createMockContext();
354
- await expect(
355
- addDeploymentRequirement({ project_id: VALID_UUID, title: 'Test' }, ctx)
356
- ).rejects.toThrow(ValidationError);
357
- });
358
-
359
- it('should throw error for missing title', async () => {
360
- const ctx = createMockContext();
361
- await expect(
362
- addDeploymentRequirement({ project_id: VALID_UUID, type: 'migration' }, ctx)
363
- ).rejects.toThrow(ValidationError);
364
- });
365
-
366
- it('should throw error for invalid type', async () => {
367
- const ctx = createMockContext();
368
- await expect(
369
- addDeploymentRequirement({
370
- project_id: VALID_UUID,
371
- type: 'invalid_type',
372
- title: 'Test',
373
- }, ctx)
374
- ).rejects.toThrow(ValidationError);
375
- });
376
-
377
- it('should throw error for invalid stage', async () => {
378
- const ctx = createMockContext();
379
- await expect(
380
- addDeploymentRequirement({
381
- project_id: VALID_UUID,
382
- type: 'migration',
383
- title: 'Test',
384
- stage: 'invalid_stage',
385
- }, ctx)
386
- ).rejects.toThrow(ValidationError);
387
- });
388
-
389
- it('should add requirement successfully', async () => {
390
- mockApiClient.addDeploymentRequirement.mockResolvedValue({
391
- ok: true,
392
- data: { success: true, requirement_id: 'req-1', stage: 'preparation' },
393
- });
394
- const ctx = createMockContext();
395
-
396
- const result = await addDeploymentRequirement(
397
- {
398
- project_id: VALID_UUID,
399
- type: 'migration',
400
- title: 'Test Migration',
401
- },
402
- ctx
403
- );
404
-
405
- expect(result.result).toMatchObject({
406
- success: true,
407
- requirement_id: 'req-1',
408
- stage: 'preparation',
409
- });
410
- });
411
- });
412
-
413
- // ============================================================================
414
- // getDeploymentRequirements Tests
415
- // ============================================================================
416
-
417
- describe('getDeploymentRequirements', () => {
418
- beforeEach(() => vi.clearAllMocks());
419
-
420
- it('should throw error for missing project_id', async () => {
421
- const ctx = createMockContext();
422
- await expect(getDeploymentRequirements({}, ctx)).rejects.toThrow(ValidationError);
423
- });
424
-
425
- it('should return empty list when no requirements', async () => {
426
- mockApiClient.getDeploymentRequirements.mockResolvedValue({
427
- ok: true,
428
- data: { requirements: [], deployment_blocked: false },
429
- });
430
- const ctx = createMockContext();
431
-
432
- const result = await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
433
-
434
- expect(result.result).toMatchObject({
435
- requirements: [],
436
- deployment_blocked: false,
437
- });
438
- });
439
-
440
- it('should query with correct project_id', async () => {
441
- mockApiClient.getDeploymentRequirements.mockResolvedValue({
442
- ok: true,
443
- data: { requirements: [], deployment_blocked: false },
444
- });
445
- const ctx = createMockContext();
446
-
447
- await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
448
-
449
- expect(mockApiClient.getDeploymentRequirements).toHaveBeenCalledWith(
450
- VALID_UUID,
451
- expect.any(Object)
452
- );
453
- });
454
-
455
- it('should return requirements list', async () => {
456
- const mockReqs = [
457
- { id: 'req-1', type: 'migration', title: 'Run migrations' },
458
- { id: 'req-2', type: 'env_var', title: 'Set API_KEY' },
459
- ];
460
- mockApiClient.getDeploymentRequirements.mockResolvedValue({
461
- ok: true,
462
- data: { requirements: mockReqs, deployment_blocked: true },
463
- });
464
- const ctx = createMockContext();
465
-
466
- const result = await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
467
-
468
- expect((result.result as { requirements: unknown[] }).requirements).toHaveLength(2);
469
- expect(result.result).toHaveProperty('deployment_blocked', true);
470
- });
471
-
472
- it('should pass pagination params to API client', async () => {
473
- mockApiClient.getDeploymentRequirements.mockResolvedValue({
474
- ok: true,
475
- data: { requirements: [], deployment_blocked: false },
476
- });
477
- const ctx = createMockContext();
478
-
479
- await getDeploymentRequirements(
480
- { project_id: VALID_UUID, limit: 10, offset: 5 },
481
- ctx
482
- );
483
-
484
- expect(mockApiClient.getDeploymentRequirements).toHaveBeenCalledWith(
485
- VALID_UUID,
486
- expect.objectContaining({ limit: 10, offset: 5 })
487
- );
488
- });
489
- });
490
-
491
- // ============================================================================
492
- // getDeploymentRequirementsStats Tests
493
- // ============================================================================
494
-
495
- describe('getDeploymentRequirementsStats', () => {
496
- beforeEach(() => vi.clearAllMocks());
497
-
498
- it('should throw error for missing project_id', async () => {
499
- const ctx = createMockContext();
500
- await expect(getDeploymentRequirementsStats({}, ctx)).rejects.toThrow(ValidationError);
501
- });
502
-
503
- it('should throw error for invalid project_id UUID', async () => {
504
- const ctx = createMockContext();
505
- await expect(
506
- getDeploymentRequirementsStats({ project_id: 'invalid' }, ctx)
507
- ).rejects.toThrow(ValidationError);
508
- });
509
-
510
- it('should return stats from API client', async () => {
511
- const mockStats = {
512
- total: 5,
513
- by_status: { pending: 3, completed: 2 },
514
- by_stage: { preparation: 2, deployment: 2, verification: 1 },
515
- by_type: { migration: 2, env_var: 2, manual: 1 },
516
- };
517
- mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
518
- ok: true,
519
- data: mockStats,
520
- });
521
- const ctx = createMockContext();
522
-
523
- const result = await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
524
-
525
- expect(result.result).toMatchObject(mockStats);
526
- });
527
-
528
- it('should call API client with correct project_id', async () => {
529
- mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
530
- ok: true,
531
- data: { total: 0, by_status: {}, by_stage: {}, by_type: {} },
532
- });
533
- const ctx = createMockContext();
534
-
535
- await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
536
-
537
- expect(mockApiClient.getDeploymentRequirementsStats).toHaveBeenCalledWith(VALID_UUID);
538
- });
539
-
540
- it('should handle API error', async () => {
541
- mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
542
- ok: false,
543
- error: 'Database error',
544
- });
545
- const ctx = createMockContext();
546
-
547
- const result = await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
548
-
549
- expect(result.result).toHaveProperty('error');
550
- });
551
- });
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import {
3
+ claimDeploymentValidation,
4
+ reportValidation,
5
+ checkDeploymentStatus,
6
+ startDeployment,
7
+ completeDeployment,
8
+ cancelDeployment,
9
+ addDeploymentRequirement,
10
+ getDeploymentRequirements,
11
+ getDeploymentRequirementsStats,
12
+ } from './deployment.js';
13
+ import { ValidationError } from '../validators.js';
14
+ import { createMockContext } from './__test-utils__.js';
15
+ import { mockApiClient } from './__test-setup__.js';
16
+
17
+ // ============================================================================
18
+ // Test Utilities
19
+ // ============================================================================
20
+
21
+ const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';
22
+
23
+ // ============================================================================
24
+ // claimDeploymentValidation Tests
25
+ // ============================================================================
26
+
27
+ describe('claimDeploymentValidation', () => {
28
+ beforeEach(() => vi.clearAllMocks());
29
+
30
+ it('should throw error for missing project_id', async () => {
31
+ const ctx = createMockContext();
32
+ await expect(claimDeploymentValidation({}, ctx)).rejects.toThrow(ValidationError);
33
+ });
34
+
35
+ it('should throw error for invalid project_id UUID', async () => {
36
+ const ctx = createMockContext();
37
+ await expect(
38
+ claimDeploymentValidation({ project_id: 'invalid' }, ctx)
39
+ ).rejects.toThrow(ValidationError);
40
+ });
41
+
42
+ it('should return error when no pending deployment', async () => {
43
+ mockApiClient.claimDeploymentValidation.mockResolvedValue({
44
+ ok: true,
45
+ data: { success: false, error: 'No pending deployment found' },
46
+ });
47
+ const ctx = createMockContext();
48
+
49
+ const result = await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
50
+
51
+ expect(result.result).toMatchObject({
52
+ success: false,
53
+ error: 'No pending deployment found',
54
+ });
55
+ });
56
+
57
+ it('should claim deployment successfully', async () => {
58
+ mockApiClient.claimDeploymentValidation.mockResolvedValue({
59
+ ok: true,
60
+ data: { success: true, deployment_id: 'deploy-1' },
61
+ });
62
+ const ctx = createMockContext();
63
+
64
+ const result = await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
65
+
66
+ expect(result.result).toMatchObject({
67
+ success: true,
68
+ deployment_id: 'deploy-1',
69
+ });
70
+ });
71
+
72
+ it('should pass session_id to API client', async () => {
73
+ mockApiClient.claimDeploymentValidation.mockResolvedValue({
74
+ ok: true,
75
+ data: { success: true },
76
+ });
77
+ const ctx = createMockContext({ sessionId: 'my-session' });
78
+
79
+ await claimDeploymentValidation({ project_id: VALID_UUID }, ctx);
80
+
81
+ expect(mockApiClient.claimDeploymentValidation).toHaveBeenCalledWith(VALID_UUID, 'my-session');
82
+ });
83
+ });
84
+
85
+ // ============================================================================
86
+ // reportValidation Tests
87
+ // ============================================================================
88
+
89
+ describe('reportValidation', () => {
90
+ beforeEach(() => vi.clearAllMocks());
91
+
92
+ it('should throw error for missing project_id', async () => {
93
+ const ctx = createMockContext();
94
+ await expect(
95
+ reportValidation({ build_passed: true }, ctx)
96
+ ).rejects.toThrow(ValidationError);
97
+ });
98
+
99
+ it('should throw error for missing build_passed', async () => {
100
+ const ctx = createMockContext();
101
+ await expect(
102
+ reportValidation({ project_id: VALID_UUID }, ctx)
103
+ ).rejects.toThrow(ValidationError);
104
+ });
105
+
106
+ it('should return error when no deployment being validated', async () => {
107
+ mockApiClient.reportValidation.mockResolvedValue({
108
+ ok: true,
109
+ data: { success: false, error: 'No deployment being validated. Use claim_deployment_validation first.' },
110
+ });
111
+ const ctx = createMockContext();
112
+
113
+ const result = await reportValidation(
114
+ { project_id: VALID_UUID, build_passed: true },
115
+ ctx
116
+ );
117
+
118
+ expect(result.result).toMatchObject({
119
+ success: false,
120
+ error: 'No deployment being validated. Use claim_deployment_validation first.',
121
+ });
122
+ });
123
+
124
+ it('should report validation successfully', async () => {
125
+ mockApiClient.reportValidation.mockResolvedValue({
126
+ ok: true,
127
+ data: { success: true, status: 'ready' },
128
+ });
129
+ const ctx = createMockContext();
130
+
131
+ const result = await reportValidation(
132
+ { project_id: VALID_UUID, build_passed: true, tests_passed: true },
133
+ ctx
134
+ );
135
+
136
+ expect(result.result).toMatchObject({
137
+ success: true,
138
+ status: 'ready',
139
+ });
140
+ });
141
+ });
142
+
143
+ // ============================================================================
144
+ // checkDeploymentStatus Tests
145
+ // ============================================================================
146
+
147
+ describe('checkDeploymentStatus', () => {
148
+ beforeEach(() => vi.clearAllMocks());
149
+
150
+ it('should throw error for missing project_id', async () => {
151
+ const ctx = createMockContext();
152
+ await expect(checkDeploymentStatus({}, ctx)).rejects.toThrow(ValidationError);
153
+ });
154
+
155
+ it('should return no deployment when none found', async () => {
156
+ mockApiClient.checkDeploymentStatus.mockResolvedValue({
157
+ ok: true,
158
+ data: { has_deployment: false, message: 'No deployments found for this project' },
159
+ });
160
+ const ctx = createMockContext();
161
+
162
+ const result = await checkDeploymentStatus({ project_id: VALID_UUID }, ctx);
163
+
164
+ expect(result.result).toMatchObject({
165
+ has_deployment: false,
166
+ message: 'No deployments found for this project',
167
+ });
168
+ });
169
+
170
+ it('should return deployment details when found', async () => {
171
+ const mockDeployment = {
172
+ id: 'deploy-1',
173
+ status: 'deployed',
174
+ environment: 'production',
175
+ };
176
+ mockApiClient.checkDeploymentStatus.mockResolvedValue({
177
+ ok: true,
178
+ data: { has_deployment: true, deployment: mockDeployment },
179
+ });
180
+ const ctx = createMockContext();
181
+
182
+ const result = await checkDeploymentStatus({ project_id: VALID_UUID }, ctx);
183
+
184
+ expect(result.result).toMatchObject({
185
+ has_deployment: true,
186
+ });
187
+ expect((result.result as { deployment: { id: string } }).deployment.id).toBe('deploy-1');
188
+ });
189
+ });
190
+
191
+ // ============================================================================
192
+ // startDeployment Tests
193
+ // ============================================================================
194
+
195
+ describe('startDeployment', () => {
196
+ beforeEach(() => vi.clearAllMocks());
197
+
198
+ it('should throw error for missing project_id', async () => {
199
+ const ctx = createMockContext();
200
+ await expect(startDeployment({}, ctx)).rejects.toThrow(ValidationError);
201
+ });
202
+
203
+ it('should return error when no deployment ready', async () => {
204
+ mockApiClient.startDeployment.mockResolvedValue({
205
+ ok: true,
206
+ data: { success: false, error: 'No deployment ready. Must pass validation first.' },
207
+ });
208
+ const ctx = createMockContext();
209
+
210
+ const result = await startDeployment({ project_id: VALID_UUID }, ctx);
211
+
212
+ expect(result.result).toMatchObject({
213
+ success: false,
214
+ error: 'No deployment ready. Must pass validation first.',
215
+ });
216
+ });
217
+
218
+ it('should start deployment successfully', async () => {
219
+ mockApiClient.startDeployment.mockResolvedValue({
220
+ ok: true,
221
+ data: { success: true, status: 'deploying' },
222
+ });
223
+ const ctx = createMockContext();
224
+
225
+ const result = await startDeployment({ project_id: VALID_UUID }, ctx);
226
+
227
+ expect(result.result).toMatchObject({
228
+ success: true,
229
+ status: 'deploying',
230
+ });
231
+ });
232
+ });
233
+
234
+ // ============================================================================
235
+ // completeDeployment Tests
236
+ // ============================================================================
237
+
238
+ describe('completeDeployment', () => {
239
+ beforeEach(() => vi.clearAllMocks());
240
+
241
+ it('should throw error for missing project_id', async () => {
242
+ const ctx = createMockContext();
243
+ await expect(
244
+ completeDeployment({ success: true }, ctx)
245
+ ).rejects.toThrow(ValidationError);
246
+ });
247
+
248
+ it('should throw error for missing success', async () => {
249
+ const ctx = createMockContext();
250
+ await expect(
251
+ completeDeployment({ project_id: VALID_UUID }, ctx)
252
+ ).rejects.toThrow(ValidationError);
253
+ });
254
+
255
+ it('should return error when no deployment in progress', async () => {
256
+ mockApiClient.completeDeployment.mockResolvedValue({
257
+ ok: true,
258
+ data: { success: false, error: 'No deployment in progress. Use start_deployment first.' },
259
+ });
260
+ const ctx = createMockContext();
261
+
262
+ const result = await completeDeployment(
263
+ { project_id: VALID_UUID, success: true },
264
+ ctx
265
+ );
266
+
267
+ expect(result.result).toMatchObject({
268
+ success: false,
269
+ error: 'No deployment in progress. Use start_deployment first.',
270
+ });
271
+ });
272
+
273
+ it('should complete deployment successfully', async () => {
274
+ mockApiClient.completeDeployment.mockResolvedValue({
275
+ ok: true,
276
+ data: { success: true, status: 'deployed' },
277
+ });
278
+ const ctx = createMockContext();
279
+
280
+ const result = await completeDeployment(
281
+ { project_id: VALID_UUID, success: true, summary: 'Deployed v1.2.0' },
282
+ ctx
283
+ );
284
+
285
+ expect(result.result).toMatchObject({
286
+ success: true,
287
+ status: 'deployed',
288
+ });
289
+ });
290
+ });
291
+
292
+ // ============================================================================
293
+ // cancelDeployment Tests
294
+ // ============================================================================
295
+
296
+ describe('cancelDeployment', () => {
297
+ beforeEach(() => vi.clearAllMocks());
298
+
299
+ it('should throw error for missing project_id', async () => {
300
+ const ctx = createMockContext();
301
+ await expect(cancelDeployment({}, ctx)).rejects.toThrow(ValidationError);
302
+ });
303
+
304
+ it('should return error when no active deployment', async () => {
305
+ mockApiClient.cancelDeployment.mockResolvedValue({
306
+ ok: true,
307
+ data: { success: false, error: 'No active deployment' },
308
+ });
309
+ const ctx = createMockContext();
310
+
311
+ const result = await cancelDeployment({ project_id: VALID_UUID }, ctx);
312
+
313
+ expect(result.result).toMatchObject({
314
+ success: false,
315
+ error: 'No active deployment',
316
+ });
317
+ });
318
+
319
+ it('should cancel deployment successfully', async () => {
320
+ mockApiClient.cancelDeployment.mockResolvedValue({
321
+ ok: true,
322
+ data: { success: true, status: 'failed' },
323
+ });
324
+ const ctx = createMockContext();
325
+
326
+ const result = await cancelDeployment(
327
+ { project_id: VALID_UUID, reason: 'Found critical bug' },
328
+ ctx
329
+ );
330
+
331
+ expect(result.result).toMatchObject({
332
+ success: true,
333
+ status: 'failed',
334
+ });
335
+ });
336
+ });
337
+
338
+ // ============================================================================
339
+ // addDeploymentRequirement Tests
340
+ // ============================================================================
341
+
342
+ describe('addDeploymentRequirement', () => {
343
+ beforeEach(() => vi.clearAllMocks());
344
+
345
+ it('should throw error for missing project_id', async () => {
346
+ const ctx = createMockContext();
347
+ await expect(
348
+ addDeploymentRequirement({ type: 'migration', title: 'Test' }, ctx)
349
+ ).rejects.toThrow(ValidationError);
350
+ });
351
+
352
+ it('should throw error for missing type', async () => {
353
+ const ctx = createMockContext();
354
+ await expect(
355
+ addDeploymentRequirement({ project_id: VALID_UUID, title: 'Test' }, ctx)
356
+ ).rejects.toThrow(ValidationError);
357
+ });
358
+
359
+ it('should throw error for missing title', async () => {
360
+ const ctx = createMockContext();
361
+ await expect(
362
+ addDeploymentRequirement({ project_id: VALID_UUID, type: 'migration' }, ctx)
363
+ ).rejects.toThrow(ValidationError);
364
+ });
365
+
366
+ it('should throw error for invalid type', async () => {
367
+ const ctx = createMockContext();
368
+ await expect(
369
+ addDeploymentRequirement({
370
+ project_id: VALID_UUID,
371
+ type: 'invalid_type',
372
+ title: 'Test',
373
+ }, ctx)
374
+ ).rejects.toThrow(ValidationError);
375
+ });
376
+
377
+ it('should throw error for invalid stage', async () => {
378
+ const ctx = createMockContext();
379
+ await expect(
380
+ addDeploymentRequirement({
381
+ project_id: VALID_UUID,
382
+ type: 'migration',
383
+ title: 'Test',
384
+ stage: 'invalid_stage',
385
+ }, ctx)
386
+ ).rejects.toThrow(ValidationError);
387
+ });
388
+
389
+ it('should add requirement successfully', async () => {
390
+ mockApiClient.addDeploymentRequirement.mockResolvedValue({
391
+ ok: true,
392
+ data: { success: true, requirement_id: 'req-1', stage: 'preparation' },
393
+ });
394
+ const ctx = createMockContext();
395
+
396
+ const result = await addDeploymentRequirement(
397
+ {
398
+ project_id: VALID_UUID,
399
+ type: 'migration',
400
+ title: 'Test Migration',
401
+ },
402
+ ctx
403
+ );
404
+
405
+ expect(result.result).toMatchObject({
406
+ success: true,
407
+ requirement_id: 'req-1',
408
+ stage: 'preparation',
409
+ });
410
+ });
411
+ });
412
+
413
+ // ============================================================================
414
+ // getDeploymentRequirements Tests
415
+ // ============================================================================
416
+
417
+ describe('getDeploymentRequirements', () => {
418
+ beforeEach(() => vi.clearAllMocks());
419
+
420
+ it('should throw error for missing project_id', async () => {
421
+ const ctx = createMockContext();
422
+ await expect(getDeploymentRequirements({}, ctx)).rejects.toThrow(ValidationError);
423
+ });
424
+
425
+ it('should return empty list when no requirements', async () => {
426
+ mockApiClient.getDeploymentRequirements.mockResolvedValue({
427
+ ok: true,
428
+ data: { requirements: [], deployment_blocked: false },
429
+ });
430
+ const ctx = createMockContext();
431
+
432
+ const result = await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
433
+
434
+ expect(result.result).toMatchObject({
435
+ requirements: [],
436
+ deployment_blocked: false,
437
+ });
438
+ });
439
+
440
+ it('should query with correct project_id', async () => {
441
+ mockApiClient.getDeploymentRequirements.mockResolvedValue({
442
+ ok: true,
443
+ data: { requirements: [], deployment_blocked: false },
444
+ });
445
+ const ctx = createMockContext();
446
+
447
+ await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
448
+
449
+ expect(mockApiClient.getDeploymentRequirements).toHaveBeenCalledWith(
450
+ VALID_UUID,
451
+ expect.any(Object)
452
+ );
453
+ });
454
+
455
+ it('should return requirements list', async () => {
456
+ const mockReqs = [
457
+ { id: 'req-1', type: 'migration', title: 'Run migrations' },
458
+ { id: 'req-2', type: 'env_var', title: 'Set API_KEY' },
459
+ ];
460
+ mockApiClient.getDeploymentRequirements.mockResolvedValue({
461
+ ok: true,
462
+ data: { requirements: mockReqs, deployment_blocked: true },
463
+ });
464
+ const ctx = createMockContext();
465
+
466
+ const result = await getDeploymentRequirements({ project_id: VALID_UUID }, ctx);
467
+
468
+ expect((result.result as { requirements: unknown[] }).requirements).toHaveLength(2);
469
+ expect(result.result).toHaveProperty('deployment_blocked', true);
470
+ });
471
+
472
+ it('should pass pagination params to API client', async () => {
473
+ mockApiClient.getDeploymentRequirements.mockResolvedValue({
474
+ ok: true,
475
+ data: { requirements: [], deployment_blocked: false },
476
+ });
477
+ const ctx = createMockContext();
478
+
479
+ await getDeploymentRequirements(
480
+ { project_id: VALID_UUID, limit: 10, offset: 5 },
481
+ ctx
482
+ );
483
+
484
+ expect(mockApiClient.getDeploymentRequirements).toHaveBeenCalledWith(
485
+ VALID_UUID,
486
+ expect.objectContaining({ limit: 10, offset: 5 })
487
+ );
488
+ });
489
+ });
490
+
491
+ // ============================================================================
492
+ // getDeploymentRequirementsStats Tests
493
+ // ============================================================================
494
+
495
+ describe('getDeploymentRequirementsStats', () => {
496
+ beforeEach(() => vi.clearAllMocks());
497
+
498
+ it('should throw error for missing project_id', async () => {
499
+ const ctx = createMockContext();
500
+ await expect(getDeploymentRequirementsStats({}, ctx)).rejects.toThrow(ValidationError);
501
+ });
502
+
503
+ it('should throw error for invalid project_id UUID', async () => {
504
+ const ctx = createMockContext();
505
+ await expect(
506
+ getDeploymentRequirementsStats({ project_id: 'invalid' }, ctx)
507
+ ).rejects.toThrow(ValidationError);
508
+ });
509
+
510
+ it('should return stats from API client', async () => {
511
+ const mockStats = {
512
+ total: 5,
513
+ by_status: { pending: 3, completed: 2 },
514
+ by_stage: { preparation: 2, deployment: 2, verification: 1 },
515
+ by_type: { migration: 2, env_var: 2, manual: 1 },
516
+ };
517
+ mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
518
+ ok: true,
519
+ data: mockStats,
520
+ });
521
+ const ctx = createMockContext();
522
+
523
+ const result = await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
524
+
525
+ expect(result.result).toMatchObject(mockStats);
526
+ });
527
+
528
+ it('should call API client with correct project_id', async () => {
529
+ mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
530
+ ok: true,
531
+ data: { total: 0, by_status: {}, by_stage: {}, by_type: {} },
532
+ });
533
+ const ctx = createMockContext();
534
+
535
+ await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
536
+
537
+ expect(mockApiClient.getDeploymentRequirementsStats).toHaveBeenCalledWith(VALID_UUID);
538
+ });
539
+
540
+ it('should handle API error', async () => {
541
+ mockApiClient.getDeploymentRequirementsStats.mockResolvedValue({
542
+ ok: false,
543
+ error: 'Database error',
544
+ });
545
+ const ctx = createMockContext();
546
+
547
+ const result = await getDeploymentRequirementsStats({ project_id: VALID_UUID }, ctx);
548
+
549
+ expect(result.result).toHaveProperty('error');
550
+ });
551
+ });