import { test } from 'node:test'; 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 { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const skillRoot = path.resolve(__dirname, '..'); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-guided-views-')); const CASES = { architecture: { example: 'web-app.architecture.json', collection: 'components' }, workflow: { example: 'agent-tool-call.workflow.json', collection: 'nodes' }, sequence: { example: 'cache-miss-request.sequence.json', collection: 'participants' }, dataflow: { example: 'product-analytics.dataflow.json', collection: 'nodes' }, lifecycle: { example: 'agent-run.lifecycle.json', collection: 'states' }, }; function run(mode, doc, suffix) { const input = path.join(tmp, `${mode}-${suffix}.json`); const output = path.join(tmp, `${mode}-${suffix}.html`); fs.writeFileSync(input, JSON.stringify(doc)); const result = spawnSync(process.execPath, [ path.join(skillRoot, `renderers/${mode}/render-${mode}.mjs`), input, output, ], { encoding: 'utf8' }); return { result, output, html: fs.existsSync(output) ? fs.readFileSync(output, 'utf8') : '' }; } function fixture(mode) { return JSON.parse(fs.readFileSync(path.join(skillRoot, 'examples', CASES[mode].example), 'utf8')); } function svg(html) { return html.match(//)?.[0] || ''; } for (const [mode, config] of Object.entries(CASES)) { test(`${mode}: guided views preserve base SVG geometry`, () => { const withViews = fixture(mode); const ids = withViews[config.collection].slice(0, 2).map((item) => item.id); withViews.meta.views = [{ id: 'reader-path', label: 'Reader path', focus: ids, note: 'A safe note with