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.

145 lines (120 loc) 6.39 kB
import { DevOpsAgent } from '../devops'; import { KnowledgeGraph } from '../../knowledge-graph'; // Adjust path import { AgentWorkflowSystem } from '../../agent-workflow'; // Adjust path // Mocks const mockKnowledgeGraph = { addNode: jest.fn(), findNodes: jest.fn(), // Though not directly used in these methods updateContext: jest.fn() }; const mockWorkflow = {}; describe('DevOpsAgent', () => { let agent; beforeEach(() => { jest.clearAllMocks(); agent = new DevOpsAgent(mockKnowledgeGraph, mockWorkflow); jest.spyOn(console, 'log').mockImplementation(() => {}); }); afterEach(() => { console.log.mockRestore(); }); it('should generate a GitHub Actions CI config template', async () => { const platform = 'github_actions'; const options = { nodeVersion: '20', testCommand: 'npm run test:ci' }; // Example option mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateCiCdConfig(platform, options); expect(config).toBeDefined(); expect(config.filename).toBe('.github/workflows/ci.yml'); expect(config.content).toContain('name: CI Pipeline'); expect(config.content).toContain('actions/checkout@v3'); expect(config.content).toContain('node-version: '20''); // Check option usage expect(config.content).toContain('npm test'); // Basic test command included expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'cicd_configuration', data: expect.objectContaining({ platform, filename: config.filename }) })); }); it('should throw error for unsupported CI/CD platform', async () => { await expect(agent.generateCiCdConfig('unsupported_platform')).rejects.toThrow( 'Unsupported CI/CD platform: unsupported_platform' ); expect(mockKnowledgeGraph.addNode).not.toHaveBeenCalled(); }); it('should generate a deployment config template', async () => { const environment = 'staging'; const platform = 'vercel'; const options = { buildCommand: 'npm run build', region: 'us-east-1' }; mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateDeploymentConfig(environment, platform, options); expect(config).toBeDefined(); expect(config.filename).toBe('deploy.config.yml'); expect(config.content).toContain(`# Deployment config for ${platform} - ${environment}`); expect(config.content).toContain(`platform: ${platform}`); expect(config.content).toContain(`environment: ${environment}`); expect(config.content).toContain('region: us-east-1'); // Check option usage expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'deployment_configuration', data: expect.objectContaining({ platform, targetEnvironment: environment, filename: config.filename }) })); }); // --- Tests for new Performance Optimization methods --- it('should generate an Nginx load balancer config template', async () => { const type = 'nginx'; const options = { backend_servers: ['10.0.0.1', '10.0.0.2'], health_check_path: '/health' }; mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateLoadBalancerConfig(type, options); expect(config).toBeDefined(); expect(config.filename).toBe('nginx_lb.conf'); expect(config.content).toContain('http {'); expect(config.content).toContain('upstream backend {'); expect(config.content).toContain('server 10.0.0.1;'); expect(config.content).toContain('server 10.0.0.2;'); expect(config.content).toContain('proxy_pass http://backend;'); expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'load_balancer_configuration', data: expect.objectContaining({ type, filename: config.filename }) })); }); it('should generate a generic load balancer config for unsupported types', async () => { const type = 'custom_lb'; const options = { setting: 'value' }; mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateLoadBalancerConfig(type, options); expect(config.filename).toBe('custom_lb_lb.conf'); expect(config.content).toContain(`# Configuration for ${type}`); expect(config.content).toContain(JSON.stringify(options, null, 2)); expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'load_balancer_configuration' })); }); it('should generate a Kubernetes HPA scaling config template', async () => { const platform = 'kubernetes_hpa'; const options = { appName: 'api-service', deploymentName: 'api-deployment', minReplicas: 2, maxReplicas: 10, cpuThreshold: 75 }; mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateScalingConfig(platform, options); expect(config).toBeDefined(); expect(config.filename).toBe('kubernetes_hpa_scaling.yml'); expect(config.content).toContain('kind: HorizontalPodAutoscaler'); expect(config.content).toContain('name: api-service-hpa'); expect(config.content).toContain('name: api-deployment'); expect(config.content).toContain('minReplicas: 2'); expect(config.content).toContain('maxReplicas: 10'); expect(config.content).toContain('averageUtilization: 75'); expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'scaling_configuration', data: expect.objectContaining({ platform, filename: config.filename }) })); }); it('should generate a generic scaling config for unsupported platforms', async () => { const platform = 'aws_lambda_provisioned_concurrency'; const options = { functionName: 'myFunc', min: 1, max: 5 }; mockKnowledgeGraph.addNode.mockResolvedValue(undefined); const config = await agent.generateScalingConfig(platform, options); expect(config.filename).toBe('aws_lambda_provisioned_concurrency_scaling.yml'); expect(config.content).toContain(`# Scaling Configuration - ${platform}`); expect(config.content).toContain(JSON.stringify(options, null, 2)); expect(mockKnowledgeGraph.addNode).toHaveBeenCalledWith(expect.objectContaining({ type: 'scaling_configuration' })); }); });