import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const validator = path.resolve(here, "../../scripts/docs/validate-svg.mjs"); test("SVG validator ignores Mermaid data-id attributes when checking duplicate IDs", () => { const fixtureDir = mkdtempSync(path.join(tmpdir(), "omniroute-svg-validator-")); const fixture = path.join(fixtureDir, "mermaid.svg"); writeFileSync( fixture, '" ); try { const result = spawnSync(process.execPath, [validator, fixture], { encoding: "utf8" }); assert.equal(result.status, 0, `${result.stdout}${result.stderr}`); assert.match(result.stdout, /PASS/); assert.doesNotMatch(`${result.stdout}${result.stderr}`, /WARN/); } finally { rmSync(fixtureDir, { recursive: true, force: true }); } }); test("SVG validator rejects duplicate XML id attributes", () => { const fixtureDir = mkdtempSync(path.join(tmpdir(), "omniroute-svg-validator-")); const fixture = path.join(fixtureDir, "duplicate.svg"); writeFileSync( fixture, '" ); try { const result = spawnSync(process.execPath, [validator, fixture], { encoding: "utf8" }); assert.equal(result.status, 1, `${result.stdout}${result.stderr}`); assert.match(result.stderr, /duplicate IDs: edge-a/); } finally { rmSync(fixtureDir, { recursive: true, force: true }); } }); test("SVG validator adds explicit accessible naming when requested for a generated diagram", () => { const fixtureDir = mkdtempSync(path.join(tmpdir(), "omniroute-svg-validator-")); const fixture = path.join(fixtureDir, "auto-combo.svg"); writeFileSync( fixture, '' ); try { const result = spawnSync( process.execPath, [ validator, "--fix-a11y", "--title", "Auto-Combo scoring", "--description", "How OmniRoute scores eligible routing targets with 15 factors.", fixture, ], { encoding: "utf8" } ); assert.equal(result.status, 0, `${result.stdout}${result.stderr}`); const repeated = spawnSync( process.execPath, [ validator, "--fix-a11y", "--title", "Auto-Combo scoring", "--description", "How OmniRoute scores eligible routing targets with 15 factors.", fixture, ], { encoding: "utf8" } ); assert.equal(repeated.status, 0, `${repeated.stdout}${repeated.stderr}`); const updated = readFileSync(fixture, "utf8"); assert.match(updated, /role="img"/); assert.match(updated, /aria-labelledby="auto-combo-title auto-combo-desc"/); assert.match(updated, /