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,49 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { hasSourceEvidence, isArchifyHtml, readDiagramSource, stripSourceEvidence, typeFromFilename } from '../src/detect';
|
||||
import { pointerSegments, rangeForPointer } from '../src/jsonPointer';
|
||||
|
||||
test('reads diagram_type from content', () => {
|
||||
const source = readDiagramSource('{"schema_version":1,"diagram_type":"sequence","meta":{}}', 'plain.json');
|
||||
assert.equal(source?.type, 'sequence');
|
||||
});
|
||||
|
||||
test('falls back to the file name for unparseable sources', () => {
|
||||
assert.equal(readDiagramSource('{"diagram_type": ', 'x.workflow.json')?.type, 'workflow');
|
||||
assert.equal(readDiagramSource('{"name":"pkg"}', 'package.json'), undefined);
|
||||
assert.equal(typeFromFilename('/a/b/Web.Architecture.json'), 'architecture');
|
||||
});
|
||||
|
||||
test('recognizes Archify HTML by its generator meta', () => {
|
||||
assert.ok(isArchifyHtml('<html><head><meta name="generator" content="archify 3.0.1"></head></html>'));
|
||||
assert.ok(!isArchifyHtml('<html><head><meta name="generator" content="hugo"></head></html>'));
|
||||
});
|
||||
|
||||
test('strips source evidence without touching the original', () => {
|
||||
const diagram = {
|
||||
meta: { title: 't', repository: { url: 'https://github.com/a/b', revision: 'x' } },
|
||||
components: [{ id: 'a', sources: [{ path: 'src/a.ts' }] }, { id: 'b' }],
|
||||
};
|
||||
assert.ok(hasSourceEvidence('architecture', diagram));
|
||||
const stripped = stripSourceEvidence('architecture', diagram);
|
||||
assert.ok(!hasSourceEvidence('architecture', stripped));
|
||||
assert.ok(diagram.meta.repository, 'original keeps its repository');
|
||||
assert.deepEqual((stripped.components as unknown[])[1], { id: 'b' });
|
||||
});
|
||||
|
||||
test('json pointer segments decode escapes and indexes', () => {
|
||||
assert.deepEqual(pointerSegments('/components/0/a~1b~0c'), ['components', 0, 'a/b~c']);
|
||||
assert.deepEqual(pointerSegments(''), []);
|
||||
});
|
||||
|
||||
test('json pointer ranges point at keys for containers and values for leaves', () => {
|
||||
const text = '{\n "meta": { "title": "x" },\n "components": [ { "id": "a" } ]\n}';
|
||||
const meta = rangeForPointer(text, '/meta');
|
||||
assert.equal(text.slice(meta.start, meta.end), '"meta"');
|
||||
const title = rangeForPointer(text, '/meta/title');
|
||||
assert.equal(text.slice(title.start, title.end), '"x"');
|
||||
const item = rangeForPointer(text, '/components/0');
|
||||
assert.equal(text.slice(item.start, item.end), '{');
|
||||
const missing = rangeForPointer(text, '/components/0/label');
|
||||
assert.equal(text.slice(missing.start, missing.end), '{', 'falls back to the nearest existing ancestor');
|
||||
});
|
||||
Reference in New Issue
Block a user