import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import url from "node:url"; const repo = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), "../../.."); const gate = path.join(repo, "apps/site/tools/design-gate.mjs"); const packagedGate = path.join(repo, "packages/skill/tools/design-gate.mjs"); const work = fs.mkdtempSync(path.join(os.tmpdir(), "design-gate-contract-")); const normalizedSource = (file) => fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n"); assert.equal( normalizedSource(gate), normalizedSource(packagedGate), "apps/site/tools/design-gate.mjs must match packages/skill/tools/design-gate.mjs", ); const configFor = (page, extra = {}) => ({ pages: [{ name: "fixture", path: page, h1: "h1", ...extra }], widths: [375, 390], fontScales: [1, 1.3], checks: { meta: false, contrast: false, stack: false, rhythm: false, scaleMatrix: true, tapTargets: false, leftInset: false, deadCss: false, cssHygiene: false, }, }); const run = (name, html, extra = {}) => { const page = path.join(work, `${name}.html`); const config = path.join(work, `${name}.json`); fs.writeFileSync(page, html.replace("", "")); fs.writeFileSync(config, JSON.stringify(configFor(page, extra))); return spawnSync(process.execPath, [gate, `--config=${config}`], { cwd: work, encoding: "utf8" }); }; const outputOf = (result) => result.stdout + result.stderr; try { const flexible = run("flexible", `