dsh-progress-union 0.5.0 → 0.5.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 +11 -0
- package/LICENSE +21 -21
- package/README.md +201 -201
- package/anchor.js +39 -39
- package/client.js +2958 -2893
- package/cordis.patch.yml +4 -4
- package/docs/slot-models-comparison.md +23 -23
- package/docs/slot-trail-fanout.md +31 -31
- package/docs/spirit-reference.md +38 -38
- package/dsh.plugin.json +16 -16
- package/icon.svg +7 -7
- package/index.js +3621 -3621
- package/package.json +77 -77
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +58 -58
- package/test/e2e.test.mjs +77 -77
- package/test/harness.mjs +220 -220
- package/test/host.test.mjs +251 -251
- package/test/observer.test.mjs +170 -170
- package/test/settings.test.mjs +81 -81
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/host.test.mjs
CHANGED
|
@@ -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
|
+
})
|