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