UNPKG

task-master-neo-sdlc

Version:

Enhanced task management system with Neo SDLC agents and MCP tools for comprehensive, AI-driven software development lifecycle management.

258 lines (223 loc) 7.67 kB
/** * QA Agent Tests * * Tests for the QA Agent and TDD Framework. */ // Import dependencies import { QAAgent } from '../qa-agent.js'; import { BaseAgent } from '../base-agent.js'; import { TDDFramework } from '../../tdd-framework.js'; import { log } from '../../../../utils/logging.js'; import fs from 'fs'; import path from 'path'; // Mock dependencies jest.mock('../../../../utils/logging.js', () => ({ log: { info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn(), }, })); // Mock developer agent class MockDeveloperAgent extends BaseAgent { constructor(id, options = {}) { super(id, { ...options, role: 'developer', capabilities: [ 'react', 'component-design', 'frontend', 'api-design', 'backend', 'data-handling', 'coding', 'problem-solving', 'algorithm-design', 'software-design' ], knowledgeDomains: ['web-development', 'react', 'node.js'] }); } async implementFeature(params, context) { return { implementationPath: `src/components/${params.implementationTarget}.js`, implementationCode: `// Implementation for ${params.implementationTarget}\nfunction ${params.implementationTarget}() {\n return <div>Hello World</div>;\n}\n\nexport default ${params.implementationTarget};`, success: true }; } async refactorImplementation(params, context) { return { implementationPath: params.implementationPath, implementationCode: `// Refactored implementation\nfunction ${params.implementationPath.split('/').pop().replace('.js', '')}() {\n return <div data-testid="component">Hello World</div>;\n}\n\nexport default ${params.implementationPath.split('/').pop().replace('.js', '')};`, refactored: true, message: 'Refactored implementation to pass tests' }; } } // Mock AgentWorkflowSystem class MockAgentWorkflowSystem { constructor() { this.agents = new Map(); this.projectRoot = process.cwd(); this.tddFramework = new TDDFramework(this); } async registerAgent(agent) { this.agents.set(agent.id, agent); return agent; } async fetchTaskMasterTaskById(taskId) { return { id: parseInt(taskId), title: 'Implement User Profile Component', description: 'Create a React component for displaying user profile information', status: 'pending', acceptanceCriteria: [ 'User can view their profile information', 'User can edit their name, bio, and avatar' ] }; } } // Test suite describe('QA Agent', () => { let qaAgent; let devAgent; let agentWorkflow; // Set up before each test beforeEach(() => { // Create QA agent qaAgent = new QAAgent('qa-1', { capabilities: ['testing', 'quality-assurance', 'tdd'], knowledgeDomains: ['jest', 'testing-library', 'react-testing'], useAI: false // Disable AI for tests }); // Create developer agent devAgent = new MockDeveloperAgent('dev-1'); // Create agent workflow system agentWorkflow = new MockAgentWorkflowSystem(); // Register agents agentWorkflow.registerAgent(qaAgent); agentWorkflow.registerAgent(devAgent); // Clear mocks jest.clearAllMocks(); }); // Test QA Agent initialization test('QA Agent initializes with correct properties', () => { expect(qaAgent.id).toBe('qa-1'); expect(qaAgent.role).toBe('qa'); expect(qaAgent.capabilities).toContain('testing'); expect(qaAgent.capabilities).toContain('quality-assurance'); expect(qaAgent.capabilities).toContain('tdd'); expect(qaAgent.knowledgeDomains).toContain('jest'); expect(qaAgent.knowledgeDomains).toContain('testing-library'); expect(qaAgent.knowledgeDomains).toContain('react-testing'); }); // Test createTest method test('QA Agent can create tests', async () => { // Create test parameters const params = { testTarget: 'UserProfile', testTypes: ['unit', 'integration'], coverage: 80, acceptanceCriteria: [ 'User can view their profile information', 'User can edit their name, bio, and avatar' ] }; // Create context const context = { taskId: '1', workflowId: 'test-workflow', testFramework: 'jest', runTests: false, projectRoot: process.cwd() }; // Call createTest method const result = await qaAgent.createTest(params, context); // Verify result expect(result).toBeDefined(); expect(result.testPath).toBeDefined(); expect(result.testCode).toBeDefined(); expect(result.testFramework).toBe('jest'); }); // Test validateImplementation method test('QA Agent can validate implementation', async () => { // Create validation parameters const params = { implementationPath: 'src/components/UserProfile.js', testPath: 'tests/components/UserProfile.test.js', coverage: 80, testFramework: 'jest', testTypes: ['unit', 'integration'] }; // Create context const context = { taskId: '1', workflowId: 'test-workflow', testFramework: 'jest', projectRoot: process.cwd(), runTests: false }; // Call validateImplementation method const result = await qaAgent.validateImplementation(params, context); // Verify result expect(result).toBeDefined(); expect(result.passed).toBeDefined(); expect(result.coverage).toBeDefined(); expect(result.feedback).toBeDefined(); }); // Test TDD Framework test('TDD Framework can create and execute workflow', async () => { // Create TDD workflow const workflow = await agentWorkflow.tddFramework.createTDDWorkflow({ id: 'tdd-workflow-1', taskMasterId: '1', makerAgentId: 'dev-1', checkerAgentId: 'qa-1', testConfig: { framework: 'jest', coverage: 80, testTypes: ['unit', 'integration'], useAI: false } }); // Verify workflow expect(workflow).toBeDefined(); expect(workflow.id).toBe('tdd-workflow-1'); expect(workflow.taskMasterId).toBe('1'); expect(workflow.makerAgentId).toBe('dev-1'); expect(workflow.checkerAgentId).toBe('qa-1'); expect(workflow.steps.length).toBeGreaterThan(0); // Execute workflow const result = await agentWorkflow.tddFramework.executeTDDWorkflow('tdd-workflow-1'); // Verify result expect(result).toBeDefined(); expect(result.success).toBeDefined(); expect(result.workflowId).toBe('tdd-workflow-1'); expect(result.results).toBeDefined(); }); }); // Test suite for test framework utilities describe('Test Framework Utilities', () => { // Test determineTestFramework method test('QA Agent can determine test framework', () => { // Create QA agent const qaAgent = new QAAgent('qa-1'); // Create context const context = { testFramework: 'jest', projectRoot: process.cwd() }; // Call determineTestFramework method const testFramework = qaAgent.determineTestFramework('UserProfile', context); // Verify result expect(testFramework).toBe('jest'); }); // Test determineTestPath method test('QA Agent can determine test path', () => { // Create QA agent const qaAgent = new QAAgent('qa-1'); // Call determineTestPath method const testPath = qaAgent.determineTestPath('UserProfile', 'jest', process.cwd()); // Verify result expect(testPath).toBeDefined(); expect(testPath).toContain('UserProfile'); expect(testPath).toContain('.test.js'); }); });