mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
fd2f37eaa0
Changes: - Fix README.md agent counts (48 QE agents = 41 main + 7 subagents) - Fix README.md skill counts (15 QE-specific skills) - Fix v3/README.md agent counts (47 → 48) - Fix init-wizard.ts hooks from 'npx @agentic-qe/v3' to 'npx agentic-qe' - Complete v2 → v2/ folder reorganization (54 items moved) - Update root package.json to point to v3 as main version Verified claims: - 48 QE agents (41 main + 7 TDD subagents) - 15 QE-specific skills - 12 DDD bounded contexts - ~5,600+ tests - HNSW, ReasoningBank, Queen Coordinator features exist Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
661 lines
20 KiB
TypeScript
661 lines
20 KiB
TypeScript
/**
|
|
* Debug & Diagnostics CLI Commands Test Suite
|
|
* Tests all debug and diagnostics commands with comprehensive coverage
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
|
|
// Mock Logger to prevent undefined errors in Database
|
|
jest.mock('@utils/Logger', () => ({
|
|
Logger: {
|
|
getInstance: jest.fn(() => ({
|
|
info: jest.fn(),
|
|
error: jest.fn(),
|
|
warn: jest.fn(),
|
|
debug: jest.fn()
|
|
}))
|
|
}
|
|
}));
|
|
import * as path from 'path';
|
|
import * as os from 'os';
|
|
|
|
// Import commands to test
|
|
import { debugAgent } from '@cli/commands/debug/agent';
|
|
import { runDiagnostics } from '@cli/commands/debug/diagnostics';
|
|
import { healthCheck } from '@cli/commands/debug/health-check';
|
|
import { troubleshoot } from '@cli/commands/debug/troubleshoot';
|
|
import { traceExecution } from '@cli/commands/debug/trace';
|
|
import { profilePerformance } from '@cli/commands/debug/profile';
|
|
|
|
describe('Debug & Diagnostics CLI Commands', () => {
|
|
let tempDir: string;
|
|
|
|
beforeEach(() => {
|
|
// Mock process.exit to prevent test interruption
|
|
jest.spyOn(process, 'exit').mockImplementation((code?: number) => {
|
|
throw new Error(`Process.exit called with code ${code}`);
|
|
});
|
|
|
|
// Create temporary directory for test outputs
|
|
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'aqe-debug-test-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Clean up temporary directory
|
|
if (fs.existsSync(tempDir)) {
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe('aqe debug agent', () => {
|
|
it('should debug agent with verbose logging', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
verbose: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.logs).toBeDefined();
|
|
expect(result.logs.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should capture agent state snapshot', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
captureState: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.state).toBeDefined();
|
|
expect(result.state).toHaveProperty('memory');
|
|
expect(result.state).toHaveProperty('tasks');
|
|
});
|
|
|
|
it('should export debug logs to file', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
expect(fs.existsSync(result.exportPath!)).toBe(true);
|
|
});
|
|
|
|
it('should filter logs by severity level', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
logLevel: 'error',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
// If logs exist, they should be filtered by level
|
|
// If no real logs exist, synthetic logs are created which may not match the filter
|
|
if (result.logs.length > 0) {
|
|
expect(result.logs).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it('should include stack traces for errors', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'failing-agent',
|
|
includeStackTraces: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const errorLogs = result.logs.filter(log => log.level === 'error');
|
|
if (errorLogs.length > 0) {
|
|
expect(errorLogs.some(log => log.stackTrace)).toBe(true);
|
|
}
|
|
});
|
|
|
|
it('should handle non-existent agent gracefully', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'non-existent-agent',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('Agent not found');
|
|
});
|
|
|
|
it('should export in JSON format', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
expect(result.exportPath).toContain('.json');
|
|
});
|
|
|
|
it('should export in YAML format', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
export: 'yaml',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
expect(result.exportPath).toContain('.yaml');
|
|
});
|
|
|
|
it('should export in text format', async () => {
|
|
const result = await debugAgent({
|
|
agentName: 'test-agent',
|
|
export: 'text',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
expect(result.exportPath).toContain('.txt');
|
|
});
|
|
});
|
|
|
|
describe('aqe diagnostics run', () => {
|
|
it('should run comprehensive system diagnostics', async () => {
|
|
const result = await runDiagnostics({
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.checks).toBeDefined();
|
|
expect(result.checks.length).toBeGreaterThan(5);
|
|
});
|
|
|
|
it('should check memory usage', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['memory'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.checks.some(c => c.name === 'memory')).toBe(true);
|
|
const memoryCheck = result.checks.find(c => c.name === 'memory');
|
|
expect(memoryCheck?.data).toHaveProperty('heapUsed');
|
|
expect(memoryCheck?.data).toHaveProperty('heapTotal');
|
|
});
|
|
|
|
it('should check CPU usage', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['cpu'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const cpuCheck = result.checks.find(c => c.name === 'cpu');
|
|
expect(cpuCheck?.data).toHaveProperty('loadAverage');
|
|
expect(cpuCheck?.data).toHaveProperty('cpuCount');
|
|
});
|
|
|
|
it('should check disk space', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['disk'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const diskCheck = result.checks.find(c => c.name === 'disk');
|
|
expect(diskCheck?.data).toBeDefined();
|
|
});
|
|
|
|
it('should check network connectivity', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['network'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const networkCheck = result.checks.find(c => c.name === 'network');
|
|
expect(networkCheck?.data).toHaveProperty('interfaces');
|
|
});
|
|
|
|
it('should validate dependencies', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['dependencies'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const depsCheck = result.checks.find(c => c.name === 'dependencies');
|
|
expect(depsCheck?.data).toBeDefined();
|
|
});
|
|
|
|
it('should check agent fleet status', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['agents'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const agentCheck = result.checks.find(c => c.name === 'agents');
|
|
expect(agentCheck?.data).toBeDefined();
|
|
});
|
|
|
|
it('should export diagnostics report in JSON', async () => {
|
|
const result = await runDiagnostics({
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.reportPath).toBeDefined();
|
|
expect(fs.existsSync(result.reportPath!)).toBe(true);
|
|
});
|
|
|
|
it('should generate HTML report', async () => {
|
|
const result = await runDiagnostics({
|
|
export: 'html',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.reportPath).toContain('.html');
|
|
const content = fs.readFileSync(result.reportPath!, 'utf-8');
|
|
expect(content).toContain('<html');
|
|
});
|
|
|
|
it('should detect performance bottlenecks', async () => {
|
|
const result = await runDiagnostics({
|
|
checks: ['performance'],
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
const perfCheck = result.checks.find(c => c.name === 'performance');
|
|
expect(perfCheck?.data).toHaveProperty('bottlenecks');
|
|
});
|
|
});
|
|
|
|
describe('aqe health-check', () => {
|
|
it('should perform basic health check', async () => {
|
|
const result = await healthCheck({
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.status).toBeDefined();
|
|
expect(['healthy', 'degraded', 'unhealthy']).toContain(result.status);
|
|
});
|
|
|
|
it('should check all system components', async () => {
|
|
const result = await healthCheck({
|
|
comprehensive: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.components).toBeDefined();
|
|
expect(result.components.length).toBeGreaterThan(3);
|
|
});
|
|
|
|
it('should export health report in JSON', async () => {
|
|
const result = await healthCheck({
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.reportPath).toBeDefined();
|
|
const content = JSON.parse(fs.readFileSync(result.reportPath!, 'utf-8'));
|
|
expect(content).toHaveProperty('status');
|
|
expect(content).toHaveProperty('timestamp');
|
|
});
|
|
|
|
it('should export health report in YAML', async () => {
|
|
const result = await healthCheck({
|
|
export: 'yaml',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.reportPath).toContain('.yaml');
|
|
});
|
|
|
|
it('should detect unhealthy components', async () => {
|
|
const result = await healthCheck({
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
if (result.status === 'unhealthy') {
|
|
expect(result.unhealthyComponents).toBeDefined();
|
|
expect(result.unhealthyComponents!.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it('should provide remediation suggestions', async () => {
|
|
const result = await healthCheck({
|
|
includeRemediation: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.components).toBeDefined();
|
|
});
|
|
|
|
it('should measure response times', async () => {
|
|
const result = await healthCheck({
|
|
measurePerformance: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.performanceMetrics).toBeDefined();
|
|
expect(result.performanceMetrics?.responseTime).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('aqe troubleshoot', () => {
|
|
it('should troubleshoot test failures', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'test-failure',
|
|
context: { testFile: 'example.test.ts' },
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.diagnosis).toBeDefined();
|
|
expect(result.suggestions).toBeDefined();
|
|
expect(result.suggestions.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should troubleshoot coverage gaps', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'coverage-gap',
|
|
context: { file: 'src/example.ts', coverage: 45 },
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.diagnosis).toContain('coverage');
|
|
expect(result.suggestions.some(s => s.includes('test'))).toBe(true);
|
|
});
|
|
|
|
it('should troubleshoot agent failures', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'agent-failure',
|
|
context: { agentName: 'qe-test-generator', error: 'Timeout' },
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.diagnosis).toBeDefined();
|
|
expect(result.suggestions.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should analyze error logs', async () => {
|
|
// Create a test log file
|
|
const logPath = path.join(tempDir, 'test.log');
|
|
fs.writeFileSync(logPath, 'Error: Test failed\nTypeError: undefined\n');
|
|
|
|
const result = await troubleshoot({
|
|
issue: 'error-analysis',
|
|
logFile: logPath,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.errorPatterns).toBeDefined();
|
|
});
|
|
|
|
it('should provide step-by-step resolution', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'test-failure',
|
|
stepByStep: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.resolutionSteps).toBeDefined();
|
|
expect(result.resolutionSteps!.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should search knowledge base for similar issues', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'test-failure',
|
|
searchKB: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.similarIssues).toBeDefined();
|
|
});
|
|
|
|
it('should export troubleshooting report', async () => {
|
|
const result = await troubleshoot({
|
|
issue: 'test-failure',
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.reportPath).toBeDefined();
|
|
expect(fs.existsSync(result.reportPath!)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('aqe trace', () => {
|
|
it('should trace test execution flow', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.trace).toBeDefined();
|
|
expect(result.trace.steps).toBeDefined();
|
|
expect(result.trace.steps.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should capture function call hierarchy', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
includeCallStack: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.trace.callStack).toBeDefined();
|
|
});
|
|
|
|
it('should measure execution time per step', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
measureTiming: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.trace.steps.every(step => step.duration !== undefined)).toBe(true);
|
|
});
|
|
|
|
it('should export trace in JSON format', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
export: 'json',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
const content = JSON.parse(fs.readFileSync(result.exportPath!, 'utf-8'));
|
|
expect(content).toHaveProperty('trace');
|
|
});
|
|
|
|
it('should export trace in Chrome DevTools format', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
export: 'chrome-devtools',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toContain('.json');
|
|
const content = JSON.parse(fs.readFileSync(result.exportPath!, 'utf-8'));
|
|
expect(content).toHaveProperty('traceEvents');
|
|
});
|
|
|
|
it('should filter trace by minimum duration', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
minDuration: 10,
|
|
measureTiming: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.trace.steps.every(step => step.duration! >= 10)).toBe(true);
|
|
});
|
|
|
|
it('should highlight slow operations', async () => {
|
|
const result = await traceExecution({
|
|
testFile: 'example.test.ts',
|
|
highlightSlow: true,
|
|
measureTiming: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.trace.steps).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('aqe profile', () => {
|
|
it('should profile test performance', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile).toBeDefined();
|
|
expect(result.profile.cpu).toBeDefined();
|
|
expect(result.profile.memory).toBeDefined();
|
|
});
|
|
|
|
it('should capture CPU profile', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
profileCPU: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile.cpu).toBeDefined();
|
|
expect(result.profile.cpu.samples).toBeDefined();
|
|
expect(result.profile.cpu.samples.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should capture memory profile', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
profileMemory: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile.memory).toBeDefined();
|
|
});
|
|
|
|
it('should detect memory leaks', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
detectLeaks: true,
|
|
profileMemory: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile.memory.leaks).toBeDefined();
|
|
});
|
|
|
|
it('should export profile in V8 format', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
export: 'v8',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toBeDefined();
|
|
expect(result.exportPath).toContain('.cpuprofile');
|
|
});
|
|
|
|
it('should export profile in Chrome DevTools format', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
export: 'chrome-devtools',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.exportPath).toContain('.json');
|
|
});
|
|
|
|
it('should generate flamegraph', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
flamegraph: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.flamegraphPath).toBeDefined();
|
|
expect(fs.existsSync(result.flamegraphPath!)).toBe(true);
|
|
});
|
|
|
|
it('should measure allocation profile', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
allocationProfile: true,
|
|
profileMemory: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile.memory.allocations).toBeDefined();
|
|
});
|
|
|
|
it('should identify hot functions', async () => {
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
identifyHotFunctions: true,
|
|
profileCPU: true,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.profile.hotFunctions).toBeDefined();
|
|
expect(result.profile.hotFunctions!.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should compare profiles', async () => {
|
|
const baseline = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
const result = await profilePerformance({
|
|
testFile: 'example.test.ts',
|
|
compareWith: baseline.profile,
|
|
outputDir: tempDir,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.comparison).toBeDefined();
|
|
expect(result.comparison?.cpuDiff).toBeDefined();
|
|
expect(result.comparison?.memoryDiff).toBeDefined();
|
|
});
|
|
});
|
|
});
|