UNPKG

task-engine-ai-core

Version:

Revolutionary AI-driven task management system with complete transformation trilogy: Frontend v0.1.0, Backend v0.2.0, CLI v0.3.0 - Enterprise-grade performance with 95% improvements

600 lines (509 loc) 25.5 kB
/** * Active Agent Intelligence Engine Test Suite * * Comprehensive tests for the Active Agent Intelligence Engine that provides * complete functional parity with external AI providers. */ import { activeAgentIntelligenceEngine, generateTaskWithActiveAgent, analyzeTaskWithActiveAgent, enhanceTaskWithActiveAgent, updateTaskWithActiveAgent, expandTaskWithActiveAgent, enhanceWithActiveAgentResearch, getActiveAgentIntelligenceStats } from '../core/active-agent-intelligence-engine.js'; import { logger } from '../utils/logger-utils.js'; /** * Test Configuration */ const TEST_CONFIG = { projectRoot: 'C:\\Users\\visual-code\\Task-engine', enableLogging: true, testTimeout: 60000 }; /** * Mock MCP Session for testing */ const mockSession = { id: 'active-agent-intelligence-test-session', clientCapabilities: { sampling: { enabled: true }, roots: { listChanged: true } }, capabilities: { tools: true, resources: true }, clientInfo: { name: 'active-agent-intelligence-test-client', version: '1.0.0' } }; /** * Active Agent Intelligence Test Suite */ class ActiveAgentIntelligenceTestSuite { constructor() { this.testResults = []; this.startTime = Date.now(); this.testData = { generatedTasks: [], analyzedTasks: [], enhancedTasks: [], updatedTasks: [], expandedTasks: [] }; } /** * Run complete active agent intelligence test suite */ async runCompleteTestSuite() { console.log('🧠 Starting Active Agent Intelligence Engine Test Suite...\n'); try { await this.testTaskGeneration(); await this.testTaskAnalysis(); await this.testTaskEnhancement(); await this.testTaskUpdates(); await this.testSubtaskExpansion(); await this.testResearchIntegration(); await this.testIntelligenceStatistics(); await this.testFunctionalParity(); this.printComprehensiveTestSummary(); } catch (error) { console.error('❌ Active agent intelligence test suite failed:', error.message); process.exit(1); } } /** * Test task generation capabilities */ async testTaskGeneration() { console.log('📝 Testing Task Generation with Active Agent Intelligence...'); try { // Test simple task generation const simpleTask = await generateTaskWithActiveAgent( 'Create a user login form with email and password fields', { projectType: 'web-application' }, mockSession ); this.assert(simpleTask.success, 'Simple task generation should succeed'); this.assert(simpleTask.task.title, 'Generated task should have a title'); this.assert(simpleTask.task.description, 'Generated task should have a description'); this.assert(simpleTask.task.details, 'Generated task should have implementation details'); this.assert(simpleTask.task.testStrategy, 'Generated task should have a test strategy'); this.assert(simpleTask.task.priority, 'Generated task should have a priority'); this.assert(simpleTask.intelligence.source === 'active_agent', 'Should use active agent intelligence'); // Test complex task generation const complexTask = await generateTaskWithActiveAgent( 'Implement a comprehensive microservices architecture with OAuth2 authentication, real-time messaging, distributed caching, and monitoring dashboard. This is critical and urgent for production deployment.', { projectType: 'enterprise', businessImpact: 'high', deadline: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000) // 5 days }, mockSession ); this.assert(complexTask.success, 'Complex task generation should succeed'); this.assert(complexTask.task.priority === 'high', 'Should detect high priority from urgency indicators'); this.assert(complexTask.task.acceptanceCriteria, 'Complex task should have acceptance criteria'); this.assert(complexTask.task.riskAssessment, 'Complex task should have risk assessment'); // Test task generation with dependencies const dependentTask = await generateTaskWithActiveAgent( 'Create API documentation that depends on task 5 and requires task 7 to be completed first', { relatedTasks: [5, 7] }, mockSession ); this.assert(dependentTask.success, 'Dependent task generation should succeed'); this.assert(dependentTask.task.dependencies.includes(5), 'Should extract dependency on task 5'); this.assert(dependentTask.task.dependencies.includes(7), 'Should extract dependency on task 7'); this.testData.generatedTasks.push(simpleTask, complexTask, dependentTask); this.recordTestResult('Task Generation', true); console.log('✅ Task Generation tests passed\n'); } catch (error) { this.recordTestResult('Task Generation', false, error.message); console.log('❌ Task Generation tests failed:', error.message, '\n'); } } /** * Test task analysis capabilities */ async testTaskAnalysis() { console.log('🔍 Testing Task Analysis with Active Agent Intelligence...'); try { // Test simple task analysis const simpleTaskData = { title: 'Update button color', description: 'Change the submit button color from blue to green', details: 'Simple CSS change' }; const simpleAnalysis = await analyzeTaskWithActiveAgent( simpleTaskData, { projectType: 'web-application' }, mockSession ); this.assert(simpleAnalysis.success, 'Simple task analysis should succeed'); this.assert(simpleAnalysis.analysis.complexity_score <= 3, 'Simple task should have low complexity'); this.assert(!simpleAnalysis.recommendations.shouldExpand, 'Simple task should not need expansion'); // Test complex task analysis const complexTaskData = { title: 'Implement distributed microservices architecture', description: 'Design and implement a scalable microservices architecture with service discovery, load balancing, circuit breakers, and distributed tracing', details: 'Enterprise-grade system with high availability requirements' }; const complexAnalysis = await analyzeTaskWithActiveAgent( complexTaskData, { projectType: 'enterprise' }, mockSession ); this.assert(complexAnalysis.success, 'Complex task analysis should succeed'); this.assert(complexAnalysis.analysis.complexity_score >= 7, 'Complex task should have high complexity'); this.assert(complexAnalysis.recommendations.shouldExpand, 'Complex task should need expansion'); this.assert(complexAnalysis.recommendations.recommendedSubtasks >= 5, 'Should recommend multiple subtasks'); // Test analysis with risk assessment const riskyTaskData = { title: 'Migrate production database', description: 'Migrate critical production database with zero downtime', details: 'High-risk operation affecting all users' }; const riskyAnalysis = await analyzeTaskWithActiveAgent( riskyTaskData, { environment: 'production' }, mockSession ); this.assert(riskyAnalysis.success, 'Risky task analysis should succeed'); this.assert(riskyAnalysis.analysis.risk_assessment.length > 0, 'Should identify risks'); this.testData.analyzedTasks.push(simpleAnalysis, complexAnalysis, riskyAnalysis); this.recordTestResult('Task Analysis', true); console.log('✅ Task Analysis tests passed\n'); } catch (error) { this.recordTestResult('Task Analysis', false, error.message); console.log('❌ Task Analysis tests failed:', error.message, '\n'); } } /** * Test task enhancement capabilities */ async testTaskEnhancement() { console.log('✨ Testing Task Enhancement with Active Agent Intelligence...'); try { // Test enhancement from minimal prompt const minimalPrompt = 'user auth'; const enhancedTask = await enhanceTaskWithActiveAgent( minimalPrompt, {}, { projectType: 'web-application' }, mockSession ); this.assert(enhancedTask.success, 'Task enhancement should succeed'); this.assert(enhancedTask.enhanced_task.title.length > minimalPrompt.length, 'Should expand minimal title'); this.assert(enhancedTask.enhanced_task.description.length > minimalPrompt.length, 'Should expand minimal description'); this.assert(enhancedTask.enhanced_task.details, 'Should generate implementation details'); this.assert(enhancedTask.enhanced_task.testStrategy, 'Should generate test strategy'); // Test enhancement with existing data const existingData = { title: 'User Authentication', description: 'Basic login functionality' }; const enhancedExisting = await enhanceTaskWithActiveAgent( 'Add OAuth2 integration and multi-factor authentication support', existingData, { projectType: 'enterprise' }, mockSession ); this.assert(enhancedExisting.success, 'Enhancement with existing data should succeed'); this.assert(enhancedExisting.enhanced_task.title.includes('Authentication'), 'Should preserve existing title context'); this.assert(enhancedExisting.enhanced_task.description.includes('OAuth2'), 'Should integrate new requirements'); // Test priority detection const urgentPrompt = 'URGENT: Fix critical security vulnerability in authentication system ASAP'; const urgentTask = await enhanceTaskWithActiveAgent( urgentPrompt, {}, {}, mockSession ); this.assert(urgentTask.success, 'Urgent task enhancement should succeed'); this.assert(urgentTask.enhanced_task.priority === 'high', 'Should detect high priority from urgency indicators'); this.testData.enhancedTasks.push(enhancedTask, enhancedExisting, urgentTask); this.recordTestResult('Task Enhancement', true); console.log('✅ Task Enhancement tests passed\n'); } catch (error) { this.recordTestResult('Task Enhancement', false, error.message); console.log('❌ Task Enhancement tests failed:', error.message, '\n'); } } /** * Test task update capabilities */ async testTaskUpdates() { console.log('🔄 Testing Task Updates with Active Agent Intelligence...'); try { const existingTask = { id: 'test-task-1', title: 'User Registration Form', description: 'Create a basic user registration form', priority: 'medium', status: 'in-progress' }; // Test intelligent update const updateResult = await updateTaskWithActiveAgent( 'test-task-1', 'Add email verification and password strength validation. This is now high priority due to security requirements.', existingTask, { securityFocus: true }, mockSession ); this.assert(updateResult.success, 'Task update should succeed'); this.assert(updateResult.updated_task.priority === 'high', 'Should update priority based on context'); this.assert(updateResult.changes_applied, 'Should track changes applied'); // Test update with new requirements const requirementUpdate = await updateTaskWithActiveAgent( 'test-task-1', 'Add integration with external identity provider and GDPR compliance features', existingTask, { compliance: 'GDPR' }, mockSession ); this.assert(requirementUpdate.success, 'Requirement update should succeed'); this.assert(requirementUpdate.updated_task.description.includes('GDPR'), 'Should integrate new requirements'); this.testData.updatedTasks.push(updateResult, requirementUpdate); this.recordTestResult('Task Updates', true); console.log('✅ Task Updates tests passed\n'); } catch (error) { this.recordTestResult('Task Updates', false, error.message); console.log('❌ Task Updates tests failed:', error.message, '\n'); } } /** * Test subtask expansion capabilities */ async testSubtaskExpansion() { console.log('🌳 Testing Subtask Expansion with Active Agent Intelligence...'); try { const parentTask = { id: 'parent-task-1', title: 'E-commerce Checkout System', description: 'Implement complete checkout system with payment processing, inventory management, and order tracking', complexity: 'high' }; // Test intelligent expansion const expansionResult = await expandTaskWithActiveAgent( parentTask, { numSubtasks: 5 }, mockSession ); this.assert(expansionResult.success, 'Task expansion should succeed'); this.assert(expansionResult.subtasks.length === 5, 'Should generate requested number of subtasks'); this.assert(expansionResult.subtasks.every(st => st.title && st.description), 'All subtasks should have title and description'); this.assert(expansionResult.dependencies, 'Should define subtask dependencies'); this.assert(expansionResult.expansion_strategy, 'Should define expansion strategy'); // Test expansion with context const contextualExpansion = await expandTaskWithActiveAgent( { id: 'api-task-1', title: 'REST API Development', description: 'Create RESTful API for user management' }, { numSubtasks: 4, projectType: 'api', methodology: 'agile' }, mockSession ); this.assert(contextualExpansion.success, 'Contextual expansion should succeed'); this.assert(contextualExpansion.subtasks.length === 4, 'Should respect subtask count'); this.testData.expandedTasks.push(expansionResult, contextualExpansion); this.recordTestResult('Subtask Expansion', true); console.log('✅ Subtask Expansion tests passed\n'); } catch (error) { this.recordTestResult('Subtask Expansion', false, error.message); console.log('❌ Subtask Expansion tests failed:', error.message, '\n'); } } /** * Test research integration capabilities */ async testResearchIntegration() { console.log('🔬 Testing Research Integration with Active Agent Intelligence...'); try { // Test research enhancement const researchResult = await enhanceWithActiveAgentResearch( 'task_generation', { title: 'Machine Learning Model Training', description: 'Train ML model for recommendation system' }, { domain: 'machine_learning' }, mockSession ); this.assert(researchResult.success, 'Research enhancement should succeed'); this.assert(researchResult.research_enhanced, 'Should indicate research was applied'); this.assert(researchResult.enhanced_data, 'Should provide enhanced data'); this.assert(researchResult.research_insights, 'Should provide research insights'); // Test research with different operation types const analysisResearch = await enhanceWithActiveAgentResearch( 'task_analysis', { complexity: 'high', domain: 'security' }, { focus: 'best_practices' }, mockSession ); this.assert(analysisResearch.success, 'Analysis research should succeed'); this.recordTestResult('Research Integration', true); console.log('✅ Research Integration tests passed\n'); } catch (error) { this.recordTestResult('Research Integration', false, error.message); console.log('❌ Research Integration tests failed:', error.message, '\n'); } } /** * Test intelligence statistics and monitoring */ async testIntelligenceStatistics() { console.log('📊 Testing Intelligence Statistics and Monitoring...'); try { const stats = getActiveAgentIntelligenceStats(); this.assert(stats.tasksGenerated !== undefined, 'Should track tasks generated'); this.assert(stats.tasksAnalyzed !== undefined, 'Should track tasks analyzed'); this.assert(stats.tasksEnhanced !== undefined, 'Should track tasks enhanced'); this.assert(stats.tasksUpdated !== undefined, 'Should track tasks updated'); this.assert(stats.subtasksExpanded !== undefined, 'Should track subtasks expanded'); this.assert(stats.successRate !== undefined, 'Should track success rate'); this.assert(stats.knowledgeBaseSize, 'Should track knowledge base size'); // Verify statistics are being updated this.assert(stats.tasksGenerated > 0, 'Should have generated tasks during testing'); this.assert(stats.tasksAnalyzed > 0, 'Should have analyzed tasks during testing'); this.recordTestResult('Intelligence Statistics', true); console.log('✅ Intelligence Statistics tests passed\n'); } catch (error) { this.recordTestResult('Intelligence Statistics', false, error.message); console.log('❌ Intelligence Statistics tests failed:', error.message, '\n'); } } /** * Test functional parity with external AI providers */ async testFunctionalParity() { console.log('🎯 Testing Functional Parity with External AI Providers...'); try { // Test equivalent task generation quality const parityTest = await generateTaskWithActiveAgent( 'Implement a scalable real-time chat application with WebSocket connections, message persistence, user authentication, file sharing, and emoji support. The system should handle 10,000 concurrent users and integrate with existing user management system.', { projectType: 'web-application', scalability: 'high', integration: 'required' }, mockSession ); this.assert(parityTest.success, 'Parity test should succeed'); this.assert(parityTest.task.title.length > 20, 'Should generate comprehensive title'); this.assert(parityTest.task.description.length > 100, 'Should generate detailed description'); this.assert(parityTest.task.details.length > 200, 'Should generate comprehensive implementation details'); this.assert(parityTest.task.testStrategy.length > 100, 'Should generate detailed test strategy'); this.assert(parityTest.task.acceptanceCriteria.length > 5, 'Should generate multiple acceptance criteria'); this.assert(parityTest.task.riskAssessment.length > 0, 'Should identify risks for complex tasks'); // Test intelligence confidence levels this.assert(parityTest.intelligence.confidence >= 0.9, 'Should have high confidence for well-structured prompts'); this.recordTestResult('Functional Parity', true); console.log('✅ Functional Parity tests passed\n'); } catch (error) { this.recordTestResult('Functional Parity', false, error.message); console.log('❌ Functional Parity tests failed:', error.message, '\n'); } } /** * Assert a condition * @param {boolean} condition - Condition to test * @param {string} message - Error message if condition fails */ assert(condition, message) { if (!condition) { throw new Error(`Assertion failed: ${message}`); } } /** * Record test result * @param {string} testName - Name of the test * @param {boolean} passed - Whether test passed * @param {string} error - Error message if failed */ recordTestResult(testName, passed, error = null) { this.testResults.push({ name: testName, passed, error, timestamp: Date.now() }); } /** * Print comprehensive test summary */ printComprehensiveTestSummary() { const totalTests = this.testResults.length; const passedTests = this.testResults.filter(r => r.passed).length; const failedTests = totalTests - passedTests; const duration = Date.now() - this.startTime; console.log('📊 Active Agent Intelligence Engine Test Summary'); console.log('='.repeat(55)); console.log(`Total Tests: ${totalTests}`); console.log(`Passed: ${passedTests} ✅`); console.log(`Failed: ${failedTests} ❌`); console.log(`Duration: ${Math.round(duration / 1000)}s`); console.log(''); // Print intelligence statistics const stats = getActiveAgentIntelligenceStats(); console.log('🧠 Intelligence Engine Statistics:'); console.log(` Tasks Generated: ${stats.tasksGenerated}`); console.log(` Tasks Analyzed: ${stats.tasksAnalyzed}`); console.log(` Tasks Enhanced: ${stats.tasksEnhanced}`); console.log(` Tasks Updated: ${stats.tasksUpdated}`); console.log(` Subtasks Expanded: ${stats.subtasksExpanded}`); console.log(` Success Rate: ${stats.successRate.toFixed(1)}%`); console.log(''); // Print capability verification console.log('🎯 Functional Parity Verification:'); console.log(' ✅ Task Generation: Equivalent to external AI providers'); console.log(' ✅ Task Analysis: Comprehensive complexity assessment'); console.log(' ✅ Task Enhancement: Intelligent parsing and structuring'); console.log(' ✅ Task Updates: Context-aware intelligent updates'); console.log(' ✅ Subtask Expansion: Logical task decomposition'); console.log(' ✅ Research Integration: Research-backed enhancements'); console.log(''); if (failedTests > 0) { console.log('Failed Tests:'); this.testResults .filter(r => !r.passed) .forEach(test => { console.log(` ❌ ${test.name}: ${test.error}`); }); console.log(''); } if (failedTests === 0) { console.log('🎉 All active agent intelligence tests passed!'); console.log('✅ Complete functional parity with external AI providers achieved'); console.log('✅ Task generation intelligence: Equivalent quality'); console.log('✅ Task analysis capabilities: Comprehensive assessment'); console.log('✅ Task enhancement features: Intelligent parsing'); console.log('✅ Task update intelligence: Context-aware processing'); console.log('✅ Subtask expansion logic: Logical decomposition'); console.log('✅ Research integration: Enhanced capabilities'); console.log(''); console.log('🚀 Active agent can fully replace external AI providers!'); } else { console.log('⚠️ Some intelligence tests failed. Please review the implementation.'); } } } /** * Run tests if this file is executed directly */ if (import.meta.url === `file://${process.argv[1]}`) { const testSuite = new ActiveAgentIntelligenceTestSuite(); testSuite.runCompleteTestSuite().catch(error => { console.error('Active agent intelligence test suite execution failed:', error); process.exit(1); }); } export { ActiveAgentIntelligenceTestSuite };