@codemcp/workflows 5.0.1 → 5.1.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 (77) hide show
  1. package/package.json +6 -2
  2. package/skill/SKILL.md +23 -0
  3. package/.prettierignore +0 -2
  4. package/.turbo/turbo-build.log +0 -4
  5. package/.vibe/conversation-state.sqlite +0 -0
  6. package/src/components/beads/beads-instruction-generator.ts +0 -230
  7. package/src/components/beads/beads-plan-manager.ts +0 -333
  8. package/src/components/beads/beads-task-backend-client.ts +0 -229
  9. package/src/index.ts +0 -93
  10. package/src/notification-service.ts +0 -23
  11. package/src/plugin-system/beads-plugin.ts +0 -649
  12. package/src/plugin-system/commit-plugin.ts +0 -252
  13. package/src/plugin-system/index.ts +0 -20
  14. package/src/plugin-system/plugin-interfaces.ts +0 -153
  15. package/src/plugin-system/plugin-registry.ts +0 -190
  16. package/src/resource-handlers/conversation-state.ts +0 -55
  17. package/src/resource-handlers/development-plan.ts +0 -48
  18. package/src/resource-handlers/index.ts +0 -73
  19. package/src/resource-handlers/system-prompt.ts +0 -55
  20. package/src/resource-handlers/workflow-resource.ts +0 -132
  21. package/src/response-renderer.ts +0 -116
  22. package/src/server-config.ts +0 -760
  23. package/src/server-helpers.ts +0 -245
  24. package/src/server-implementation.ts +0 -277
  25. package/src/server.ts +0 -9
  26. package/src/tool-handlers/base-tool-handler.ts +0 -151
  27. package/src/tool-handlers/conduct-review.ts +0 -190
  28. package/src/tool-handlers/get-tool-info.ts +0 -273
  29. package/src/tool-handlers/index.ts +0 -115
  30. package/src/tool-handlers/list-workflows.ts +0 -78
  31. package/src/tool-handlers/no-idea.ts +0 -47
  32. package/src/tool-handlers/proceed-to-phase.ts +0 -296
  33. package/src/tool-handlers/reset-development.ts +0 -90
  34. package/src/tool-handlers/resume-workflow.ts +0 -378
  35. package/src/tool-handlers/setup-project-docs.ts +0 -232
  36. package/src/tool-handlers/start-development.ts +0 -746
  37. package/src/tool-handlers/whats-next.ts +0 -246
  38. package/src/types.ts +0 -135
  39. package/src/version-info.ts +0 -213
  40. package/test/e2e/beads-plugin-integration.test.ts +0 -1623
  41. package/test/e2e/commit-plugin-integration.test.ts +0 -222
  42. package/test/e2e/core-functionality.test.ts +0 -167
  43. package/test/e2e/git-branch-detection.test.ts +0 -351
  44. package/test/e2e/mcp-contract.test.ts +0 -509
  45. package/test/e2e/plan-management.test.ts +0 -334
  46. package/test/e2e/plugin-system-integration.test.ts +0 -1410
  47. package/test/e2e/state-management.test.ts +0 -387
  48. package/test/e2e/workflow-integration.test.ts +0 -498
  49. package/test/unit/beads-instruction-generator.test.ts +0 -979
  50. package/test/unit/beads-phase-task-id-integration.test.ts +0 -535
  51. package/test/unit/beads-plugin-behavioral.test.ts +0 -545
  52. package/test/unit/beads-plugin.test.ts +0 -117
  53. package/test/unit/commit-plugin.test.ts +0 -196
  54. package/test/unit/conduct-review.test.ts +0 -151
  55. package/test/unit/conversation-not-found-error.test.ts +0 -120
  56. package/test/unit/plugin-error-handling.test.ts +0 -240
  57. package/test/unit/proceed-to-phase-plugin-integration.test.ts +0 -150
  58. package/test/unit/reset-functionality.test.ts +0 -72
  59. package/test/unit/resume-workflow.test.ts +0 -193
  60. package/test/unit/server-config-plugin-registry.test.ts +0 -99
  61. package/test/unit/server-tools.test.ts +0 -310
  62. package/test/unit/setup-project-docs-handler.test.ts +0 -268
  63. package/test/unit/start-development-artifact-detection.test.ts +0 -387
  64. package/test/unit/start-development-gitignore.test.ts +0 -178
  65. package/test/unit/start-development-goal-extraction.test.ts +0 -226
  66. package/test/unit/system-prompt-resource.test.ts +0 -102
  67. package/test/unit/tool-handlers/no-idea.test.ts +0 -40
  68. package/test/utils/e2e-test-setup.ts +0 -451
  69. package/test/utils/run-server-in-dir.sh +0 -27
  70. package/test/utils/temp-files.ts +0 -320
  71. package/test/utils/test-access.ts +0 -79
  72. package/test/utils/test-helpers.ts +0 -288
  73. package/test/utils/test-setup.ts +0 -77
  74. package/tsconfig.build.json +0 -10
  75. package/tsconfig.build.tsbuildinfo +0 -1
  76. package/tsconfig.json +0 -12
  77. package/vitest.config.ts +0 -19
@@ -1,979 +0,0 @@
1
- /**
2
- * BeadsInstructionGenerator Content Validation Tests
3
- *
4
- * Tests for validating that BeadsInstructionGenerator generates the correct
5
- * beads-specific instruction content and does not contain markdown-specific content.
6
- */
7
-
8
- import { describe, it, expect, beforeEach } from 'vitest';
9
- import { BeadsInstructionGenerator } from '../../src/components/beads/beads-instruction-generator.js';
10
- import type {
11
- InstructionContext,
12
- ConversationContext,
13
- } from '@codemcp/workflows-core';
14
-
15
- describe('BeadsInstructionGenerator Content Validation', () => {
16
- let beadsInstructionGenerator: BeadsInstructionGenerator;
17
- let mockInstructionContext: InstructionContext;
18
- let mockConversationContext: ConversationContext;
19
-
20
- beforeEach(() => {
21
- beadsInstructionGenerator = new BeadsInstructionGenerator();
22
-
23
- // Set up mock contexts
24
- mockConversationContext = {
25
- conversationId: 'test-conversation',
26
- projectPath: '/test/project',
27
- planFilePath: '/test/project/.vibe/plan.md',
28
- gitBranch: 'main',
29
- currentPhase: 'design',
30
- workflowName: 'epcc',
31
- };
32
-
33
- mockInstructionContext = {
34
- phase: 'design',
35
- conversationContext: mockConversationContext,
36
- transitionReason: 'test transition',
37
- isModeled: false,
38
- planFileExists: true,
39
- instructionSource: 'whats_next', // Default to whats_next for tests expecting BD guidance
40
- };
41
- });
42
-
43
- describe('Beads-Specific Content Must Be Present', () => {
44
- it('should generate complete beads task management header structure for whats_next', async () => {
45
- const result = await beadsInstructionGenerator.generateInstructions(
46
- 'Work on design tasks.',
47
- { ...mockInstructionContext, instructionSource: 'whats_next' }
48
- );
49
-
50
- // Verify beads-specific elements are present for whats_next
51
- expect(result.instructions).toContain('bd Task Management:');
52
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
53
- });
54
-
55
- it('should not generate BD CLI guidance for proceed_to_phase', async () => {
56
- const result = await beadsInstructionGenerator.generateInstructions(
57
- 'Work on design tasks.',
58
- { ...mockInstructionContext, instructionSource: 'proceed_to_phase' }
59
- );
60
-
61
- // Verify BD CLI guidance is NOT present for proceed_to_phase (your optimization!)
62
- expect(result.instructions).not.toContain('bd:');
63
- expect(result.instructions).not.toContain('bd Task Management:');
64
- expect(result.instructions).not.toContain('bd list --parent');
65
- // But should still contain basic beads reminders
66
- expect(result.instructions).toContain(
67
- 'Use ONLY bd CLI tool for task management'
68
- );
69
- });
70
-
71
- it('should contain core beads CLI commands with proper formatting for whats_next', async () => {
72
- const result = await beadsInstructionGenerator.generateInstructions(
73
- 'Work on tasks.',
74
- { ...mockInstructionContext, instructionSource: 'whats_next' }
75
- );
76
-
77
- // Verify specific beads CLI commands are present for whats_next
78
- expect(result.instructions).toContain(
79
- 'bd list --parent <phase-task-id> --status open'
80
- );
81
- expect(result.instructions).toContain(
82
- "bd create 'Task title' --parent <phase-task-id> -p <priority>"
83
- );
84
- expect(result.instructions).toContain(
85
- 'bd update <task-id> --status in_progress'
86
- );
87
- expect(result.instructions).toContain('bd close <task-id>');
88
- });
89
-
90
- it('should contain beads-specific task management prohibition', async () => {
91
- const result = await beadsInstructionGenerator.generateInstructions(
92
- 'Work on tasks.',
93
- { ...mockInstructionContext, instructionSource: 'whats_next' }
94
- );
95
-
96
- // Verify beads-specific prohibition
97
- expect(result.instructions).toContain(
98
- 'Do NOT enter tasks in the plan file, use beads CLI exclusively'
99
- );
100
- });
101
-
102
- it('should contain beads-specific reminders section', async () => {
103
- const result = await beadsInstructionGenerator.generateInstructions(
104
- 'Work on tasks.',
105
- mockInstructionContext // Works for any instructionSource
106
- );
107
-
108
- // Verify beads-specific reminders (always present)
109
- expect(result.instructions).toContain(
110
- 'Use ONLY bd CLI tool for task management - do not use your own task management tools'
111
- );
112
- expect(result.instructions).toContain(
113
- 'Call whats_next() after the next user message to maintain the development workflow'
114
- );
115
- });
116
-
117
- it('should contain beads plan file guidance', async () => {
118
- const result = await beadsInstructionGenerator.generateInstructions(
119
- 'Work on tasks.',
120
- mockInstructionContext // Works for any instructionSource
121
- );
122
-
123
- // Verify beads plan file guidance (always present)
124
- expect(result.instructions).toContain('Plan File Guidance:');
125
- expect(result.instructions).toContain(
126
- 'Do NOT enter tasks in the plan file, use beads CLI exclusively'
127
- );
128
- });
129
-
130
- it('should contain beads-specific reminders section', async () => {
131
- const result = await beadsInstructionGenerator.generateInstructions(
132
- 'Work on tasks.',
133
- mockInstructionContext
134
- );
135
-
136
- // Verify beads-specific reminders
137
- expect(result.instructions).toContain(
138
- 'Use ONLY bd CLI tool for task management - do not use your own task management tools'
139
- );
140
- expect(result.instructions).toContain(
141
- 'Call whats_next() after the next user message to maintain the development workflow'
142
- );
143
- });
144
-
145
- it('should contain beads plan file guidance', async () => {
146
- const result = await beadsInstructionGenerator.generateInstructions(
147
- 'Work on tasks.',
148
- mockInstructionContext
149
- );
150
-
151
- // Verify beads-specific plan file guidance
152
- expect(result.planFileGuidance).toContain(
153
- 'Using beads CLI for task management - plan file serves as context only'
154
- );
155
- });
156
-
157
- it('should use proper beads terminology and structure for whats_next', async () => {
158
- const result = await beadsInstructionGenerator.generateInstructions(
159
- 'Work on tasks.',
160
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
161
- );
162
-
163
- // Verify beads terminology (only present in whats_next detailed guidance)
164
- expect(result.instructions).toContain('ready tasks');
165
- expect(result.instructions).toContain('phase-task-id');
166
- // Removed 'Current Phase' expectation - no longer part of minimal output
167
- });
168
-
169
- it('should not contain beads CLI terminology for proceed_to_phase', async () => {
170
- const result = await beadsInstructionGenerator.generateInstructions(
171
- 'Work on tasks.',
172
- {
173
- ...mockInstructionContext,
174
- instructionSource: 'proceed_to_phase' as const,
175
- }
176
- );
177
-
178
- // Verify beads CLI terminology is NOT present for proceed_to_phase (your optimization!)
179
- expect(result.instructions).not.toContain('ready tasks');
180
- expect(result.instructions).not.toContain('phase-task-id');
181
- expect(result.instructions).not.toContain('Current Phase'); // Removed from minimal output
182
- // But should still contain basic beads reminders
183
- expect(result.instructions).toContain(
184
- 'Use ONLY bd CLI tool for task management'
185
- );
186
- });
187
-
188
- it('should not contain beads CLI terminology for proceed_to_phase', async () => {
189
- const result = await beadsInstructionGenerator.generateInstructions(
190
- 'Work on tasks.',
191
- { ...mockInstructionContext, instructionSource: 'proceed_to_phase' }
192
- );
193
-
194
- // Verify beads CLI terminology is NOT present for proceed_to_phase
195
- expect(result.instructions).not.toContain('ready tasks');
196
- expect(result.instructions).not.toContain('phase-task-id');
197
- // Removed 'Current Phase:' expectation - no longer part of minimal output for proceed_to_phase
198
- });
199
- });
200
-
201
- describe('Anti-Contamination (Should NOT contain markdown-specific content)', () => {
202
- it('should never contain markdown task management instructions', async () => {
203
- const result = await beadsInstructionGenerator.generateInstructions(
204
- 'Work on tasks.',
205
- mockInstructionContext
206
- );
207
-
208
- // Should NOT contain markdown-specific content
209
- expect(result.instructions).not.toContain(
210
- 'Mark completed tasks with [x]'
211
- );
212
- expect(result.instructions).not.toContain(
213
- 'Use ONLY the development plan for task management'
214
- );
215
- expect(result.instructions).not.toContain(
216
- 'Work on the tasks listed in the Design section'
217
- );
218
- });
219
-
220
- it('should never contain markdown plan file task instructions', async () => {
221
- const result = await beadsInstructionGenerator.generateInstructions(
222
- 'Work on tasks.',
223
- mockInstructionContext
224
- );
225
-
226
- // Should NOT contain markdown plan file task management
227
- expect(result.instructions).not.toContain(
228
- 'Mark completed tasks with [x] as you finish them'
229
- );
230
- expect(result.instructions).not.toContain(
231
- 'focus on the "Design" section'
232
- );
233
- expect(result.instructions).not.toContain(
234
- 'focus on the "Design" section'
235
- );
236
- });
237
-
238
- it('should not include markdown-style task format examples', async () => {
239
- const result = await beadsInstructionGenerator.generateInstructions(
240
- 'Work on tasks.',
241
- mockInstructionContext
242
- );
243
-
244
- // Should NOT contain markdown task formatting
245
- expect(result.instructions).not.toContain('- [ ]');
246
- expect(result.instructions).not.toContain('- [x]');
247
- expect(result.instructions).not.toContain('Check your plan file at');
248
- });
249
-
250
- it('should provide exclusive beads guidance without markdown contamination', async () => {
251
- const result = await beadsInstructionGenerator.generateInstructions(
252
- 'Complex task management scenario',
253
- mockInstructionContext
254
- );
255
-
256
- // Comprehensive check against markdown contamination
257
- const markdownTerms = [
258
- 'Mark completed tasks with [x]',
259
- 'Use ONLY the development plan for task management',
260
- 'Work on the tasks listed in',
261
- 'focus on the "Design" section',
262
- 'Mark completed tasks with [x] as you finish them',
263
- 'Check your plan file at',
264
- '- [ ]',
265
- '- [x]',
266
- ];
267
-
268
- for (const term of markdownTerms) {
269
- expect(
270
- result.instructions,
271
- `Should not contain markdown term: "${term}"`
272
- ).not.toContain(term);
273
- }
274
- });
275
- });
276
-
277
- describe('Phase-Specific Content Validation', () => {
278
- it('should generate phase-specific beads instructions for different phases', async () => {
279
- const phases = ['explore', 'plan', 'code', 'commit'];
280
-
281
- for (const phase of phases) {
282
- const context = {
283
- ...mockInstructionContext,
284
- phase,
285
- instructionSource: 'whats_next' as const,
286
- };
287
- const result = await beadsInstructionGenerator.generateInstructions(
288
- `${phase} instructions`,
289
- context
290
- );
291
-
292
- // All phases should have consistent beads structure when instructionSource is whats_next
293
- expect(
294
- result.instructions,
295
- `Phase ${phase} should have bd Task Management header for whats_next`
296
- ).toContain('bd Task Management:');
297
- expect(
298
- result.instructions,
299
- `Phase ${phase} should have beads CLI commands for whats_next`
300
- ).toContain('bd list --parent');
301
- expect(
302
- result.instructions,
303
- `Phase ${phase} should not have markdown content`
304
- ).not.toContain('Mark completed tasks with [x]');
305
-
306
- // Should contain the phase name somewhere (either in instructions or section headers)
307
- expect(result.instructions).toContain(phase); // Phase name should appear somewhere
308
- }
309
-
310
- // Test that non-whats_next instruction sources don't get BD CLI guidance
311
- for (const phase of phases) {
312
- const context = {
313
- ...mockInstructionContext,
314
- phase,
315
- instructionSource: 'proceed_to_phase' as const,
316
- };
317
- const result = await beadsInstructionGenerator.generateInstructions(
318
- `${phase} instructions`,
319
- context
320
- );
321
-
322
- // Should NOT have BD CLI guidance for proceed_to_phase
323
- expect(
324
- result.instructions,
325
- `Phase ${phase} should NOT have bd guidance for proceed_to_phase`
326
- ).not.toContain('bd Task Management:');
327
- expect(
328
- result.instructions,
329
- `Phase ${phase} should NOT have beads CLI commands for proceed_to_phase`
330
- ).not.toContain('bd list --parent');
331
-
332
- // But should still contain the phase name somewhere
333
- expect(result.instructions).toContain(phase);
334
- }
335
- });
336
-
337
- it('should customize beads guidance based on phase context', async () => {
338
- // Test design phase
339
- const designResult = await beadsInstructionGenerator.generateInstructions(
340
- 'Design phase instructions',
341
- {
342
- ...mockInstructionContext,
343
- phase: 'design',
344
- instructionSource: 'whats_next' as const,
345
- }
346
- );
347
-
348
- // The phase is referenced in instructions passed to the generator
349
- expect(designResult.instructions).toContain('Design phase instructions');
350
- // Removed phase name expectation - no longer appears in phase context section
351
-
352
- // Test implementation phase
353
- const implResult = await beadsInstructionGenerator.generateInstructions(
354
- 'Implementation phase instructions',
355
- {
356
- ...mockInstructionContext,
357
- phase: 'implementation',
358
- instructionSource: 'whats_next' as const,
359
- }
360
- );
361
-
362
- expect(implResult.instructions).toContain(
363
- 'Implementation phase instructions'
364
- );
365
- // Removed phase name expectation - no longer appears in phase context section
366
- });
367
- });
368
-
369
- describe('Variable Substitution in Beads Context', () => {
370
- it('should properly substitute variables while maintaining beads structure', async () => {
371
- const instructionsWithVariables =
372
- 'Review the design in $DESIGN_DOC and implement according to $ARCHITECTURE_DOC.';
373
-
374
- const result = await beadsInstructionGenerator.generateInstructions(
375
- instructionsWithVariables,
376
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
377
- );
378
-
379
- // Variable substitution should work (though paths may not exist)
380
- expect(result.instructions).toContain('Review the design in');
381
- expect(result.instructions).toContain('implement according to');
382
-
383
- // Should maintain beads structure with BD CLI guidance for whats_next
384
- expect(result.instructions).toContain('bd Task Management:');
385
- });
386
-
387
- it('should handle multiple variable occurrences in beads context', async () => {
388
- const baseInstructions =
389
- 'Check $DESIGN_DOC for details. Update $DESIGN_DOC with new information.';
390
-
391
- const result = await beadsInstructionGenerator.generateInstructions(
392
- baseInstructions,
393
- mockInstructionContext
394
- );
395
-
396
- const designDocPath = '/test/project/.vibe/docs/design.md';
397
- const occurrences = (
398
- result.instructions.match(
399
- new RegExp(designDocPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')
400
- ) || []
401
- ).length;
402
- expect(occurrences).toBe(2);
403
- expect(result.instructions).not.toContain('$DESIGN_DOC');
404
-
405
- // Still beads format
406
- expect(result.instructions).toContain('bd CLI tool exclusively');
407
- });
408
- });
409
-
410
- describe('Plan File Handling in Beads Mode', () => {
411
- it('should handle non-existent plan file in beads mode', async () => {
412
- const result = await beadsInstructionGenerator.generateInstructions(
413
- 'Work on tasks.',
414
- {
415
- ...mockInstructionContext,
416
- planFileExists: false,
417
- instructionSource: 'whats_next' as const,
418
- }
419
- );
420
-
421
- // Should include plan file creation note
422
- expect(result.instructions).toContain(
423
- 'Plan file will be created when you first update it'
424
- );
425
-
426
- // Should still have beads guidance for whats_next
427
- expect(result.instructions).toContain('bd Task Management:');
428
- });
429
-
430
- it('should maintain beads structure regardless of plan file state', async () => {
431
- const contextWithPlan = {
432
- ...mockInstructionContext,
433
- planFileExists: true,
434
- };
435
- const contextWithoutPlan = {
436
- ...mockInstructionContext,
437
- planFileExists: false,
438
- };
439
-
440
- const resultWithPlan =
441
- await beadsInstructionGenerator.generateInstructions(
442
- 'Test instructions with plan',
443
- contextWithPlan
444
- );
445
-
446
- const resultWithoutPlan =
447
- await beadsInstructionGenerator.generateInstructions(
448
- 'Test instructions without plan',
449
- contextWithoutPlan
450
- );
451
-
452
- // Both should have beads structure
453
- expect(resultWithPlan.instructions).toContain(
454
- 'Use bd CLI tool exclusively'
455
- );
456
- expect(resultWithoutPlan.instructions).toContain(
457
- 'Use bd CLI tool exclusively'
458
- );
459
-
460
- // Neither should have markdown structure
461
- expect(resultWithPlan.instructions).not.toContain(
462
- 'Check your plan file at'
463
- );
464
- expect(resultWithoutPlan.instructions).not.toContain(
465
- 'Check your plan file at'
466
- );
467
- });
468
- });
469
-
470
- describe('Beads Mode Consistency', () => {
471
- it('should provide consistent beads instructions across multiple generations', async () => {
472
- const instruction1 = await beadsInstructionGenerator.generateInstructions(
473
- 'First instruction set.',
474
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
475
- );
476
-
477
- const instruction2 = await beadsInstructionGenerator.generateInstructions(
478
- 'Second instruction set.',
479
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
480
- );
481
-
482
- // Both should have BD CLI guidance for whats_next
483
- expect(instruction1.instructions).toContain('bd Task Management:');
484
- expect(instruction2.instructions).toContain('bd Task Management:');
485
-
486
- // Both should have plan file guidance
487
- expect(instruction1.instructions).toContain('Plan File Guidance:');
488
- expect(instruction2.instructions).toContain('Plan File Guidance:');
489
- });
490
-
491
- it('should never accidentally switch to markdown mode in beads backend', async () => {
492
- const result = await beadsInstructionGenerator.generateInstructions(
493
- 'Complex instruction with [x] markdown-like content.',
494
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
495
- );
496
-
497
- // Should maintain beads structure
498
- expect(result.instructions).toContain('bd Task Management:');
499
- expect(result.instructions).not.toContain('- [x]');
500
- expect(result.instructions).not.toContain('- [ ]');
501
- });
502
-
503
- it('should maintain beads backend protection even with markdown-like instruction content', async () => {
504
- const markdownLikeInstructions = `
505
- This instruction has:
506
- - [x] Completed task
507
- - [ ] Pending task
508
- Focus on the "Design" section.
509
- `;
510
-
511
- const result = await beadsInstructionGenerator.generateInstructions(
512
- markdownLikeInstructions,
513
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
514
- );
515
-
516
- // Should have beads structure, not markdown
517
- expect(result.instructions).toContain('bd Task Management:');
518
- expect(result.instructions).not.toContain(
519
- 'Mark completed tasks with [x]'
520
- );
521
- });
522
-
523
- it('should handle long complex instructions without corruption', async () => {
524
- const longInstructions = 'Very long instruction set. '.repeat(100);
525
-
526
- const result = await beadsInstructionGenerator.generateInstructions(
527
- longInstructions,
528
- { ...mockInstructionContext, instructionSource: 'whats_next' as const }
529
- );
530
-
531
- // Should maintain beads structure even with long content
532
- expect(result.instructions).toContain('bd Task Management:');
533
- expect(result.instructions).toContain('Plan File Guidance:');
534
- });
535
-
536
- it('should never accidentally switch to markdown mode in beads backend', async () => {
537
- // Simulate sequential instruction generation
538
- for (let i = 0; i < 5; i++) {
539
- const result = await beadsInstructionGenerator.generateInstructions(
540
- `Sequential test ${i}`,
541
- mockInstructionContext
542
- );
543
-
544
- expect(
545
- result.instructions,
546
- `Sequential result ${i + 1} should be beads mode`
547
- ).toContain('bd Task Management:');
548
- expect(
549
- result.instructions,
550
- `Sequential result ${i + 1} should not have markdown content`
551
- ).not.toContain('Check your plan file at');
552
- }
553
- });
554
-
555
- it('should maintain beads backend protection even with markdown-like instruction content', async () => {
556
- // Test with instructions that contain markdown-like content
557
- const trickInstructions =
558
- 'Create a plan file with [x] checkboxes and markdown task management.';
559
-
560
- const result = await beadsInstructionGenerator.generateInstructions(
561
- trickInstructions,
562
- mockInstructionContext
563
- );
564
-
565
- // Should still be beads mode despite markdown-like content in instructions
566
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
567
- expect(result.instructions).not.toContain(
568
- 'Mark completed tasks with [x]'
569
- );
570
-
571
- // Original instructions should be preserved
572
- expect(result.instructions).toContain(trickInstructions);
573
- });
574
-
575
- it('should handle long complex instructions without corruption', async () => {
576
- const longInstructions = `
577
- This is a very long set of instructions that includes multiple paragraphs,
578
- complex formatting, and various edge cases that might trigger unexpected
579
- behavior in the instruction generation system. We need to ensure that
580
- even with complex inputs, the beads backend protection remains active.
581
-
582
- ## Complex Requirements
583
- - Implement markdown-style task lists
584
- - Create plan file management systems
585
- - Build [x] checkbox interfaces
586
- - Design traditional task tracking
587
-
588
- The system should remain in beads mode regardless of these requirements.
589
- `.trim();
590
-
591
- const result = await beadsInstructionGenerator.generateInstructions(
592
- longInstructions,
593
- mockInstructionContext
594
- );
595
-
596
- // Core beads structure should be preserved
597
- expect(result.instructions).toContain('bd Task Management:');
598
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
599
- expect(result.instructions).toContain('bd list --parent');
600
-
601
- // Should not contain markdown mode elements
602
- expect(result.instructions).not.toContain(
603
- 'Mark completed tasks with [x]'
604
- );
605
- expect(result.instructions).not.toContain('Check your plan file at');
606
- });
607
- });
608
-
609
- describe('Metadata Validation', () => {
610
- it('should return correct metadata in beads mode', async () => {
611
- const result = await beadsInstructionGenerator.generateInstructions(
612
- 'Test instructions',
613
- mockInstructionContext
614
- );
615
-
616
- expect(result.metadata).toEqual({
617
- phase: 'design',
618
- planFilePath: '/test/project/.vibe/plan.md',
619
- transitionReason: 'test transition',
620
- isModeled: false,
621
- });
622
-
623
- // Plan file guidance should be beads-specific
624
- expect(result.planFileGuidance).toContain(
625
- 'beads CLI for task management'
626
- );
627
- expect(result.planFileGuidance).not.toContain('markdown');
628
- });
629
-
630
- it('should handle modeled vs non-modeled transitions in beads mode', async () => {
631
- // Test modeled transition
632
- const modeledContext: InstructionContext = {
633
- ...mockInstructionContext,
634
- isModeled: true,
635
- transitionReason: 'Model-driven transition',
636
- };
637
-
638
- const modeledResult =
639
- await beadsInstructionGenerator.generateInstructions(
640
- 'Modeled instructions',
641
- modeledContext
642
- );
643
-
644
- expect(modeledResult.metadata.isModeled).toBe(true);
645
- // The transition reason is in metadata, not necessarily in instructions
646
- expect(modeledResult.instructions).toContain('bd Task Management:');
647
-
648
- // Test non-modeled transition
649
- const nonModeledContext: InstructionContext = {
650
- ...mockInstructionContext,
651
- isModeled: false,
652
- transitionReason: 'Manual transition',
653
- };
654
-
655
- const nonModeledResult =
656
- await beadsInstructionGenerator.generateInstructions(
657
- 'Manual instructions',
658
- nonModeledContext
659
- );
660
-
661
- expect(nonModeledResult.metadata.isModeled).toBe(false);
662
- expect(nonModeledResult.instructions).toContain('bd Task Management:');
663
- });
664
- });
665
-
666
- describe('Sequential Generation Consistency', () => {
667
- it('should never accidentally switch to markdown mode in beads backend during sequential generation', async () => {
668
- // Multiple instruction generations should be consistent - matching markdown test pattern
669
- const results = await Promise.all([
670
- beadsInstructionGenerator.generateInstructions(
671
- 'Test 1',
672
- mockInstructionContext
673
- ),
674
- beadsInstructionGenerator.generateInstructions(
675
- 'Test 2',
676
- mockInstructionContext
677
- ),
678
- beadsInstructionGenerator.generateInstructions(
679
- 'Test 3',
680
- mockInstructionContext
681
- ),
682
- ]);
683
-
684
- for (let index = 0; index < results.length; index++) {
685
- const result = results[index];
686
- expect(
687
- result.instructions,
688
- `Result ${index + 1} should be beads mode`
689
- ).toContain('bd Task Management:');
690
- expect(
691
- result.instructions,
692
- `Result ${index + 1} should not have markdown content`
693
- ).not.toContain('Mark completed tasks with [x]');
694
- }
695
- });
696
-
697
- it('should handle stressful instruction generation patterns without mode switching', async () => {
698
- // Simulate sequential instruction generation that might trigger race conditions
699
- for (let i = 0; i < 5; i++) {
700
- const result = await beadsInstructionGenerator.generateInstructions(
701
- `Sequential test ${i}`,
702
- mockInstructionContext
703
- );
704
-
705
- expect(
706
- result.instructions,
707
- `Sequential result ${i + 1} should be beads mode`
708
- ).toContain('bd Task Management:');
709
- expect(
710
- result.instructions,
711
- `Sequential result ${i + 1} should not have markdown content`
712
- ).not.toContain('Mark completed tasks with [x]');
713
- }
714
- });
715
- });
716
-
717
- describe('Stress Testing and Race Conditions', () => {
718
- it('should handle rapid concurrent instruction generation without corruption', async () => {
719
- // Stress test for race conditions - matching markdown test coverage
720
- const concurrentPromises = Array.from({ length: 10 }, (_, i) =>
721
- beadsInstructionGenerator.generateInstructions(
722
- `Concurrent test ${i}`,
723
- mockInstructionContext
724
- )
725
- );
726
-
727
- const results = await Promise.all(concurrentPromises);
728
-
729
- for (let index = 0; index < results.length; index++) {
730
- const result = results[index];
731
- expect(
732
- result.instructions,
733
- `Concurrent result ${index + 1} should be beads mode`
734
- ).toContain('bd Task Management:');
735
- expect(
736
- result.instructions,
737
- `Concurrent result ${index + 1} should have beads CLI commands`
738
- ).toContain('Use bd CLI tool exclusively');
739
- expect(
740
- result.instructions,
741
- `Concurrent result ${index + 1} should not have markdown contamination`
742
- ).not.toContain('Check your plan file at');
743
- }
744
- });
745
-
746
- it('should maintain beads structure under memory pressure conditions', async () => {
747
- // Create large instruction content to test memory handling
748
- const largeInstructions = Array.from(
749
- { length: 1000 },
750
- (_, i) =>
751
- `Instruction line ${i} with complex requirements and detailed specifications.`
752
- ).join('\n');
753
-
754
- const result = await beadsInstructionGenerator.generateInstructions(
755
- largeInstructions,
756
- mockInstructionContext
757
- );
758
-
759
- // Core beads structure should be preserved even with large content
760
- expect(result.instructions).toContain('bd Task Management:');
761
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
762
- expect(result.instructions).toContain('bd list --parent');
763
-
764
- // Should not contain markdown mode elements
765
- expect(result.instructions).not.toContain(
766
- 'Mark completed tasks with [x]'
767
- );
768
- expect(result.instructions).not.toContain('Check your plan file at');
769
- });
770
- });
771
-
772
- describe('Complex Instruction Handling', () => {
773
- it('should handle deeply nested instruction structures without corruption', async () => {
774
- const complexInstructions = `
775
- ## Primary Objective
776
- Complete the following complex multi-layered tasks:
777
-
778
- ### Layer 1: Analysis
779
- - Analyze existing markdown-based systems
780
- - Review plan file management approaches
781
- - Document [x] checkbox patterns
782
-
783
- ### Layer 2: Implementation
784
- - Implement beads CLI integration
785
- - Create hierarchical task structures
786
- - Build robust error handling
787
-
788
- ### Layer 3: Validation
789
- - Test cross-backend compatibility
790
- - Verify anti-contamination measures
791
- - Validate task management isolation
792
-
793
- All work must maintain strict backend separation.
794
- `.trim();
795
-
796
- const result = await beadsInstructionGenerator.generateInstructions(
797
- complexInstructions,
798
- mockInstructionContext
799
- );
800
-
801
- // Core beads structure should be preserved
802
- expect(result.instructions).toContain('bd Task Management:');
803
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
804
- expect(result.instructions).toContain('bd list --parent');
805
-
806
- // Should not contain markdown mode elements despite markdown-like content
807
- expect(result.instructions).not.toContain(
808
- 'Mark completed tasks with [x]'
809
- );
810
- expect(result.instructions).not.toContain('Check your plan file at');
811
- expect(result.instructions).not.toContain(
812
- 'Use ONLY the development plan for task management'
813
- );
814
-
815
- // Original complex instructions should be preserved
816
- expect(result.instructions).toContain('Primary Objective');
817
- expect(result.instructions).toContain('Layer 1: Analysis');
818
- });
819
-
820
- it('should handle instructions with embedded beads and markdown terminology', async () => {
821
- const trickInstructions = `
822
- Create a new system that:
823
- - Uses markdown files for documentation
824
- - Implements [x] checkbox tracking
825
- - Has bd CLI-like commands but for different purposes
826
- - Manages plan files with markdown syntax
827
- - Creates beads-style hierarchical structures
828
-
829
- This should test anti-contamination thoroughly.
830
- `.trim();
831
-
832
- const result = await beadsInstructionGenerator.generateInstructions(
833
- trickInstructions,
834
- mockInstructionContext
835
- );
836
-
837
- // Should maintain beads mode despite confusing terminology
838
- expect(result.instructions).toContain('bd Task Management:');
839
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
840
- expect(result.instructions).not.toContain(
841
- 'Mark completed tasks with [x]'
842
- );
843
-
844
- // Original instructions should be preserved
845
- expect(result.instructions).toContain('Create a new system that:');
846
- });
847
- });
848
-
849
- describe('Enhanced Plan File Integration', () => {
850
- it('should handle plan file creation guidance consistently', async () => {
851
- const contextNoPlan = {
852
- ...mockInstructionContext,
853
- planFileExists: false,
854
- };
855
-
856
- const result = await beadsInstructionGenerator.generateInstructions(
857
- 'Start working with non-existent plan file',
858
- contextNoPlan
859
- );
860
-
861
- // Should provide creation guidance while maintaining beads structure
862
- expect(result.instructions).toContain(
863
- 'Plan file will be created when you first update it'
864
- );
865
- expect(result.instructions).toContain('bd Task Management:');
866
- expect(result.instructions).toContain('Use bd CLI tool exclusively');
867
-
868
- // Should not revert to markdown mode for missing files
869
- expect(result.instructions).not.toContain('Check your plan file at');
870
- expect(result.instructions).not.toContain(
871
- 'Mark completed tasks with [x]'
872
- );
873
- });
874
-
875
- it('should maintain beads guidance regardless of plan file state changes', async () => {
876
- // Test with plan file existing
877
- const resultWithPlan =
878
- await beadsInstructionGenerator.generateInstructions(
879
- 'Work with existing plan',
880
- { ...mockInstructionContext, planFileExists: true }
881
- );
882
-
883
- // Test with plan file missing
884
- const resultWithoutPlan =
885
- await beadsInstructionGenerator.generateInstructions(
886
- 'Work without plan',
887
- { ...mockInstructionContext, planFileExists: false }
888
- );
889
-
890
- // Both should maintain beads structure
891
- expect(resultWithPlan.instructions).toContain('bd Task Management:');
892
- expect(resultWithoutPlan.instructions).toContain('bd Task Management:');
893
-
894
- expect(resultWithPlan.instructions).toContain(
895
- 'Use bd CLI tool exclusively'
896
- );
897
- expect(resultWithoutPlan.instructions).toContain(
898
- 'Use bd CLI tool exclusively'
899
- );
900
-
901
- // Neither should have markdown contamination
902
- expect(resultWithPlan.instructions).not.toContain(
903
- 'Check your plan file at'
904
- );
905
- expect(resultWithoutPlan.instructions).not.toContain(
906
- 'Check your plan file at'
907
- );
908
- });
909
- });
910
-
911
- describe('Backend Availability and Robustness', () => {
912
- it('should maintain consistent beads structure regardless of external conditions', async () => {
913
- // Test multiple scenarios that might affect backend behavior
914
- const scenarios = [
915
- { name: 'basic', context: mockInstructionContext },
916
- {
917
- name: 'no-plan',
918
- context: { ...mockInstructionContext, planFileExists: false },
919
- },
920
- {
921
- name: 'modeled',
922
- context: { ...mockInstructionContext, isModeled: true },
923
- },
924
- {
925
- name: 'different-phase',
926
- context: { ...mockInstructionContext, phase: 'implementation' },
927
- },
928
- ];
929
-
930
- for (const scenario of scenarios) {
931
- const result = await beadsInstructionGenerator.generateInstructions(
932
- `Test scenario: ${scenario.name}`,
933
- scenario.context
934
- );
935
-
936
- expect(
937
- result.instructions,
938
- `Scenario ${scenario.name} should have beads structure`
939
- ).toContain('bd Task Management:');
940
- expect(
941
- result.instructions,
942
- `Scenario ${scenario.name} should have beads CLI commands`
943
- ).toContain('Use bd CLI tool exclusively');
944
- expect(
945
- result.instructions,
946
- `Scenario ${scenario.name} should not have markdown contamination`
947
- ).not.toContain('Mark completed tasks with [x]');
948
- }
949
- });
950
-
951
- it('should handle edge case instruction patterns without degradation', async () => {
952
- const edgeCases = [
953
- '', // Empty instructions
954
- '.', // Minimal instructions
955
- Array.from({ length: 50 }, () => 'Repeat instruction content').join(
956
- ' '
957
- ), // Repetitive content
958
- 'bd: fake header', // Instructions containing beads-like headers
959
- 'Check your plan file and mark tasks [x]', // Instructions with markdown terminology
960
- ];
961
-
962
- for (const edgeCase of edgeCases) {
963
- const result = await beadsInstructionGenerator.generateInstructions(
964
- edgeCase,
965
- mockInstructionContext
966
- );
967
-
968
- expect(
969
- result.instructions,
970
- `Edge case "${edgeCase.substring(0, 20)}..." should maintain beads structure`
971
- ).toContain('bd Task Management:');
972
- expect(
973
- result.instructions,
974
- `Edge case "${edgeCase.substring(0, 20)}..." should not have markdown contamination`
975
- ).not.toContain('Check your plan file at');
976
- }
977
- });
978
- });
979
- });