Files
archify-vscode-ext/test/brands.test.ts
T
root-at-skic adc5cdbe97 Suggest brand IDs after brand: and place unknown-brand errors on their line
- Completion for brand values in .archify (YAML) and Archify JSON sources,
  from the bundled brand-marks/catalog.json (107 marks); aliases and
  product names match, so "kafka" offers apache-kafka
- brand/unknown diagnostics carry their JSON pointer only at the start of
  the message; use it when subject.path is missing, so the error lands on
  the brand line instead of the top of the file
- Unit tests for catalog loading, value detection and pointer fallback;
  integration checks for completion and diagnostic placement

Closes #5
2026-10-04 22:05:30 +03:00

45 lines
2.3 KiB
TypeScript

import assert from 'node:assert/strict';
import path from 'node:path';
import { test } from 'node:test';
import { brandValueAt, loadBrandCatalog } from '../src/brands';
import { diagnosticPointer } from '../src/jsonPointer';
const root = path.resolve(__dirname, '..', '..');
const catalogFile = path.join(root, 'vendor', 'archify', 'brand-marks', 'catalog.json');
test('loads the bundled brand catalog', () => {
const brands = loadBrandCatalog(catalogFile);
assert.ok(brands.length >= 100, `${brands.length} brands`);
const postgres = brands.find((brand) => brand.id === 'postgresql');
assert.ok(postgres);
assert.ok(postgres.aliases.includes('postgres'));
assert.ok(brands.every((brand) => brand.id && brand.title));
});
test('finds a brand value being typed in YAML', () => {
assert.deepEqual(brandValueAt(' brand: ', 'yaml'), { typed: '' });
assert.deepEqual(brandValueAt(' brand: post', 'yaml'), { typed: 'post' });
assert.deepEqual(brandValueAt(' - brand: apache-ka', 'yaml'), { typed: 'apache-ka' });
assert.deepEqual(brandValueAt(' brand: "red', 'yaml'), { typed: 'red' });
assert.deepEqual(brandValueAt(' - { id: db, brand: post', 'yaml'), { typed: 'post' });
assert.equal(brandValueAt(' label: post', 'yaml'), undefined);
assert.equal(brandValueAt(' subbrand: post', 'yaml'), undefined);
assert.equal(brandValueAt(' brand: postgresql ', 'yaml'), undefined, 'value already finished');
});
test('finds a brand value being typed in JSON', () => {
assert.deepEqual(brandValueAt(' "brand": "', 'json'), { typed: '' });
assert.deepEqual(brandValueAt('{ "id": "db", "brand": "post', 'json'), { typed: 'post' });
assert.equal(brandValueAt(' "brand": ', 'json'), undefined, 'not inside the string yet');
assert.equal(brandValueAt(' "label": "post', 'json'), undefined);
});
test('diagnostic pointer comes from subject.path, else from a leading pointer in the message', () => {
assert.equal(diagnosticPointer({ message: 'x', subject: { path: '/components/0' } }), '/components/0');
assert.equal(
diagnosticPointer({ message: '/components/0/brand "aws" is not a built-in brand; closest IDs: airtable' }),
'/components/0/brand',
);
assert.equal(diagnosticPointer({ message: 'Label "x" is wider than node' }), undefined);
});