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.

218 lines (179 loc) 7.64 kB
import { NeoOrchestrator } from '../orchestrator.js'; import { jest } from '@jest/globals'; // Mock all dependencies jest.mock('../knowledge-graph.js'); jest.mock('../agent-workflow.js'); jest.mock('../chain-system.js'); jest.mock('../monitoring.js'); jest.mock('../design-system-manager.js'); describe('NeoOrchestrator', () => { let orchestrator; beforeEach(() => { jest.clearAllMocks(); orchestrator = new NeoOrchestrator(); }); describe('Initialization', () => { it('should initialize all systems successfully', async () => { await orchestrator.initialize(); expect(orchestrator.knowledgeGraph.initialize).toHaveBeenCalled(); expect(orchestrator.agentWorkflow.initialize).toHaveBeenCalled(); expect(orchestrator.chainSystem.initialize).toHaveBeenCalled(); expect(orchestrator.monitoring.initialize).toHaveBeenCalled(); expect(orchestrator.designSystem.initialize).toHaveBeenCalled(); expect(orchestrator.knowledgeGraph.addNode).toHaveBeenCalledWith({ id: 'neo-orchestrator', type: 'system', data: { status: 'active', version: '1.0.0', systems: ['knowledge-graph', 'agent-workflow', 'chain-system', 'monitoring', 'design-system'] } }); expect(orchestrator.initialized).toBe(true); }); it('should prevent multiple initializations', async () => { await orchestrator.initialize(); await expect(orchestrator.initialize()).rejects.toThrow('Neo Orchestrator already initialized'); }); }); describe('Workflow Creation', () => { beforeEach(async () => { await orchestrator.initialize(); }); it('should create workflow with agents and chain', async () => { const config = { name: 'Test Workflow', description: 'Test workflow description', agents: [ { id: 'agent1', capabilities: ['task1'] }, { id: 'agent2', capabilities: ['task2'] } ], steps: [ { id: 'step1', agentId: 'agent1' }, { id: 'step2', agentId: 'agent2' } ] }; orchestrator.agentWorkflow.hasAgent.mockReturnValue(false); orchestrator.agentWorkflow.createWorkflow.mockResolvedValue('workflow-1'); orchestrator.chainSystem.registerChain.mockResolvedValue('chain-1'); const result = await orchestrator.createWorkflow(config); expect(result).toEqual({ workflowId: 'workflow-1', chainId: 'chain-workflow-1' }); // Verify agents were registered expect(orchestrator.agentWorkflow.registerAgent).toHaveBeenCalledTimes(2); expect(orchestrator.agentWorkflow.registerAgent).toHaveBeenCalledWith(config.agents[0]); expect(orchestrator.agentWorkflow.registerAgent).toHaveBeenCalledWith(config.agents[1]); // Verify workflow was created expect(orchestrator.agentWorkflow.createWorkflow).toHaveBeenCalledWith({ name: config.name, description: config.description, metadata: config.metadata }); // Verify chain was created expect(orchestrator.chainSystem.registerChain).toHaveBeenCalledWith({ id: 'chain-workflow-1', type: 'sequential', steps: ['step1', 'step2'], options: {} }); // Verify step handlers were registered expect(orchestrator.chainSystem.registerStepHandler).toHaveBeenCalledTimes(2); }); }); describe('Workflow Execution', () => { beforeEach(async () => { await orchestrator.initialize(); }); it('should execute workflow successfully', async () => { const workflowId = 'workflow-1'; const monitoringSession = 'session-1'; const results = [{ status: 'success' }]; orchestrator.monitoring.startSession.mockResolvedValue(monitoringSession); orchestrator.chainSystem.executeChain.mockResolvedValue(results); const executionResults = await orchestrator.executeWorkflow(workflowId); expect(orchestrator.monitoring.startSession).toHaveBeenCalledWith(workflowId); expect(orchestrator.chainSystem.executeChain).toHaveBeenCalledWith('chain-workflow-1'); expect(orchestrator.agentWorkflow.updateWorkflowStatus).toHaveBeenCalledWith(workflowId, 'completed'); expect(orchestrator.monitoring.endSession).toHaveBeenCalledWith(monitoringSession); expect(executionResults).toBe(results); }); it('should handle workflow execution failure', async () => { const workflowId = 'workflow-1'; const error = new Error('Execution failed'); orchestrator.chainSystem.executeChain.mockRejectedValue(error); await expect(orchestrator.executeWorkflow(workflowId)).rejects.toThrow(error); expect(orchestrator.agentWorkflow.updateWorkflowStatus).toHaveBeenCalledWith(workflowId, 'failed'); }); }); describe('Agent Step Execution', () => { beforeEach(async () => { await orchestrator.initialize(); }); it('should execute agent step with design system components', async () => { const agent = { id: 'agent1', execute: jest.fn().mockResolvedValue({ status: 'success' }) }; const step = { id: 'step1', requiresDesignSystem: true, designRequirements: ['button', 'input'] }; const designComponents = { button: {}, input: {} }; orchestrator.designSystem.getComponents.mockResolvedValue(designComponents); orchestrator.agentWorkflow.validateStepResult.mockResolvedValue({ valid: true }); await orchestrator._executeAgentStep(agent, step); expect(orchestrator.designSystem.getComponents).toHaveBeenCalledWith(step.designRequirements); expect(agent.execute).toHaveBeenCalledWith(step, { designComponents }); expect(orchestrator.monitoring.recordMetric).toHaveBeenCalledWith('stepExecution', expect.objectContaining({ agentId: 'agent1', stepId: 'step1', status: 'success' })); }); it('should handle step execution failure', async () => { const agent = { id: 'agent1', execute: jest.fn().mockRejectedValue(new Error('Step failed')) }; const step = { id: 'step1' }; await expect(orchestrator._executeAgentStep(agent, step)).rejects.toThrow('Step failed'); expect(orchestrator.monitoring.recordMetric).toHaveBeenCalledWith('stepExecution', expect.objectContaining({ agentId: 'agent1', stepId: 'step1', status: 'failed', error: 'Step failed' })); }); }); describe('System Status', () => { beforeEach(async () => { await orchestrator.initialize(); }); it('should return comprehensive system status', async () => { const mockStats = { knowledgeGraph: { nodes: 100 }, workflow: { active: 5 }, chain: { completed: 10 }, monitoring: { alerts: 0 } }; orchestrator.knowledgeGraph.getStats.mockResolvedValue(mockStats.knowledgeGraph); orchestrator.agentWorkflow.getStats.mockResolvedValue(mockStats.workflow); orchestrator.chainSystem.getChainSystemStats.mockResolvedValue(mockStats.chain); orchestrator.monitoring.getMetricsReport.mockResolvedValue(mockStats.monitoring); const status = await orchestrator.getSystemStatus(); expect(status).toEqual({ status: 'active', timestamp: expect.any(String), systems: { knowledgeGraph: mockStats.knowledgeGraph, agentWorkflow: mockStats.workflow, chainSystem: mockStats.chain, monitoring: mockStats.monitoring } }); }); }); });