Files
archify-vscode-ext/test/renderer.test.ts
T
root-at-skic 97b3b5f685 Add a 3D view of every diagram; organise source by job; 0.6.0
3D view: a "3D" menu beside Export switches the diagram to a three.js
scene built from the live Archify SVG. Nodes become blocks topped with
the node as Archify draws it, relationships become lit pipes along
Archify's routes, and the canvas, frames, lanes and legend form the
floor. Clicks and hover go to the SVG nodes, so focus, the Semantic
Passport and the intent trace work as in 2D; Archify's own animations
(trace, node pulse, passport/path/lens flows) are mirrored live. The
menu also offers flat or stacked levels, reset view and a top view;
Export gains "3D view" (PNG). Trackpad scrolling pans, pinch and the
mouse wheel zoom, and the zoom buttons work beyond the 2D limits.
The scene draws only when something moves. New setting
archify.defaultView.

Source: src/ is split by job (commands, views, webview, archify,
sources, language, util, viewer3d); behaviour unchanged.
2026-10-11 00:54:00 +03:00

77 lines
3.3 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { test } from 'node:test';
import { renderDiagram, renderToFile, RuntimeOptions, validate } from '../src/archify/cli';
import { readDiagramSource } from '../src/sources/detect';
const root = path.resolve(__dirname, '..', '..');
const fixtures = path.join(root, 'test', 'fixtures');
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-ext-test-'));
function runtime(extra: Partial<RuntimeOptions> = {}): RuntimeOptions {
return {
cliPath: path.join(root, 'vendor', 'archify', 'bin', 'archify.mjs'),
nodePath: process.execPath,
runAsNode: false,
workDir,
...extra,
};
}
function load(name: string) {
const text = fs.readFileSync(path.join(fixtures, name), 'utf8');
const source = readDiagramSource(text, name);
assert.ok(source, `${name} is a diagram source`);
return source;
}
for (const name of fs.readdirSync(fixtures).filter((file) => !file.startsWith('mco-'))) {
test(`renders ${name}`, async () => {
const result = await renderDiagram(runtime(), load(name), 'strict');
assert.equal(result.error, undefined);
assert.ok(result.ok);
assert.match(result.html ?? '', /<meta name="generator" content="archify/);
assert.equal(result.evidenceNotice, undefined);
});
}
test('reports schema problems with JSON pointer paths', async () => {
const text = JSON.stringify({ schema_version: 1, diagram_type: 'architecture', meta: { title: 'x' }, components: [{ id: 'a' }] });
const result = await validate(runtime(), 'architecture', text);
assert.equal(result.ok, false);
assert.ok(result.diagnostics.some((d) => d.subject?.path === '/components/0' && d.severity === 'error'));
});
test('render failure returns the CLI error', async () => {
const text = JSON.stringify({ schema_version: 1, diagram_type: 'architecture', meta: {}, components: [] });
const result = await renderDiagram(runtime(), { type: 'architecture', diagram: JSON.parse(text), format: 'json', json: text }, 'fallback');
assert.equal(result.ok, false);
assert.match(result.error ?? '', /schema validation failed/);
});
test('unverifiable source evidence falls back to a render without source links', async () => {
// This checkout's origin is not mco-org/mco, so verification must fail.
const source = load('mco-runtime.architecture.json');
const strict = await renderDiagram(runtime({ repoRoot: root }), source, 'strict');
assert.equal(strict.ok, false);
const fallback = await renderDiagram(runtime({ repoRoot: root }), source, 'fallback');
assert.ok(fallback.ok, fallback.error);
assert.match(fallback.evidenceNotice ?? '', /Source links are hidden/);
const noRoot = await renderDiagram(runtime(), source, 'fallback');
assert.ok(noRoot.ok);
assert.match(noRoot.evidenceNotice ?? '', /not inside a Git checkout/);
});
test('renders to a chosen file', async () => {
const output = path.join(workDir, 'exported.html');
const result = await renderToFile(runtime(), load('event-stream.dataflow.json'), output);
assert.ok(result.ok, result.error);
assert.ok(fs.statSync(output).size > 10_000);
});
test('scratch directories are cleaned up', () => {
assert.deepEqual(fs.readdirSync(workDir).filter((entry) => entry.startsWith('run-')), []);
});