dsh-project-flow 0.9.0 → 0.9.1
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/CHANGELOG.md +0 -0
- package/README.md +58 -11
- package/cordis.patch.yml +30 -11
- package/docs/DETAIL.md +6 -6
- package/docs/FEATURES.md +12 -5
- package/docs/LAUNCH.md +3 -3
- package/docs/MOMENTS.md +4 -4
- package/docs/USAGE.md +2 -2
- package/domains.mjs +1 -1
- package/evidence.mjs +19 -3
- package/flow.schema.mjs +192 -35
- package/gate.mjs +49 -23
- package/index.js +639 -120
- package/locale/en.json +15 -4
- package/locale/zh.json +17 -6
- package/package.json +5 -3
- package/tests/_heartbeat-regression.test.mjs +124 -0
- package/tests/_wd_sandbox/.project-flow/demo/run.log +1 -0
- package/tests/_wd_sandbox/a.txt +1 -0
- package/tests/aesthetic.test.mjs +534 -0
- package/tests/assertions-e2e.mjs +234 -0
- package/tests/bench-check.mjs +32 -0
- package/tests/client-bundle.test.mjs +707 -0
- package/tests/contract.test.mjs +137 -0
- package/tests/desktop.test.mjs +130 -0
- package/tests/domains.test.mjs +220 -0
- package/tests/e2e.mjs +300 -0
- package/tests/evidence.test.mjs +408 -0
- package/tests/extra-phase.test.mjs +133 -0
- package/tests/feedback.test.mjs +187 -0
- package/tests/flow-create.test.mjs +168 -0
- package/tests/flow-gate.test.mjs +232 -0
- package/tests/flow-schema.test.mjs +213 -0
- package/tests/gate.test.mjs +246 -0
- package/tests/issue-loop.test.mjs +254 -0
- package/tests/issues-e2e.mjs +246 -0
- package/tests/panel-independence.test.mjs +78 -0
- package/tests/panel-report.test.mjs +129 -0
- package/tests/patch-ledger.test.mjs +280 -0
- package/tests/paths.mjs +94 -0
- package/tests/preview-path.test.mjs +69 -0
- package/tests/qa-assertions.test.mjs +352 -0
- package/tests/run-all.mjs +90 -0
- package/tests/stage-model.test.mjs +120 -0
- package/tests/stop-resume.test.mjs +260 -0
- package/tests/watch-root.test.mjs +167 -0
- package/tests/watchdog-tokens.test.mjs +49 -0
- package/tests/watchdog.test.mjs +301 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 问题级闭环(T1)的单测。
|
|
3
|
+
*
|
|
4
|
+
* 盯四件事:
|
|
5
|
+
* 1. 编号是身份:跨轮沿用,不新发号
|
|
6
|
+
* 2. closed 不许复活,除非 diff 真动了同一处
|
|
7
|
+
* 3. detect / pass 缺一个,这条问题就不成立
|
|
8
|
+
* 4. 没有声明严重级的表格整张跳过,不许猜
|
|
9
|
+
*/
|
|
10
|
+
import { test } from 'node:test'
|
|
11
|
+
import assert from 'node:assert/strict'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { pathToFileURL } from 'node:url'
|
|
14
|
+
import { LIVE_DIR } from './paths.mjs'
|
|
15
|
+
|
|
16
|
+
const mod = await import(pathToFileURL(join(LIVE_DIR, 'index.js')).href + `?t=${Date.now()}`)
|
|
17
|
+
const {
|
|
18
|
+
issueKeyOf,
|
|
19
|
+
normalizeIncomingIssues,
|
|
20
|
+
parseIssueBlock,
|
|
21
|
+
mergeIssueRounds,
|
|
22
|
+
diffTouches,
|
|
23
|
+
parseIssueTables,
|
|
24
|
+
renderFixLog,
|
|
25
|
+
renderKnownIssues,
|
|
26
|
+
renderQaFrontMatter,
|
|
27
|
+
} = mod
|
|
28
|
+
|
|
29
|
+
const issue = over => ({
|
|
30
|
+
severity: 'P1',
|
|
31
|
+
location: 'src/a.ts:12',
|
|
32
|
+
claim: '空数组会抛错',
|
|
33
|
+
evidence: 'diff 第 12 行没有 length 判断',
|
|
34
|
+
detect: 'node -e "require(\'./a\')([])"',
|
|
35
|
+
pass: '返回 [] 而不是抛错',
|
|
36
|
+
...over,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const DIFF = [
|
|
40
|
+
'diff --git a/src/a.ts b/src/a.ts',
|
|
41
|
+
'--- a/src/a.ts',
|
|
42
|
+
'+++ b/src/a.ts',
|
|
43
|
+
'@@ -8,6 +8,9 @@',
|
|
44
|
+
' const x = 1',
|
|
45
|
+
'+if (list.length === 0) return []',
|
|
46
|
+
'+const y = 2',
|
|
47
|
+
' }',
|
|
48
|
+
'--- a/src/b.ts',
|
|
49
|
+
'+++ b/src/b.ts',
|
|
50
|
+
'@@ -100,3 +100,3 @@',
|
|
51
|
+
'-old',
|
|
52
|
+
'+new',
|
|
53
|
+
].join('\n')
|
|
54
|
+
|
|
55
|
+
// ── 身份 ──────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
test('同一条问题:空白、大小写、标点变了,还是同一个键', () => {
|
|
58
|
+
const a = issueKeyOf(issue({ claim: '空数组会抛错。', location: './src/a.ts:12' }))
|
|
59
|
+
const b = issueKeyOf(issue({ claim: ' 空数组会抛错 ', location: 'SRC/a.ts:12' }))
|
|
60
|
+
assert.equal(a, b)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('严重级换了不算换问题(那是同一处的同一个毛病,只是这轮判得更重)', () => {
|
|
64
|
+
assert.equal(issueKeyOf(issue({ severity: 'P0' })), issueKeyOf(issue({ severity: 'P2' })))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('位置或说法变了就是另一条', () => {
|
|
68
|
+
assert.notEqual(issueKeyOf(issue()), issueKeyOf(issue({ location: 'src/c.ts:12' })))
|
|
69
|
+
assert.notEqual(issueKeyOf(issue()), issueKeyOf(issue({ claim: '返回类型不对' })))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// ── 规整 ──────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
test('模型给的 severity 不合法时按 P1 收着,空问题直接丢掉', () => {
|
|
75
|
+
const list = normalizeIncomingIssues([
|
|
76
|
+
{ severity: 'blocker', location: 'x', claim: 'y', detect: 'd', pass: 'p' },
|
|
77
|
+
{ severity: 'P0', location: '', claim: '', detect: 'd', pass: 'p' },
|
|
78
|
+
'not an object',
|
|
79
|
+
null,
|
|
80
|
+
])
|
|
81
|
+
assert.equal(list.length, 1)
|
|
82
|
+
assert.equal(list[0].severity, 'P1')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// ── 台账写读 ──────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
test('台账写进报告前置块再读回来,八条字段一个不少', () => {
|
|
88
|
+
const issues = [
|
|
89
|
+
{ id: 'Q-001', severity: 'P0', location: 'src/a.ts:12', claim: '空数组会抛错', evidence: 'diff 12', detect: 'node -e 1', pass: '返回 []', status: 'open', roundsOpen: 1 },
|
|
90
|
+
{ id: 'Q-002', severity: 'P2', location: 'src/b.ts', claim: '命名不好', evidence: '自述', detect: '人工看', pass: '名字能读懂', status: 'closed' },
|
|
91
|
+
]
|
|
92
|
+
const block = renderQaFrontMatter({ verdict: 'FAIL', round: 1, issues, assertions: [] })
|
|
93
|
+
const back = parseIssueBlock(block)
|
|
94
|
+
assert.equal(back.length, 2)
|
|
95
|
+
for (const key of ['id', 'severity', 'location', 'claim', 'evidence', 'detect', 'pass', 'status']) {
|
|
96
|
+
assert.ok(back[0][key] !== undefined, `缺字段 ${key}`)
|
|
97
|
+
}
|
|
98
|
+
assert.equal(back[0].id, 'Q-001')
|
|
99
|
+
assert.equal(back[0].claim, '空数组会抛错')
|
|
100
|
+
assert.equal(back[0].roundsOpen, 1)
|
|
101
|
+
assert.equal(back[1].status, 'closed')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('没有 issues 的报告也能读,读出来是空表', () => {
|
|
105
|
+
assert.deepEqual(parseIssueBlock(renderQaFrontMatter({ verdict: 'PASS', round: 0, issues: [], assertions: [] })), [])
|
|
106
|
+
assert.deepEqual(parseIssueBlock(''), [])
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// ── 跨轮合并 ──────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
test('第一轮:三条新问题依次发号 Q-001 / Q-002 / Q-003', () => {
|
|
112
|
+
const ledger = mergeIssueRounds([], [
|
|
113
|
+
issue({ claim: '第一条' }),
|
|
114
|
+
issue({ claim: '第二条', location: 'src/b.ts:3' }),
|
|
115
|
+
issue({ claim: '第三条', location: 'src/c.ts:7' }),
|
|
116
|
+
], DIFF)
|
|
117
|
+
assert.deepEqual(ledger.issues.map(item => item.id), ['Q-001', 'Q-002', 'Q-003'])
|
|
118
|
+
assert.equal(ledger.openCount, 3)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('第二轮只提 Q-002 修好:它的编号不变并 closed,另外两条仍是原来的号且 open', () => {
|
|
122
|
+
const round1 = mergeIssueRounds([], [
|
|
123
|
+
issue({ claim: '第一条' }),
|
|
124
|
+
issue({ claim: '第二条', location: 'src/b.ts:3' }),
|
|
125
|
+
issue({ claim: '第三条', location: 'src/c.ts:7' }),
|
|
126
|
+
], DIFF)
|
|
127
|
+
const round2 = mergeIssueRounds(round1.issues, [
|
|
128
|
+
issue({ claim: '第二条', location: 'src/b.ts:3', resolved: true }),
|
|
129
|
+
], DIFF)
|
|
130
|
+
const byId = new Map(round2.issues.map(item => [item.id, item]))
|
|
131
|
+
assert.equal(byId.get('Q-002').status, 'closed')
|
|
132
|
+
assert.equal(byId.get('Q-001').status, 'open')
|
|
133
|
+
assert.equal(byId.get('Q-003').status, 'open')
|
|
134
|
+
assert.equal(round2.openCount, 2)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('模型没提的老问题不会自己消失(没提到不等于修好了)', () => {
|
|
138
|
+
const round1 = mergeIssueRounds([], [issue({ claim: '第一条' })], DIFF)
|
|
139
|
+
const round2 = mergeIssueRounds(round1.issues, [], DIFF)
|
|
140
|
+
assert.equal(round2.issues.length, 1)
|
|
141
|
+
assert.equal(round2.issues[0].status, 'open')
|
|
142
|
+
assert.equal(round2.issues[0].roundsOpen, 1)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test('closed 的不许复活:diff 没碰那一处时,这轮又提也不认', () => {
|
|
146
|
+
const closed = [{ ...issue({ location: 'src/z.ts:1', claim: '第一条' }), id: 'Q-001', status: 'closed' }]
|
|
147
|
+
const ledger = mergeIssueRounds(closed, [issue({ location: 'src/z.ts:1', claim: '第一条' })], DIFF)
|
|
148
|
+
assert.equal(ledger.issues.length, 0)
|
|
149
|
+
assert.equal(ledger.openCount, 0)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('closed 的复活要有条件:diff 真改了同一文件同一区段才算 reopened', () => {
|
|
153
|
+
const closed = [{ ...issue(), id: 'Q-001', status: 'closed' }]
|
|
154
|
+
const revived = mergeIssueRounds(closed, [issue()], DIFF)
|
|
155
|
+
assert.equal(revived.issues.length, 1)
|
|
156
|
+
assert.equal(revived.issues[0].status, 'reopened')
|
|
157
|
+
assert.match(revived.issues[0].note, /同一处/u)
|
|
158
|
+
|
|
159
|
+
const closedElsewhere = [{ ...issue({ location: 'src/z.ts:1' }), id: 'Q-002', status: 'closed' }]
|
|
160
|
+
const untouched = mergeIssueRounds(closedElsewhere, [issue({ location: 'src/z.ts:1' })], DIFF)
|
|
161
|
+
assert.equal(untouched.issues.length, 0)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('缺 detect 或 pass → invalid,整轮不许算过', () => {
|
|
165
|
+
const ledger = mergeIssueRounds([], [issue({ detect: '' })], DIFF)
|
|
166
|
+
assert.equal(ledger.issues[0].status, 'invalid')
|
|
167
|
+
assert.equal(ledger.invalid.length, 1)
|
|
168
|
+
const ledger2 = mergeIssueRounds([], [issue({ pass: ' ' })], DIFF)
|
|
169
|
+
assert.equal(ledger2.invalid.length, 1)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('同一条问题连着三轮没闭环会被点名(stuck)', () => {
|
|
173
|
+
let ledger = mergeIssueRounds([], [issue()], DIFF)
|
|
174
|
+
for (let round = 0; round < 3; round += 1) {
|
|
175
|
+
ledger = mergeIssueRounds(ledger.issues, [], DIFF)
|
|
176
|
+
}
|
|
177
|
+
assert.equal(ledger.issues[0].roundsOpen, 3)
|
|
178
|
+
assert.equal(ledger.stuck.length, 1)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('新问题不跟老问题抢号:接着最大号往后发', () => {
|
|
182
|
+
const previous = [
|
|
183
|
+
{ ...issue({ claim: 'a' }), id: 'Q-007', status: 'open' },
|
|
184
|
+
]
|
|
185
|
+
const ledger = mergeIssueRounds(previous, [issue({ claim: 'b', location: 'src/b.ts:1' })], DIFF)
|
|
186
|
+
assert.deepEqual(ledger.issues.map(item => item.id).sort(), ['Q-007', 'Q-008'])
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
// ── diff 命中 ─────────────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
test('diff 命中:文件对上且行号落在 hunk 里', () => {
|
|
192
|
+
assert.equal(diffTouches(DIFF, 'src/a.ts:12'), true)
|
|
193
|
+
assert.equal(diffTouches(DIFF, 'src/a.ts'), true)
|
|
194
|
+
assert.equal(diffTouches(DIFF, 'src/b.ts:101'), true)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('diff 没命中:行号在外、文件不同、没有 diff', () => {
|
|
198
|
+
assert.equal(diffTouches(DIFF, 'src/a.ts:500'), false)
|
|
199
|
+
assert.equal(diffTouches(DIFF, 'src/nope.ts:12'), false)
|
|
200
|
+
assert.equal(diffTouches('', 'src/a.ts:12'), false)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// ── 表格兜底 ──────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
test('表头声明了严重级的表才认,逐行变成问题', () => {
|
|
206
|
+
const text = [
|
|
207
|
+
'| 严重级 | 位置 | 问题 | 证据 | 检测 | 通过标准 |',
|
|
208
|
+
'| --- | --- | --- | --- | --- | --- |',
|
|
209
|
+
'| P1 | src/a.ts:12 | 空数组抛错 | diff 12 行 | node -e 1 | 返回 [] |',
|
|
210
|
+
'| P2 | src/b.ts | 命名难读 | 自述 | 人工 | 能读懂 |',
|
|
211
|
+
].join('\n')
|
|
212
|
+
const issues = parseIssueTables(text)
|
|
213
|
+
assert.equal(issues.length, 2)
|
|
214
|
+
assert.equal(issues[0].severity, 'P1')
|
|
215
|
+
assert.equal(issues[0].detect, 'node -e 1')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('没有严重级列的表整张跳过,不许凭「第二格像 P0」猜', () => {
|
|
219
|
+
const text = [
|
|
220
|
+
'| 编号 | 位置 | 问题 |',
|
|
221
|
+
'| --- | --- | --- |',
|
|
222
|
+
'| P1 | src/a.ts | 空数组抛错 |',
|
|
223
|
+
'| P0 | src/b.ts | 死循环 |',
|
|
224
|
+
].join('\n')
|
|
225
|
+
assert.deepEqual(parseIssueTables(text), [])
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
// ── 两份给人看的东西 ──────────────────────────────────────────
|
|
229
|
+
|
|
230
|
+
test('修复台账一行一条:编号 → 改了什么 → 命令 → 结果', () => {
|
|
231
|
+
const text = renderFixLog([
|
|
232
|
+
{ id: 'Q-002', change: '补了空数组判断', command: 'npm test -- a', result: '通过' },
|
|
233
|
+
{ id: 'Q-001', change: '改了类型', command: 'npx tsc --noEmit', result: '还是 2 个错' },
|
|
234
|
+
], 2)
|
|
235
|
+
assert.match(text, /^## 本轮修复(R2)/u)
|
|
236
|
+
assert.match(text, /Q-002 → 补了空数组判断 → `npm test -- a` → 通过/u)
|
|
237
|
+
assert.match(text, /Q-001 → 改了类型 → `npx tsc --noEmit` → 还是 2 个错/u)
|
|
238
|
+
assert.equal(text.split('\n').filter(line => line.startsWith('- ')).length, 2)
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('修复台账:没写命令也不编,留个空档', () => {
|
|
242
|
+
const text = renderFixLog([{ id: 'Q-003', change: '改了点东西', result: '应该好了' }], 1)
|
|
243
|
+
assert.match(text, /Q-003 → 改了点东西 → 应该好了/u)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('给质检看的上一轮台账只列还没闭环的', () => {
|
|
247
|
+
const text = renderKnownIssues([
|
|
248
|
+
{ ...issue({ claim: '还开着' }), id: 'Q-001', status: 'open' },
|
|
249
|
+
{ ...issue({ claim: '修好了' }), id: 'Q-002', status: 'closed' },
|
|
250
|
+
])
|
|
251
|
+
assert.match(text, /Q-001/u)
|
|
252
|
+
assert.equal(text.includes('Q-002'), false)
|
|
253
|
+
assert.match(text, /resolved/u)
|
|
254
|
+
})
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 问题级闭环(T1)的端到端四场戏。
|
|
3
|
+
*
|
|
4
|
+
* 三阶子会话是假的(回放固定文本),但台账是真的:报告落盘、下一轮读回来、
|
|
5
|
+
* 编号沿用、closed 不复活、连续三轮卡住就停。
|
|
6
|
+
*/
|
|
7
|
+
import { mkdtemp, mkdir, writeFile, readFile, rm } from 'node:fs/promises'
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
9
|
+
import { join, dirname } from 'node:path'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
12
|
+
|
|
13
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
const LIVE = 'C:/Users/ASUS/.dsh/profiles/desktop/node_modules/dsh-project-flow/index.js'
|
|
15
|
+
process.env.DSH_HOME = await mkdtemp(join(tmpdir(), 'pf-issues-home-'))
|
|
16
|
+
const mod = await import(pathToFileURL(LIVE).href + `?t=${Date.now()}`)
|
|
17
|
+
const { parseIssueBlock } = mod
|
|
18
|
+
|
|
19
|
+
const issue = (over = {}) => ({
|
|
20
|
+
severity: 'P1',
|
|
21
|
+
location: 'src/a.ts:1',
|
|
22
|
+
claim: '没有处理空数组',
|
|
23
|
+
evidence: 'diff 第 1 行直接 reduce',
|
|
24
|
+
detect: 'node -e "require(\'./src/a\')([])"',
|
|
25
|
+
pass: '返回 [] 而不是抛错',
|
|
26
|
+
...over,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function fakeSubagents(script) {
|
|
30
|
+
return {
|
|
31
|
+
startActivation(options) {
|
|
32
|
+
const reply = script(options)
|
|
33
|
+
return {
|
|
34
|
+
result: (async () => {
|
|
35
|
+
if (reply === undefined) return { stopReason: 'error', diagnostic: '脚本没给这一段' }
|
|
36
|
+
const text = typeof reply === 'string' ? reply : reply.text
|
|
37
|
+
if (typeof reply === 'object') await reply.before?.()
|
|
38
|
+
return { stopReason: 'completed', output: [{ type: 'text', text }] }
|
|
39
|
+
})(),
|
|
40
|
+
dispose: async () => {},
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fakeCtx(subagents) {
|
|
47
|
+
const tools = new Map()
|
|
48
|
+
const effects = []
|
|
49
|
+
return {
|
|
50
|
+
tools,
|
|
51
|
+
effects,
|
|
52
|
+
ctx: {
|
|
53
|
+
subagents,
|
|
54
|
+
tools: { register(tool) { tools.set(tool.name, tool); return () => tools.delete(tool.name) } },
|
|
55
|
+
systemPrompt: { section() { return () => {} }, getSectionOrder() { return 2800 } },
|
|
56
|
+
effect(fn) { effects.push(fn) },
|
|
57
|
+
inject(_names, fn) { fn({ get: () => undefined, effect: () => {} }) },
|
|
58
|
+
get() { return undefined },
|
|
59
|
+
on() { return () => {} },
|
|
60
|
+
logger: { info() {}, warn() {}, error() {} },
|
|
61
|
+
root: {},
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const results = []
|
|
67
|
+
const check = (label, fn) => {
|
|
68
|
+
let ok = false
|
|
69
|
+
let detail = ''
|
|
70
|
+
try {
|
|
71
|
+
const out = fn()
|
|
72
|
+
ok = out === true || (out !== null && typeof out === 'object' && out.ok === true)
|
|
73
|
+
detail = out !== null && typeof out === 'object' && typeof out.detail === 'string' ? out.detail : ''
|
|
74
|
+
} catch (error) {
|
|
75
|
+
ok = false
|
|
76
|
+
detail = error.message
|
|
77
|
+
}
|
|
78
|
+
results.push({ label, ok, detail })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const planReply = ['```json', JSON.stringify({ plan: '把 src 改对', buildTicket: '改 src/a.ts' }), '```'].join('\n')
|
|
82
|
+
|
|
83
|
+
const qaReply = issues => ['```json', JSON.stringify({
|
|
84
|
+
verdict: issues.length === 0 ? 'PASS' : 'FAIL',
|
|
85
|
+
issues,
|
|
86
|
+
reasons: issues.length === 0 ? ['核过三条要求'] : issues.map(item => item.claim),
|
|
87
|
+
acceptable_risks: [],
|
|
88
|
+
}), '```'].join('\n')
|
|
89
|
+
|
|
90
|
+
async function runOnce({ maxRework, qaFor, buildFixes = [] }) {
|
|
91
|
+
const base = join(tmpdir(), '工作流')
|
|
92
|
+
await mkdir(base, { recursive: true })
|
|
93
|
+
const dir = await mkdtemp(join(base, 'pf-issues-'))
|
|
94
|
+
await mkdir(join(dir, 'src'), { recursive: true })
|
|
95
|
+
await writeFile(join(dir, 'src/a.ts'), 'const f = (x) => x\n', 'utf8')
|
|
96
|
+
const stateDir = join(dir, '.project-flow', 'issue-demo')
|
|
97
|
+
|
|
98
|
+
let round = 0
|
|
99
|
+
const snapshots = []
|
|
100
|
+
const subagents = fakeSubagents(options => {
|
|
101
|
+
if (options.label.includes('规划')) return planReply
|
|
102
|
+
if (options.label.includes('实施')) {
|
|
103
|
+
return {
|
|
104
|
+
text: ['```json', JSON.stringify({ summary: '改了 src/a.ts', files: ['src/a.ts'], fixes: buildFixes }), '```'].join('\n'),
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (options.label.includes('质检')) {
|
|
108
|
+
round += 1
|
|
109
|
+
// 每轮质检开跑之前,把上一轮写下的报告抄一份——报告每轮覆盖写,
|
|
110
|
+
// 事后只能看到最后一版,而「修了一轮之后那一版」正是要验的东西。
|
|
111
|
+
const path = join(stateDir, 'QA_Report.md')
|
|
112
|
+
snapshots.push({ round, text: existsSync(path) ? readFileSync(path, 'utf8') : '' })
|
|
113
|
+
return qaReply(qaFor(round))
|
|
114
|
+
}
|
|
115
|
+
return undefined
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const { ctx, tools, effects } = fakeCtx(subagents)
|
|
119
|
+
mod.apply(ctx, { testCommand: '', testTimeoutMs: 60000 })
|
|
120
|
+
for (const fn of effects) fn()
|
|
121
|
+
|
|
122
|
+
const runTool = tools.get('project_run')
|
|
123
|
+
const agent = { session: { header: { cwd: dir } } }
|
|
124
|
+
const value = await runTool.execute({
|
|
125
|
+
project: 'issue-demo',
|
|
126
|
+
intent: '把 src/a.ts 改对,并且这件事要能被逐条核',
|
|
127
|
+
requirements: ['处理空数组', '保留类型', '不引入依赖'],
|
|
128
|
+
maxRework,
|
|
129
|
+
intentConfidence: 96,
|
|
130
|
+
questionsAsked: 2,
|
|
131
|
+
blindspots: {
|
|
132
|
+
permissions: '只动这个临时目录,不碰别处',
|
|
133
|
+
concurrency: '单人单次运行,不会撞车',
|
|
134
|
+
edge_cases: '任何一步失败就停下等人看',
|
|
135
|
+
stack: '纯文本改动,不加任何依赖',
|
|
136
|
+
data_flow: '读 src/a.ts 再写回去',
|
|
137
|
+
},
|
|
138
|
+
assumptions: [],
|
|
139
|
+
}, { agent, signal: undefined })
|
|
140
|
+
|
|
141
|
+
const read = async name => {
|
|
142
|
+
const path = join(stateDir, name)
|
|
143
|
+
return existsSync(path) ? readFile(path, 'utf8') : ''
|
|
144
|
+
}
|
|
145
|
+
const report = await read('QA_Report.md')
|
|
146
|
+
return {
|
|
147
|
+
dir,
|
|
148
|
+
value,
|
|
149
|
+
rounds: round,
|
|
150
|
+
snapshots,
|
|
151
|
+
report,
|
|
152
|
+
issues: parseIssueBlock(report),
|
|
153
|
+
log: await read('Execution_Log.md'),
|
|
154
|
+
state: await read('state.json'),
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ── 一:3 条要求只做 2 条 → 恰好三条问题,Q-001 / Q-002 / Q-003 ──
|
|
159
|
+
|
|
160
|
+
const threeIssues = [
|
|
161
|
+
issue({ claim: '空数组会抛错', location: 'src/a.ts:1' }),
|
|
162
|
+
issue({ claim: '类型没保留', location: 'src/a.ts:2', severity: 'P0' }),
|
|
163
|
+
issue({ claim: '多了个依赖', location: 'package.json:3', severity: 'P2' }),
|
|
164
|
+
]
|
|
165
|
+
const runOne = await runOnce({ maxRework: 0, qaFor: () => threeIssues })
|
|
166
|
+
check('一:一轮就产出恰好三条问题,编号 Q-001 到 Q-003', () => ({
|
|
167
|
+
ok: runOne.issues.length === 3
|
|
168
|
+
&& runOne.issues.map(item => item.id).join(',') === 'Q-001,Q-002,Q-003',
|
|
169
|
+
detail: JSON.stringify(runOne.issues.map(item => `${item.id}:${item.status}`)),
|
|
170
|
+
}))
|
|
171
|
+
check('一:三条都带 detect 和 pass(不然它们本来就该判 invalid)', () =>
|
|
172
|
+
runOne.issues.every(item => item.detect !== '' && item.pass !== ''))
|
|
173
|
+
check('一:没闭环就不许算过,返工上限 0 时直接停在没闭环', () => ({
|
|
174
|
+
ok: runOne.value.outcome !== 'passed' && /没闭环/u.test(runOne.value.verdict),
|
|
175
|
+
detail: `${runOne.value.outcome}|${runOne.value.verdict}`,
|
|
176
|
+
}))
|
|
177
|
+
|
|
178
|
+
// ── 二:只修 Q-002 → 它 closed,另外两条编号不变仍 open;三轮后停机 ──
|
|
179
|
+
|
|
180
|
+
const runTwo = await runOnce({
|
|
181
|
+
maxRework: 5,
|
|
182
|
+
qaFor: round => {
|
|
183
|
+
if (round === 1) return threeIssues
|
|
184
|
+
if (round === 2) return [issue({ claim: '类型没保留', location: 'src/a.ts:2', severity: 'P0', resolved: true })]
|
|
185
|
+
return []
|
|
186
|
+
},
|
|
187
|
+
buildFixes: [{ id: 'Q-002', change: '补了类型注解', command: 'npx tsc --noEmit', result: '通过' }],
|
|
188
|
+
})
|
|
189
|
+
// 「只修 Q-002 再跑一轮」之后那一版报告:是第 2 轮写下的、第 3 轮开跑前抄到的那份。
|
|
190
|
+
const afterRound2 = parseIssueBlock(runTwo.snapshots.find(item => item.round === 3)?.text ?? '')
|
|
191
|
+
check('二:只修一轮之后的那版报告里,Q-002 是 closed,Q-001 / Q-003 仍是原编号 open', () => {
|
|
192
|
+
const byId = new Map(afterRound2.map(item => [item.id, item]))
|
|
193
|
+
return {
|
|
194
|
+
ok: byId.get('Q-002')?.status === 'closed'
|
|
195
|
+
&& byId.get('Q-001')?.status === 'open'
|
|
196
|
+
&& byId.get('Q-003')?.status === 'open',
|
|
197
|
+
detail: afterRound2.map(item => `${item.id}:${item.status}`).join(','),
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
check('二:修好的那条不再参与返工判据(report 里剩下的 open 只有两条)', () => ({
|
|
201
|
+
ok: runTwo.issues.filter(item => item.status === 'open').length === 2,
|
|
202
|
+
detail: runTwo.issues.map(item => `${item.id}:${item.status}`).join(','),
|
|
203
|
+
}))
|
|
204
|
+
check('二:连续三轮不闭环 → 停机,判词点名卡在哪几条', () => ({
|
|
205
|
+
ok: runTwo.value.outcome === 'stopped' && /连续 3 轮没闭环/u.test(runTwo.value.verdict),
|
|
206
|
+
detail: `${runTwo.value.outcome}|${runTwo.value.verdict}`,
|
|
207
|
+
}))
|
|
208
|
+
check('二:停机说明里写得出编号(不是「有一些问题」)', () =>
|
|
209
|
+
/Q-001/u.test(runTwo.value.note) || /Q-003/u.test(runTwo.value.note))
|
|
210
|
+
check('二:Execution_Log.md 里有「本轮修复」,一行一条', () => ({
|
|
211
|
+
ok: /## 本轮修复/u.test(runTwo.log) && /Q-002 → 补了类型注解/u.test(runTwo.log),
|
|
212
|
+
detail: runTwo.log.split('\n').filter(line => line.includes('本轮修复')).join(''),
|
|
213
|
+
}))
|
|
214
|
+
check('二:台账里记着连续几轮没闭环', () => ({
|
|
215
|
+
ok: runTwo.issues.some(item => typeof item.roundsOpen === 'number' && item.roundsOpen >= 3),
|
|
216
|
+
detail: runTwo.issues.map(item => `${item.id}:${item.roundsOpen ?? 0}`).join(','),
|
|
217
|
+
}))
|
|
218
|
+
|
|
219
|
+
// ── 三:少写 detect → 判「问题缺少可执行定义」,整轮 FAIL,不返工 ──
|
|
220
|
+
|
|
221
|
+
const runThree = await runOnce({
|
|
222
|
+
maxRework: 3,
|
|
223
|
+
qaFor: () => [issue({ claim: '说不太清楚哪里不对', detect: '' })],
|
|
224
|
+
})
|
|
225
|
+
check('三:缺 detect 的问题 → 停机,判词是「问题缺少可执行定义」', () => ({
|
|
226
|
+
ok: runThree.value.outcome === 'blocked' && /问题缺少可执行定义/u.test(runThree.value.verdict),
|
|
227
|
+
detail: `${runThree.value.outcome}|${runThree.value.verdict}`,
|
|
228
|
+
}))
|
|
229
|
+
check('三:这一轮不返工(只跑了一次质检)', () => runThree.rounds === 1)
|
|
230
|
+
check('三:报告里那条问题的状态是 invalid', () => ({
|
|
231
|
+
ok: runThree.issues[0]?.status === 'invalid',
|
|
232
|
+
detail: JSON.stringify(runThree.issues.map(item => `${item.id}:${item.status}`)),
|
|
233
|
+
}))
|
|
234
|
+
|
|
235
|
+
// ── 收尾 ──────────────────────────────────────────────────────
|
|
236
|
+
|
|
237
|
+
let failed = 0
|
|
238
|
+
for (const item of results) {
|
|
239
|
+
console.log(`${item.ok ? '✔' : '✖'} ${item.label}${item.ok || item.detail === '' ? '' : `\n → ${item.detail}`}`)
|
|
240
|
+
if (!item.ok) failed += 1
|
|
241
|
+
}
|
|
242
|
+
console.log(`\n${results.length - failed}/${results.length} 通过`)
|
|
243
|
+
for (const dir of [runOne.dir, runTwo.dir, runThree.dir]) {
|
|
244
|
+
await rm(dir, { recursive: true, force: true }).catch(() => {})
|
|
245
|
+
}
|
|
246
|
+
process.exit(failed === 0 ? 0 : 1)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 状态栏独立性。
|
|
3
|
+
*
|
|
4
|
+
* 用户报的原话:「所有的工作区对话像是共用着这一个状态栏」。
|
|
5
|
+
*
|
|
6
|
+
* 根因是两处叠加:
|
|
7
|
+
* 1. `mine` 只在这一轮正在跑时为真,跑完就假了;
|
|
8
|
+
* 2. 客户端拿 `panel.projects[0]` 兜底——全表第一个项目。
|
|
9
|
+
* 于是每个对话看到的都是同一个。
|
|
10
|
+
*
|
|
11
|
+
* 这一套只做一件事:把这条退路盯死。它是最容易被后人「顺手加回来」的那种补丁,
|
|
12
|
+
* 因为加回一行代码就能让空态变得「好看」,代价是所有人又共用了。
|
|
13
|
+
*/
|
|
14
|
+
import { test } from 'node:test'
|
|
15
|
+
import assert from 'node:assert/strict'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
import { readFile } from 'node:fs/promises'
|
|
18
|
+
import { LIVE_DIR } from './paths.mjs'
|
|
19
|
+
|
|
20
|
+
const host = await readFile(join(LIVE_DIR, 'index.js'), 'utf8')
|
|
21
|
+
const client = await readFile(join(LIVE_DIR, 'client.js'), 'utf8')
|
|
22
|
+
|
|
23
|
+
test('target 的四档:自己的在跑的 → 自己碰过的 → 当前目录 → 归属未知的老项目', () => {
|
|
24
|
+
assert.ok(client.includes('const target = mine ?? owned[0] ?? focused ?? legacy[0]'),
|
|
25
|
+
'target 应该是这四档;明确不归我的(owned === false)永远不该被顶上来')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('「归属未知」和「不归我」是两件事', () => {
|
|
29
|
+
assert.ok(client.includes('const legacy = panel.projects.filter(project => project.owned !== true && project.owned !== false)'),
|
|
30
|
+
'老项目是「不知道归谁」,不能跟「明确不是我的」混成一个桶')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('owned 按最近更新排序,不是拿到哪个算哪个', () => {
|
|
34
|
+
assert.ok(client.includes('project.owned === true'), '要按 owned 过滤')
|
|
35
|
+
assert.ok(client.includes('localeCompare(String(left.updatedAt'),
|
|
36
|
+
'同一个对话开过多个项目时,要显示最近更新的那个')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('宿主把 ownerSessions 落盘,不是只留在内存里', () => {
|
|
40
|
+
assert.ok(host.includes('ownerSessions'), '要落盘')
|
|
41
|
+
assert.ok(host.includes('panelSessionId'), '要拿到当前会话 id')
|
|
42
|
+
assert.ok(
|
|
43
|
+
host.includes('await writeState(cwd, project, { ownerSessions'),
|
|
44
|
+
'写进 state.json——只放 panelStops 里的话,跑完就没了',
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('ownerSessions 只留最近 8 个,不无限长', () => {
|
|
49
|
+
assert.ok(host.includes('.slice(-8)'), '长年累月跑下去,这个数组不能一直涨')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('面板数据带 owned 字段', () => {
|
|
53
|
+
assert.ok(host.includes('owned: sessionId !== undefined'), 'owned 要按会话算')
|
|
54
|
+
assert.ok(host.includes('state.ownerSessions.includes(sessionId)'), '认的是数组里有没有这个会话')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('老项目归属未知,不能一刀切成「不是我的」', () => {
|
|
58
|
+
assert.ok(
|
|
59
|
+
host.includes(': null,'),
|
|
60
|
+
'没有 ownerSessions 的老项目要输出 null,不能输出 false——否则升级当天历史项目全消失',
|
|
61
|
+
)
|
|
62
|
+
assert.ok(client.includes('project.owned !== true && project.owned !== false'),
|
|
63
|
+
'客户端要单独把「归属未知」挑出来')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('没有自己的项目时显示空态,不借别人的结论', () => {
|
|
67
|
+
assert.ok(
|
|
68
|
+
client.includes("const verdict = target === undefined ? '' : verdictOf([target])"),
|
|
69
|
+
'以前是 verdictOf(panel.projects)——target 为空时拿全表算,还是别人的数据',
|
|
70
|
+
)
|
|
71
|
+
assert.ok(client.includes('这个对话还没开工'), '空态要有明确说法')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('停止按钮:自己 → 自己碰过在跑的 → 归属未知在跑的', () => {
|
|
75
|
+
assert.ok(client.includes('const stoppable = mine'), '第一档是自己正在跑的那个')
|
|
76
|
+
assert.ok(client.includes('?? owned.find(project => project.running === true)'), '第二档是自己碰过且在跑的')
|
|
77
|
+
assert.ok(client.includes('?? legacy.find(project => project.running === true)'), '第三档才轮到归属未知的')
|
|
78
|
+
})
|