.archify files are Archify JSON diagram sources. They open as JSON, preview with the same commands, report validation problems, and get completion from a schema that dispatches on diagram_type. Adds a hello.archify example and tests for detection, the dispatching schema and the VS Code behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { test } from 'node:test';
|
|
import Ajv2020 from 'ajv/dist/2020';
|
|
|
|
const root = path.resolve(__dirname, '..', '..');
|
|
const schemas = path.join(root, 'schemas');
|
|
const fixtures = path.join(root, 'test', 'fixtures');
|
|
|
|
function validator() {
|
|
const ajv = new Ajv2020({ strict: false, allErrors: true });
|
|
// Register every schema under its file name, exactly how the relative
|
|
// $refs in the bundled copies resolve inside VS Code.
|
|
for (const file of fs.readdirSync(schemas)) {
|
|
ajv.addSchema(JSON.parse(fs.readFileSync(path.join(schemas, file), 'utf8')), file);
|
|
}
|
|
return ajv.getSchema('archify.schema.json')!;
|
|
}
|
|
|
|
test('bundled schemas carry no absolute $id', () => {
|
|
for (const file of fs.readdirSync(schemas)) {
|
|
assert.equal(JSON.parse(fs.readFileSync(path.join(schemas, file), 'utf8')).$id, undefined, file);
|
|
}
|
|
});
|
|
|
|
test('the .archify schema accepts every fixture', () => {
|
|
const validate = validator();
|
|
for (const file of fs.readdirSync(fixtures)) {
|
|
const ok = validate(JSON.parse(fs.readFileSync(path.join(fixtures, file), 'utf8')));
|
|
assert.ok(ok, `${file}: ${JSON.stringify(validate.errors?.slice(0, 3))}`);
|
|
}
|
|
});
|
|
|
|
test('the .archify schema applies the schema of the declared type', () => {
|
|
const validate = validator();
|
|
const sequence = JSON.parse(fs.readFileSync(path.join(fixtures, 'cache-miss.archify'), 'utf8'));
|
|
// A sequence diagram is not a valid architecture diagram.
|
|
assert.equal(validate({ ...sequence, diagram_type: 'architecture' }), false);
|
|
assert.equal(validate({ ...sequence, diagram_type: 'poster' }), false);
|
|
const { diagram_type: _omitted, ...untyped } = sequence;
|
|
assert.equal(validate(untyped), false);
|
|
});
|