agentic-qe
Version:
Agentic Quality Engineering Fleet System - AI-driven quality management platform
160 lines • 6.13 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTraceCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
function createTraceCommand() {
const command = new commander_1.Command('trace');
command
.description('Trace test execution flow and timing')
.argument('[testFile]', 'Specific test file to trace')
.option('--timeline', 'Show execution timeline', false)
.option('--save <file>', 'Save trace data to file')
.option('--call-stack', 'Show call stack for each step', false)
.action(async (testFile, options) => {
console.log(chalk_1.default.bold('Tracing tests...\n'));
const tests = testFile ? [testFile] : [
'tests/unit/auth.test.ts',
'tests/integration/api.test.ts'
];
const traces = [];
for (const test of tests) {
console.log(chalk_1.default.cyan(`Tracing test: ${test}`));
const testTraces = await traceTest(test, options);
traces.push(...testTraces);
}
// Display results
if (options.timeline) {
displayTimeline(traces);
}
else {
displayTraces(traces, options);
}
// Save if requested
if (options.save) {
saveTraces(traces, options.save);
console.log(chalk_1.default.green(`\n✓ Saved trace to: ${options.save}`));
}
});
return command;
}
exports.createTraceCommand = createTraceCommand;
async function traceTest(testFile, options) {
const traces = [];
const startTime = Date.now();
// Start event
traces.push({
timestamp: Date.now() - startTime,
type: 'start',
test: testFile
});
// Simulate test steps
const steps = [
'Setup test environment',
'Initialize test data',
'Execute test case',
'Verify assertions',
'Cleanup resources'
];
for (const step of steps) {
await new Promise(resolve => setTimeout(resolve, Math.random() * 200 + 50));
traces.push({
timestamp: Date.now() - startTime,
type: 'step',
test: testFile,
details: step
});
if (options.callStack) {
console.log(chalk_1.default.gray(` [${Date.now() - startTime}ms] ${step}`));
console.log(chalk_1.default.gray(` at TestRunner.runStep (runner.ts:45:10)`));
console.log(chalk_1.default.gray(` at async TestRunner.run (runner.ts:120:5)`));
}
}
// End event
traces.push({
timestamp: Date.now() - startTime,
type: 'end',
test: testFile
});
return traces;
}
function displayTraces(traces, options) {
console.log(chalk_1.default.bold('\nExecution Trace:'));
console.log(chalk_1.default.gray('─'.repeat(80)));
let currentTest = '';
traces.forEach(trace => {
if (trace.test !== currentTest) {
console.log(chalk_1.default.bold(`\n${trace.test}`));
currentTest = trace.test;
}
const timeStr = `${trace.timestamp}ms`.padStart(8);
const typeIcon = {
start: '▶',
step: '→',
end: '■'
}[trace.type];
console.log(`${chalk_1.default.gray(timeStr)} ${typeIcon} ${trace.details || trace.type}`);
});
console.log(chalk_1.default.gray('\n' + '─'.repeat(80)));
}
function displayTimeline(traces) {
console.log(chalk_1.default.bold('\nTimeline:'));
console.log(chalk_1.default.gray('─'.repeat(80)));
const maxTime = Math.max(...traces.map(t => t.timestamp));
const scale = 60 / maxTime; // Scale to 60 characters
let currentTest = '';
traces.forEach(trace => {
if (trace.test !== currentTest) {
console.log(chalk_1.default.bold(`\n${trace.test}`));
console.log(chalk_1.default.gray('│'));
currentTest = trace.test;
}
const position = Math.floor(trace.timestamp * scale);
const timeline = ' '.repeat(position) + '●';
const label = trace.details || trace.type;
console.log(chalk_1.default.gray('│') + timeline + ` ${label} (${trace.timestamp}ms)`);
});
console.log(chalk_1.default.gray('│'));
console.log(chalk_1.default.gray('└' + '─'.repeat(60)));
console.log(chalk_1.default.gray(` 0ms${' '.repeat(50)}${maxTime}ms`));
}
function saveTraces(traces, filename) {
const data = {
timestamp: new Date().toISOString(),
traces,
summary: {
totalEvents: traces.length,
duration: Math.max(...traces.map(t => t.timestamp)),
tests: [...new Set(traces.map(t => t.test))]
}
};
fs.writeFileSync(filename, JSON.stringify(data, null, 2));
}
//# sourceMappingURL=trace.js.map