/** * Receipt writer shared by the headed diagnostic tools. * * Machine-readable JSON lands in tests/golden (tracked, never overwritten); * regenerable media (screenshots, full stderr) stays outside the repo unless * the caller chooses otherwise. */ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { REPO_ROOT } from "./browser.mjs"; const pad = (value) => String(value).padStart(2, "0"); export function stamp(date = new Date()) { return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`; } export function receiptDir(topic, explicit) { if (explicit) return path.resolve(explicit); return path.join(REPO_ROOT, "tests/golden", `${topic}-${stamp()}`); } export function mediaDir(topic, explicit) { if (explicit) return path.resolve(explicit); const dir = path.join(os.tmpdir(), `${topic}-${stamp()}`); fs.mkdirSync(dir, { recursive: true }); return dir; } export function writeReceipt(dir, report) { fs.mkdirSync(dir, { recursive: true }); let target = path.join(dir, "report.json"); if (fs.existsSync(target)) target = path.join(dir, `report-${stamp()}.json`); fs.writeFileSync(target, JSON.stringify({ schemaVersion: 1, acceptance: "NOT_CLAIMED", ...report }, null, 2)); return target; }