knowledgeWorkflow.test.mjs
4.81 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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)), '../..')
function absolute(relativePath) {
return path.join(projectRoot, relativePath)
}
function read(relativePath) {
assert.equal(fs.existsSync(absolute(relativePath)), true, `${relativePath} must exist`)
return fs.readFileSync(absolute(relativePath), 'utf8')
}
test('package commands and upload exclusions expose the knowledge workflow safely', () => {
const packageJson = JSON.parse(read('package.json'))
assert.deepEqual(
Object.fromEntries(
[
'knowledge:build',
'knowledge:check',
'impact',
'test:affected',
'test:knowledge',
].map((name) => [name, packageJson.scripts[name]]),
),
{
'knowledge:build': 'node scripts/knowledge-graph/knowledge-build.mjs',
'knowledge:check': 'node scripts/knowledge-graph/knowledge-check.mjs',
impact: 'node scripts/knowledge-graph/query-knowledge-graph.mjs',
'test:affected': 'node scripts/knowledge-graph/affected-tests.mjs',
'test:knowledge': 'node scripts/run-node-tests.mjs tests/knowledge-graph',
},
)
const config = JSON.parse(read('project.config.json'))
const ignoredFolders = new Set(
(config.packOptions?.ignore || [])
.filter((item) => item.type === 'folder')
.map((item) => item.value),
)
for (const folder of ['.agents', 'docs', 'scripts', 'tests']) {
assert.ok(ignoredFolders.has(folder), `${folder} must stay outside uploads`)
}
})
test('domain index maps all six domains and keeps generated and work-order entrypoints', () => {
const catalog = JSON.parse(read('docs/knowledge/domain-catalog.json'))
const domainIndex = read('docs/DOMAIN-INDEX.md')
assert.deepEqual(
catalog.domains.map((domain) => domain.name),
['application', 'workspace', 'study', 'matters', 'workOrder', 'shared'],
)
for (const domain of catalog.domains) {
assert.match(domainIndex, new RegExp(`\\b${domain.name}\\b`))
}
for (const target of [
'./generated/PROJECT-SUMMARY.md',
'./generated/ROUTE-PAGE-INDEX.md',
'./generated/API-CALLER-INDEX.md',
'./generated/GLOBAL-STATE-INDEX.md',
'./COMPONENT-PAGE-INDEX.md',
'./order-creation/README.md',
'./order-lifecycle/README.md',
'./tabWorkOrder/精品工单页面接口清单.md',
]) {
assert.ok(domainIndex.includes(`(${target})`), `missing domain link: ${target}`)
}
})
test('project documentation teaches build, query, uncertainty and safe Live boundaries', () => {
const rootReadme = read('README.md')
const docsReadme = read('docs/README.md')
for (const command of [
'npm run knowledge:build',
'npm run knowledge:check',
'npm run impact',
'npm run test:affected',
]) {
assert.ok(rootReadme.includes(command), `root README missing ${command}`)
assert.ok(docsReadme.includes(command), `docs README missing ${command}`)
}
for (const concept of ['docs/generated', 'unresolved', '上传排除', 'Live', '环境变量']) {
assert.ok(docsReadme.includes(concept), `docs README missing ${concept}`)
}
})
test('project skill enforces evidence-led impact classification in execution order', () => {
const skillPath = '.agents/skills/requirement-impact-analysis/SKILL.md'
const skill = read(skillPath)
const frontmatter = skill.match(/^---\n([\s\S]*?)\n---/)
assert.ok(frontmatter, 'skill frontmatter must exist')
assert.match(frontmatter[1], /^name:\s*requirement-impact-analysis$/m)
assert.match(frontmatter[1], /description:[\s\S]*Use when/)
assert.ok(frontmatter[1].length <= 1024)
const orderedSignals = [
'DOMAIN-INDEX',
'knowledge:check',
'npm run impact',
'`rg`',
'必改',
'可能波及',
'明确不改',
'test:affected',
]
let previous = -1
for (const signal of orderedSignals) {
const current = skill.indexOf(signal, previous + 1)
assert.ok(current > previous, `skill workflow missing or misordered: ${signal}`)
previous = current
}
assert.match(skill, /图谱邻接不等于必改/)
for (const reference of [
'.agents/skills/requirement-impact-analysis/references/reference.md',
'.agents/skills/requirement-impact-analysis/references/reference-full.md',
]) {
read(reference)
}
})
test('new workflow documentation never stores mobile credentials', () => {
const content = [
read('README.md'),
read('docs/README.md'),
read('docs/DOMAIN-INDEX.md'),
read('.agents/skills/requirement-impact-analysis/SKILL.md'),
read('.agents/skills/requirement-impact-analysis/references/reference.md'),
read('.agents/skills/requirement-impact-analysis/references/reference-full.md'),
].join('\n')
assert.doesNotMatch(content, /\b1\d{10}\b/)
})