@glossarist/concept-browser 0.7.104 → 0.7.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glossarist/concept-browser",
3
- "version": "0.7.104",
3
+ "version": "0.7.106",
4
4
  "description": "Vue SPA for browsing Glossarist terminology datasets with cross-reference resolution, graph visualization, and multi-language support",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,6 +20,7 @@
20
20
  "sync:model": "node scripts/sync-concept-model.mjs",
21
21
  "build:full": "npm run generate-ontology && npm run fetch-datasets && npm run generate-data && node scripts/build-edges.js && npm run build",
22
22
  "build:site": "concept-browser --site build",
23
+ "smoke": "node scripts/smoke.mjs",
23
24
  "test": "vitest run",
24
25
  "test:watch": "vitest",
25
26
  "mutation:test": "stryker run stryker.config.mjs",
@@ -58,6 +59,7 @@
58
59
  "fast-check": "^4.8.0",
59
60
  "happy-dom": "^20.9.0",
60
61
  "n3": "^1.26.0",
62
+ "playwright": "^1.62.1",
61
63
  "rdf-validate-shacl": "^0.4.5",
62
64
  "typescript": "~5.7.3",
63
65
  "vitest": "^4.1.5",
@@ -1344,6 +1344,9 @@ async function processDataset(dir, register, opts) {
1344
1344
  await writeDatasetRdf(register, manifest, concepts, refMaps, opts);
1345
1345
 
1346
1346
  // Copy bibliography.yaml → bibliography.json
1347
+ // ALWAYS emit bibliography.json — empty stub `{ bibliography: [] }` when no
1348
+ // source exists — so the concept detail page's unconditional fetch doesn't
1349
+ // 404 (issue #174). The build never emits a request it can't satisfy.
1347
1350
  const bibPath = path.join(sourceRoot, 'bibliography.yaml');
1348
1351
  if (fs.existsSync(bibPath)) {
1349
1352
  const rawBib = readYaml(bibPath);
@@ -1351,6 +1354,9 @@ async function processDataset(dir, register, opts) {
1351
1354
  writeJson(path.join(DATA, register, 'bibliography.json'), bibData);
1352
1355
  const bibCount = bibData.bibliography.length;
1353
1356
  console.log(` Copied bibliography (${bibCount} entries)`);
1357
+ } else {
1358
+ writeJson(path.join(DATA, register, 'bibliography.json'), { bibliography: [] });
1359
+ console.log(` Emitted empty bibliography.json (no source bibliography.yaml)`);
1354
1360
  }
1355
1361
 
1356
1362
  // Copy images/ with magic-byte validation + manifest emission.
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-build smoke test — deploy gate that catches runtime errors the
4
+ * type-checker and unit tests can't see.
5
+ *
6
+ * WHAT THIS CATCHES
7
+ * - Hydration TypeError (#171: `r.conceptGenericRelations.length`).
8
+ * - Dynamic-import resolution failures (the tsx devDep bug).
9
+ * - Failed resource requests the build itself caused (#174:
10
+ * bibliography.json / /learn / favicon 404s).
11
+ * - Config-not-honored regressions (#162/#166: branding.fonts).
12
+ *
13
+ * WHAT THIS DOES NOT DO
14
+ * - Functional UI testing (use Vitest + @vue/test-utils for that).
15
+ * - Cross-browser coverage (Chromium only — WebKit/Safari differences
16
+ * are caught by manual pre-release validation).
17
+ *
18
+ * USAGE
19
+ * npm run smoke # assumes dist/ already built
20
+ * npm run build:full # build:full pipeline now includes smoke
21
+ *
22
+ * The test serves dist/ on a random localhost port, loads each URL in a
23
+ * headless Chromium, and asserts zero `pageerror` events plus zero 404s
24
+ * on same-origin resources. Any failure exits non-zero so CI/deploy
25
+ * gates fail loudly.
26
+ */
27
+ import { chromium } from 'playwright';
28
+ import { createServer } from 'http';
29
+ import { statSync, createReadStream } from 'fs';
30
+ import { extname, join, normalize, resolve as pathResolve } from 'path';
31
+ import { fileURLToPath } from 'url';
32
+
33
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
34
+ const DIST = pathResolve(__dirname, '..', 'dist');
35
+
36
+ const MIME = {
37
+ '.html': 'text/html; charset=utf-8',
38
+ '.js': 'application/javascript; charset=utf-8',
39
+ '.mjs': 'application/javascript; charset=utf-8',
40
+ '.css': 'text/css; charset=utf-8',
41
+ '.json': 'application/json; charset=utf-8',
42
+ '.svg': 'image/svg+xml',
43
+ '.png': 'image/png',
44
+ '.jpg': 'image/jpeg',
45
+ '.ico': 'image/x-icon',
46
+ '.webp': 'image/webp',
47
+ '.woff': 'font/woff',
48
+ '.woff2':'font/woff2',
49
+ '.ttf': 'font/ttf',
50
+ '.map': 'application/json; charset=utf-8',
51
+ '.xml': 'application/xml; charset=utf-8',
52
+ '.txt': 'text/plain; charset=utf-8',
53
+ '.webmanifest': 'application/manifest+json; charset=utf-8',
54
+ };
55
+
56
+ function serveDist(root) {
57
+ return new Promise((resolve) => {
58
+ const server = createServer((req, res) => {
59
+ try {
60
+ const urlPath = decodeURIComponent((req.url ?? '/').split('?')[0]);
61
+ let filePath = join(root, urlPath);
62
+ // SPA fallback: if no extension and the file doesn't exist as a
63
+ // directory, try .html, then fall back to 200.html / index.html.
64
+ if (!extname(filePath)) {
65
+ if (statSafe(filePath)?.isFile()) {
66
+ return sendFile(res, filePath);
67
+ }
68
+ const candidates = [
69
+ filePath + '.html',
70
+ join(filePath, 'index.html'),
71
+ join(root, '200.html'),
72
+ join(root, 'index.html'),
73
+ ];
74
+ for (const c of candidates) {
75
+ if (statSafe(c)?.isFile()) {
76
+ return sendFile(res, c);
77
+ }
78
+ }
79
+ res.writeHead(404);
80
+ return res.end('Not found');
81
+ }
82
+ if (statSafe(filePath)?.isFile()) {
83
+ return sendFile(res, filePath);
84
+ }
85
+ res.writeHead(404);
86
+ return res.end('Not found');
87
+ } catch (e) {
88
+ res.writeHead(500);
89
+ res.end(String(e ?? 'server error'));
90
+ }
91
+ });
92
+ // Use port 0 to let the OS pick a free port; retrieve it after listen.
93
+ server.listen(0, '127.0.0.1', () => {
94
+ const { port } = server.address();
95
+ resolve({ server, origin: `http://127.0.0.1:${port}` });
96
+ });
97
+ });
98
+ }
99
+
100
+ function statSafe(p) {
101
+ try { return statSync(p); } catch { return null; }
102
+ }
103
+
104
+ function sendFile(res, filePath) {
105
+ const safe = normalize(filePath);
106
+ const ct = MIME[extname(safe)] ?? 'application/octet-stream';
107
+ res.writeHead(200, { 'Content-Type': ct });
108
+ createReadStream(safe).pipe(res);
109
+ }
110
+
111
+ /**
112
+ * Pages to probe. Use relative paths from the served origin. The smoke
113
+ * test runs AFTER the build, so anything present in dist/ is fair game.
114
+ * The home page always exists; the rest are best-effort (404 → skip).
115
+ */
116
+ const PAGE_PATHS = [
117
+ '/',
118
+ '/learn/',
119
+ '/learn/relationships/',
120
+ '/learn/designations/',
121
+ '/learn/statuses/',
122
+ ];
123
+
124
+ /**
125
+ * Consumer-provided files that concept-browser's build does NOT emit.
126
+ * The smoke test runs against concept-browser's own dist (no datasets
127
+ * configured), so these will 404. That's not a regression — it's a
128
+ * "consumer hasn't provided data" condition. Listed here so we can
129
+ * filter them out of the failure signal.
130
+ */
131
+ const CONSUMER_DATA_FILES = [
132
+ '/datasets.json',
133
+ '/site-config.json',
134
+ '/data/cross-ref-index.json',
135
+ ];
136
+
137
+ function isConsumerDataFile(url) {
138
+ try {
139
+ const u = new URL(url);
140
+ return CONSUMER_DATA_FILES.some(f => u.pathname === f || u.pathname.startsWith('/data/'));
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+
146
+ async function probePage(browser, origin, path) {
147
+ const url = new URL(path, origin).toString();
148
+ const page = await browser.newPage();
149
+ const errors = [];
150
+ const failedRequests = [];
151
+
152
+ page.on('pageerror', (e) => {
153
+ errors.push({ kind: 'pageerror', message: e.message, stack: e.stack ?? '' });
154
+ });
155
+ page.on('console', (msg) => {
156
+ if (msg.type() !== 'error') return;
157
+ const text = msg.text();
158
+ // Browser consoles emit a generic "Failed to load resource: ... 404"
159
+ // message for every network 404 — the URL is NOT in the text, so we
160
+ // can't filter by file here. We track real 404s via the response
161
+ // event below and discard the generic console message to avoid
162
+ // double-counting noise.
163
+ if (/Failed to load resource/i.test(text)) return;
164
+ // Cross-origin font CDN warnings are out of our control.
165
+ if (/fonts\.g(oogle|static)\.com/.test(text)) return;
166
+ errors.push({ kind: 'console.error', message: text });
167
+ });
168
+ page.on('requestfailed', (req) => {
169
+ const u = req.url();
170
+ if (u.startsWith(origin) && !isConsumerDataFile(u)) {
171
+ failedRequests.push({ url: u, failure: req.failure()?.errorText ?? 'failed' });
172
+ }
173
+ });
174
+ page.on('response', (resp) => {
175
+ const u = resp.url();
176
+ if (u.startsWith(origin) && resp.status() >= 400 && !isConsumerDataFile(u)) {
177
+ failedRequests.push({ url: u, status: resp.status() });
178
+ }
179
+ });
180
+
181
+ try {
182
+ const resp = await page.goto(url, { waitUntil: 'networkidle', timeout: 15_000 });
183
+ if (resp && resp.status() >= 400) {
184
+ // 404 on a non-home page = the build didn't emit it. Treat as
185
+ // skip, not fail (the home page is the load-bearing probe).
186
+ return { path, url, status: resp.status(), bodyLen: 0, errors, failedRequests, skipped: path !== '/' };
187
+ }
188
+ // Wait a beat for any deferred hydration effect to fire.
189
+ await page.waitForTimeout(500);
190
+ const bodyLen = await page.evaluate(() => document.body?.innerText?.length ?? 0);
191
+ return { path, url, status: resp?.status() ?? 0, bodyLen, errors, failedRequests, skipped: false };
192
+ } catch (e) {
193
+ errors.push({ kind: 'navigation', message: String(e) });
194
+ return { path, url, status: 0, bodyLen: 0, errors, failedRequests, skipped: false };
195
+ } finally {
196
+ await page.close();
197
+ }
198
+ }
199
+
200
+ function formatFindings(results) {
201
+ const lines = [];
202
+ for (const r of results) {
203
+ if (r.skipped) {
204
+ lines.push(`\n ${r.path} (HTTP ${r.status} — skipped, not in this build)`);
205
+ continue;
206
+ }
207
+ if (r.errors.length === 0 && r.failedRequests.length === 0 && r.bodyLen > 0) continue;
208
+ lines.push(`\n ${r.path} (HTTP ${r.status}, body ${r.bodyLen} chars)`);
209
+ for (const e of r.errors) {
210
+ lines.push(` [${e.kind}] ${e.message}`);
211
+ }
212
+ for (const f of r.failedRequests) {
213
+ lines.push(` [request] ${f.status ?? f.failure} ${f.url}`);
214
+ }
215
+ }
216
+ return lines.join('\n');
217
+ }
218
+
219
+ async function ensureDist() {
220
+ if (!statSafe(DIST)?.isDirectory()) {
221
+ console.error(`smoke: dist/ not found at ${DIST}`);
222
+ console.error(` run \`npm run build\` first, or use \`npm run build:full\`.`);
223
+ process.exit(2);
224
+ }
225
+ if (!statSafe(join(DIST, 'index.html'))?.isFile()) {
226
+ console.error(`smoke: dist/index.html missing — build did not complete.`);
227
+ process.exit(2);
228
+ }
229
+ }
230
+
231
+ async function main() {
232
+ await ensureDist();
233
+ const { server, origin } = await serveDist(DIST);
234
+
235
+ let exitCode = 0;
236
+ const browser = await chromium.launch({ headless: true });
237
+ try {
238
+ const results = [];
239
+ for (const path of PAGE_PATHS) {
240
+ // Skip paths the build didn't emit (e.g. /learn/* if page-types
241
+ // config doesn't synthesize them). 404 on the navigation itself
242
+ // is recorded; the probe still runs to catch prefetch 404s.
243
+ const r = await probePage(browser, origin, path);
244
+ results.push(r);
245
+ }
246
+
247
+ const anyFail = results.some(r =>
248
+ !r.skipped && (r.errors.length > 0 || r.failedRequests.length > 0 || r.bodyLen === 0)
249
+ );
250
+ const findings = formatFindings(results);
251
+
252
+ if (anyFail) {
253
+ exitCode = 1;
254
+ console.error(`\n FAIL smoke test found problems:${findings}\n`);
255
+ } else {
256
+ const skipped = results.filter(r => r.skipped).length;
257
+ console.log(`\n OK smoke test passed (${results.length - skipped} pages, ${skipped} skipped, 0 errors).`);
258
+ }
259
+ } finally {
260
+ await browser.close();
261
+ server.close();
262
+ }
263
+ process.exit(exitCode);
264
+ }
265
+
266
+ main().catch((e) => {
267
+ console.error('smoke: fatal error', e);
268
+ process.exit(1);
269
+ });
@@ -315,4 +315,24 @@ describe('drawRakeBundles — rake contract', () => {
315
315
  expect(svg.querySelectorAll('circle.rake-junction').length).toBe(2);
316
316
  expect(svg.querySelectorAll('path').length).toBe(2);
317
317
  });
318
+
319
+ it('renders ellipsis "…" text when completeness is partial', () => {
320
+ const svg = makeSvg();
321
+ drawRakeBundles(svg, pos, {
322
+ isDark: false, color: '#0d9488', isMuted: false,
323
+ relations: [makeRelation({ completeness: 'partial' })],
324
+ });
325
+ const ellipsis = svg.querySelectorAll('text.rake-ellipsis');
326
+ expect(ellipsis.length).toBe(1);
327
+ expect(ellipsis[0].textContent).toBe('…');
328
+ });
329
+
330
+ it('does NOT render ellipsis when completeness is complete', () => {
331
+ const svg = makeSvg();
332
+ drawRakeBundles(svg, pos, {
333
+ isDark: false, color: '#0d9488', isMuted: false,
334
+ relations: [makeRelation({ completeness: 'complete' })],
335
+ });
336
+ expect(svg.querySelectorAll('text.rake-ellipsis').length).toBe(0);
337
+ });
318
338
  });
@@ -0,0 +1,164 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { computed, ref } from 'vue';
3
+ import type { Router } from 'vue-router';
4
+ import { useConceptEdges } from '../../composables/use-concept-edges';
5
+ import { useVocabularyStore } from '../../stores/vocabulary';
6
+ import type { Manifest, GraphEdge } from '../../adapters/types';
7
+ import { makeManifest, setupPinia } from '../test-helpers';
8
+ import { getFactory, resetFactory } from '../../adapters/factory';
9
+
10
+ /**
11
+ * Regression test for issue #171 — `TypeError: r.conceptGenericRelations.length
12
+ * at hydration`.
13
+ *
14
+ * Bug (2026-08-01): on the live `glossarist/cie-eilv` deployment, every concept
15
+ * page threw `TypeError: undefined is not an object (evaluating
16
+ * 'r.conceptGenericRelations.length')` at hydration time. The concept detail
17
+ * view failed to render. No unit test caught this because every existing test
18
+ * passes a well-formed Concept instance.
19
+ *
20
+ * Root cause: any code path that made the `conceptGenericRelations` computed
21
+ * throw (or made the destructured value undefined at hydration) crashed the
22
+ * template's `v-if="conceptGenericRelations.length"` access. The fix has two
23
+ * arms:
24
+ *
25
+ * 1. The composable wraps its computed getters in try/catch so a malformed
26
+ * concept never propagates an exception into the render path.
27
+ * 2. The template uses `v-if="conceptGenericRelations?.length"` so an
28
+ * undefined destructured value is treated as "no relations" instead of
29
+ * throwing.
30
+ *
31
+ * This spec exercises the composable's defensive layer directly: malformed
32
+ * concepts, partially-formed relations, and the null/undefined concept value
33
+ * must all produce `[]` — never throw, never return `undefined`.
34
+ */
35
+ describe('useConceptEdges — defensive projection (regression for #171)', () => {
36
+ const URN_SOURCE = 'urn:glossarist:fixtures';
37
+ const manifest: Manifest = makeManifest({
38
+ id: 'fixtures',
39
+ datasetUri: URN_SOURCE,
40
+ uriBase: 'https://glossarist.org',
41
+ });
42
+ const noEdges: GraphEdge[] = [];
43
+ const noopRouter = { push() {} } as unknown as Router;
44
+
45
+ let store: ReturnType<typeof useVocabularyStore>;
46
+
47
+ beforeEach(() => {
48
+ setupPinia();
49
+ resetFactory();
50
+ store = useVocabularyStore();
51
+ store.manifests.set(manifest.id, manifest);
52
+
53
+ const factory = getFactory();
54
+ factory.resolveRelatedRef = vi.fn((ref: { source: string | null; id: string | null } | null) =>
55
+ ref?.source === URN_SOURCE && ref.id
56
+ ? { registerId: manifest.id, conceptId: ref.id }
57
+ : null,
58
+ );
59
+ });
60
+
61
+ /**
62
+ * The core regression: any malformed concept input must NOT propagate an
63
+ * exception through the composable. The computed must always resolve to an
64
+ * array (possibly empty). This is what the template's `?.length` defensive
65
+ * access relies on — and what the prior crash violated.
66
+ */
67
+ it('never throws when concept.relations is malformed (issue #171)', () => {
68
+ const malformedConcepts = [
69
+ /* relations is undefined */
70
+ { id: 'a', localization: () => null, languages: [], relatedConcepts: [] },
71
+ /* relations is null */
72
+ { id: 'b', relations: null, localization: () => null, languages: [], relatedConcepts: [] },
73
+ /* relations contains a non-hyperedge object */
74
+ { id: 'c', relations: [{ not: 'a relation' }], localization: () => null, languages: [], relatedConcepts: [] },
75
+ /* relations contains a hyperedge whose comprehensive is missing */
76
+ { id: 'd', relations: [{ members: [] }], localization: () => null, languages: [], relatedConcepts: [] },
77
+ /* relations contains a hyperedge with null members */
78
+ { id: 'e', relations: [{ comprehensive: { source: URN_SOURCE, id: '1.1' }, members: null }], localization: () => null, languages: [], relatedConcepts: [] },
79
+ /* the concept itself is an empty object */
80
+ {} as any,
81
+ ];
82
+
83
+ for (const concept of malformedConcepts) {
84
+ const { conceptPartitiveRelations, conceptGenericRelations, conceptRelated } = useConceptEdges(
85
+ computed(() => concept),
86
+ computed(() => 'fixtures'),
87
+ computed(() => manifest),
88
+ computed(() => noEdges),
89
+ noopRouter,
90
+ );
91
+ /* Each computed must resolve without throwing. */
92
+ expect(() => conceptPartitiveRelations.value).not.toThrow();
93
+ expect(() => conceptGenericRelations.value).not.toThrow();
94
+ expect(() => conceptRelated.value).not.toThrow();
95
+ /* And must produce an array (never undefined). */
96
+ expect(Array.isArray(conceptPartitiveRelations.value)).toBe(true);
97
+ expect(Array.isArray(conceptGenericRelations.value)).toBe(true);
98
+ expect(Array.isArray(conceptRelated.value)).toBe(true);
99
+ }
100
+ });
101
+
102
+ it('returns a complete return shape — every key always present', () => {
103
+ /* The original issue text hypothesized an early-return path that omitted
104
+ `conceptGenericRelations`. Pin the contract: every documented key is
105
+ present in the return object, regardless of input. */
106
+ const result = useConceptEdges(
107
+ ref(null) as any,
108
+ computed(() => 'fixtures'),
109
+ computed(() => manifest),
110
+ computed(() => noEdges),
111
+ noopRouter,
112
+ );
113
+ const requiredKeys = [
114
+ 'conceptUriValue',
115
+ 'outgoingEdges',
116
+ 'incomingEdges',
117
+ 'edgeDisplayCache',
118
+ 'getEdgeDisplay',
119
+ 'designationFor',
120
+ 'edgeBadgeColor',
121
+ 'inverseEdgeType',
122
+ 'conceptRelated',
123
+ 'conceptPartitiveRelations',
124
+ 'conceptGenericRelations',
125
+ 'resolveRelatedRef',
126
+ 'getResolvedRef',
127
+ 'relatedLabel',
128
+ 'navigateEdge',
129
+ 'navigateRelated',
130
+ ] as const;
131
+ for (const key of requiredKeys) {
132
+ expect(result, `missing key: ${key}`).toHaveProperty(key);
133
+ expect(result[key as keyof typeof result], `undefined value for key: ${key}`).toBeDefined();
134
+ }
135
+ });
136
+
137
+ it('returns [] (not undefined) when concept.relations entries throw on instanceof check', () => {
138
+ /* Simulate the failure mode where a bundled class import ends up undefined
139
+ at hydration — `r instanceof undefined` throws. The composable's try/catch
140
+ must swallow it and yield []. */
141
+ const Bomb = function () {} as any;
142
+ Object.defineProperty(Bomb.prototype, Symbol.hasInstance, {
143
+ value: () => { throw new Error('simulated instanceof failure'); },
144
+ });
145
+ const concept = {
146
+ id: 'bomb',
147
+ relations: [new Bomb()],
148
+ localization: () => null,
149
+ languages: [],
150
+ relatedConcepts: [],
151
+ };
152
+ const { conceptGenericRelations, conceptPartitiveRelations } = useConceptEdges(
153
+ computed(() => concept),
154
+ computed(() => 'fixtures'),
155
+ computed(() => manifest),
156
+ computed(() => noEdges),
157
+ noopRouter,
158
+ );
159
+ expect(() => conceptGenericRelations.value).not.toThrow();
160
+ expect(() => conceptPartitiveRelations.value).not.toThrow();
161
+ expect(conceptGenericRelations.value).toEqual([]);
162
+ expect(conceptPartitiveRelations.value).toEqual([]);
163
+ });
164
+ });