Archify Diagram Viewer 0.1.0
VS Code extension that previews Archify diagrams from their JSON sources (live, as you type) and opens rendered Archify HTML in a viewer tab. Bundles the Archify 3.0.1 renderer and runs it on VS Code's Node runtime. Adds validation diagnostics, JSON schema help, source-link navigation, export saving, render-to-file and open-in-browser commands. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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 { readDiagramSource } from '../src/detect';
|
||||
import { renderDiagram, renderToFile, RuntimeOptions, validate } from '../src/renderer';
|
||||
|
||||
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, text };
|
||||
}
|
||||
|
||||
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), 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-')), []);
|
||||
});
|
||||
Reference in New Issue
Block a user