98 lines
3.8 KiB
JavaScript
98 lines
3.8 KiB
JavaScript
"use strict";
|
|
/**
|
|
* JSONExporter — produces a structured JSON report for AI debugging workflows.
|
|
* Output: reports/{anomaly-id}/report.json
|
|
*/
|
|
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 () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.JSONExporter = void 0;
|
|
const fs = __importStar(require("fs"));
|
|
const path = __importStar(require("path"));
|
|
const os = __importStar(require("os"));
|
|
class JSONExporter {
|
|
constructor(targetUrl = '', abeVersion = '0.1.0') {
|
|
this.targetUrl = targetUrl;
|
|
this.abeVersion = abeVersion;
|
|
this.format = 'json';
|
|
}
|
|
async export(anomaly, outputDir) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
const report = {
|
|
version: '1.0',
|
|
generated_at: new Date(anomaly.timestamp).toISOString(),
|
|
environment: {
|
|
target_url: this.targetUrl,
|
|
abe_version: this.abeVersion,
|
|
os: os.platform(),
|
|
node_version: process.version,
|
|
},
|
|
anomaly: {
|
|
id: anomaly.id,
|
|
type: anomaly.type,
|
|
severity: anomaly.severity,
|
|
description: anomaly.description,
|
|
timestamp: anomaly.timestamp,
|
|
},
|
|
reproduction: {
|
|
seed: anomaly.actionTrace[0]?.seed ?? null,
|
|
steps: anomaly.actionTrace.map((action, index) => ({
|
|
step: index + 1,
|
|
action_type: action.type,
|
|
selector: action.selector,
|
|
value: action.value,
|
|
url: action.url,
|
|
timestamp: action.timestamp,
|
|
})),
|
|
},
|
|
evidence: {
|
|
screenshot: anomaly.evidence.screenshotPath ?? null,
|
|
dom_snapshot: anomaly.evidence.domSnapshotPath ?? null,
|
|
http_log: (anomaly.evidence.httpLog ?? []).map((r) => ({
|
|
url: r.url,
|
|
method: r.method,
|
|
status: r.status,
|
|
duration_ms: r.durationMs,
|
|
})),
|
|
console_errors: anomaly.evidence.rawErrors?.filter((e) => e.startsWith('console:')) ?? [],
|
|
js_exceptions: anomaly.evidence.rawErrors?.filter((e) => !e.startsWith('console:')) ?? [],
|
|
},
|
|
};
|
|
const filePath = path.join(outputDir, 'report.json');
|
|
fs.writeFileSync(filePath, JSON.stringify(report, null, 2), 'utf8');
|
|
return filePath;
|
|
}
|
|
}
|
|
exports.JSONExporter = JSONExporter;
|