ai-ctrf
Version:
Generate AI summaries of test results using a wide range of AI models like OpenAI, Anthropic, Gemini, Mistral, Grok, DeepSeek, Azure, Perplexity, and OpenRouter
55 lines (51 loc) • 2.05 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCtrfFile = validateCtrfFile;
exports.ansiRegex = ansiRegex;
exports.stripAnsi = stripAnsi;
exports.generateFailedTestPrompt = generateFailedTestPrompt;
const fs_1 = __importDefault(require("fs"));
function validateCtrfFile(filePath) {
var _a;
try {
const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
const jsonData = JSON.parse(fileContent);
if (((_a = jsonData.results) === null || _a === void 0 ? void 0 : _a.summary) == null || jsonData.results.tests == null) {
console.warn('Warning: The file does not contain valid CTRF data.');
return null;
}
return jsonData;
}
catch (error) {
console.error('Failed to read or process the file:', error);
return null;
}
}
function ansiRegex({ onlyFirst = false } = {}) {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
].join('|');
return new RegExp(pattern, onlyFirst ? undefined : 'g');
}
function stripAnsi(message) {
if (typeof message !== 'string') {
throw new TypeError(`Expected a \`string\`, got \`${typeof message}\``);
}
return message.replace(ansiRegex(), '');
}
function generateFailedTestPrompt(test, report) {
return `Analyze this test failure:
Test Name: ${test.name}
Test Tool: ${report.results.tool.name}
${report.results.environment != null ? `Environment: ${JSON.stringify(report.results.environment)}` : ''}
Failure Details:
${JSON.stringify(test, null, 2)}
What I need:
1. What specifically failed in this test
2. The likely root cause based on the error messages and context
3. The potential impact of this failure on the system`;
}
;