Models: main.archify, registries, refs, links and the model page; 0.7.0

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.
This commit is contained in:
2026-10-19 11:37:20 +03:00
parent 701ffc7607
commit 7a2b661afe
50 changed files with 2154 additions and 47 deletions
+92
View File
@@ -248,4 +248,96 @@ export async function run(): Promise<void> {
'unverifiable evidence is a warning in fallback mode',
);
});
// --- models: a folder with main.archify, registries and diagrams that use `ref`
await check('a diagram inside a model resolves registry refs and validates clean', async () => {
const uri = workspaceFile('model/0200-containers/online-shop.archify');
const doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc);
// Validation runs through the Archify CLI; give it time, then expect no errors at all.
await new Promise((resolve) => setTimeout(resolve, 6000));
const errors = vscode.languages.getDiagnostics(doc.uri).filter((d) => d.source === 'archify' && d.severity === vscode.DiagnosticSeverity.Error);
assert.deepEqual(errors.map((d) => d.message), []);
});
await check('an unknown ref is reported at its line', async () => {
const target = workspaceFile('model/0300-components/ghost.archify');
await vscode.workspace.fs.writeFile(
target,
new TextEncoder().encode('schema_version: 1\ndiagram_type: architecture\nmeta: { title: Ghost, output: ghost.html }\ncomponents:\n - ref: ghost\n pos: [40, 40]\n size: [130, 60]\n'),
);
const doc = await vscode.workspace.openTextDocument(target);
await vscode.window.showTextDocument(doc);
const diagnostic = await waitFor('unknown ref diagnostic', () =>
vscode.languages.getDiagnostics(doc.uri).find((d) => d.source === 'archify' && /Unknown element "ghost"/.test(d.message)),
);
assert.equal(diagnostic.range.start.line, 4, 'reported on the ref line');
});
await check('hover and completion on ref come from the registry', async () => {
const uri = workspaceFile('model/0200-containers/online-shop.archify');
const doc = await vscode.workspace.openTextDocument(uri);
const line = doc.getText().split('\n').findIndex((l) => /ref: api$/.test(l));
assert.ok(line >= 0, 'the containers diagram refers to api');
const hovers = await vscode.commands.executeCommand<vscode.Hover[]>('vscode.executeHoverProvider', uri, new vscode.Position(line, 10));
const text = hovers.flatMap((h) => h.contents).map((c) => (typeof c === 'string' ? c : c.value)).join('\n');
assert.match(text, /Owns authentication/);
const defs = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', uri, new vscode.Position(line, 10));
assert.match(defs[0].uri.path, /registry\/containers\.archify-registry$/);
const completions = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', uri, new vscode.Position(line, 9));
const labels = completions.items.map((i) => (typeof i.label === 'string' ? i.label : i.label.label));
assert.ok(labels.includes('api') && labels.includes('queue'), `completion lists registry elements: ${labels.join(', ')}`);
});
await check('a registry file reports duplicate ids and parse problems', async () => {
const target = workspaceFile('model/registry/extra.archify-registry');
await vscode.workspace.fs.writeFile(target, new TextEncoder().encode('schema_version: 1\nelements:\n api:\n type: backend\n label: API again\n'));
const doc = await vscode.workspace.openTextDocument(target);
await vscode.window.showTextDocument(doc);
const diagnostic = await waitFor('duplicate id diagnostic', () =>
vscode.languages.getDiagnostics(doc.uri).find((d) => d.source === 'archify' && /defined twice/.test(d.message)),
);
assert.equal(diagnostic.range.start.line, 2);
await vscode.workspace.fs.delete(target);
});
await check('main.archify opens as the model page and Open Model finds it from a diagram', async () => {
const main = workspaceFile('model/main.archify');
await vscode.commands.executeCommand('vscode.open', main);
await waitFor('model page tab', () =>
vscode.window.tabGroups.all.flatMap((g) => g.tabs).some((t) => t.input instanceof vscode.TabInputCustom && t.input.viewType === 'archify.diagram' && t.input.uri.toString() === main.toString()),
);
const diagram = workspaceFile('model/0100-context/online-shop.archify');
await vscode.window.showTextDocument(await vscode.workspace.openTextDocument(diagram));
await vscode.commands.executeCommand('archify.openModel', diagram);
const tab = await waitFor('model page active', () =>
vscode.window.tabGroups.all.flatMap((g) => g.tabs).find((t) => t.isActive && t.input instanceof vscode.TabInputCustom && t.input.uri.toString() === main.toString()),
);
assert.ok(tab);
});
await check('Archify | New Diagram… → Model creates main.archify from the folder name', async () => {
const folder = workspaceFile('new-shop');
await vscode.workspace.fs.createDirectory(folder);
const { window } = vscode;
const originalPick = window.showQuickPick;
(window as { showQuickPick: unknown }).showQuickPick = async (items: Thenable<{ label: string }[]> | { label: string }[]) => (await items).find((i) => /^Model/.test(i.label));
try {
await vscode.commands.executeCommand('archify.newDiagram', folder);
} finally {
window.showQuickPick = originalPick;
}
const main = vscode.Uri.joinPath(folder, 'main.archify');
let content = '';
for (let i = 0; i < 50 && !content; i++) {
try {
content = new TextDecoder().decode(await vscode.workspace.fs.readFile(main));
} catch {
await new Promise((resolve) => setTimeout(resolve, 200));
}
}
assert.match(content, /id: new-shop/);
assert.match(content, /name: New shop/);
});
}