domainCatalog.test.mjs
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const catalogPath = path.join(projectRoot, 'docs/knowledge/domain-catalog.json')
const gapsPath = path.join(projectRoot, 'docs/knowledge/known-gaps.json')
const graphPath = path.join(projectRoot, 'docs/generated/knowledge-graph.json')
test('catalog defines the six current-project domains and classifies every route', () => {
assert.equal(fs.existsSync(catalogPath), true, 'domain catalog must exist')
const catalog = JSON.parse(fs.readFileSync(catalogPath, 'utf8'))
const app = JSON.parse(fs.readFileSync(path.join(projectRoot, 'app.json'), 'utf8'))
assert.deepEqual(
catalog.domains.map((domain) => domain.name),
['application', 'workspace', 'study', 'matters', 'workOrder', 'shared'],
)
const roots = catalog.domains.flatMap((domain) =>
domain.roots.map((root) => ({
domain: domain.name,
root: root.replace(/\/$/, ''),
})),
)
const routes = [
...(app.pages || []),
...(app.subpackages || app.subPackages || []).flatMap((subpackage) =>
(subpackage.pages || []).map((page) => `${subpackage.root}/${page}`),
),
]
for (const route of routes) {
assert.ok(
roots.some(({ root }) => route === root || route.startsWith(`${root}/`)),
`unclassified route: ${route}`,
)
}
for (const root of ['components', 'api', 'store', 'utils', 'behaviors', 'wxs']) {
assert.ok(
roots.some((entry) => entry.domain === 'shared' && entry.root === root),
`shared root missing: ${root}`,
)
}
for (const domain of catalog.domains) {
for (const document of domain.documents) {
assert.equal(
fs.existsSync(path.join(projectRoot, document)),
true,
`catalog document missing: ${document}`,
)
}
}
})
test('known gaps explicitly describe only the two static-analysis boundaries', () => {
assert.equal(fs.existsSync(gapsPath), true, 'known gaps file must exist')
const catalog = JSON.parse(fs.readFileSync(catalogPath, 'utf8'))
const domains = new Set(catalog.domains.map((domain) => domain.name))
const gaps = JSON.parse(fs.readFileSync(gapsPath, 'utf8'))
assert.deepEqual(
gaps.gaps.map((gap) => [gap.domain, gap.kind]),
[
['application', 'route'],
['shared', 'endpoint'],
],
)
for (const gap of gaps.gaps) {
assert.ok(domains.has(gap.domain), `unknown gap domain: ${gap.domain}`)
assert.ok(gap.reason)
assert.ok(gap.nextStep)
}
})
test('generated graph indexes all 72 pages without scanner fixtures', () => {
assert.equal(fs.existsSync(graphPath), true, 'generated graph must exist')
const graph = JSON.parse(fs.readFileSync(graphPath, 'utf8'))
const fixturePrefix = 'tests/knowledge-graph/fixtures/'
assert.equal(graph.stats.nodeTypes.page, 72)
assert.equal(
graph.nodes.some((node) => node.path?.startsWith(fixturePrefix)),
false,
)
assert.equal(
graph.unresolved.some((item) => item.path.startsWith(fixturePrefix)),
false,
)
})