// Rewrite three replay gates as v2 artifact descriptors, so their new // viewers (CtePlanViewer, CteResultViewer, PhaseSummaryViewer) render in // replay. Pattern of augment-schema-linking.mjs: load replay.json, find each // gate by regex on its title, replace artifact.data with the matching v2 // fixture. Run after editing a fixture: node tools/replay/augment-review-gates.mjs import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; const HERE = dirname(fileURLToPath(import.meta.url)); const replayPath = join(HERE, "replay.json"); const replay = JSON.parse(readFileSync(replayPath, "utf8")); const ctePlan = JSON.parse(readFileSync(join(HERE, "cte-plan-fixture.json"), "utf8")); const cteResult = JSON.parse(readFileSync(join(HERE, "cte-result-fixture.json"), "utf8")); const phaseSummary = JSON.parse(readFileSync(join(HERE, "phase-summary-fixture.json"), "utf8")); function findGate(re, widget) { return replay.gates.findIndex( (g) => re.test(g.descriptor?.title ?? "") && (!widget || g.descriptor?.widget === widget) ); } function replaceArtifactData(idx, kind, data) { const d = replay.gates[idx].descriptor; d.artifact = { kind, data }; } const targets = [ { name: "F6 cte_plan", re: /Piano CTE \(persisti cte_plan\.json\)/, widget: "artifact-gate", kind: "cte_plan", data: ctePlan }, { name: "F6 CTE 1 approvato (cte_result)", re: /CTE 1 approvato/, widget: "artifact-gate", kind: "cte_result", data: cteResult }, { name: "Fase 5 completata (phase)", re: /Fase 5 completata/, widget: "artifact-gate", kind: "phase", data: phaseSummary }, ]; for (const t of targets) { const idx = findGate(t.re, t.widget); if (idx < 0) { console.error(`✗ ${t.name} gate not found in replay.json (title /${t.re.source}/)`); process.exit(1); } replaceArtifactData(idx, t.kind, t.data); console.log(`✓ Rewrote gate ${idx} ("${replay.gates[idx].descriptor.title}") -> kind:"${t.kind}"`); } writeFileSync(replayPath, JSON.stringify(replay, null, 2) + "\n"); console.log(`Wrote ${replayPath}`);