Files
workinf_Blender_Wasm/tools/web/wbv2-failure-ledger.mjs
mes123456 d602a13e2b
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
perf(web): deduplicate control plane gate state
2026-09-03 15:35:18 +08:00

22 lines
1.0 KiB
JavaScript

import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
const ledgerPath = (root) => path.join(root, "tests/golden/WBV2/failure-ledger.json");
const keyFor = (entry) => crypto.createHash("sha256").update(JSON.stringify({ task: entry.task, phase: entry.phase, reason: entry.reason, childExit: entry.childExit ?? null })).digest("hex");
export function recordFailure(root, entry) {
const file = ledgerPath(root);
let ledger = { schemaVersion: 1, entries: [] };
try { ledger = JSON.parse(fs.readFileSync(file, "utf8")); }
catch { /* First failure or an interrupted write. */ }
const key = keyFor(entry);
if (ledger.entries.some((candidate) => candidate.key === key)) return false;
ledger.entries = [...ledger.entries, { ...entry, key, recordedAt: new Date().toISOString() }].slice(-200);
fs.mkdirSync(path.dirname(file), { recursive: true });
const temporary = `${file}.tmp-${process.pid}`;
fs.writeFileSync(temporary, `${JSON.stringify(ledger, null, 2)}\n`);
fs.renameSync(temporary, file);
return true;
}