Files
ThothII/tools/replay/augment-review-gates.mjs
T
marcopan 4042d0b44d feat(replay): fixtures + augment script for v2 artifact-gate viewers
Add cte-plan-fixture.json, cte-result-fixture.json, and
phase-summary-fixture.json — realistic Italian-language payloads for the
cardiology DWH replay session, conforming exactly to contracts.md (A/B/C).

Add augment-review-gates.mjs (pattern of augment-schema-linking.mjs): finds
the F6 cte_plan gate, first CTE 1 cte_result gate, and Fase 5 phase-summary
gate by title regex and swaps in the v2 artifact.data, so CtePlanViewer,
CteResultViewer, and PhaseSummaryViewer render in the offline replay.
Idempotent; exits 1 if an expected gate is missing.

Document the augment scripts and re-extract note in tools/replay/README.md.
2026-07-07 01:19:44 +02:00

47 lines
2.1 KiB
JavaScript

// 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}`);