dsh-progress-union 0.5.1 → 0.5.2

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.
@@ -1,251 +1,251 @@
1
- /**
2
- * Phase 1 验收:board 增量协议 + ack 语义(fork 自 dsh-progress-board 的协议断言)。
3
- */
4
- import assert from 'node:assert/strict'
5
- import fs from 'node:fs'
6
- import os from 'node:os'
7
- import path from 'node:path'
8
- import test from 'node:test'
9
-
10
- // 先钉住 DSH_HOME 再动态引入(index.js 模块求值时即读环境变量),避免测试碰真机 stats。
11
- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
- const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
13
-
14
- async function booted(config) {
15
- const harness = createHarness({ config })
16
- await harness.run()
17
- // 启用板(走 active 路由的 command 源,等价 /progress on)
18
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
19
- return harness
20
- }
21
-
22
- function execUpdate(harness, args) {
23
- const tool = harness.toolMap.get('progress_update')
24
- return tool.definition.execute(args, { agent: harness.agent })
25
- }
26
-
27
- test('when 门控:默认不加载工具,启用后可见', async () => {
28
- const harness = createHarness()
29
- await harness.run()
30
- const tool = harness.toolMap.get('progress_update')
31
- assert.equal(tool.options.when({ agent: harness.agent }), false, '未启用时 when 必须为 false')
32
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
33
- assert.equal(tool.options.when({ agent: harness.agent }), true)
34
- })
35
-
36
- test('新增/按 id 更新/删除:只回变化项与紧凑摘要', async () => {
37
- const harness = await booted()
38
- const added = await execUpdate(harness, {
39
- changes: [
40
- { title: '步骤一', status: 'doing', current: '正在做一', next: '二' },
41
- { title: '步骤二' },
42
- ],
43
- })
44
- assert.equal(added.ok, true)
45
- assert.equal(added.revision, 1)
46
- assert.equal(added.changed.length, 2)
47
- assert.deepEqual(added.summary, { total: 2, done: 0, doing: 1, todo: 1, blocked: 0, percent: 0 })
48
-
49
- const firstId = added.changed[0].id
50
- const edited = await execUpdate(harness, { changes: [{ id: firstId, status: 'done' }] })
51
- assert.equal(edited.revision, 2)
52
- assert.deepEqual(edited.changed[0].fields.sort(), ['percent', 'status'])
53
- assert.equal(edited.summary.done, 1)
54
- // done 强制 100%
55
- assert.equal(edited.summary.percent, 50)
56
-
57
- const removed = await execUpdate(harness, { changes: [{ id: firstId, remove: true }] })
58
- assert.equal(removed.changed[0].removed, true)
59
- assert.equal(removed.summary.total, 1)
60
- })
61
-
62
- test('按精确 title 更新;单命中正常、新增不误伤', async () => {
63
- const harness = await booted()
64
- await execUpdate(harness, { changes: [{ title: '唯一名' }] })
65
- const byTitle = await execUpdate(harness, { changes: [{ title: '唯一名', status: 'doing' }] })
66
- assert.equal(byTitle.changed[0].change, 'edit')
67
- const added = await execUpdate(harness, { changes: [{ title: '不存在的名' }] })
68
- assert.equal(added.changed[0].change, 'add')
69
- })
70
-
71
- test('历史重名数据歧义:按 title 更新报错要求 id', async () => {
72
- const mkItem = (id, order) => ({
73
- id, title: '重名', status: 'todo', percent: 0, current: '', next: '', approach: '', note: '',
74
- group: '', order, updatedAt: 1, updatedBy: 'user',
75
- })
76
- const key = Buffer.from(SESSION, 'utf8').toString('base64url')
77
- const harness = createHarness({
78
- seed: {
79
- [key]: {
80
- record: {
81
- version: 1, sessionId: SESSION, revision: 3, userRevision: 0, agentSeenRevision: 0,
82
- enabled: true, createdAt: 1, updatedAt: 1, items: [mkItem('p_a', 0), mkItem('p_b', 1)], userChanges: [],
83
- },
84
- },
85
- },
86
- })
87
- await harness.run()
88
- await assert.rejects(
89
- () => execUpdate(harness, { changes: [{ title: '重名', status: 'done' }] }),
90
- /对应多个任务/,
91
- )
92
- })
93
-
94
- test('批量全成全败:坏条目不得让前半批落盘', async () => {
95
- // 注意「全成全败」只针对**真语义错误**(remove 找不到目标、新增缺 title、percent
96
- // 非数字、歧义 title)。status 词表错已改为宽容跳过 + warnings(见下个用例)——
97
- // 那些是 PTC 通道绕过 schema 导致的输入噪声,不该让整批丢失。
98
- const harness = await booted()
99
- const before = await execUpdate(harness, { changes: [{ title: '已有任务' }] })
100
- await assert.rejects(
101
- () => execUpdate(harness, { changes: [{ title: '新增成功' }, { id: 'p_不存在', remove: true }] }),
102
- /找不到要删除的任务/,
103
- )
104
- const snapshot = harness.provided.get('progressAnchor').get(SESSION)
105
- assert.equal(snapshot.revision, before.revision, '失败批次不得推 revision')
106
- assert.equal(snapshot.board.summary.total, 1, '失败批次不得留下半应用条目')
107
- })
108
-
109
- test('PTC 容错:官方 todo 词表别名归一,不再整批抛错', async () => {
110
- const harness = await booted()
111
- // PTC 通道(run_code 内 tools.progress_update)绕过工具 JSON Schema,
112
- // 模型按官方 todo 词表传 pending / in_progress / completed。
113
- const added = await execUpdate(harness, {
114
- changes: [
115
- { title: '待办项', status: 'pending' },
116
- { title: '进行项', status: 'in_progress' },
117
- { title: '完成项', status: 'completed' },
118
- ],
119
- })
120
- assert.equal(added.ok, true, 'pending 不得再抛「未知状态」')
121
- assert.deepEqual(added.warnings, [], '合法别名不产生 warning')
122
- assert.deepEqual(added.summary, { total: 3, done: 1, doing: 1, todo: 1, blocked: 0, percent: 33 })
123
- })
124
-
125
- test('PTC 容错:无法识别的 status 跳过该字段并回 warning,同批其它条目照落', async () => {
126
- const harness = await booted()
127
- const added = await execUpdate(harness, {
128
- changes: [
129
- { title: '好条目', status: 'doing' },
130
- { title: '坏状态条目', status: '半吊子' },
131
- ],
132
- })
133
- assert.equal(added.ok, true, '坏词表不得让整批失败')
134
- assert.equal(added.warnings.length, 1)
135
- assert.match(added.warnings[0], /半吊子/)
136
- assert.match(added.warnings[0], /todo\|doing\|done\|blocked/)
137
- // 坏状态条目仍然建成功,只保留默认 status=todo
138
- const snap = harness.provided.get('progressAnchor').get(SESSION)
139
- assert.equal(snap.board.summary.total, 2)
140
- assert.equal(snap.board.summary.doing, 1)
141
- assert.equal(snap.board.summary.todo, 1)
142
- })
143
-
144
- test('409:expectedRevision 过期拒写并回快照', async () => {
145
- const harness = await booted()
146
- await execUpdate(harness, { changes: [{ title: 'A' }] })
147
- const res = await callRoute(
148
- harness,
149
- '/progress-union/action',
150
- jsonReq('POST', '/progress-union/action', { sessionId: SESSION, expectedRevision: 0, changes: [{ title: 'B' }] }),
151
- )
152
- assert.equal(res.status, 409)
153
- assert.match(res.json().error, /已被更新/)
154
- })
155
-
156
- test('ack 语义:用户改动未确认时 pending>0,ackUserRevision 后归零', async () => {
157
- const harness = await booted()
158
- const added = await execUpdate(harness, { changes: [{ title: '任务一' }] })
159
- const itemId = added.changed[0].id
160
-
161
- // 用户在面板改状态(origin=user 走 action 路由)
162
- const userRes = await callRoute(
163
- harness,
164
- '/progress-union/action',
165
- jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, status: 'blocked', note: '在等确认' }] }),
166
- )
167
- assert.equal(userRes.status, 200)
168
- const anchorAfterUserEdit = harness.provided.get('progressAnchor').get(SESSION)
169
- assert.equal(anchorAfterUserEdit.board.pendingUserChanges, 1)
170
- assert.equal(anchorAfterUserEdit.userEdits.length, 1)
171
- assert.equal(anchorAfterUserEdit.userEdits[0].kind, 'edit')
172
-
173
- // 注入面出现"用户改动"文本,且带 ackUserRevision 指引
174
- const userEditsText = harness.contexts.get('progress-union-user-edits')()
175
- assert.match(userEditsText, /progress-board-user-edits/)
176
- assert.match(userEditsText, new RegExp(`ackUserRevision=${anchorAfterUserEdit.revision}`))
177
-
178
- // agent 确认(changes=[] + ack),revision 不再增长
179
- const acked = await execUpdate(harness, { changes: [], ackUserRevision: anchorAfterUserEdit.revision })
180
- assert.equal(acked.revision, anchorAfterUserEdit.revision)
181
- const anchorAfterAck = harness.provided.get('progressAnchor').get(SESSION)
182
- assert.equal(anchorAfterAck.board.pendingUserChanges, 0)
183
- assert.equal(anchorAfterAck.userEdits.length, 0)
184
- assert.equal(harness.contexts.get('progress-union-user-edits')(), '')
185
- })
186
-
187
- test('ack 越界钳制:ackUserRevision 超过 userRevision 时被钳到 userRevision', async () => {
188
- const harness = await booted()
189
- const added = await execUpdate(harness, { changes: [{ title: '任务一' }] })
190
- const itemId = added.changed[0].id
191
- await callRoute(
192
- harness,
193
- '/progress-union/action',
194
- jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: 'x' }] }),
195
- )
196
- await execUpdate(harness, { changes: [], ackUserRevision: 999 })
197
- const anchor = harness.provided.get('progressAnchor').get(SESSION)
198
- assert.equal(anchor.board.pendingUserChanges, 0)
199
- })
200
-
201
- test('面板卸载不关掉工具;/progress off(command 源)才关', async () => {
202
- const harness = await booted()
203
- // panel 源的 active=false:不是用户决定,必须忽略
204
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: false, source: 'panel' }))
205
- assert.equal(harness.toolMap.get('progress_update').options.when({ agent: harness.agent }), true)
206
- // command 源的 off:真关
207
- const cmd = harness.commandMap.get('progress')
208
- cmd.handler({ agent: harness.agent, rawInput: 'off' })
209
- await flush()
210
- assert.equal(harness.toolMap.get('progress_update').options.when({ agent: harness.agent }), false)
211
- // 关板后三块投影全部静默(0 token 回归)
212
- assert.equal(harness.sections.get('progress-union-policy')(), '')
213
- assert.equal(harness.contexts.get('progress-union-kickoff')(), '')
214
- assert.equal(harness.contexts.get('progress-union-user-edits')(), '')
215
- })
216
-
217
- test('PTC 内层工具进观察块:ptc-dispatch 不再只剩 run_code', async () => {
218
- const harness = await booted()
219
- await execUpdate(harness, { changes: [{ title: '做点事', status: 'doing' }] })
220
- // 外层只有 run_code(PTC 特征)
221
- harness.emit('tool/call', { name: 'run_code', arguments: '{"code":"tools.shell(1)"}' })
222
- // 内层真实工具在 ptc-dispatch 的终态事件上
223
- harness.emit('tool/ptc-dispatch', { name: 'shell', arguments: '{"command":"ls"}', isError: false })
224
- harness.emit('tool/ptc-dispatch', { name: 'read', arguments: '{"file_path":"a.js"}', isError: false })
225
- // dispatch-start 是起始事件,必须被忽略(否则同一条会记两次)
226
- harness.emit('tool/ptc-dispatch-start', { name: 'shell', arguments: '{"command":"ls"}' })
227
- const text = harness.contexts.get('progress-union-observer')()
228
- assert.match(text, /最近动作:.*shell/, 'PTC 内层 tool 必须出现在最近动作里')
229
- assert.match(text, /read/, '第二条内层 tool 也要在')
230
- })
231
-
232
- test('PTC 内层工具失败:观察块给出最近失败行', async () => {
233
- const harness = await booted()
234
- await execUpdate(harness, { changes: [{ title: '做点事', status: 'doing' }] })
235
- harness.emit('tool/ptc-dispatch', {
236
- name: 'glob',
237
- arguments: '{"pattern":"**/*"}',
238
- isError: true,
239
- content: [{ type: 'text', text: 'Error: tool call timed out after 30000ms' }],
240
- })
241
- const text = harness.contexts.get('progress-union-observer')()
242
- assert.match(text, /最近失败:glob/)
243
- assert.match(text, /timed out/)
244
- })
245
-
246
- test('旧前缀别名 /progress-board/* 仍可用一版', async () => {
247
- const harness = await booted()
248
- const res = await callRoute(harness, '/progress-board/snapshot', { method: 'GET', url: `/progress-board/snapshot?sessionId=${SESSION}`, headers: {} })
249
- assert.equal(res.status, 200)
250
- assert.equal(res.json().enabled, true)
251
- })
1
+ /**
2
+ * Phase 1 验收:board 增量协议 + ack 语义(fork 自 dsh-progress-board 的协议断言)。
3
+ */
4
+ import assert from 'node:assert/strict'
5
+ import fs from 'node:fs'
6
+ import os from 'node:os'
7
+ import path from 'node:path'
8
+ import test from 'node:test'
9
+
10
+ // 先钉住 DSH_HOME 再动态引入(index.js 模块求值时即读环境变量),避免测试碰真机 stats。
11
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
+ const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
13
+
14
+ async function booted(config) {
15
+ const harness = createHarness({ config })
16
+ await harness.run()
17
+ // 启用板(走 active 路由的 command 源,等价 /progress on)
18
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
19
+ return harness
20
+ }
21
+
22
+ function execUpdate(harness, args) {
23
+ const tool = harness.toolMap.get('progress_update')
24
+ return tool.definition.execute(args, { agent: harness.agent })
25
+ }
26
+
27
+ test('when 门控:默认不加载工具,启用后可见', async () => {
28
+ const harness = createHarness()
29
+ await harness.run()
30
+ const tool = harness.toolMap.get('progress_update')
31
+ assert.equal(tool.options.when({ agent: harness.agent }), false, '未启用时 when 必须为 false')
32
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
33
+ assert.equal(tool.options.when({ agent: harness.agent }), true)
34
+ })
35
+
36
+ test('新增/按 id 更新/删除:只回变化项与紧凑摘要', async () => {
37
+ const harness = await booted()
38
+ const added = await execUpdate(harness, {
39
+ changes: [
40
+ { title: '步骤一', status: 'doing', current: '正在做一', next: '二' },
41
+ { title: '步骤二' },
42
+ ],
43
+ })
44
+ assert.equal(added.ok, true)
45
+ assert.equal(added.revision, 1)
46
+ assert.equal(added.changed.length, 2)
47
+ assert.deepEqual(added.summary, { total: 2, done: 0, doing: 1, todo: 1, blocked: 0, percent: 0 })
48
+
49
+ const firstId = added.changed[0].id
50
+ const edited = await execUpdate(harness, { changes: [{ id: firstId, status: 'done' }] })
51
+ assert.equal(edited.revision, 2)
52
+ assert.deepEqual(edited.changed[0].fields.sort(), ['percent', 'status'])
53
+ assert.equal(edited.summary.done, 1)
54
+ // done 强制 100%
55
+ assert.equal(edited.summary.percent, 50)
56
+
57
+ const removed = await execUpdate(harness, { changes: [{ id: firstId, remove: true }] })
58
+ assert.equal(removed.changed[0].removed, true)
59
+ assert.equal(removed.summary.total, 1)
60
+ })
61
+
62
+ test('按精确 title 更新;单命中正常、新增不误伤', async () => {
63
+ const harness = await booted()
64
+ await execUpdate(harness, { changes: [{ title: '唯一名' }] })
65
+ const byTitle = await execUpdate(harness, { changes: [{ title: '唯一名', status: 'doing' }] })
66
+ assert.equal(byTitle.changed[0].change, 'edit')
67
+ const added = await execUpdate(harness, { changes: [{ title: '不存在的名' }] })
68
+ assert.equal(added.changed[0].change, 'add')
69
+ })
70
+
71
+ test('历史重名数据歧义:按 title 更新报错要求 id', async () => {
72
+ const mkItem = (id, order) => ({
73
+ id, title: '重名', status: 'todo', percent: 0, current: '', next: '', approach: '', note: '',
74
+ group: '', order, updatedAt: 1, updatedBy: 'user',
75
+ })
76
+ const key = Buffer.from(SESSION, 'utf8').toString('base64url')
77
+ const harness = createHarness({
78
+ seed: {
79
+ [key]: {
80
+ record: {
81
+ version: 1, sessionId: SESSION, revision: 3, userRevision: 0, agentSeenRevision: 0,
82
+ enabled: true, createdAt: 1, updatedAt: 1, items: [mkItem('p_a', 0), mkItem('p_b', 1)], userChanges: [],
83
+ },
84
+ },
85
+ },
86
+ })
87
+ await harness.run()
88
+ await assert.rejects(
89
+ () => execUpdate(harness, { changes: [{ title: '重名', status: 'done' }] }),
90
+ /对应多个任务/,
91
+ )
92
+ })
93
+
94
+ test('批量全成全败:坏条目不得让前半批落盘', async () => {
95
+ // 注意「全成全败」只针对**真语义错误**(remove 找不到目标、新增缺 title、percent
96
+ // 非数字、歧义 title)。status 词表错已改为宽容跳过 + warnings(见下个用例)——
97
+ // 那些是 PTC 通道绕过 schema 导致的输入噪声,不该让整批丢失。
98
+ const harness = await booted()
99
+ const before = await execUpdate(harness, { changes: [{ title: '已有任务' }] })
100
+ await assert.rejects(
101
+ () => execUpdate(harness, { changes: [{ title: '新增成功' }, { id: 'p_不存在', remove: true }] }),
102
+ /找不到要删除的任务/,
103
+ )
104
+ const snapshot = harness.provided.get('progressAnchor').get(SESSION)
105
+ assert.equal(snapshot.revision, before.revision, '失败批次不得推 revision')
106
+ assert.equal(snapshot.board.summary.total, 1, '失败批次不得留下半应用条目')
107
+ })
108
+
109
+ test('PTC 容错:官方 todo 词表别名归一,不再整批抛错', async () => {
110
+ const harness = await booted()
111
+ // PTC 通道(run_code 内 tools.progress_update)绕过工具 JSON Schema,
112
+ // 模型按官方 todo 词表传 pending / in_progress / completed。
113
+ const added = await execUpdate(harness, {
114
+ changes: [
115
+ { title: '待办项', status: 'pending' },
116
+ { title: '进行项', status: 'in_progress' },
117
+ { title: '完成项', status: 'completed' },
118
+ ],
119
+ })
120
+ assert.equal(added.ok, true, 'pending 不得再抛「未知状态」')
121
+ assert.deepEqual(added.warnings, [], '合法别名不产生 warning')
122
+ assert.deepEqual(added.summary, { total: 3, done: 1, doing: 1, todo: 1, blocked: 0, percent: 33 })
123
+ })
124
+
125
+ test('PTC 容错:无法识别的 status 跳过该字段并回 warning,同批其它条目照落', async () => {
126
+ const harness = await booted()
127
+ const added = await execUpdate(harness, {
128
+ changes: [
129
+ { title: '好条目', status: 'doing' },
130
+ { title: '坏状态条目', status: '半吊子' },
131
+ ],
132
+ })
133
+ assert.equal(added.ok, true, '坏词表不得让整批失败')
134
+ assert.equal(added.warnings.length, 1)
135
+ assert.match(added.warnings[0], /半吊子/)
136
+ assert.match(added.warnings[0], /todo\|doing\|done\|blocked/)
137
+ // 坏状态条目仍然建成功,只保留默认 status=todo
138
+ const snap = harness.provided.get('progressAnchor').get(SESSION)
139
+ assert.equal(snap.board.summary.total, 2)
140
+ assert.equal(snap.board.summary.doing, 1)
141
+ assert.equal(snap.board.summary.todo, 1)
142
+ })
143
+
144
+ test('409:expectedRevision 过期拒写并回快照', async () => {
145
+ const harness = await booted()
146
+ await execUpdate(harness, { changes: [{ title: 'A' }] })
147
+ const res = await callRoute(
148
+ harness,
149
+ '/progress-union/action',
150
+ jsonReq('POST', '/progress-union/action', { sessionId: SESSION, expectedRevision: 0, changes: [{ title: 'B' }] }),
151
+ )
152
+ assert.equal(res.status, 409)
153
+ assert.match(res.json().error, /已被更新/)
154
+ })
155
+
156
+ test('ack 语义:用户改动未确认时 pending>0,ackUserRevision 后归零', async () => {
157
+ const harness = await booted()
158
+ const added = await execUpdate(harness, { changes: [{ title: '任务一' }] })
159
+ const itemId = added.changed[0].id
160
+
161
+ // 用户在面板改状态(origin=user 走 action 路由)
162
+ const userRes = await callRoute(
163
+ harness,
164
+ '/progress-union/action',
165
+ jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, status: 'blocked', note: '在等确认' }] }),
166
+ )
167
+ assert.equal(userRes.status, 200)
168
+ const anchorAfterUserEdit = harness.provided.get('progressAnchor').get(SESSION)
169
+ assert.equal(anchorAfterUserEdit.board.pendingUserChanges, 1)
170
+ assert.equal(anchorAfterUserEdit.userEdits.length, 1)
171
+ assert.equal(anchorAfterUserEdit.userEdits[0].kind, 'edit')
172
+
173
+ // 注入面出现"用户改动"文本,且带 ackUserRevision 指引
174
+ const userEditsText = harness.contexts.get('progress-union-user-edits')()
175
+ assert.match(userEditsText, /progress-board-user-edits/)
176
+ assert.match(userEditsText, new RegExp(`ackUserRevision=${anchorAfterUserEdit.revision}`))
177
+
178
+ // agent 确认(changes=[] + ack),revision 不再增长
179
+ const acked = await execUpdate(harness, { changes: [], ackUserRevision: anchorAfterUserEdit.revision })
180
+ assert.equal(acked.revision, anchorAfterUserEdit.revision)
181
+ const anchorAfterAck = harness.provided.get('progressAnchor').get(SESSION)
182
+ assert.equal(anchorAfterAck.board.pendingUserChanges, 0)
183
+ assert.equal(anchorAfterAck.userEdits.length, 0)
184
+ assert.equal(harness.contexts.get('progress-union-user-edits')(), '')
185
+ })
186
+
187
+ test('ack 越界钳制:ackUserRevision 超过 userRevision 时被钳到 userRevision', async () => {
188
+ const harness = await booted()
189
+ const added = await execUpdate(harness, { changes: [{ title: '任务一' }] })
190
+ const itemId = added.changed[0].id
191
+ await callRoute(
192
+ harness,
193
+ '/progress-union/action',
194
+ jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: 'x' }] }),
195
+ )
196
+ await execUpdate(harness, { changes: [], ackUserRevision: 999 })
197
+ const anchor = harness.provided.get('progressAnchor').get(SESSION)
198
+ assert.equal(anchor.board.pendingUserChanges, 0)
199
+ })
200
+
201
+ test('面板卸载不关掉工具;/progress off(command 源)才关', async () => {
202
+ const harness = await booted()
203
+ // panel 源的 active=false:不是用户决定,必须忽略
204
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: false, source: 'panel' }))
205
+ assert.equal(harness.toolMap.get('progress_update').options.when({ agent: harness.agent }), true)
206
+ // command 源的 off:真关
207
+ const cmd = harness.commandMap.get('progress')
208
+ cmd.handler({ agent: harness.agent, rawInput: 'off' })
209
+ await flush()
210
+ assert.equal(harness.toolMap.get('progress_update').options.when({ agent: harness.agent }), false)
211
+ // 关板后三块投影全部静默(0 token 回归)
212
+ assert.equal(harness.sections.get('progress-union-policy')(), '')
213
+ assert.equal(harness.contexts.get('progress-union-kickoff')(), '')
214
+ assert.equal(harness.contexts.get('progress-union-user-edits')(), '')
215
+ })
216
+
217
+ test('PTC 内层工具进观察块:ptc-dispatch 不再只剩 run_code', async () => {
218
+ const harness = await booted()
219
+ await execUpdate(harness, { changes: [{ title: '做点事', status: 'doing' }] })
220
+ // 外层只有 run_code(PTC 特征)
221
+ harness.emit('tool/call', { name: 'run_code', arguments: '{"code":"tools.shell(1)"}' })
222
+ // 内层真实工具在 ptc-dispatch 的终态事件上
223
+ harness.emit('tool/ptc-dispatch', { name: 'shell', arguments: '{"command":"ls"}', isError: false })
224
+ harness.emit('tool/ptc-dispatch', { name: 'read', arguments: '{"file_path":"a.js"}', isError: false })
225
+ // dispatch-start 是起始事件,必须被忽略(否则同一条会记两次)
226
+ harness.emit('tool/ptc-dispatch-start', { name: 'shell', arguments: '{"command":"ls"}' })
227
+ const text = harness.contexts.get('progress-union-observer')()
228
+ assert.match(text, /最近动作:.*shell/, 'PTC 内层 tool 必须出现在最近动作里')
229
+ assert.match(text, /read/, '第二条内层 tool 也要在')
230
+ })
231
+
232
+ test('PTC 内层工具失败:观察块给出最近失败行', async () => {
233
+ const harness = await booted()
234
+ await execUpdate(harness, { changes: [{ title: '做点事', status: 'doing' }] })
235
+ harness.emit('tool/ptc-dispatch', {
236
+ name: 'glob',
237
+ arguments: '{"pattern":"**/*"}',
238
+ isError: true,
239
+ content: [{ type: 'text', text: 'Error: tool call timed out after 30000ms' }],
240
+ })
241
+ const text = harness.contexts.get('progress-union-observer')()
242
+ assert.match(text, /最近失败:glob/)
243
+ assert.match(text, /timed out/)
244
+ })
245
+
246
+ test('旧前缀别名 /progress-board/* 仍可用一版', async () => {
247
+ const harness = await booted()
248
+ const res = await callRoute(harness, '/progress-board/snapshot', { method: 'GET', url: `/progress-board/snapshot?sessionId=${SESSION}`, headers: {} })
249
+ assert.equal(res.status, 200)
250
+ assert.equal(res.json().enabled, true)
251
+ })
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 窄栏布局回归:进度板副标题在 335px 侧栏里不得被按钮挤成竖排。
3
+ * 起因:截图里 .pb-side-head 是 flex 行,左侧标题+副标题块与三个按钮同行,
4
+ * 按钮 flex:none 把文字列压到约 8em,中文说明被折成每列 2~3 字。
5
+ * 契约:副标题必须是按钮下方独占整行的块,可用宽度接近整个面板内容宽度。
6
+ */
7
+ import { test } from 'node:test'
8
+ import assert from 'node:assert/strict'
9
+ import { readFileSync } from 'node:fs'
10
+ import { fileURLToPath } from 'node:url'
11
+
12
+ const root = fileURLToPath(new URL('..', import.meta.url))
13
+ const client = readFileSync(root + 'client.js', 'utf8')
14
+
15
+ function rule(selector) {
16
+ const i = client.indexOf(selector + ' {')
17
+ assert.notEqual(i, -1, `样式里找不到规则:${selector}`)
18
+ return client.slice(i, client.indexOf('}', i))
19
+ }
20
+
21
+ test('副标题是 pb-side-head 的兄弟节点,不再嵌在左侧标题块里', () => {
22
+ // 重构后:head 内有 h2 + actions,随后紧跟独立的 <p class="pb-side-sub">
23
+ const headMarker = "{ className: 'pb-side-head' }"
24
+ const headPos = client.indexOf(headMarker)
25
+ assert.notEqual(headPos, -1, '找不到 pb-side-head 渲染块')
26
+ // pb-side-head 的收尾:actions 的 ) 之后是 head div 的 ), 再下一行是副标题 <p>
27
+ const subPos = client.indexOf("h('p', { className: 'pb-side-sub' }", headPos)
28
+ assert.notEqual(subPos, -1, '副标题应渲染在 pb-side-head 之后,作为独占一行的兄弟节点')
29
+ const headBlock = client.slice(headPos, subPos)
30
+ assert.equal(headBlock.includes("className: 'pb-side-sub'"), false,
31
+ 'pb-side-head 内部不得再包含副标题(否则仍与按钮同行被挤压)')
32
+ // 副标题紧邻 head 结束(中间只有 actions 的闭合括号),确认不是嵌在别的容器里
33
+ const gap = headBlock.slice(headBlock.lastIndexOf('),'))
34
+ assert.ok(gap.length < 40, `副标题应紧跟 head 容器收尾,实际间隔:${JSON.stringify(gap)}`)
35
+ })
36
+
37
+ test('pb-side-head 只是标题+按钮的一行,副标题样式整行可用', () => {
38
+ const head = rule('.pb-side-head')
39
+ assert.match(head, /display:\s*flex/, 'header 仍是 flex 行')
40
+ assert.equal(/pb-side-sub/.test(head), false)
41
+
42
+ const sub = rule('.pb-side-sub')
43
+ assert.match(sub, /max-width:\s*none/, '副标题不得有窄 max-width 限制')
44
+ assert.match(sub, /margin:\s*[^;]*14px/, '副标题自带下边距,取代旧 head 的 margin-bottom')
45
+ })
46
+
47
+ test('窄栏几何:335px 面板里副标题可用宽度 >= 元素宽度的 90%', () => {
48
+ // 复现截图 335px 面板(左右各 14px padding + 2px 边框),按钮组约 168px。
49
+ // 旧布局:副标题在左侧块内 => 可用宽 ≈ 305 - 168 - 8 ≈ 129px(≈ 竖排 2-3 字)。
50
+ // 新布局:副标题独占一行 => 可用宽 = 305px(按钮下方也能铺文字)。
51
+ const panel = 335
52
+ const padding = 14 * 2
53
+ const borders = 2
54
+ const inner = panel - padding - borders // 293
55
+ const buttons = 168 // Agent 更新:开 + 全面展开 + 收起,实测约 56+52+40 + gaps
56
+ const oldWidth = inner - buttons - 8
57
+ const newWidth = inner
58
+ assert.ok(oldWidth < inner * 0.5, `旧布局应明显受限,实测 ${oldWidth}px`)
59
+ assert.ok(newWidth >= inner * 0.9, `新副标题应占满整行,实测 ${newWidth}px`)
60
+ // 中文 11px 字约 11px 宽 => 293px 一行约可放 24+ 字;旧布局只能 10 字左右。
61
+ const charsPerLineNew = Math.floor(newWidth / 11)
62
+ const charsPerLineOld = Math.floor(oldWidth / 11)
63
+ assert.ok(charsPerLineNew >= charsPerLineOld * 2,
64
+ '副标题每行可容纳字数应至少翻倍,才不会被挤成竖排')
65
+ })