@vibescope/mcp-server 0.2.4 → 0.2.5

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 (84) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -181
  3. package/dist/cli.d.ts +6 -3
  4. package/dist/cli.js +28 -10
  5. package/dist/handlers/tool-docs.js +828 -828
  6. package/dist/index.js +73 -73
  7. package/dist/knowledge.d.ts +6 -0
  8. package/dist/knowledge.js +218 -0
  9. package/dist/setup.d.ts +22 -0
  10. package/dist/setup.js +313 -0
  11. package/dist/templates/agent-guidelines.js +185 -185
  12. package/dist/tools.js +65 -65
  13. package/dist/utils.js +11 -11
  14. package/docs/TOOLS.md +2053 -2053
  15. package/package.json +1 -1
  16. package/scripts/generate-docs.ts +212 -212
  17. package/scripts/version-bump.ts +203 -203
  18. package/src/api-client.test.ts +723 -723
  19. package/src/api-client.ts +2499 -2499
  20. package/src/cli.ts +27 -10
  21. package/src/handlers/__test-setup__.ts +236 -236
  22. package/src/handlers/__test-utils__.ts +87 -87
  23. package/src/handlers/blockers.test.ts +468 -468
  24. package/src/handlers/blockers.ts +163 -163
  25. package/src/handlers/bodies-of-work.test.ts +704 -704
  26. package/src/handlers/bodies-of-work.ts +526 -526
  27. package/src/handlers/connectors.test.ts +834 -834
  28. package/src/handlers/connectors.ts +229 -229
  29. package/src/handlers/cost.test.ts +462 -462
  30. package/src/handlers/cost.ts +285 -285
  31. package/src/handlers/decisions.test.ts +382 -382
  32. package/src/handlers/decisions.ts +153 -153
  33. package/src/handlers/deployment.test.ts +551 -551
  34. package/src/handlers/deployment.ts +541 -541
  35. package/src/handlers/discovery.test.ts +206 -206
  36. package/src/handlers/discovery.ts +390 -390
  37. package/src/handlers/fallback.test.ts +537 -537
  38. package/src/handlers/fallback.ts +194 -194
  39. package/src/handlers/file-checkouts.test.ts +750 -750
  40. package/src/handlers/file-checkouts.ts +185 -185
  41. package/src/handlers/findings.test.ts +633 -633
  42. package/src/handlers/findings.ts +239 -239
  43. package/src/handlers/git-issues.test.ts +631 -631
  44. package/src/handlers/git-issues.ts +136 -136
  45. package/src/handlers/ideas.test.ts +644 -644
  46. package/src/handlers/ideas.ts +207 -207
  47. package/src/handlers/index.ts +84 -84
  48. package/src/handlers/milestones.test.ts +475 -475
  49. package/src/handlers/milestones.ts +180 -180
  50. package/src/handlers/organizations.test.ts +826 -826
  51. package/src/handlers/organizations.ts +315 -315
  52. package/src/handlers/progress.test.ts +269 -269
  53. package/src/handlers/progress.ts +77 -77
  54. package/src/handlers/project.test.ts +546 -546
  55. package/src/handlers/project.ts +239 -239
  56. package/src/handlers/requests.test.ts +303 -303
  57. package/src/handlers/requests.ts +99 -99
  58. package/src/handlers/roles.test.ts +303 -303
  59. package/src/handlers/roles.ts +226 -226
  60. package/src/handlers/session.test.ts +875 -875
  61. package/src/handlers/session.ts +738 -738
  62. package/src/handlers/sprints.test.ts +732 -732
  63. package/src/handlers/sprints.ts +537 -537
  64. package/src/handlers/tasks.test.ts +907 -907
  65. package/src/handlers/tasks.ts +945 -945
  66. package/src/handlers/tool-categories.test.ts +66 -66
  67. package/src/handlers/tool-docs.ts +1096 -1096
  68. package/src/handlers/types.test.ts +259 -259
  69. package/src/handlers/types.ts +175 -175
  70. package/src/handlers/validation.test.ts +582 -582
  71. package/src/handlers/validation.ts +97 -97
  72. package/src/index.ts +792 -792
  73. package/src/setup.test.ts +231 -0
  74. package/src/setup.ts +370 -0
  75. package/src/templates/agent-guidelines.ts +210 -210
  76. package/src/token-tracking.test.ts +453 -453
  77. package/src/token-tracking.ts +164 -164
  78. package/src/tools.ts +3562 -3562
  79. package/src/utils.test.ts +683 -683
  80. package/src/utils.ts +436 -436
  81. package/src/validators.test.ts +223 -223
  82. package/src/validators.ts +249 -249
  83. package/tsconfig.json +16 -16
  84. package/vitest.config.ts +14 -14
package/src/utils.test.ts CHANGED
@@ -1,683 +1,683 @@
1
- import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
2
- import {
3
- AGENT_PERSONAS,
4
- FALLBACK_ACTIVITIES,
5
- getRandomFallbackActivity,
6
- selectPersona,
7
- RateLimiter,
8
- canValidateTask,
9
- isValidStatusTransition,
10
- isValidDeploymentStatusTransition,
11
- extractProjectNameFromGitUrl,
12
- normalizeGitUrl,
13
- } from './utils.js';
14
-
15
- // ============================================================================
16
- // Agent Personas Tests
17
- // ============================================================================
18
-
19
- describe('AGENT_PERSONAS', () => {
20
- it('should have unique personas', () => {
21
- expect(AGENT_PERSONAS.length).toBeGreaterThanOrEqual(22);
22
- const uniquePersonas = new Set(AGENT_PERSONAS);
23
- expect(uniquePersonas.size).toBe(AGENT_PERSONAS.length);
24
- });
25
-
26
- it('should contain expected personas', () => {
27
- // Sci-fi & fantasy character names
28
- expect(AGENT_PERSONAS).toContain('Yoda');
29
- expect(AGENT_PERSONAS).toContain('Gandalf');
30
- expect(AGENT_PERSONAS).toContain('Spock');
31
- expect(AGENT_PERSONAS).toContain('Neo');
32
- });
33
-
34
- it('should have short memorable names', () => {
35
- // All personas should be reasonably short for dashboard display
36
- // Max 8 chars to accommodate names like "Morpheus"
37
- for (const persona of AGENT_PERSONAS) {
38
- expect(persona.length).toBeLessThanOrEqual(8);
39
- }
40
- });
41
- });
42
-
43
- // ============================================================================
44
- // Fallback Activities Tests
45
- // ============================================================================
46
-
47
- describe('FALLBACK_ACTIVITIES', () => {
48
- it('should have 12 activities', () => {
49
- expect(FALLBACK_ACTIVITIES).toHaveLength(12);
50
- });
51
-
52
- it('should have required fields on each activity', () => {
53
- for (const activity of FALLBACK_ACTIVITIES) {
54
- expect(activity).toHaveProperty('activity');
55
- expect(activity).toHaveProperty('title');
56
- expect(activity).toHaveProperty('description');
57
- expect(activity).toHaveProperty('prompt');
58
- expect(typeof activity.activity).toBe('string');
59
- expect(typeof activity.title).toBe('string');
60
- expect(typeof activity.description).toBe('string');
61
- expect(typeof activity.prompt).toBe('string');
62
- }
63
- });
64
-
65
- it('should have unique activity identifiers', () => {
66
- const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
67
- const uniqueIds = new Set(activityIds);
68
- expect(uniqueIds.size).toBe(FALLBACK_ACTIVITIES.length);
69
- });
70
-
71
- it('should include critical activities', () => {
72
- const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
73
- expect(activityIds).toContain('feature_ideation');
74
- expect(activityIds).toContain('code_review');
75
- expect(activityIds).toContain('security_review');
76
- expect(activityIds).toContain('test_coverage');
77
- expect(activityIds).toContain('validate_completed_tasks');
78
- });
79
- });
80
-
81
- describe('getRandomFallbackActivity', () => {
82
- it('should return a valid fallback activity', () => {
83
- const activity = getRandomFallbackActivity();
84
- expect(activity).toHaveProperty('activity');
85
- expect(activity).toHaveProperty('title');
86
- expect(activity).toHaveProperty('description');
87
- expect(activity).toHaveProperty('prompt');
88
- });
89
-
90
- it('should return activity from the pool', () => {
91
- const activity = getRandomFallbackActivity();
92
- const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
93
- expect(activityIds).toContain(activity.activity);
94
- });
95
- });
96
-
97
- // ============================================================================
98
- // Persona Selection Tests
99
- // ============================================================================
100
-
101
- describe('selectPersona', () => {
102
- it('should return a random persona when none are in use', () => {
103
- const usedPersonas = new Set<string>();
104
- const instanceId = 'abc123-def456';
105
-
106
- const selected = selectPersona(usedPersonas, instanceId);
107
-
108
- expect(AGENT_PERSONAS).toContain(selected);
109
- });
110
-
111
- it('should skip personas that are in use', () => {
112
- const usedPersonas = new Set<string>([AGENT_PERSONAS[0], AGENT_PERSONAS[1]]);
113
- const instanceId = 'abc123-def456';
114
-
115
- const selected = selectPersona(usedPersonas, instanceId);
116
-
117
- expect(usedPersonas.has(selected)).toBe(false);
118
- expect(AGENT_PERSONAS).toContain(selected);
119
- });
120
-
121
- it('should return fallback name when all personas are in use', () => {
122
- const usedPersonas = new Set(AGENT_PERSONAS);
123
- const instanceId = 'abc123-def456';
124
-
125
- const selected = selectPersona(usedPersonas, instanceId);
126
-
127
- expect(selected).toBe('Agent-abc123');
128
- });
129
-
130
- it('should handle partial instance ID', () => {
131
- const usedPersonas = new Set(AGENT_PERSONAS);
132
- const instanceId = 'xyz';
133
-
134
- const selected = selectPersona(usedPersonas, instanceId);
135
-
136
- expect(selected).toBe('Agent-xyz');
137
- });
138
-
139
- it('should be case-sensitive for used personas', () => {
140
- const firstPersona = AGENT_PERSONAS[0];
141
- const usedPersonas = new Set([firstPersona.toLowerCase(), firstPersona.toUpperCase()]); // Different case
142
- const instanceId = 'abc123-def456';
143
-
144
- const selected = selectPersona(usedPersonas, instanceId);
145
-
146
- // Original case versions are still available (case-sensitive match)
147
- expect(AGENT_PERSONAS).toContain(selected);
148
- expect(usedPersonas.has(selected)).toBe(false);
149
- });
150
- });
151
-
152
- // ============================================================================
153
- // Rate Limiter Tests
154
- // ============================================================================
155
-
156
- describe('RateLimiter', () => {
157
- let rateLimiter: RateLimiter;
158
-
159
- beforeEach(() => {
160
- vi.useFakeTimers();
161
- rateLimiter = new RateLimiter(5, 1000); // 5 requests per second for testing
162
- });
163
-
164
- afterEach(() => {
165
- vi.useRealTimers();
166
- });
167
-
168
- describe('constructor', () => {
169
- it('should use default values when none provided', () => {
170
- const defaultLimiter = new RateLimiter();
171
- const result = defaultLimiter.check('test');
172
- expect(result.remaining).toBe(59); // 60 - 1
173
- });
174
-
175
- it('should use custom values', () => {
176
- const customLimiter = new RateLimiter(10, 5000);
177
- const result = customLimiter.check('test');
178
- expect(result.remaining).toBe(9); // 10 - 1
179
- expect(result.resetIn).toBe(5000);
180
- });
181
- });
182
-
183
- describe('check', () => {
184
- it('should allow first request', () => {
185
- const result = rateLimiter.check('user-1');
186
-
187
- expect(result.allowed).toBe(true);
188
- expect(result.remaining).toBe(4);
189
- expect(result.resetIn).toBe(1000);
190
- });
191
-
192
- it('should decrement remaining count on subsequent requests', () => {
193
- rateLimiter.check('user-1');
194
- const result = rateLimiter.check('user-1');
195
-
196
- expect(result.allowed).toBe(true);
197
- expect(result.remaining).toBe(3);
198
- });
199
-
200
- it('should block requests when limit exceeded', () => {
201
- // Use up all requests
202
- for (let i = 0; i < 5; i++) {
203
- rateLimiter.check('user-1');
204
- }
205
-
206
- const result = rateLimiter.check('user-1');
207
-
208
- expect(result.allowed).toBe(false);
209
- expect(result.remaining).toBe(0);
210
- });
211
-
212
- it('should track different keys separately', () => {
213
- // Use up user-1's limit
214
- for (let i = 0; i < 5; i++) {
215
- rateLimiter.check('user-1');
216
- }
217
-
218
- // user-2 should still be allowed
219
- const result = rateLimiter.check('user-2');
220
-
221
- expect(result.allowed).toBe(true);
222
- expect(result.remaining).toBe(4);
223
- });
224
-
225
- it('should reset after window expires', () => {
226
- // Use up all requests
227
- for (let i = 0; i < 5; i++) {
228
- rateLimiter.check('user-1');
229
- }
230
-
231
- // Blocked
232
- expect(rateLimiter.check('user-1').allowed).toBe(false);
233
-
234
- // Advance time past window
235
- vi.advanceTimersByTime(1001);
236
-
237
- // Should be allowed again
238
- const result = rateLimiter.check('user-1');
239
- expect(result.allowed).toBe(true);
240
- expect(result.remaining).toBe(4);
241
- });
242
-
243
- it('should report correct resetIn time', () => {
244
- rateLimiter.check('user-1');
245
-
246
- // Advance time by 300ms
247
- vi.advanceTimersByTime(300);
248
-
249
- const result = rateLimiter.check('user-1');
250
- expect(result.resetIn).toBeLessThanOrEqual(700);
251
- expect(result.resetIn).toBeGreaterThan(0);
252
- });
253
- });
254
-
255
- describe('cleanup', () => {
256
- it('should remove expired entries', () => {
257
- rateLimiter.check('user-1');
258
- rateLimiter.check('user-2');
259
-
260
- expect(rateLimiter.getRequestCount('user-1')).toBe(1);
261
- expect(rateLimiter.getRequestCount('user-2')).toBe(1);
262
-
263
- // Advance past window
264
- vi.advanceTimersByTime(1001);
265
-
266
- rateLimiter.cleanup();
267
-
268
- expect(rateLimiter.getRequestCount('user-1')).toBeUndefined();
269
- expect(rateLimiter.getRequestCount('user-2')).toBeUndefined();
270
- });
271
-
272
- it('should keep non-expired entries', () => {
273
- rateLimiter.check('user-1');
274
-
275
- // Advance but not past window
276
- vi.advanceTimersByTime(500);
277
-
278
- rateLimiter.cleanup();
279
-
280
- expect(rateLimiter.getRequestCount('user-1')).toBe(1);
281
- });
282
- });
283
-
284
- describe('getRequestCount', () => {
285
- it('should return undefined for unknown key', () => {
286
- expect(rateLimiter.getRequestCount('unknown')).toBeUndefined();
287
- });
288
-
289
- it('should return correct count', () => {
290
- rateLimiter.check('user-1');
291
- rateLimiter.check('user-1');
292
- rateLimiter.check('user-1');
293
-
294
- expect(rateLimiter.getRequestCount('user-1')).toBe(3);
295
- });
296
- });
297
- });
298
-
299
- // ============================================================================
300
- // Task Validation Tests
301
- // ============================================================================
302
-
303
- describe('canValidateTask', () => {
304
- it('should allow validation of completed tasks', () => {
305
- const task = {
306
- status: 'completed',
307
- validated_at: null,
308
- working_agent_session_id: null,
309
- };
310
-
311
- const result = canValidateTask(task, 'session-123');
312
-
313
- expect(result.canValidate).toBe(true);
314
- expect(result.reason).toBeUndefined();
315
- });
316
-
317
- it('should reject non-completed tasks', () => {
318
- const statuses = ['pending', 'in_progress', 'cancelled'];
319
-
320
- for (const status of statuses) {
321
- const task = {
322
- status,
323
- validated_at: null,
324
- working_agent_session_id: null,
325
- };
326
-
327
- const result = canValidateTask(task, 'session-123');
328
-
329
- expect(result.canValidate).toBe(false);
330
- expect(result.reason).toBe('Can only validate completed tasks');
331
- }
332
- });
333
-
334
- it('should reject already validated tasks', () => {
335
- const task = {
336
- status: 'completed',
337
- validated_at: '2026-01-12T00:00:00Z',
338
- working_agent_session_id: null,
339
- };
340
-
341
- const result = canValidateTask(task, 'session-123');
342
-
343
- expect(result.canValidate).toBe(false);
344
- expect(result.reason).toBe('Task has already been validated');
345
- });
346
-
347
- it('should handle null validator session', () => {
348
- const task = {
349
- status: 'completed',
350
- validated_at: null,
351
- working_agent_session_id: null,
352
- };
353
-
354
- const result = canValidateTask(task, null);
355
-
356
- expect(result.canValidate).toBe(true);
357
- });
358
- });
359
-
360
- // ============================================================================
361
- // Status Transition Tests
362
- // ============================================================================
363
-
364
- describe('isValidStatusTransition', () => {
365
- describe('from pending', () => {
366
- it('should allow transition to in_progress', () => {
367
- const result = isValidStatusTransition('pending', 'in_progress');
368
- expect(result.isValid).toBe(true);
369
- });
370
-
371
- it('should allow transition to cancelled', () => {
372
- const result = isValidStatusTransition('pending', 'cancelled');
373
- expect(result.isValid).toBe(true);
374
- });
375
-
376
- it('should reject transition to completed', () => {
377
- const result = isValidStatusTransition('pending', 'completed');
378
- expect(result.isValid).toBe(false);
379
- expect(result.reason).toContain('Cannot transition');
380
- });
381
- });
382
-
383
- describe('from in_progress', () => {
384
- it('should allow transition to completed', () => {
385
- const result = isValidStatusTransition('in_progress', 'completed');
386
- expect(result.isValid).toBe(true);
387
- });
388
-
389
- it('should allow transition to pending', () => {
390
- const result = isValidStatusTransition('in_progress', 'pending');
391
- expect(result.isValid).toBe(true);
392
- });
393
-
394
- it('should allow transition to cancelled', () => {
395
- const result = isValidStatusTransition('in_progress', 'cancelled');
396
- expect(result.isValid).toBe(true);
397
- });
398
- });
399
-
400
- describe('from completed', () => {
401
- it('should allow transition to in_progress (validation failure)', () => {
402
- const result = isValidStatusTransition('completed', 'in_progress');
403
- expect(result.isValid).toBe(true);
404
- });
405
-
406
- it('should reject transition to pending', () => {
407
- const result = isValidStatusTransition('completed', 'pending');
408
- expect(result.isValid).toBe(false);
409
- });
410
-
411
- it('should reject transition to cancelled', () => {
412
- const result = isValidStatusTransition('completed', 'cancelled');
413
- expect(result.isValid).toBe(false);
414
- });
415
- });
416
-
417
- describe('from cancelled', () => {
418
- it('should allow transition to pending (reactivate)', () => {
419
- const result = isValidStatusTransition('cancelled', 'pending');
420
- expect(result.isValid).toBe(true);
421
- });
422
-
423
- it('should reject transition to in_progress', () => {
424
- const result = isValidStatusTransition('cancelled', 'in_progress');
425
- expect(result.isValid).toBe(false);
426
- });
427
-
428
- it('should reject transition to completed', () => {
429
- const result = isValidStatusTransition('cancelled', 'completed');
430
- expect(result.isValid).toBe(false);
431
- });
432
- });
433
-
434
- describe('unknown status', () => {
435
- it('should reject unknown current status', () => {
436
- const result = isValidStatusTransition('unknown', 'pending');
437
- expect(result.isValid).toBe(false);
438
- expect(result.reason).toContain('Unknown current status');
439
- });
440
- });
441
- });
442
-
443
- // ============================================================================
444
- // Deployment Status Transition Tests
445
- // ============================================================================
446
-
447
- describe('isValidDeploymentStatusTransition', () => {
448
- describe('from pending', () => {
449
- it('should allow pending → validating', () => {
450
- const result = isValidDeploymentStatusTransition('pending', 'validating');
451
- expect(result.isValid).toBe(true);
452
- });
453
-
454
- it('should allow pending → failed', () => {
455
- const result = isValidDeploymentStatusTransition('pending', 'failed');
456
- expect(result.isValid).toBe(true);
457
- });
458
-
459
- it('should reject pending → ready', () => {
460
- const result = isValidDeploymentStatusTransition('pending', 'ready');
461
- expect(result.isValid).toBe(false);
462
- });
463
-
464
- it('should reject pending → deployed', () => {
465
- const result = isValidDeploymentStatusTransition('pending', 'deployed');
466
- expect(result.isValid).toBe(false);
467
- });
468
- });
469
-
470
- describe('from validating', () => {
471
- it('should allow validating → ready', () => {
472
- const result = isValidDeploymentStatusTransition('validating', 'ready');
473
- expect(result.isValid).toBe(true);
474
- });
475
-
476
- it('should allow validating → failed', () => {
477
- const result = isValidDeploymentStatusTransition('validating', 'failed');
478
- expect(result.isValid).toBe(true);
479
- });
480
-
481
- it('should reject validating → deployed', () => {
482
- const result = isValidDeploymentStatusTransition('validating', 'deployed');
483
- expect(result.isValid).toBe(false);
484
- });
485
- });
486
-
487
- describe('from ready', () => {
488
- it('should allow ready → deploying', () => {
489
- const result = isValidDeploymentStatusTransition('ready', 'deploying');
490
- expect(result.isValid).toBe(true);
491
- });
492
-
493
- it('should allow ready → failed', () => {
494
- const result = isValidDeploymentStatusTransition('ready', 'failed');
495
- expect(result.isValid).toBe(true);
496
- });
497
-
498
- it('should reject ready → pending', () => {
499
- const result = isValidDeploymentStatusTransition('ready', 'pending');
500
- expect(result.isValid).toBe(false);
501
- });
502
- });
503
-
504
- describe('from deploying', () => {
505
- it('should allow deploying → deployed', () => {
506
- const result = isValidDeploymentStatusTransition('deploying', 'deployed');
507
- expect(result.isValid).toBe(true);
508
- });
509
-
510
- it('should allow deploying → failed', () => {
511
- const result = isValidDeploymentStatusTransition('deploying', 'failed');
512
- expect(result.isValid).toBe(true);
513
- });
514
-
515
- it('should reject deploying → pending', () => {
516
- const result = isValidDeploymentStatusTransition('deploying', 'pending');
517
- expect(result.isValid).toBe(false);
518
- });
519
- });
520
-
521
- describe('terminal states', () => {
522
- it('should reject deployed → any transition', () => {
523
- const result = isValidDeploymentStatusTransition('deployed', 'pending');
524
- expect(result.isValid).toBe(false);
525
- expect(result.reason).toContain('terminal state');
526
- });
527
-
528
- it('should reject failed → any transition', () => {
529
- const result = isValidDeploymentStatusTransition('failed', 'pending');
530
- expect(result.isValid).toBe(false);
531
- expect(result.reason).toContain('terminal state');
532
- });
533
- });
534
-
535
- describe('unknown status', () => {
536
- it('should reject unknown current status', () => {
537
- const result = isValidDeploymentStatusTransition('unknown', 'pending');
538
- expect(result.isValid).toBe(false);
539
- expect(result.reason).toContain('Unknown current status');
540
- });
541
- });
542
- });
543
-
544
- // ============================================================================
545
- // Git URL Parsing Tests
546
- // ============================================================================
547
-
548
- describe('extractProjectNameFromGitUrl', () => {
549
- it('should extract project name from https GitHub URL', () => {
550
- expect(extractProjectNameFromGitUrl('https://github.com/user/repo')).toBe('repo');
551
- });
552
-
553
- it('should extract project name from https GitHub URL with .git', () => {
554
- expect(extractProjectNameFromGitUrl('https://github.com/user/repo.git')).toBe('repo');
555
- });
556
-
557
- it('should extract project name from SSH GitHub URL', () => {
558
- expect(extractProjectNameFromGitUrl('git@github.com:user/repo.git')).toBe('repo');
559
- });
560
-
561
- it('should extract project name from SSH URL without .git', () => {
562
- expect(extractProjectNameFromGitUrl('git@github.com:user/repo')).toBe('repo');
563
- });
564
-
565
- it('should extract project name from GitLab URL', () => {
566
- expect(extractProjectNameFromGitUrl('https://gitlab.com/user/project-name')).toBe('project-name');
567
- });
568
-
569
- it('should extract project name from ssh:// protocol URL', () => {
570
- expect(extractProjectNameFromGitUrl('ssh://git@github.com/user/repo.git')).toBe('repo');
571
- });
572
-
573
- it('should handle nested paths (monorepo)', () => {
574
- expect(extractProjectNameFromGitUrl('https://github.com/org/monorepo')).toBe('monorepo');
575
- });
576
-
577
- it('should handle dashes and underscores in project names', () => {
578
- expect(extractProjectNameFromGitUrl('https://github.com/user/my-awesome_project')).toBe('my-awesome_project');
579
- });
580
-
581
- it('should return default for empty string', () => {
582
- expect(extractProjectNameFromGitUrl('')).toBe('my-project');
583
- });
584
-
585
- it('should return default for malformed URL', () => {
586
- expect(extractProjectNameFromGitUrl('not-a-url')).toBe('my-project');
587
- });
588
-
589
- it('should handle real Vibescope URL', () => {
590
- expect(extractProjectNameFromGitUrl('https://github.com/Nonatomic/Vibescope')).toBe('Vibescope');
591
- });
592
- });
593
-
594
- // ============================================================================
595
- // normalizeGitUrl Tests
596
- // ============================================================================
597
-
598
- describe('normalizeGitUrl', () => {
599
- describe('removing .git suffix', () => {
600
- it('should remove .git suffix from HTTPS URL', () => {
601
- expect(normalizeGitUrl('https://github.com/user/repo.git')).toBe('https://github.com/user/repo');
602
- });
603
-
604
- it('should not affect URL without .git suffix', () => {
605
- expect(normalizeGitUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo');
606
- });
607
-
608
- it('should only remove .git at the end', () => {
609
- expect(normalizeGitUrl('https://github.com/user/dotgit')).toBe('https://github.com/user/dotgit');
610
- });
611
- });
612
-
613
- describe('converting SSH to HTTPS for GitHub', () => {
614
- it('should convert SSH URL with .git', () => {
615
- expect(normalizeGitUrl('git@github.com:user/repo.git')).toBe('https://github.com/user/repo');
616
- });
617
-
618
- it('should convert SSH URL without .git', () => {
619
- expect(normalizeGitUrl('git@github.com:user/repo')).toBe('https://github.com/user/repo');
620
- });
621
-
622
- it('should convert SSH URL with org path', () => {
623
- expect(normalizeGitUrl('git@github.com:Nonatomic/Vibescope.git')).toBe('https://github.com/Nonatomic/Vibescope');
624
- });
625
- });
626
-
627
- describe('converting SSH to HTTPS for GitLab', () => {
628
- it('should convert SSH URL with .git', () => {
629
- expect(normalizeGitUrl('git@gitlab.com:user/repo.git')).toBe('https://gitlab.com/user/repo');
630
- });
631
-
632
- it('should convert SSH URL without .git', () => {
633
- expect(normalizeGitUrl('git@gitlab.com:user/repo')).toBe('https://gitlab.com/user/repo');
634
- });
635
- });
636
-
637
- describe('converting SSH to HTTPS for Bitbucket', () => {
638
- it('should convert SSH URL with .git', () => {
639
- expect(normalizeGitUrl('git@bitbucket.org:user/repo.git')).toBe('https://bitbucket.org/user/repo');
640
- });
641
-
642
- it('should convert SSH URL without .git', () => {
643
- expect(normalizeGitUrl('git@bitbucket.org:user/repo')).toBe('https://bitbucket.org/user/repo');
644
- });
645
- });
646
-
647
- describe('passthrough behavior', () => {
648
- it('should pass through already-normalized HTTPS GitHub URL', () => {
649
- expect(normalizeGitUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo');
650
- });
651
-
652
- it('should pass through HTTPS GitLab URL', () => {
653
- expect(normalizeGitUrl('https://gitlab.com/user/repo')).toBe('https://gitlab.com/user/repo');
654
- });
655
-
656
- it('should pass through HTTPS Bitbucket URL', () => {
657
- expect(normalizeGitUrl('https://bitbucket.org/user/repo')).toBe('https://bitbucket.org/user/repo');
658
- });
659
-
660
- it('should pass through empty string', () => {
661
- expect(normalizeGitUrl('')).toBe('');
662
- });
663
-
664
- it('should pass through unsupported git hosts', () => {
665
- expect(normalizeGitUrl('git@selfhosted.example.com:user/repo.git')).toBe('git@selfhosted.example.com:user/repo');
666
- });
667
- });
668
-
669
- describe('edge cases', () => {
670
- it('should handle complex paths with dashes and underscores', () => {
671
- expect(normalizeGitUrl('git@github.com:my-org/my_awesome-project.git')).toBe('https://github.com/my-org/my_awesome-project');
672
- });
673
-
674
- it('should handle nested paths', () => {
675
- expect(normalizeGitUrl('https://gitlab.com/group/subgroup/repo.git')).toBe('https://gitlab.com/group/subgroup/repo');
676
- });
677
-
678
- it('should handle URLs with port numbers', () => {
679
- // Port in URL - should just remove .git
680
- expect(normalizeGitUrl('https://github.com:443/user/repo.git')).toBe('https://github.com:443/user/repo');
681
- });
682
- });
683
- });
1
+ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
2
+ import {
3
+ AGENT_PERSONAS,
4
+ FALLBACK_ACTIVITIES,
5
+ getRandomFallbackActivity,
6
+ selectPersona,
7
+ RateLimiter,
8
+ canValidateTask,
9
+ isValidStatusTransition,
10
+ isValidDeploymentStatusTransition,
11
+ extractProjectNameFromGitUrl,
12
+ normalizeGitUrl,
13
+ } from './utils.js';
14
+
15
+ // ============================================================================
16
+ // Agent Personas Tests
17
+ // ============================================================================
18
+
19
+ describe('AGENT_PERSONAS', () => {
20
+ it('should have unique personas', () => {
21
+ expect(AGENT_PERSONAS.length).toBeGreaterThanOrEqual(22);
22
+ const uniquePersonas = new Set(AGENT_PERSONAS);
23
+ expect(uniquePersonas.size).toBe(AGENT_PERSONAS.length);
24
+ });
25
+
26
+ it('should contain expected personas', () => {
27
+ // Sci-fi & fantasy character names
28
+ expect(AGENT_PERSONAS).toContain('Yoda');
29
+ expect(AGENT_PERSONAS).toContain('Gandalf');
30
+ expect(AGENT_PERSONAS).toContain('Spock');
31
+ expect(AGENT_PERSONAS).toContain('Neo');
32
+ });
33
+
34
+ it('should have short memorable names', () => {
35
+ // All personas should be reasonably short for dashboard display
36
+ // Max 8 chars to accommodate names like "Morpheus"
37
+ for (const persona of AGENT_PERSONAS) {
38
+ expect(persona.length).toBeLessThanOrEqual(8);
39
+ }
40
+ });
41
+ });
42
+
43
+ // ============================================================================
44
+ // Fallback Activities Tests
45
+ // ============================================================================
46
+
47
+ describe('FALLBACK_ACTIVITIES', () => {
48
+ it('should have 12 activities', () => {
49
+ expect(FALLBACK_ACTIVITIES).toHaveLength(12);
50
+ });
51
+
52
+ it('should have required fields on each activity', () => {
53
+ for (const activity of FALLBACK_ACTIVITIES) {
54
+ expect(activity).toHaveProperty('activity');
55
+ expect(activity).toHaveProperty('title');
56
+ expect(activity).toHaveProperty('description');
57
+ expect(activity).toHaveProperty('prompt');
58
+ expect(typeof activity.activity).toBe('string');
59
+ expect(typeof activity.title).toBe('string');
60
+ expect(typeof activity.description).toBe('string');
61
+ expect(typeof activity.prompt).toBe('string');
62
+ }
63
+ });
64
+
65
+ it('should have unique activity identifiers', () => {
66
+ const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
67
+ const uniqueIds = new Set(activityIds);
68
+ expect(uniqueIds.size).toBe(FALLBACK_ACTIVITIES.length);
69
+ });
70
+
71
+ it('should include critical activities', () => {
72
+ const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
73
+ expect(activityIds).toContain('feature_ideation');
74
+ expect(activityIds).toContain('code_review');
75
+ expect(activityIds).toContain('security_review');
76
+ expect(activityIds).toContain('test_coverage');
77
+ expect(activityIds).toContain('validate_completed_tasks');
78
+ });
79
+ });
80
+
81
+ describe('getRandomFallbackActivity', () => {
82
+ it('should return a valid fallback activity', () => {
83
+ const activity = getRandomFallbackActivity();
84
+ expect(activity).toHaveProperty('activity');
85
+ expect(activity).toHaveProperty('title');
86
+ expect(activity).toHaveProperty('description');
87
+ expect(activity).toHaveProperty('prompt');
88
+ });
89
+
90
+ it('should return activity from the pool', () => {
91
+ const activity = getRandomFallbackActivity();
92
+ const activityIds = FALLBACK_ACTIVITIES.map((a) => a.activity);
93
+ expect(activityIds).toContain(activity.activity);
94
+ });
95
+ });
96
+
97
+ // ============================================================================
98
+ // Persona Selection Tests
99
+ // ============================================================================
100
+
101
+ describe('selectPersona', () => {
102
+ it('should return a random persona when none are in use', () => {
103
+ const usedPersonas = new Set<string>();
104
+ const instanceId = 'abc123-def456';
105
+
106
+ const selected = selectPersona(usedPersonas, instanceId);
107
+
108
+ expect(AGENT_PERSONAS).toContain(selected);
109
+ });
110
+
111
+ it('should skip personas that are in use', () => {
112
+ const usedPersonas = new Set<string>([AGENT_PERSONAS[0], AGENT_PERSONAS[1]]);
113
+ const instanceId = 'abc123-def456';
114
+
115
+ const selected = selectPersona(usedPersonas, instanceId);
116
+
117
+ expect(usedPersonas.has(selected)).toBe(false);
118
+ expect(AGENT_PERSONAS).toContain(selected);
119
+ });
120
+
121
+ it('should return fallback name when all personas are in use', () => {
122
+ const usedPersonas = new Set(AGENT_PERSONAS);
123
+ const instanceId = 'abc123-def456';
124
+
125
+ const selected = selectPersona(usedPersonas, instanceId);
126
+
127
+ expect(selected).toBe('Agent-abc123');
128
+ });
129
+
130
+ it('should handle partial instance ID', () => {
131
+ const usedPersonas = new Set(AGENT_PERSONAS);
132
+ const instanceId = 'xyz';
133
+
134
+ const selected = selectPersona(usedPersonas, instanceId);
135
+
136
+ expect(selected).toBe('Agent-xyz');
137
+ });
138
+
139
+ it('should be case-sensitive for used personas', () => {
140
+ const firstPersona = AGENT_PERSONAS[0];
141
+ const usedPersonas = new Set([firstPersona.toLowerCase(), firstPersona.toUpperCase()]); // Different case
142
+ const instanceId = 'abc123-def456';
143
+
144
+ const selected = selectPersona(usedPersonas, instanceId);
145
+
146
+ // Original case versions are still available (case-sensitive match)
147
+ expect(AGENT_PERSONAS).toContain(selected);
148
+ expect(usedPersonas.has(selected)).toBe(false);
149
+ });
150
+ });
151
+
152
+ // ============================================================================
153
+ // Rate Limiter Tests
154
+ // ============================================================================
155
+
156
+ describe('RateLimiter', () => {
157
+ let rateLimiter: RateLimiter;
158
+
159
+ beforeEach(() => {
160
+ vi.useFakeTimers();
161
+ rateLimiter = new RateLimiter(5, 1000); // 5 requests per second for testing
162
+ });
163
+
164
+ afterEach(() => {
165
+ vi.useRealTimers();
166
+ });
167
+
168
+ describe('constructor', () => {
169
+ it('should use default values when none provided', () => {
170
+ const defaultLimiter = new RateLimiter();
171
+ const result = defaultLimiter.check('test');
172
+ expect(result.remaining).toBe(59); // 60 - 1
173
+ });
174
+
175
+ it('should use custom values', () => {
176
+ const customLimiter = new RateLimiter(10, 5000);
177
+ const result = customLimiter.check('test');
178
+ expect(result.remaining).toBe(9); // 10 - 1
179
+ expect(result.resetIn).toBe(5000);
180
+ });
181
+ });
182
+
183
+ describe('check', () => {
184
+ it('should allow first request', () => {
185
+ const result = rateLimiter.check('user-1');
186
+
187
+ expect(result.allowed).toBe(true);
188
+ expect(result.remaining).toBe(4);
189
+ expect(result.resetIn).toBe(1000);
190
+ });
191
+
192
+ it('should decrement remaining count on subsequent requests', () => {
193
+ rateLimiter.check('user-1');
194
+ const result = rateLimiter.check('user-1');
195
+
196
+ expect(result.allowed).toBe(true);
197
+ expect(result.remaining).toBe(3);
198
+ });
199
+
200
+ it('should block requests when limit exceeded', () => {
201
+ // Use up all requests
202
+ for (let i = 0; i < 5; i++) {
203
+ rateLimiter.check('user-1');
204
+ }
205
+
206
+ const result = rateLimiter.check('user-1');
207
+
208
+ expect(result.allowed).toBe(false);
209
+ expect(result.remaining).toBe(0);
210
+ });
211
+
212
+ it('should track different keys separately', () => {
213
+ // Use up user-1's limit
214
+ for (let i = 0; i < 5; i++) {
215
+ rateLimiter.check('user-1');
216
+ }
217
+
218
+ // user-2 should still be allowed
219
+ const result = rateLimiter.check('user-2');
220
+
221
+ expect(result.allowed).toBe(true);
222
+ expect(result.remaining).toBe(4);
223
+ });
224
+
225
+ it('should reset after window expires', () => {
226
+ // Use up all requests
227
+ for (let i = 0; i < 5; i++) {
228
+ rateLimiter.check('user-1');
229
+ }
230
+
231
+ // Blocked
232
+ expect(rateLimiter.check('user-1').allowed).toBe(false);
233
+
234
+ // Advance time past window
235
+ vi.advanceTimersByTime(1001);
236
+
237
+ // Should be allowed again
238
+ const result = rateLimiter.check('user-1');
239
+ expect(result.allowed).toBe(true);
240
+ expect(result.remaining).toBe(4);
241
+ });
242
+
243
+ it('should report correct resetIn time', () => {
244
+ rateLimiter.check('user-1');
245
+
246
+ // Advance time by 300ms
247
+ vi.advanceTimersByTime(300);
248
+
249
+ const result = rateLimiter.check('user-1');
250
+ expect(result.resetIn).toBeLessThanOrEqual(700);
251
+ expect(result.resetIn).toBeGreaterThan(0);
252
+ });
253
+ });
254
+
255
+ describe('cleanup', () => {
256
+ it('should remove expired entries', () => {
257
+ rateLimiter.check('user-1');
258
+ rateLimiter.check('user-2');
259
+
260
+ expect(rateLimiter.getRequestCount('user-1')).toBe(1);
261
+ expect(rateLimiter.getRequestCount('user-2')).toBe(1);
262
+
263
+ // Advance past window
264
+ vi.advanceTimersByTime(1001);
265
+
266
+ rateLimiter.cleanup();
267
+
268
+ expect(rateLimiter.getRequestCount('user-1')).toBeUndefined();
269
+ expect(rateLimiter.getRequestCount('user-2')).toBeUndefined();
270
+ });
271
+
272
+ it('should keep non-expired entries', () => {
273
+ rateLimiter.check('user-1');
274
+
275
+ // Advance but not past window
276
+ vi.advanceTimersByTime(500);
277
+
278
+ rateLimiter.cleanup();
279
+
280
+ expect(rateLimiter.getRequestCount('user-1')).toBe(1);
281
+ });
282
+ });
283
+
284
+ describe('getRequestCount', () => {
285
+ it('should return undefined for unknown key', () => {
286
+ expect(rateLimiter.getRequestCount('unknown')).toBeUndefined();
287
+ });
288
+
289
+ it('should return correct count', () => {
290
+ rateLimiter.check('user-1');
291
+ rateLimiter.check('user-1');
292
+ rateLimiter.check('user-1');
293
+
294
+ expect(rateLimiter.getRequestCount('user-1')).toBe(3);
295
+ });
296
+ });
297
+ });
298
+
299
+ // ============================================================================
300
+ // Task Validation Tests
301
+ // ============================================================================
302
+
303
+ describe('canValidateTask', () => {
304
+ it('should allow validation of completed tasks', () => {
305
+ const task = {
306
+ status: 'completed',
307
+ validated_at: null,
308
+ working_agent_session_id: null,
309
+ };
310
+
311
+ const result = canValidateTask(task, 'session-123');
312
+
313
+ expect(result.canValidate).toBe(true);
314
+ expect(result.reason).toBeUndefined();
315
+ });
316
+
317
+ it('should reject non-completed tasks', () => {
318
+ const statuses = ['pending', 'in_progress', 'cancelled'];
319
+
320
+ for (const status of statuses) {
321
+ const task = {
322
+ status,
323
+ validated_at: null,
324
+ working_agent_session_id: null,
325
+ };
326
+
327
+ const result = canValidateTask(task, 'session-123');
328
+
329
+ expect(result.canValidate).toBe(false);
330
+ expect(result.reason).toBe('Can only validate completed tasks');
331
+ }
332
+ });
333
+
334
+ it('should reject already validated tasks', () => {
335
+ const task = {
336
+ status: 'completed',
337
+ validated_at: '2026-01-12T00:00:00Z',
338
+ working_agent_session_id: null,
339
+ };
340
+
341
+ const result = canValidateTask(task, 'session-123');
342
+
343
+ expect(result.canValidate).toBe(false);
344
+ expect(result.reason).toBe('Task has already been validated');
345
+ });
346
+
347
+ it('should handle null validator session', () => {
348
+ const task = {
349
+ status: 'completed',
350
+ validated_at: null,
351
+ working_agent_session_id: null,
352
+ };
353
+
354
+ const result = canValidateTask(task, null);
355
+
356
+ expect(result.canValidate).toBe(true);
357
+ });
358
+ });
359
+
360
+ // ============================================================================
361
+ // Status Transition Tests
362
+ // ============================================================================
363
+
364
+ describe('isValidStatusTransition', () => {
365
+ describe('from pending', () => {
366
+ it('should allow transition to in_progress', () => {
367
+ const result = isValidStatusTransition('pending', 'in_progress');
368
+ expect(result.isValid).toBe(true);
369
+ });
370
+
371
+ it('should allow transition to cancelled', () => {
372
+ const result = isValidStatusTransition('pending', 'cancelled');
373
+ expect(result.isValid).toBe(true);
374
+ });
375
+
376
+ it('should reject transition to completed', () => {
377
+ const result = isValidStatusTransition('pending', 'completed');
378
+ expect(result.isValid).toBe(false);
379
+ expect(result.reason).toContain('Cannot transition');
380
+ });
381
+ });
382
+
383
+ describe('from in_progress', () => {
384
+ it('should allow transition to completed', () => {
385
+ const result = isValidStatusTransition('in_progress', 'completed');
386
+ expect(result.isValid).toBe(true);
387
+ });
388
+
389
+ it('should allow transition to pending', () => {
390
+ const result = isValidStatusTransition('in_progress', 'pending');
391
+ expect(result.isValid).toBe(true);
392
+ });
393
+
394
+ it('should allow transition to cancelled', () => {
395
+ const result = isValidStatusTransition('in_progress', 'cancelled');
396
+ expect(result.isValid).toBe(true);
397
+ });
398
+ });
399
+
400
+ describe('from completed', () => {
401
+ it('should allow transition to in_progress (validation failure)', () => {
402
+ const result = isValidStatusTransition('completed', 'in_progress');
403
+ expect(result.isValid).toBe(true);
404
+ });
405
+
406
+ it('should reject transition to pending', () => {
407
+ const result = isValidStatusTransition('completed', 'pending');
408
+ expect(result.isValid).toBe(false);
409
+ });
410
+
411
+ it('should reject transition to cancelled', () => {
412
+ const result = isValidStatusTransition('completed', 'cancelled');
413
+ expect(result.isValid).toBe(false);
414
+ });
415
+ });
416
+
417
+ describe('from cancelled', () => {
418
+ it('should allow transition to pending (reactivate)', () => {
419
+ const result = isValidStatusTransition('cancelled', 'pending');
420
+ expect(result.isValid).toBe(true);
421
+ });
422
+
423
+ it('should reject transition to in_progress', () => {
424
+ const result = isValidStatusTransition('cancelled', 'in_progress');
425
+ expect(result.isValid).toBe(false);
426
+ });
427
+
428
+ it('should reject transition to completed', () => {
429
+ const result = isValidStatusTransition('cancelled', 'completed');
430
+ expect(result.isValid).toBe(false);
431
+ });
432
+ });
433
+
434
+ describe('unknown status', () => {
435
+ it('should reject unknown current status', () => {
436
+ const result = isValidStatusTransition('unknown', 'pending');
437
+ expect(result.isValid).toBe(false);
438
+ expect(result.reason).toContain('Unknown current status');
439
+ });
440
+ });
441
+ });
442
+
443
+ // ============================================================================
444
+ // Deployment Status Transition Tests
445
+ // ============================================================================
446
+
447
+ describe('isValidDeploymentStatusTransition', () => {
448
+ describe('from pending', () => {
449
+ it('should allow pending → validating', () => {
450
+ const result = isValidDeploymentStatusTransition('pending', 'validating');
451
+ expect(result.isValid).toBe(true);
452
+ });
453
+
454
+ it('should allow pending → failed', () => {
455
+ const result = isValidDeploymentStatusTransition('pending', 'failed');
456
+ expect(result.isValid).toBe(true);
457
+ });
458
+
459
+ it('should reject pending → ready', () => {
460
+ const result = isValidDeploymentStatusTransition('pending', 'ready');
461
+ expect(result.isValid).toBe(false);
462
+ });
463
+
464
+ it('should reject pending → deployed', () => {
465
+ const result = isValidDeploymentStatusTransition('pending', 'deployed');
466
+ expect(result.isValid).toBe(false);
467
+ });
468
+ });
469
+
470
+ describe('from validating', () => {
471
+ it('should allow validating → ready', () => {
472
+ const result = isValidDeploymentStatusTransition('validating', 'ready');
473
+ expect(result.isValid).toBe(true);
474
+ });
475
+
476
+ it('should allow validating → failed', () => {
477
+ const result = isValidDeploymentStatusTransition('validating', 'failed');
478
+ expect(result.isValid).toBe(true);
479
+ });
480
+
481
+ it('should reject validating → deployed', () => {
482
+ const result = isValidDeploymentStatusTransition('validating', 'deployed');
483
+ expect(result.isValid).toBe(false);
484
+ });
485
+ });
486
+
487
+ describe('from ready', () => {
488
+ it('should allow ready → deploying', () => {
489
+ const result = isValidDeploymentStatusTransition('ready', 'deploying');
490
+ expect(result.isValid).toBe(true);
491
+ });
492
+
493
+ it('should allow ready → failed', () => {
494
+ const result = isValidDeploymentStatusTransition('ready', 'failed');
495
+ expect(result.isValid).toBe(true);
496
+ });
497
+
498
+ it('should reject ready → pending', () => {
499
+ const result = isValidDeploymentStatusTransition('ready', 'pending');
500
+ expect(result.isValid).toBe(false);
501
+ });
502
+ });
503
+
504
+ describe('from deploying', () => {
505
+ it('should allow deploying → deployed', () => {
506
+ const result = isValidDeploymentStatusTransition('deploying', 'deployed');
507
+ expect(result.isValid).toBe(true);
508
+ });
509
+
510
+ it('should allow deploying → failed', () => {
511
+ const result = isValidDeploymentStatusTransition('deploying', 'failed');
512
+ expect(result.isValid).toBe(true);
513
+ });
514
+
515
+ it('should reject deploying → pending', () => {
516
+ const result = isValidDeploymentStatusTransition('deploying', 'pending');
517
+ expect(result.isValid).toBe(false);
518
+ });
519
+ });
520
+
521
+ describe('terminal states', () => {
522
+ it('should reject deployed → any transition', () => {
523
+ const result = isValidDeploymentStatusTransition('deployed', 'pending');
524
+ expect(result.isValid).toBe(false);
525
+ expect(result.reason).toContain('terminal state');
526
+ });
527
+
528
+ it('should reject failed → any transition', () => {
529
+ const result = isValidDeploymentStatusTransition('failed', 'pending');
530
+ expect(result.isValid).toBe(false);
531
+ expect(result.reason).toContain('terminal state');
532
+ });
533
+ });
534
+
535
+ describe('unknown status', () => {
536
+ it('should reject unknown current status', () => {
537
+ const result = isValidDeploymentStatusTransition('unknown', 'pending');
538
+ expect(result.isValid).toBe(false);
539
+ expect(result.reason).toContain('Unknown current status');
540
+ });
541
+ });
542
+ });
543
+
544
+ // ============================================================================
545
+ // Git URL Parsing Tests
546
+ // ============================================================================
547
+
548
+ describe('extractProjectNameFromGitUrl', () => {
549
+ it('should extract project name from https GitHub URL', () => {
550
+ expect(extractProjectNameFromGitUrl('https://github.com/user/repo')).toBe('repo');
551
+ });
552
+
553
+ it('should extract project name from https GitHub URL with .git', () => {
554
+ expect(extractProjectNameFromGitUrl('https://github.com/user/repo.git')).toBe('repo');
555
+ });
556
+
557
+ it('should extract project name from SSH GitHub URL', () => {
558
+ expect(extractProjectNameFromGitUrl('git@github.com:user/repo.git')).toBe('repo');
559
+ });
560
+
561
+ it('should extract project name from SSH URL without .git', () => {
562
+ expect(extractProjectNameFromGitUrl('git@github.com:user/repo')).toBe('repo');
563
+ });
564
+
565
+ it('should extract project name from GitLab URL', () => {
566
+ expect(extractProjectNameFromGitUrl('https://gitlab.com/user/project-name')).toBe('project-name');
567
+ });
568
+
569
+ it('should extract project name from ssh:// protocol URL', () => {
570
+ expect(extractProjectNameFromGitUrl('ssh://git@github.com/user/repo.git')).toBe('repo');
571
+ });
572
+
573
+ it('should handle nested paths (monorepo)', () => {
574
+ expect(extractProjectNameFromGitUrl('https://github.com/org/monorepo')).toBe('monorepo');
575
+ });
576
+
577
+ it('should handle dashes and underscores in project names', () => {
578
+ expect(extractProjectNameFromGitUrl('https://github.com/user/my-awesome_project')).toBe('my-awesome_project');
579
+ });
580
+
581
+ it('should return default for empty string', () => {
582
+ expect(extractProjectNameFromGitUrl('')).toBe('my-project');
583
+ });
584
+
585
+ it('should return default for malformed URL', () => {
586
+ expect(extractProjectNameFromGitUrl('not-a-url')).toBe('my-project');
587
+ });
588
+
589
+ it('should handle real Vibescope URL', () => {
590
+ expect(extractProjectNameFromGitUrl('https://github.com/Nonatomic/Vibescope')).toBe('Vibescope');
591
+ });
592
+ });
593
+
594
+ // ============================================================================
595
+ // normalizeGitUrl Tests
596
+ // ============================================================================
597
+
598
+ describe('normalizeGitUrl', () => {
599
+ describe('removing .git suffix', () => {
600
+ it('should remove .git suffix from HTTPS URL', () => {
601
+ expect(normalizeGitUrl('https://github.com/user/repo.git')).toBe('https://github.com/user/repo');
602
+ });
603
+
604
+ it('should not affect URL without .git suffix', () => {
605
+ expect(normalizeGitUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo');
606
+ });
607
+
608
+ it('should only remove .git at the end', () => {
609
+ expect(normalizeGitUrl('https://github.com/user/dotgit')).toBe('https://github.com/user/dotgit');
610
+ });
611
+ });
612
+
613
+ describe('converting SSH to HTTPS for GitHub', () => {
614
+ it('should convert SSH URL with .git', () => {
615
+ expect(normalizeGitUrl('git@github.com:user/repo.git')).toBe('https://github.com/user/repo');
616
+ });
617
+
618
+ it('should convert SSH URL without .git', () => {
619
+ expect(normalizeGitUrl('git@github.com:user/repo')).toBe('https://github.com/user/repo');
620
+ });
621
+
622
+ it('should convert SSH URL with org path', () => {
623
+ expect(normalizeGitUrl('git@github.com:Nonatomic/Vibescope.git')).toBe('https://github.com/Nonatomic/Vibescope');
624
+ });
625
+ });
626
+
627
+ describe('converting SSH to HTTPS for GitLab', () => {
628
+ it('should convert SSH URL with .git', () => {
629
+ expect(normalizeGitUrl('git@gitlab.com:user/repo.git')).toBe('https://gitlab.com/user/repo');
630
+ });
631
+
632
+ it('should convert SSH URL without .git', () => {
633
+ expect(normalizeGitUrl('git@gitlab.com:user/repo')).toBe('https://gitlab.com/user/repo');
634
+ });
635
+ });
636
+
637
+ describe('converting SSH to HTTPS for Bitbucket', () => {
638
+ it('should convert SSH URL with .git', () => {
639
+ expect(normalizeGitUrl('git@bitbucket.org:user/repo.git')).toBe('https://bitbucket.org/user/repo');
640
+ });
641
+
642
+ it('should convert SSH URL without .git', () => {
643
+ expect(normalizeGitUrl('git@bitbucket.org:user/repo')).toBe('https://bitbucket.org/user/repo');
644
+ });
645
+ });
646
+
647
+ describe('passthrough behavior', () => {
648
+ it('should pass through already-normalized HTTPS GitHub URL', () => {
649
+ expect(normalizeGitUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo');
650
+ });
651
+
652
+ it('should pass through HTTPS GitLab URL', () => {
653
+ expect(normalizeGitUrl('https://gitlab.com/user/repo')).toBe('https://gitlab.com/user/repo');
654
+ });
655
+
656
+ it('should pass through HTTPS Bitbucket URL', () => {
657
+ expect(normalizeGitUrl('https://bitbucket.org/user/repo')).toBe('https://bitbucket.org/user/repo');
658
+ });
659
+
660
+ it('should pass through empty string', () => {
661
+ expect(normalizeGitUrl('')).toBe('');
662
+ });
663
+
664
+ it('should pass through unsupported git hosts', () => {
665
+ expect(normalizeGitUrl('git@selfhosted.example.com:user/repo.git')).toBe('git@selfhosted.example.com:user/repo');
666
+ });
667
+ });
668
+
669
+ describe('edge cases', () => {
670
+ it('should handle complex paths with dashes and underscores', () => {
671
+ expect(normalizeGitUrl('git@github.com:my-org/my_awesome-project.git')).toBe('https://github.com/my-org/my_awesome-project');
672
+ });
673
+
674
+ it('should handle nested paths', () => {
675
+ expect(normalizeGitUrl('https://gitlab.com/group/subgroup/repo.git')).toBe('https://gitlab.com/group/subgroup/repo');
676
+ });
677
+
678
+ it('should handle URLs with port numbers', () => {
679
+ // Port in URL - should just remove .git
680
+ expect(normalizeGitUrl('https://github.com:443/user/repo.git')).toBe('https://github.com:443/user/repo');
681
+ });
682
+ });
683
+ });