Spaces:
Running
Running
sync: 190 file da Baida98/AI@e58203cc (2026-08-26 09:16 UTC) [deploy-all]
#70
by Baida07 - opened
scripts/lib/report-engine.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
| 2 |
+
import { join, resolve } from "node:path";
|
| 3 |
+
|
| 4 |
+
const DEFAULT_REPORT_DIRECTORY = "/tmp/agente-ai";
|
| 5 |
+
|
| 6 |
+
function safeSegment(value) {
|
| 7 |
+
return String(value ?? "benchmark")
|
| 8 |
+
.trim()
|
| 9 |
+
.replace(/[^a-zA-Z0-9._-]+/g, "-")
|
| 10 |
+
.replace(/^-+|-+$/g, "")
|
| 11 |
+
.slice(0, 96) || "benchmark";
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Persiste un artefatto diagnostico del runner senza incidere sui calcoli.
|
| 16 |
+
* Il write-then-rename evita file JSON parziali in caso di interruzione.
|
| 17 |
+
*/
|
| 18 |
+
export function saveBenchmarkReport(reportName, payload) {
|
| 19 |
+
const reportDirectory = resolve(process.env.BENCHMARK_REPORT_DIR || DEFAULT_REPORT_DIRECTORY);
|
| 20 |
+
mkdirSync(reportDirectory, { recursive: true });
|
| 21 |
+
|
| 22 |
+
const safeName = safeSegment(reportName);
|
| 23 |
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
| 24 |
+
const finalPath = join(reportDirectory, `${safeName}-${stamp}.json`);
|
| 25 |
+
const temporaryPath = `${finalPath}.${process.pid}.tmp`;
|
| 26 |
+
const document = {
|
| 27 |
+
schemaVersion: "benchmark-report-v1",
|
| 28 |
+
generatedAt: new Date().toISOString(),
|
| 29 |
+
reportName: safeName,
|
| 30 |
+
...payload,
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
writeFileSync(temporaryPath, `${JSON.stringify(document, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
| 34 |
+
renameSync(temporaryPath, finalPath);
|
| 35 |
+
return finalPath;
|
| 36 |
+
}
|