0.9.2: Source view, schema checks without the YAML extension

Every Archify page can show its file's YAML in place. Diagrams get
Diagram | Graph | Source (Graph only inside a model), main.archify
Model | Graph | Source, registry and decision pages View | Source, and the
Graph page a Source segment. 2D | 3D moves left of that switch and hides
while Source shows.

The YAML opens in a CodeMirror editor inside the page (dist/source.js,
loaded on first use), themed with the page's colours. Edits go to the VS
Code document as WorkspaceEdits; outside changes come back to the page.
Undo and redo are the editor's own, since VS Code sends ⌘Z in a focused
webview to the webview; save and find stay VS Code's. Problems come from
the host only (what the Problems panel holds for the file) and are
counted on the Source segment; completion and hover come from the schema,
folded into one draft-07 document per diagram type.

The host now checks .archify files against the extension's schema with
ajv on the YAML as written, before archify validate, and checks
.archify-registry files against the registry schema for the first time.
Registry and decision pages become text editor providers. While Source
shows, new renders wait and appear when the picture comes back.

Show Source switches the page to Source; Open in Text Editor (the editor
title button) opens the text beside it, as Show Source did. The decision
schema is no longer given to the YAML extension. Fixed: YAML errors in
registry and decision files were reported on line 1; "Webview is
disposed" when a diagram closed mid-render; the model heading under the
toolbar in narrow editors.
This commit is contained in:
root-at-skic committed 2026-10-27 23:46:05 +02:00
1 parent 5bcd34b839
commit 27d4794ff8
32 files changed
+2486 -127

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { test } from 'node:test';
import { DIAGRAM_SCHEMA, REGISTRY_SCHEMA, SchemaChecker, readSchemas, readablePointer } from '../src/language/schemaCheck';
const root = path.resolve(__dirname, '..', '..');
const checker = new SchemaChecker(readSchemas(path.join(root, 'schemas')));
function walk(dir: string, out: string[] = []): string[] {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full, out);
else if (/\.archify(-registry)?$/.test(entry.name)) out.push(full);
}
return out;
}
const schemaFor = (file: string) => (file.endsWith('-registry') ? REGISTRY_SCHEMA : DIAGRAM_SCHEMA);
test('every shipped .archify and registry file passes the schema check', () => {
const files = ['examples', 'templates', path.join('test', 'fixtures')].flatMap((dir) => walk(path.join(root, dir)));
assert.ok(files.length > 30, `found ${files.length} files`);
for (const file of files) {
const problems = checker.check(fs.readFileSync(file, 'utf8'), schemaFor(file));
assert.deepEqual(problems.map((p) => p.message), [], path.relative(root, file));
}
});
function problemsAfter(file: string, from: string, to: string) {
const original = fs.readFileSync(path.join(root, file), 'utf8');
assert.ok(original.includes(from), `${file} contains ${from}`);
const text = original.replace(from, to);
return checker.check(text, schemaFor(file)).map((p) => ({ ...p, text: text.slice(p.from, p.to) }));
}
const DIAGRAM = 'templates/models/c4-standard-web-app/0200-containers/web-app.archify';
const REGISTRY = 'templates/models/c4-standard-web-app/registry/containers.archify-registry';
test('an unknown key is placed on the key', () => {
const [problem, ...rest] = problemsAfter(DIAGRAM, 'label: SQL', 'lable: SQL');
assert.equal(rest.length, 0);
assert.equal(problem.text, 'lable');
assert.match(problem.message, /^Unknown key "lable" in connections\[\d+\]\.$/);
});
test('a point with one number is placed on the whole flow list', () => {
const problems = problemsAfter(DIAGRAM, 'pos: [690, 160]', 'pos: [690]');
assert.equal(problems.length, 1);
assert.equal(problems[0].text, '[690]');
assert.match(problems[0].message, /pos needs at least 2 items\.$/);
});
test('registry: a misspelt type key, a bad type, a bad id', () => {
const typo = problemsAfter(REGISTRY, ' type: database', ' typ: database');
assert.deepEqual(typo.map((p) => p.text).sort(), ['db', 'typ']);
assert.ok(typo.some((p) => p.text === 'typ' && /Unknown key "typ"/.test(p.message)));
assert.ok(typo.some((p) => p.text === 'db' && /"type" is required in elements\.db/.test(p.message)));
const bad = problemsAfter(REGISTRY, ' type: cloud', ' type: bucket');
assert.equal(bad.length, 1);
assert.equal(bad[0].text, 'bucket');
assert.match(bad[0].message, /must be one of: frontend, backend, database, cloud, security, messagebus, external\.$/);
});
test('a YAML syntax error is reported once, as YAML', () => {
const problems = problemsAfter(REGISTRY, 'label: API', 'label: [API');
assert.equal(problems.length, 1);
assert.equal(problems[0].kind, 'yaml');
assert.match(problems[0].message, /^YAML: /);
});
test('pointers read like paths', () => {
assert.equal(readablePointer('/connections/4/label'), 'connections[4].label');
assert.equal(readablePointer('/elements/db'), 'elements.db');
assert.equal(readablePointer(''), 'the file');
});