This document provides comprehensive testing guidance for the AI-powered task management and requirements traceability features.
tests/
├── ai-services/ # AI service layer tests
│ ├── AIServiceFactory.test.ts # AI provider management
│ ├── PRDGenerationService.test.ts
│ ├── TaskGenerationService.test.ts
│ └── RequirementsTraceabilityService.test.ts
├── ai-tools/ # MCP tool tests
│ ├── GeneratePRDTool.test.ts
│ ├── ParsePRDTool.test.ts
│ ├── CreateTraceabilityMatrixTool.test.ts
│ └── [other AI tool tests]
└── integration/ # End-to-end tests
└── ai-workflow.test.ts
npm test# Run only AI-related tests
npm run test:ai
# Watch mode for AI tests
npm run test:ai:watch
# Coverage for AI tests
npm run test:ai:coveragenpm run test:corenpm run test:integration- Provider Detection: Tests automatic detection of available AI providers
- Fallback Logic: Tests switching between providers on failure
- Rate Limiting: Tests rate limit handling and provider switching
- Configuration: Tests model configuration and API key validation
- Health Checks: Tests provider health monitoring
- Metrics: Tests usage tracking and error reporting
- PRD Generation: Tests complete PRD generation from project ideas
- Research Integration: Tests market research inclusion
- Quality Validation: Tests PRD completeness scoring
- Feature Extraction: Tests feature extraction from PRD content
- Enhancement: Tests PRD improvement functionality
- Error Handling: Tests AI service error scenarios
- Task Generation: Tests task creation from PRD content
- Complexity Analysis: Tests AI-powered complexity assessment
- Task Expansion: Tests breaking down complex tasks
- Recommendations: Tests next task recommendation logic
- Validation: Tests generated task structure validation
- Subtask Handling: Tests subtask generation and management
- Business Requirements Extraction: Tests extraction from PRD objectives
- Use Case Generation: Tests actor-goal-scenario creation
- Task Enhancement: Tests adding traceability to tasks
- Matrix Creation: Tests comprehensive traceability matrix
- Relationship Detection: Tests automatic relationship identification
- Coverage Analysis: Tests gap identification and metrics
- Successful Generation: Tests complete PRD generation workflow
- Research Integration: Tests PRD generation with market research
- Quality Assessment: Tests completeness scoring and recommendations
- Error Handling: Tests service error scenarios
- Input Validation: Tests parameter validation
- Output Formatting: Tests comprehensive summary generation
- Task Generation: Tests PRD parsing and task creation
- Traceability Matrix: Tests automatic traceability creation
- Complexity Filtering: Tests task filtering by complexity
- Coverage Analysis: Tests orphaned task detection
- Error Handling: Tests service failure scenarios
- Metrics Calculation: Tests project metrics computation
- Matrix Creation: Tests comprehensive traceability matrix generation
- Validation: Tests completeness scoring and gap identification
- Sample Paths: Tests traceability path generation
- Content Extraction: Tests objective and metric extraction
- Error Handling: Tests service error scenarios
- Coverage Metrics: Tests coverage calculation accuracy
- Complete Project Workflow: Tests PRD → Tasks → Traceability
- Feature Addition: Tests feature addition with lifecycle management
- Requirements Tracking: Tests end-to-end traceability
- AI Provider Fallback: Tests multi-provider scenarios
- Error Recovery: Tests error handling across services
const mockPRD = {
id: 'prd-1',
title: 'Task Management App PRD',
overview: 'Comprehensive task management application',
objectives: ['Improve productivity', 'Streamline workflows'],
features: [
{
id: 'feature-1',
title: 'Task Creation',
description: 'Create and manage tasks',
priority: 'high',
userStories: ['As a user, I want to create tasks'],
acceptanceCriteria: ['User can create task with title'],
estimatedComplexity: 5
}
],
// ... additional PRD properties
};const mockTasks = [
{
id: 'task-1',
title: 'Setup authentication infrastructure',
description: 'Configure OAuth and JWT handling',
complexity: 4,
estimatedHours: 8,
priority: 'high',
status: 'pending',
dependencies: [],
acceptanceCriteria: ['OAuth is configured'],
tags: ['auth', 'setup']
}
];const mockTraceabilityMatrix = {
id: 'tm-1',
projectId: 'test-project',
prdId: 'prd-1',
businessRequirements: [...],
features: [...],
useCases: [...],
tasks: [...],
traceabilityLinks: [...],
coverage: {
businessRequirementsCovered: 5,
featuresCovered: 3,
useCasesCovered: 8,
tasksWithTraceability: 22,
orphanedTasks: [],
unimplementedRequirements: []
}
};// Mock AI service responses
vi.mocked(AIServiceFactory).mockImplementation(() => ({
getProvider: vi.fn().mockResolvedValue({
generateText: vi.fn().mockResolvedValue('Generated content'),
generateObject: vi.fn().mockResolvedValue(mockObject)
})
}));// Mock service methods
vi.mocked(PRDGenerationService).mockImplementation(() => ({
generatePRDFromIdea: vi.fn().mockResolvedValue(mockPRD),
validatePRDCompleteness: vi.fn().mockResolvedValue(mockValidation)
}));- Complete Workflow: PRD generation → Task parsing → Traceability creation
- Feature Addition: Add feature → Generate tasks → Create lifecycle
- Task Management: Get recommendations → Analyze complexity → Expand tasks
- AI Provider Failures: Test fallback mechanisms
- Invalid Input: Test parameter validation
- Service Errors: Test error propagation and handling
- Rate Limiting: Test provider switching on rate limits
- Empty Content: Test handling of minimal input
- Large Projects: Test performance with many tasks/features
- Complex Dependencies: Test circular dependency detection
- Malformed Data: Test resilience to invalid data structures
- AI Services: 85% line coverage
- AI Tools: 80% line coverage
- Integration Tests: 70% path coverage
- AI provider selection and fallback
- Traceability link generation
- Task complexity analysis
- Error handling and recovery
- Test with large PRDs (50+ features)
- Test with complex traceability matrices (100+ tasks)
- Test AI provider response times
- Monitor memory usage during large operations
- Test for memory leaks in long-running processes
# Enable debug logging for tests
DEBUG=ai-services:*,test:* npm run test:ai
# Run specific test with verbose output
npm run test:ai -- --testNamePattern="PRD generation"Error: No AI providers available
Solution: Mock AI providers in test setup
Error: Test timeout
Solution: Increase timeout for AI operations or mock responses
Error: JavaScript heap out of memory
Solution: Use --max-old-space-size=4096 for large test suites
- name: Run AI Tests
run: |
npm run test:ai:coverage
env:
# Mock API keys for testing
ANTHROPIC_API_KEY: test-key
OPENAI_API_KEY: test-key- Coverage reports generated in
coverage/directory - Test results exported in JUnit format
- Performance metrics tracked over time
- Start MCP Server:
npm start - List Tools: Verify all 8 AI tools are available
- Test Tool Execution: Run sample commands
- Validate Output: Check response format and content
- Complete Workflow: Test end-to-end scenarios
- Error Scenarios: Test with invalid inputs
- Performance: Test with realistic data sizes
- Use Descriptive Names: Test names should clearly describe the scenario
- Mock External Dependencies: Always mock AI providers and external services
- Test Error Paths: Include negative test cases
- Validate Output Structure: Check both content and format
- Use Realistic Data: Test with representative data sizes
- Update Mocks: Keep mock data synchronized with real responses
- Review Coverage: Regularly check and improve test coverage
- Performance Monitoring: Track test execution times
- Documentation: Keep test documentation up to date
- Ensure all external dependencies are properly mocked
- Verify mock return values match expected types
- Check async mock handling
- Increase test timeouts for AI operations
- Mock slow AI provider responses
- Use fake timers for time-dependent tests
- Clean up resources in test teardown
- Use smaller test data sets
- Monitor memory usage patterns
- Use
console.logfor debugging test data - Enable debug logging for specific modules
- Use Jest's
--verboseflag for detailed output - Use
--detectOpenHandlesto find resource leaks