realQueries.test.mjs
3.47 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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'
import { queryKnowledgeGraph } from '../../scripts/knowledge-graph/query-knowledge-graph.mjs'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const graphPath = path.join(projectRoot, 'docs/generated/knowledge-graph.json')
assert.equal(fs.existsSync(graphPath), true, 'generated graph must exist')
const graph = JSON.parse(fs.readFileSync(graphPath, 'utf8'))
const nodeById = new Map(graph.nodes.map((node) => [node.id, node]))
function query(keyword, depth = 2) {
return queryKnowledgeGraph(graph, {
keywords: [keyword],
depth,
direction: 'both',
})
}
function allNodes(result) {
return [
...result.directMatches,
...result.upstreamConsumers,
...result.downstreamDependencies,
]
}
test('createOrder connects the work-order implementation, tests and documents', () => {
const result = query('createOrder')
const nodes = allNodes(result)
assert.ok(
result.directMatches.some(
(node) =>
node.path === 'tabWorkOrder/pages/createOrder/createOrder' ||
node.path === 'tabWorkOrder/pages/createOrder/createOrder.js',
),
)
assert.ok(nodes.some((node) => node.domain === 'workOrder'))
assert.ok(
result.testCandidates.some((node) =>
node.path?.includes('createOrder'),
),
)
assert.ok(
result.documents.some((node) =>
node.path?.startsWith('docs/order-'),
),
)
})
test('order list refresh exposes the shared write, page read/reset and uncertainty', () => {
const result = query('wx.$orderListRefresh', 3)
const nodes = allNodes(result)
assert.ok(nodes.some((node) => node.path === 'utils/util.js'))
assert.ok(
nodes.some(
(node) => node.path === 'pages/tabWorkOrder/pages/index/index.js',
),
)
assert.ok(
result.evidence.some(
(edge) =>
edge.type === 'writesState' &&
edge.to === 'globalState:wx.$orderListRefresh' &&
nodeById.get(edge.from)?.path === 'utils/util.js',
),
)
assert.ok(
result.evidence.some(
(edge) =>
edge.type === 'readsState' &&
edge.to === 'globalState:wx.$orderListRefresh' &&
nodeById.get(edge.from)?.path ===
'pages/tabWorkOrder/pages/index/index.js',
),
)
assert.ok(result.unresolved.length > 0)
assert.ok(result.unresolved.every((item) => item.path && item.reason))
})
test('packageWorkspace resolves to workspace pages and modules', () => {
const result = query('packageWorkspace')
assert.ok(
result.directMatches.some((node) =>
node.path?.startsWith('packageWorkspace/'),
),
)
assert.ok(
result.directMatches.some((node) => node.domain === 'workspace'),
)
})
test('gl-cust-form connects global registration with its workspace consumer', () => {
const result = query('gl-cust-form', 3)
assert.ok(
result.directMatches.some(
(node) => node.id === 'component:components/GLCustForm/GLCustForm',
),
)
assert.ok(
result.evidence.some(
(edge) =>
edge.type === 'usesComponent' &&
edge.evidence.path === 'app.json' &&
edge.to === 'component:components/GLCustForm/GLCustForm',
),
)
assert.ok(
result.evidence.some(
(edge) =>
edge.type === 'usesComponent' &&
nodeById.get(edge.from)?.domain === 'workspace' &&
edge.to === 'component:components/GLCustForm/GLCustForm',
),
)
})