import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync, writeFileSync, mkdtempSync, rmSync, mkdirSync} from 'node:fs'; import {execFileSync} from 'node:child_process'; import {roadmapViewer} from './roadmap-viewer.mjs'; for (const suffix of ['', '-mobile']) test(`native Workflow${suffix} retains graph and passes final composition`, () => { mkdirSync('.cache', {recursive:true}); const dir = mkdtempSync('.cache/roadmap-test-'); try { const source = `diagrams/strategy-roadmap${suffix}.workflow.json`; const spec = JSON.parse(readFileSync(source, 'utf8')); const output = `${dir}/index.html`; execFileSync(process.execPath, ['vendor/archify/renderers/workflow/render-workflow.mjs', source, output], {env:{...process.env, ARCHIFY_UPDATE_CHECK_DISABLED:'1'}}); const native = readFileSync(output, 'utf8'); const styled = roadmapViewer(native, spec); const graph = html => [...html.matchAll(/]*data-edge-id="[^"]+"[^>]*>/g)].map(m => m[0]); assert.equal(graph(native).length, 4); assert.deepEqual(graph(styled), graph(native), 'native paths must not be rewritten'); for (const node of spec.nodes) assert(styled.includes(`data-node-id="${node.id}"`)); assert.equal((styled.match(/ roadmapViewer('', spec), /drift/); const oversized = structuredClone(spec); oversized.nodes[0].sublabel = 'Too much copy '.repeat(20); assert.throws(() => roadmapViewer(native, oversized), /capacity/); assert.throws(() => roadmapViewer(native, {...spec,diagram_type:'architecture'}), /contract drift/); } finally {rmSync(dir, {recursive:true, force:true});} });