A folder with main.archify at its top is a model, a set of diagrams that belong together. Opening main.archify shows the model page: the model's name and description, its own overview diagram when the file has one, the diagrams grouped by folder (click to open), and the registry with where each element is used. The page is built by traversing the folder tree and refreshes when files change. *.archify-registry files define shared elements once; diagrams draw them with `ref: <id>` plus position and may override label, sublabel and tag. References are resolved before Archify runs, so Archify is unchanged. Hover, go-to-definition and completion on ref; unknown names, forbidden overrides, duplicate ids and broken registries in Problems; registry edits re-render open diagrams. `diagram:` links on elements and components open the linked diagram on double-click. New command Archify | Open Model, a Model template for New Diagram…, editor schemas for the new keys and for registries, docs/model.md and examples/online-shop. Single diagrams behave exactly as before.
77 lines
3.3 KiB
TypeScript
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-') && fs.statSync(path.join(fixtures, file)).isFile())) {
|
|
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-')), []);
|
|
});
|