sillyspec 3.20.2 → 3.20.4
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/.claude/skills/sillyspec-archive/SKILL.md +21 -21
- package/.claude/skills/sillyspec-auto/SKILL.md +83 -83
- package/.claude/skills/sillyspec-brainstorm/SKILL.md +44 -44
- package/.claude/skills/sillyspec-commit/SKILL.md +106 -106
- package/.claude/skills/sillyspec-continue/SKILL.md +45 -45
- package/.claude/skills/sillyspec-doctor/SKILL.md +31 -31
- package/.claude/skills/sillyspec-execute/SKILL.md +30 -30
- package/.claude/skills/sillyspec-explore/SKILL.md +109 -109
- package/.claude/skills/sillyspec-knowledge/SKILL.md +269 -269
- package/.claude/skills/sillyspec-plan/SKILL.md +21 -21
- package/.claude/skills/sillyspec-propose/SKILL.md +21 -21
- package/.claude/skills/sillyspec-quick/SKILL.md +21 -21
- package/.claude/skills/sillyspec-resume/SKILL.md +68 -68
- package/.claude/skills/sillyspec-scan/SKILL.md +21 -21
- package/.claude/skills/sillyspec-state/SKILL.md +54 -54
- package/.claude/skills/sillyspec-status/SKILL.md +21 -21
- package/.claude/skills/sillyspec-verify/SKILL.md +21 -21
- package/.claude/skills/sillyspec-workspace/SKILL.md +157 -157
- package/.husky/pre-push +13 -13
- package/CLAUDE.md +18 -18
- package/README.md +198 -188
- package/SKILL.md +90 -91
- package/bin/sillyspec.js +2 -2
- package/docs/brainstorm-plan-contract.md +64 -64
- package/docs/plan-execute-contract.md +123 -123
- package/docs/platform-scan-protocol.md +298 -298
- package/docs/revision-mode.md +115 -115
- package/docs/sillyspec/file-lifecycle/known-implementation-gaps.md +99 -99
- package/docs/sillyspec/file-lifecycle/platform-workflows-sync.md +218 -218
- package/docs/sillyspec/file-lifecycle/stage-artifacts.md +167 -167
- package/docs/sillyspec/file-lifecycle/storage-and-state.md +148 -148
- package/docs/sillyspec/file-lifecycle/worktree-and-guard.md +211 -193
- package/docs/sillyspec/file-lifecycle.md +125 -125
- package/docs/workflow-contract-regression.md +106 -106
- package/docs/worktree-isolation.md +252 -252
- package/package.json +40 -40
- package/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -7446
- package/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -1
- package/packages/dashboard/dist/index.html +16 -16
- package/packages/dashboard/index.html +15 -15
- package/packages/dashboard/package-lock.json +2384 -2384
- package/packages/dashboard/package.json +25 -25
- package/packages/dashboard/server/executor.js +86 -86
- package/packages/dashboard/server/index.js +588 -588
- package/packages/dashboard/server/parser.js +526 -526
- package/packages/dashboard/server/watcher.js +344 -344
- package/packages/dashboard/src/App.vue +558 -558
- package/packages/dashboard/src/components/ActionBar.vue +93 -93
- package/packages/dashboard/src/components/CommandPalette.vue +96 -96
- package/packages/dashboard/src/components/DetailPanel.vue +137 -137
- package/packages/dashboard/src/components/LogStream.vue +65 -65
- package/packages/dashboard/src/components/PipelineStage.vue +95 -95
- package/packages/dashboard/src/components/PipelineView.vue +156 -156
- package/packages/dashboard/src/components/ProjectList.vue +210 -210
- package/packages/dashboard/src/components/StageBadge.vue +67 -67
- package/packages/dashboard/src/components/StepCard.vue +94 -94
- package/packages/dashboard/src/components/detail/DocsDetail.vue +48 -48
- package/packages/dashboard/src/components/detail/GitDetail.vue +61 -61
- package/packages/dashboard/src/components/detail/TechDetail.vue +43 -43
- package/packages/dashboard/src/composables/useDashboard.js +170 -170
- package/packages/dashboard/src/composables/useKeyboard.js +119 -119
- package/packages/dashboard/src/composables/useWebSocket.js +129 -129
- package/packages/dashboard/src/main.js +8 -8
- package/packages/dashboard/src/style.css +132 -132
- package/packages/dashboard/vite.config.js +18 -18
- package/src/brainstorm-postcheck.js +158 -158
- package/src/change-list.js +52 -52
- package/src/change-risk-profile.js +352 -352
- package/src/classify-change.js +73 -73
- package/src/constants.js +70 -70
- package/src/contract-matrix.js +278 -278
- package/src/db.js +201 -201
- package/src/endpoint-extractor.js +315 -315
- package/src/hooks/claude-pre-tool-use.cjs +125 -125
- package/src/hooks/worktree-guard.js +653 -653
- package/src/index.js +922 -900
- package/src/init.js +431 -431
- package/src/knowledge-match.js +130 -130
- package/src/migrate.js +117 -117
- package/src/modules.js +482 -482
- package/src/progress.js +1734 -1734
- package/src/run.js +3465 -3358
- package/src/scan-postcheck.js +387 -383
- package/src/setup.js +398 -398
- package/src/stage-contract.js +700 -700
- package/src/stages/archive.js +160 -160
- package/src/stages/brainstorm-auto.js +229 -229
- package/src/stages/brainstorm.js +645 -645
- package/src/stages/doctor.js +365 -365
- package/src/stages/execute.js +625 -625
- package/src/stages/explore.js +34 -34
- package/src/stages/index.js +29 -29
- package/src/stages/knowledge.js +498 -498
- package/src/stages/plan-postcheck.js +511 -513
- package/src/stages/plan.js +582 -582
- package/src/stages/propose.js +174 -174
- package/src/stages/quick.js +82 -82
- package/src/stages/scan.js +558 -558
- package/src/stages/status.js +65 -65
- package/src/stages/verify.js +322 -322
- package/src/sync.js +497 -497
- package/src/task-review.js +346 -346
- package/src/workflow.js +785 -785
- package/src/worktree-apply.js +549 -549
- package/src/worktree-deps.js +185 -0
- package/src/worktree.js +982 -932
- package/templates/workflows/archive-impact.yaml +79 -79
- package/templates/workflows/scan-docs.yaml +132 -132
- package/test/brainstorm-plan-contract.test.mjs +273 -273
- package/test/check-syntax.mjs +26 -26
- package/test/contract-artifacts.test.mjs +323 -323
- package/test/decision-supersede.test.mjs +277 -277
- package/test/knowledge-match.test.mjs +231 -231
- package/test/plan-execute-contract.test.mjs +330 -330
- package/test/plan-optimization.test.mjs +572 -572
- package/test/platform-artifacts.test.mjs +166 -166
- package/test/platform-failure-samples.test.mjs +199 -199
- package/test/platform-recovery-chain.test.mjs +167 -167
- package/test/platform-recovery.test.mjs +136 -136
- package/test/platform-scan-p0.test.mjs +168 -168
- package/test/revision-v1.test.mjs +1145 -1145
- package/test/run-scan-project-parse.test.mjs +200 -200
- package/test/run-tests.mjs +48 -48
- package/test/scan-knowledge.test.mjs +175 -175
- package/test/scan-paths.test.mjs +68 -68
- package/test/scan-postcheck.test.mjs +197 -197
- package/test/spec-dir.test.mjs +206 -206
- package/test/stage-contract.test.mjs +299 -299
- package/test/stage-definitions.test.mjs +39 -39
- package/test/wait-gates.test.mjs +496 -496
- package/test/worktree-deps-provision.test.mjs +148 -0
- package/test/worktree-guard.test.mjs +71 -71
- package/test/worktree-native-overlay.test.mjs +188 -188
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* scan step 2 项目列表解析 — 强契约测试
|
|
3
|
-
*
|
|
4
|
-
* 解析只接受两种结构化格式:
|
|
5
|
-
* A) YAML block: scan_projects:\n - id: name
|
|
6
|
-
* B) BEGIN_PROJECT_LIST ... END_PROJECT_LIST
|
|
7
|
-
*
|
|
8
|
-
* 自由文本列表不再解析,防止误识别垃圾项目名。
|
|
9
|
-
*/
|
|
10
|
-
import { sanitizeProjectName, validateParsedProjects } from '../src/run.js'
|
|
11
|
-
|
|
12
|
-
let passed = 0
|
|
13
|
-
let failed = 0
|
|
14
|
-
function assertDeepEqual (actual, expected, msg) {
|
|
15
|
-
const a = JSON.stringify(actual)
|
|
16
|
-
const e = JSON.stringify(expected)
|
|
17
|
-
if (a === e) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
18
|
-
else { console.error(`❌ FAIL: ${msg}\n expected: ${e}\n actual: ${a}`); failed++ }
|
|
19
|
-
}
|
|
20
|
-
function assertEqual (actual, expected, msg) {
|
|
21
|
-
if (actual === expected) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
22
|
-
else { console.error(`❌ FAIL: ${msg}\n expected: ${expected}\n actual: ${actual}`); failed++ }
|
|
23
|
-
}
|
|
24
|
-
function assertIncludes (str, sub, msg) {
|
|
25
|
-
if (str.includes(sub)) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
26
|
-
else { console.error(`❌ FAIL: ${msg}\n expected to include: ${sub}\n actual: ${str}`); failed++ }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// ---- 复刻 run.js 中新的解析逻辑 ----
|
|
30
|
-
function parseProjectListFromOutput(outputText) {
|
|
31
|
-
let parsedProjects = [] // Array<{id, path?}>
|
|
32
|
-
let parsedFromStructuredOutput = false
|
|
33
|
-
if (outputText) {
|
|
34
|
-
// 格式 A: YAML block
|
|
35
|
-
const yamlBlock = outputText.match(/scan_projects:\s*\n([\s\S]+?)(?=$|\n[^\s])/)
|
|
36
|
-
if (yamlBlock) {
|
|
37
|
-
const entries = [...yamlBlock[1].matchAll(/-\s+id:\s*(\S+)(?:[\s\S]*?)(?=\n\s+-\s+id:|$)/g)]
|
|
38
|
-
for (const m of entries) {
|
|
39
|
-
const id = sanitizeProjectName(m[1])
|
|
40
|
-
if (!id) continue
|
|
41
|
-
const pathMatch = m[0].match(/path:\s*(\S+)/)
|
|
42
|
-
const entry = pathMatch ? { id, path: pathMatch[1].trim() } : { id }
|
|
43
|
-
parsedProjects.push(entry)
|
|
44
|
-
}
|
|
45
|
-
parsedFromStructuredOutput = parsedProjects.length > 0
|
|
46
|
-
}
|
|
47
|
-
// 格式 B: BEGIN_PROJECT_LIST
|
|
48
|
-
if (!parsedFromStructuredOutput) {
|
|
49
|
-
const blockMatch = outputText.match(/BEGIN_PROJECT_LIST\s*\n([\s\S]*?)\n*END_PROJECT_LIST/)
|
|
50
|
-
if (blockMatch) {
|
|
51
|
-
const raw = [...blockMatch[1].matchAll(/^-\s+(\S+)/gm)].map(m => m[1])
|
|
52
|
-
parsedProjects = raw.map(s => sanitizeProjectName(s)).filter(Boolean).map(id => ({ id }))
|
|
53
|
-
parsedFromStructuredOutput = parsedProjects.length > 0
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { parsedProjects, parsedFromStructuredOutput }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ======== 解析测试 ========
|
|
61
|
-
|
|
62
|
-
// 1. YAML block 正常解析
|
|
63
|
-
assertDeepEqual(
|
|
64
|
-
parseProjectListFromOutput(`scan_projects:
|
|
65
|
-
- id: backend
|
|
66
|
-
- id: frontend
|
|
67
|
-
- id: daemon
|
|
68
|
-
`).parsedProjects,
|
|
69
|
-
[{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }],
|
|
70
|
-
'YAML block 正常解析 3 个项目'
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
// 2. YAML block 带 path 字段(多行属性)
|
|
74
|
-
const r2 = parseProjectListFromOutput(`scan_projects:
|
|
75
|
-
- id: api
|
|
76
|
-
path: backend/
|
|
77
|
-
- id: web
|
|
78
|
-
path: frontend/
|
|
79
|
-
`).parsedProjects
|
|
80
|
-
assertDeepEqual(r2, [{ id: 'api', path: 'backend/' }, { id: 'web', path: 'frontend/' }],
|
|
81
|
-
'YAML block 带 path 字段正常解析')
|
|
82
|
-
|
|
83
|
-
// 3. BEGIN_PROJECT_LIST 正常解析
|
|
84
|
-
assertDeepEqual(
|
|
85
|
-
parseProjectListFromOutput(`BEGIN_PROJECT_LIST
|
|
86
|
-
- backend
|
|
87
|
-
- frontend
|
|
88
|
-
- daemon
|
|
89
|
-
END_PROJECT_LIST`).parsedProjects,
|
|
90
|
-
[{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }],
|
|
91
|
-
'BEGIN_PROJECT_LIST 标记块正常解析'
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
// 4. 自由文本编号列表 → 不解析
|
|
95
|
-
const { parsedProjects: fn, parsedFromStructuredOutput: fnParsed } =
|
|
96
|
-
parseProjectListFromOutput('扫描项目列表:\n1. scan1backendmulti-agent-platform-api FastAPI Python\n2. frontendmulti-agent-platform-web Next.js TS\n3. sillyhub-daemon Node.js TS')
|
|
97
|
-
assertEqual(fnParsed, false, '自由文本编号列表不触发解析')
|
|
98
|
-
assertDeepEqual(fn, [], '自由文本编号列表不产生任何项目名')
|
|
99
|
-
|
|
100
|
-
// 5. 自由文本括号枚举 → 不解析
|
|
101
|
-
const { parsedProjects: fn2, parsedFromStructuredOutput: fn2Parsed } =
|
|
102
|
-
parseProjectListFromOutput('子项目: backend / frontend / user-service')
|
|
103
|
-
assertEqual(fn2Parsed, false, '自由文本括号枚举不触发解析')
|
|
104
|
-
assertDeepEqual(fn2, [], '自由文本括号枚举不产生任何项目名')
|
|
105
|
-
|
|
106
|
-
// 6. 空 outputText → 不解析
|
|
107
|
-
const { parsedFromStructuredOutput: emptyParsed } = parseProjectListFromOutput('')
|
|
108
|
-
assertEqual(emptyParsed, false, '空 outputText 不触发解析')
|
|
109
|
-
|
|
110
|
-
// 7. 普通摘要文本 → 不解析
|
|
111
|
-
const { parsedProjects: summary, parsedFromStructuredOutput: summaryParsed } =
|
|
112
|
-
parseProjectListFromOutput('确认扫描 3 个子项目:backend、frontend、daemon,全部重新扫描')
|
|
113
|
-
assertEqual(summaryParsed, false, '普通摘要文本不触发解析')
|
|
114
|
-
assertDeepEqual(summary, [], '普通摘要文本不产生任何项目名')
|
|
115
|
-
|
|
116
|
-
// ======== validateParsedProjects — 基础校验 ========
|
|
117
|
-
|
|
118
|
-
// 8. 正常列表(无 path)
|
|
119
|
-
assertDeepEqual(
|
|
120
|
-
validateParsedProjects([{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }], '/tmp/proj'),
|
|
121
|
-
{ ok: true, errors: [] },
|
|
122
|
-
'正常列表校验通过(无 path)'
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
// 9. 正常列表(有合法 path)——需要用真实路径
|
|
126
|
-
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs'
|
|
127
|
-
import { join } from 'path'
|
|
128
|
-
import os from 'os'
|
|
129
|
-
const tmpDir = mkdtempSync(join(os.tmpdir(), 'sillyspec-test-'))
|
|
130
|
-
mkdirSync(join(tmpDir, 'backend'))
|
|
131
|
-
mkdirSync(join(tmpDir, 'frontend'))
|
|
132
|
-
assertDeepEqual(
|
|
133
|
-
validateParsedProjects([
|
|
134
|
-
{ id: 'backend', path: 'backend' },
|
|
135
|
-
{ id: 'frontend', path: 'frontend' }
|
|
136
|
-
], tmpDir),
|
|
137
|
-
{ ok: true, errors: [] },
|
|
138
|
-
'合法 path 校验通过'
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
// 10. path 不存在 → 失败
|
|
142
|
-
const v10 = validateParsedProjects([{ id: 'backend', path: 'nonexistent' }], tmpDir)
|
|
143
|
-
assertEqual(v10.ok, false, 'path 不存在校验失败')
|
|
144
|
-
assertIncludes(v10.errors[0], '不存在', '错误提示包含"不存在"')
|
|
145
|
-
|
|
146
|
-
// 11. path 含 .. 越界 → 失败
|
|
147
|
-
const v11 = validateParsedProjects([{ id: 'backend', path: '../etc/passwd' }], tmpDir)
|
|
148
|
-
assertEqual(v11.ok, false, 'path 包含 .. 校验失败')
|
|
149
|
-
assertIncludes(v11.errors[0], '..', '错误提示包含 ..')
|
|
150
|
-
|
|
151
|
-
// 12. path 解析后超出 source_root → 失败
|
|
152
|
-
const v12 = validateParsedProjects([{ id: 'backend', path: '/etc/passwd' }], tmpDir)
|
|
153
|
-
assertEqual(v12.ok, false, '绝对路径超出 source_root 校验失败')
|
|
154
|
-
assertIncludes(v12.errors[0], '超出', '错误提示包含"超出"')
|
|
155
|
-
|
|
156
|
-
// 13. 超过 10 个项目 → 失败
|
|
157
|
-
const many = Array.from({ length: 11 }, (_, i) => ({ id: `project${i}` }))
|
|
158
|
-
const v13 = validateParsedProjects(many, tmpDir)
|
|
159
|
-
assertEqual(v13.ok, false, '超过 10 个项目校验失败')
|
|
160
|
-
assertIncludes(v13.errors[0], '超过上限', '错误提示包含"超过上限"')
|
|
161
|
-
|
|
162
|
-
// 14. 重复项目名 → 失败
|
|
163
|
-
const v14 = validateParsedProjects([{ id: 'backend' }, { id: 'frontend' }, { id: 'backend' }], tmpDir)
|
|
164
|
-
assertEqual(v14.ok, false, '重复项目名校验失败')
|
|
165
|
-
assertIncludes(v14.errors[0], '重复', '错误提示包含"重复"')
|
|
166
|
-
|
|
167
|
-
// 15. 非法 slug(中文)→ 失败
|
|
168
|
-
const v15 = validateParsedProjects([{ id: 'backend' }, { id: '前端服务' }], tmpDir)
|
|
169
|
-
assertEqual(v15.ok, false, '非法 slug 校验失败')
|
|
170
|
-
|
|
171
|
-
// 16. 空列表 → 失败
|
|
172
|
-
const v16 = validateParsedProjects([], tmpDir)
|
|
173
|
-
assertEqual(v16.ok, false, '空列表校验失败')
|
|
174
|
-
|
|
175
|
-
// 17. null 列表 → 失败
|
|
176
|
-
const v17 = validateParsedProjects(null, tmpDir)
|
|
177
|
-
assertEqual(v17.ok, false, 'null 列表校验失败')
|
|
178
|
-
|
|
179
|
-
// 18. 单字符 → 失败
|
|
180
|
-
const v18 = validateParsedProjects([{ id: 'a' }], tmpDir)
|
|
181
|
-
assertEqual(v18.ok, false, '单字符项目名校验失败')
|
|
182
|
-
|
|
183
|
-
// 19. 纯数字 → 失败
|
|
184
|
-
const v19 = validateParsedProjects([{ id: '123' }], tmpDir)
|
|
185
|
-
assertEqual(v19.ok, false, '纯数字项目名校验失败')
|
|
186
|
-
|
|
187
|
-
// 20. 兼容旧 API(纯字符串数组)
|
|
188
|
-
assertDeepEqual(
|
|
189
|
-
validateParsedProjects(['backend', 'frontend'], tmpDir),
|
|
190
|
-
{ ok: true, errors: [] },
|
|
191
|
-
'旧 API 兼容:纯字符串数组仍通过'
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
// 清理
|
|
195
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
196
|
-
|
|
197
|
-
console.log(`\n${'='.repeat(50)}`)
|
|
198
|
-
console.log(`✅ 通过: ${passed} ❌ 失败: ${failed}`)
|
|
199
|
-
console.log(`${'='.repeat(50)}`)
|
|
200
|
-
if (failed > 0) process.exit(1)
|
|
1
|
+
/**
|
|
2
|
+
* scan step 2 项目列表解析 — 强契约测试
|
|
3
|
+
*
|
|
4
|
+
* 解析只接受两种结构化格式:
|
|
5
|
+
* A) YAML block: scan_projects:\n - id: name
|
|
6
|
+
* B) BEGIN_PROJECT_LIST ... END_PROJECT_LIST
|
|
7
|
+
*
|
|
8
|
+
* 自由文本列表不再解析,防止误识别垃圾项目名。
|
|
9
|
+
*/
|
|
10
|
+
import { sanitizeProjectName, validateParsedProjects } from '../src/run.js'
|
|
11
|
+
|
|
12
|
+
let passed = 0
|
|
13
|
+
let failed = 0
|
|
14
|
+
function assertDeepEqual (actual, expected, msg) {
|
|
15
|
+
const a = JSON.stringify(actual)
|
|
16
|
+
const e = JSON.stringify(expected)
|
|
17
|
+
if (a === e) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
18
|
+
else { console.error(`❌ FAIL: ${msg}\n expected: ${e}\n actual: ${a}`); failed++ }
|
|
19
|
+
}
|
|
20
|
+
function assertEqual (actual, expected, msg) {
|
|
21
|
+
if (actual === expected) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
22
|
+
else { console.error(`❌ FAIL: ${msg}\n expected: ${expected}\n actual: ${actual}`); failed++ }
|
|
23
|
+
}
|
|
24
|
+
function assertIncludes (str, sub, msg) {
|
|
25
|
+
if (str.includes(sub)) { console.log(`✅ PASS: ${msg}`); passed++ }
|
|
26
|
+
else { console.error(`❌ FAIL: ${msg}\n expected to include: ${sub}\n actual: ${str}`); failed++ }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ---- 复刻 run.js 中新的解析逻辑 ----
|
|
30
|
+
function parseProjectListFromOutput(outputText) {
|
|
31
|
+
let parsedProjects = [] // Array<{id, path?}>
|
|
32
|
+
let parsedFromStructuredOutput = false
|
|
33
|
+
if (outputText) {
|
|
34
|
+
// 格式 A: YAML block
|
|
35
|
+
const yamlBlock = outputText.match(/scan_projects:\s*\n([\s\S]+?)(?=$|\n[^\s])/)
|
|
36
|
+
if (yamlBlock) {
|
|
37
|
+
const entries = [...yamlBlock[1].matchAll(/-\s+id:\s*(\S+)(?:[\s\S]*?)(?=\n\s+-\s+id:|$)/g)]
|
|
38
|
+
for (const m of entries) {
|
|
39
|
+
const id = sanitizeProjectName(m[1])
|
|
40
|
+
if (!id) continue
|
|
41
|
+
const pathMatch = m[0].match(/path:\s*(\S+)/)
|
|
42
|
+
const entry = pathMatch ? { id, path: pathMatch[1].trim() } : { id }
|
|
43
|
+
parsedProjects.push(entry)
|
|
44
|
+
}
|
|
45
|
+
parsedFromStructuredOutput = parsedProjects.length > 0
|
|
46
|
+
}
|
|
47
|
+
// 格式 B: BEGIN_PROJECT_LIST
|
|
48
|
+
if (!parsedFromStructuredOutput) {
|
|
49
|
+
const blockMatch = outputText.match(/BEGIN_PROJECT_LIST\s*\n([\s\S]*?)\n*END_PROJECT_LIST/)
|
|
50
|
+
if (blockMatch) {
|
|
51
|
+
const raw = [...blockMatch[1].matchAll(/^-\s+(\S+)/gm)].map(m => m[1])
|
|
52
|
+
parsedProjects = raw.map(s => sanitizeProjectName(s)).filter(Boolean).map(id => ({ id }))
|
|
53
|
+
parsedFromStructuredOutput = parsedProjects.length > 0
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { parsedProjects, parsedFromStructuredOutput }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ======== 解析测试 ========
|
|
61
|
+
|
|
62
|
+
// 1. YAML block 正常解析
|
|
63
|
+
assertDeepEqual(
|
|
64
|
+
parseProjectListFromOutput(`scan_projects:
|
|
65
|
+
- id: backend
|
|
66
|
+
- id: frontend
|
|
67
|
+
- id: daemon
|
|
68
|
+
`).parsedProjects,
|
|
69
|
+
[{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }],
|
|
70
|
+
'YAML block 正常解析 3 个项目'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
// 2. YAML block 带 path 字段(多行属性)
|
|
74
|
+
const r2 = parseProjectListFromOutput(`scan_projects:
|
|
75
|
+
- id: api
|
|
76
|
+
path: backend/
|
|
77
|
+
- id: web
|
|
78
|
+
path: frontend/
|
|
79
|
+
`).parsedProjects
|
|
80
|
+
assertDeepEqual(r2, [{ id: 'api', path: 'backend/' }, { id: 'web', path: 'frontend/' }],
|
|
81
|
+
'YAML block 带 path 字段正常解析')
|
|
82
|
+
|
|
83
|
+
// 3. BEGIN_PROJECT_LIST 正常解析
|
|
84
|
+
assertDeepEqual(
|
|
85
|
+
parseProjectListFromOutput(`BEGIN_PROJECT_LIST
|
|
86
|
+
- backend
|
|
87
|
+
- frontend
|
|
88
|
+
- daemon
|
|
89
|
+
END_PROJECT_LIST`).parsedProjects,
|
|
90
|
+
[{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }],
|
|
91
|
+
'BEGIN_PROJECT_LIST 标记块正常解析'
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
// 4. 自由文本编号列表 → 不解析
|
|
95
|
+
const { parsedProjects: fn, parsedFromStructuredOutput: fnParsed } =
|
|
96
|
+
parseProjectListFromOutput('扫描项目列表:\n1. scan1backendmulti-agent-platform-api FastAPI Python\n2. frontendmulti-agent-platform-web Next.js TS\n3. sillyhub-daemon Node.js TS')
|
|
97
|
+
assertEqual(fnParsed, false, '自由文本编号列表不触发解析')
|
|
98
|
+
assertDeepEqual(fn, [], '自由文本编号列表不产生任何项目名')
|
|
99
|
+
|
|
100
|
+
// 5. 自由文本括号枚举 → 不解析
|
|
101
|
+
const { parsedProjects: fn2, parsedFromStructuredOutput: fn2Parsed } =
|
|
102
|
+
parseProjectListFromOutput('子项目: backend / frontend / user-service')
|
|
103
|
+
assertEqual(fn2Parsed, false, '自由文本括号枚举不触发解析')
|
|
104
|
+
assertDeepEqual(fn2, [], '自由文本括号枚举不产生任何项目名')
|
|
105
|
+
|
|
106
|
+
// 6. 空 outputText → 不解析
|
|
107
|
+
const { parsedFromStructuredOutput: emptyParsed } = parseProjectListFromOutput('')
|
|
108
|
+
assertEqual(emptyParsed, false, '空 outputText 不触发解析')
|
|
109
|
+
|
|
110
|
+
// 7. 普通摘要文本 → 不解析
|
|
111
|
+
const { parsedProjects: summary, parsedFromStructuredOutput: summaryParsed } =
|
|
112
|
+
parseProjectListFromOutput('确认扫描 3 个子项目:backend、frontend、daemon,全部重新扫描')
|
|
113
|
+
assertEqual(summaryParsed, false, '普通摘要文本不触发解析')
|
|
114
|
+
assertDeepEqual(summary, [], '普通摘要文本不产生任何项目名')
|
|
115
|
+
|
|
116
|
+
// ======== validateParsedProjects — 基础校验 ========
|
|
117
|
+
|
|
118
|
+
// 8. 正常列表(无 path)
|
|
119
|
+
assertDeepEqual(
|
|
120
|
+
validateParsedProjects([{ id: 'backend' }, { id: 'frontend' }, { id: 'daemon' }], '/tmp/proj'),
|
|
121
|
+
{ ok: true, errors: [] },
|
|
122
|
+
'正常列表校验通过(无 path)'
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
// 9. 正常列表(有合法 path)——需要用真实路径
|
|
126
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs'
|
|
127
|
+
import { join } from 'path'
|
|
128
|
+
import os from 'os'
|
|
129
|
+
const tmpDir = mkdtempSync(join(os.tmpdir(), 'sillyspec-test-'))
|
|
130
|
+
mkdirSync(join(tmpDir, 'backend'))
|
|
131
|
+
mkdirSync(join(tmpDir, 'frontend'))
|
|
132
|
+
assertDeepEqual(
|
|
133
|
+
validateParsedProjects([
|
|
134
|
+
{ id: 'backend', path: 'backend' },
|
|
135
|
+
{ id: 'frontend', path: 'frontend' }
|
|
136
|
+
], tmpDir),
|
|
137
|
+
{ ok: true, errors: [] },
|
|
138
|
+
'合法 path 校验通过'
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
// 10. path 不存在 → 失败
|
|
142
|
+
const v10 = validateParsedProjects([{ id: 'backend', path: 'nonexistent' }], tmpDir)
|
|
143
|
+
assertEqual(v10.ok, false, 'path 不存在校验失败')
|
|
144
|
+
assertIncludes(v10.errors[0], '不存在', '错误提示包含"不存在"')
|
|
145
|
+
|
|
146
|
+
// 11. path 含 .. 越界 → 失败
|
|
147
|
+
const v11 = validateParsedProjects([{ id: 'backend', path: '../etc/passwd' }], tmpDir)
|
|
148
|
+
assertEqual(v11.ok, false, 'path 包含 .. 校验失败')
|
|
149
|
+
assertIncludes(v11.errors[0], '..', '错误提示包含 ..')
|
|
150
|
+
|
|
151
|
+
// 12. path 解析后超出 source_root → 失败
|
|
152
|
+
const v12 = validateParsedProjects([{ id: 'backend', path: '/etc/passwd' }], tmpDir)
|
|
153
|
+
assertEqual(v12.ok, false, '绝对路径超出 source_root 校验失败')
|
|
154
|
+
assertIncludes(v12.errors[0], '超出', '错误提示包含"超出"')
|
|
155
|
+
|
|
156
|
+
// 13. 超过 10 个项目 → 失败
|
|
157
|
+
const many = Array.from({ length: 11 }, (_, i) => ({ id: `project${i}` }))
|
|
158
|
+
const v13 = validateParsedProjects(many, tmpDir)
|
|
159
|
+
assertEqual(v13.ok, false, '超过 10 个项目校验失败')
|
|
160
|
+
assertIncludes(v13.errors[0], '超过上限', '错误提示包含"超过上限"')
|
|
161
|
+
|
|
162
|
+
// 14. 重复项目名 → 失败
|
|
163
|
+
const v14 = validateParsedProjects([{ id: 'backend' }, { id: 'frontend' }, { id: 'backend' }], tmpDir)
|
|
164
|
+
assertEqual(v14.ok, false, '重复项目名校验失败')
|
|
165
|
+
assertIncludes(v14.errors[0], '重复', '错误提示包含"重复"')
|
|
166
|
+
|
|
167
|
+
// 15. 非法 slug(中文)→ 失败
|
|
168
|
+
const v15 = validateParsedProjects([{ id: 'backend' }, { id: '前端服务' }], tmpDir)
|
|
169
|
+
assertEqual(v15.ok, false, '非法 slug 校验失败')
|
|
170
|
+
|
|
171
|
+
// 16. 空列表 → 失败
|
|
172
|
+
const v16 = validateParsedProjects([], tmpDir)
|
|
173
|
+
assertEqual(v16.ok, false, '空列表校验失败')
|
|
174
|
+
|
|
175
|
+
// 17. null 列表 → 失败
|
|
176
|
+
const v17 = validateParsedProjects(null, tmpDir)
|
|
177
|
+
assertEqual(v17.ok, false, 'null 列表校验失败')
|
|
178
|
+
|
|
179
|
+
// 18. 单字符 → 失败
|
|
180
|
+
const v18 = validateParsedProjects([{ id: 'a' }], tmpDir)
|
|
181
|
+
assertEqual(v18.ok, false, '单字符项目名校验失败')
|
|
182
|
+
|
|
183
|
+
// 19. 纯数字 → 失败
|
|
184
|
+
const v19 = validateParsedProjects([{ id: '123' }], tmpDir)
|
|
185
|
+
assertEqual(v19.ok, false, '纯数字项目名校验失败')
|
|
186
|
+
|
|
187
|
+
// 20. 兼容旧 API(纯字符串数组)
|
|
188
|
+
assertDeepEqual(
|
|
189
|
+
validateParsedProjects(['backend', 'frontend'], tmpDir),
|
|
190
|
+
{ ok: true, errors: [] },
|
|
191
|
+
'旧 API 兼容:纯字符串数组仍通过'
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
// 清理
|
|
195
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
196
|
+
|
|
197
|
+
console.log(`\n${'='.repeat(50)}`)
|
|
198
|
+
console.log(`✅ 通过: ${passed} ❌ 失败: ${failed}`)
|
|
199
|
+
console.log(`${'='.repeat(50)}`)
|
|
200
|
+
if (failed > 0) process.exit(1)
|
package/test/run-tests.mjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { readdirSync } from 'node:fs'
|
|
2
|
-
import { dirname, join } from 'node:path'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import { execFileSync } from 'node:child_process'
|
|
5
|
-
|
|
6
|
-
const testDir = dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
const files = readdirSync(testDir)
|
|
8
|
-
.filter(file => file.endsWith('.test.mjs'))
|
|
9
|
-
.sort()
|
|
10
|
-
|
|
11
|
-
if (files.length === 0) {
|
|
12
|
-
console.log('No test files found')
|
|
13
|
-
process.exit(0)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let passed = 0
|
|
17
|
-
let failed = 0
|
|
18
|
-
const failures = []
|
|
19
|
-
|
|
20
|
-
for (const file of files) {
|
|
21
|
-
const fullPath = join(testDir, file)
|
|
22
|
-
console.log(`\nRunning ${file}`)
|
|
23
|
-
try {
|
|
24
|
-
const output = execFileSync(process.execPath, [fullPath], {
|
|
25
|
-
cwd: testDir,
|
|
26
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
27
|
-
encoding: 'utf8',
|
|
28
|
-
timeout: 120_000
|
|
29
|
-
})
|
|
30
|
-
if (output) process.stdout.write(output)
|
|
31
|
-
passed++
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err.stdout) process.stdout.write(err.stdout)
|
|
34
|
-
if (err.stderr) process.stderr.write(err.stderr)
|
|
35
|
-
failed++
|
|
36
|
-
failures.push(file)
|
|
37
|
-
console.log(` ❌ ${file} exited with code ${err.status || 1}`)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log(`\n${'='.repeat(50)}`)
|
|
42
|
-
console.log(`✅ 通过: ${passed} ❌ 失败: ${failed}`)
|
|
43
|
-
if (failures.length > 0) {
|
|
44
|
-
console.log(`失败文件: ${failures.join(', ')}`)
|
|
45
|
-
}
|
|
46
|
-
console.log(`${'='.repeat(50)}`)
|
|
47
|
-
|
|
48
|
-
process.exit(failed > 0 ? 1 : 0)
|
|
1
|
+
import { readdirSync } from 'node:fs'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { execFileSync } from 'node:child_process'
|
|
5
|
+
|
|
6
|
+
const testDir = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const files = readdirSync(testDir)
|
|
8
|
+
.filter(file => file.endsWith('.test.mjs'))
|
|
9
|
+
.sort()
|
|
10
|
+
|
|
11
|
+
if (files.length === 0) {
|
|
12
|
+
console.log('No test files found')
|
|
13
|
+
process.exit(0)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let passed = 0
|
|
17
|
+
let failed = 0
|
|
18
|
+
const failures = []
|
|
19
|
+
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
const fullPath = join(testDir, file)
|
|
22
|
+
console.log(`\nRunning ${file}`)
|
|
23
|
+
try {
|
|
24
|
+
const output = execFileSync(process.execPath, [fullPath], {
|
|
25
|
+
cwd: testDir,
|
|
26
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
timeout: 120_000
|
|
29
|
+
})
|
|
30
|
+
if (output) process.stdout.write(output)
|
|
31
|
+
passed++
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err.stdout) process.stdout.write(err.stdout)
|
|
34
|
+
if (err.stderr) process.stderr.write(err.stderr)
|
|
35
|
+
failed++
|
|
36
|
+
failures.push(file)
|
|
37
|
+
console.log(` ❌ ${file} exited with code ${err.status || 1}`)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(`\n${'='.repeat(50)}`)
|
|
42
|
+
console.log(`✅ 通过: ${passed} ❌ 失败: ${failed}`)
|
|
43
|
+
if (failures.length > 0) {
|
|
44
|
+
console.log(`失败文件: ${failures.join(', ')}`)
|
|
45
|
+
}
|
|
46
|
+
console.log(`${'='.repeat(50)}`)
|
|
47
|
+
|
|
48
|
+
process.exit(failed > 0 ? 1 : 0)
|