dsh-progress-union 0.3.0 → 0.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -16,6 +16,7 @@
16
16
  "exports": {
17
17
  ".": "./index.js",
18
18
  "./client": "./client.js",
19
+ "./anchor": "./anchor.js",
19
20
  "./cordis.patch.yml": "./cordis.patch.yml",
20
21
  "./package.json": "./package.json"
21
22
  },
@@ -23,6 +24,7 @@
23
24
  "README.md",
24
25
  "LICENSE",
25
26
  "index.js",
27
+ "anchor.js",
26
28
  "client.js",
27
29
  "cordis.patch.yml",
28
30
  "dsh.plugin.json",
@@ -9,10 +9,14 @@ import os from 'node:os'
9
9
  import path from 'node:path'
10
10
  import test from 'node:test'
11
11
 
12
+ import { fileURLToPath } from 'node:url'
13
+
12
14
  process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
13
15
  const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
14
16
 
15
- const clientFile = new URL('../client.js', import.meta.url).pathname.replace(/^\//, '')
17
+ // 必须用 fileURLToPath:`new URL(...).pathname` 在 Windows 得到 `/E:/...`(需去前导斜杠),
18
+ // 但 Linux 的 `/` 是根目录,`.replace(/^[/]/,'')` 会把它变成相对路径 → CI 上 ENOENT。
19
+ const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
16
20
 
17
21
  test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
18
22
  const src = fs.readFileSync(clientFile, 'utf8')
@@ -0,0 +1,101 @@
1
+ /**
2
+ * v0.4.0 消费者视角验收:
3
+ * - 经 service get/list 读锚点并断言字段;
4
+ * - 经 subscribe 拿到板变更通知(revision 递增、同 rev 不重复、退订后零回调);
5
+ * - isAnchor/anchorLine 对新旧快照都能工作(含未启用板场景)。
6
+ */
7
+ import assert from 'node:assert/strict'
8
+ import fs from 'node:fs'
9
+ import os from 'node:os'
10
+ import path from 'node:path'
11
+ import test from 'node:test'
12
+
13
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
14
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
+ const { ANCHOR_VERSION, ANCHOR_ROUTES, BOARD_STATUSES, isAnchor, anchorLine } = await import('../anchor.js')
16
+
17
+ function execUpdate(harness, args) {
18
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
19
+ }
20
+
21
+ async function booted() {
22
+ const harness = createHarness()
23
+ await harness.run()
24
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
25
+ return harness
26
+ }
27
+
28
+ test('./anchor 子路径导出齐全;常量与 service.version 握手一致', async () => {
29
+ assert.equal(ANCHOR_VERSION, 1)
30
+ assert.deepEqual(ANCHOR_ROUTES, {
31
+ anchor: '/progress-union/anchor',
32
+ snapshot: '/progress-union/snapshot',
33
+ status: '/dsh-progress/status',
34
+ })
35
+ assert.deepEqual(BOARD_STATUSES, ['todo', 'doing', 'done', 'blocked'])
36
+ assert.equal(typeof isAnchor, 'function')
37
+ assert.equal(typeof anchorLine, 'function')
38
+ const harness = await booted()
39
+ assert.equal(harness.provided.get('progressAnchor').version, ANCHOR_VERSION, '握手:service.version === ANCHOR_VERSION')
40
+ })
41
+
42
+ test('消费者经 get/list 读锚点:字段齐、未启用板 board.enabled=false 不抛', async () => {
43
+ const harness = await booted()
44
+ const service = harness.provided.get('progressAnchor')
45
+ const anchor = service.get(SESSION)
46
+ assert.equal(isAnchor(anchor), true)
47
+ assert.equal(anchor.sessionId, SESSION)
48
+ assert.equal(typeof anchor.revision, 'number')
49
+ assert.equal(typeof anchor.board.enabled, 'boolean')
50
+ const listed = service.list()
51
+ assert.ok(Array.isArray(listed))
52
+ assert.ok(listed.some((a) => a.sessionId === SESSION))
53
+
54
+ const off = createHarness()
55
+ await off.run()
56
+ const disabled = off.provided.get('progressAnchor').get('session-never-enabled')
57
+ assert.equal(isAnchor(disabled), true, '未启用板仍是合法锚点')
58
+ assert.equal(disabled.board.enabled, false)
59
+ assert.equal(anchorLine(disabled), '0% 0/0', '未启用板不抛错,给 0 值摘要')
60
+ })
61
+
62
+ test('subscribe:板 revision 递增回调一次;同 revision 不重复;退订后零回调', async () => {
63
+ const harness = await booted()
64
+ const service = harness.provided.get('progressAnchor')
65
+ const events = []
66
+ const off = service.subscribe((evt) => events.push(evt), SESSION)
67
+
68
+ await execUpdate(harness, { changes: [{ title: '甲', status: 'doing' }] })
69
+ await execUpdate(harness, { changes: [{ title: '乙', status: 'todo' }] })
70
+ assert.equal(events.length, 2, '两次写板、两次不同 revision → 两次回调')
71
+ assert.ok(events[0].revision < events[1].revision)
72
+ assert.equal(events[0].sessionId, SESSION)
73
+
74
+ // 同 revision 不重复:先记下当前 revision,重复订阅探测不会因读操作再触发。
75
+ const rev = events[1].revision
76
+ assert.equal(events.filter((e) => e.revision === rev).length, 1)
77
+
78
+ off()
79
+ await execUpdate(harness, { changes: [{ title: '丙' }] })
80
+ assert.equal(events.length, 2, '退订后不再回调')
81
+
82
+ // 无参数订阅(全会话)也应可退订。
83
+ const all = []
84
+ const offAll = service.subscribe((evt) => all.push(evt))
85
+ await execUpdate(harness, { changes: [{ title: '丁', status: 'done' }] })
86
+ assert.equal(all.length, 1)
87
+ offAll()
88
+ await execUpdate(harness, { changes: [{ title: '戊' }] })
89
+ assert.equal(all.length, 1)
90
+ })
91
+
92
+ test('isAnchor/anchorLine:新旧快照都能工作(缺新字段不抛,坏形状返回空串)', async () => {
93
+ const modern = { version: 1, sessionId: 's', board: { enabled: true, summary: { percent: 45, done: 3, total: 7 } }, time: { etaMin: 6, staleMin: 12 } }
94
+ const legacy = { version: 1, sessionId: 's', board: { enabled: true, summary: { percent: 80, done: 4, total: 5, doing: 0, todo: 1, blocked: 0 } }, time: { staleMin: 0 } }
95
+ assert.equal(isAnchor(modern), true)
96
+ assert.equal(isAnchor(legacy), true)
97
+ assert.equal(anchorLine(modern), '45% 3/7 · ETA 6m · stale 12m')
98
+ assert.equal(anchorLine(legacy), '80% 4/5')
99
+ assert.equal(isAnchor({ version: 1, sessionId: 's', board: {}, time: {} }), false)
100
+ assert.equal(anchorLine(null), '')
101
+ })
@@ -1,110 +1,110 @@
1
- /**
2
- * /progress-goal 迷你目标域验收:
3
- * - create/status/budget/pause/resume/clear 命令;
4
- * - progress_goal_report 的 complete(证据+全板)/blocked(连续3次)/continue;
5
- * - 预算到顶转 blocked;followup 续轮身份与注入避让。
6
- */
7
- import assert from 'node:assert/strict'
8
- import fs from 'node:fs'
9
- import os from 'node:os'
10
- import path from 'node:path'
11
- import test from 'node:test'
12
-
13
- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-goal-test-'))
14
- const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
-
16
- async function booted(config = {}) {
17
- const harness = createHarness({ config })
18
- await harness.run()
19
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
20
- return harness
21
- }
22
-
23
- function cmd(harness, input) {
24
- return harness.commandMap.get('progress-goal').handler({ agent: harness.agent, rawInput: input })
25
- }
26
-
27
- function report(harness, args) {
28
- return harness.toolMap.get('progress_goal_report').definition.execute(args, { agent: harness.agent })
29
- }
30
-
31
- async function snapshotOf(harness) {
32
- const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
33
- return res.json()
34
- }
35
-
36
- test('create/status/budget/pause/resume/clear 全命令链', async () => {
37
- const h = await booted()
38
- let r = await cmd(h, '把插件改完并测试')
39
- assert.equal(r.kind, 'success')
40
- assert.match(r.text, /Status: active/)
41
- assert.match(r.text, /Rounds: 0\/256/)
42
-
43
- r = await cmd(h, 'budget 3')
44
- assert.match(r.text, /Rounds: 0\/3/)
45
-
46
- r = await cmd(h, 'status')
47
- assert.match(r.text, /Objective: "把插件改完并测试"/)
48
-
49
- r = await cmd(h, 'pause')
50
- assert.match(r.text, /Status: paused/)
51
- r = await cmd(h, 'resume')
52
- assert.match(r.text, /Status: active/)
53
-
54
- r = await cmd(h, 'clear')
55
- assert.equal(r.text, '目标已清除。')
56
- r = await cmd(h, 'status')
57
- assert.match(r.text, /没有目标/)
58
- })
59
-
60
- test('progress_goal_report: complete 需证据 + 全板完成', async () => {
61
- const h = await booted()
62
- await cmd(h, '目标A')
63
- // 无证据 → 拒
64
- let err = null
65
- try { await report(h, { status: 'complete' }) } catch (e) { err = e }
66
- assert.ok(err && /evidence/.test(err.message))
67
- // 建板但不全完成 → 拒
68
- await h.toolMap.get('progress_update').definition.execute(
69
- { changes: [{ title: 't1', status: 'doing', percent: 50 }, { title: 't2', status: 'todo' }] },
70
- { agent: h.agent },
71
- )
72
- err = null
73
- try { await report(h, { status: 'complete', evidence: ['x'] }) } catch (e) { err = e }
74
- assert.ok(err && /全部完成/.test(err.message))
75
- // 全部 done → 成功
76
- await h.toolMap.get('progress_update').definition.execute(
77
- { changes: [{ title: 't1', status: 'done' }, { title: 't2', status: 'done' }] },
78
- { agent: h.agent },
79
- )
80
- const r = await report(h, { status: 'complete', evidence: ['测试通过'] })
81
- assert.equal(r.goal.phase, 'complete')
82
- })
83
-
84
- test('blocked 连续 3 轮同因才落 phase,continue 清零', async () => {
85
- const h = await booted()
86
- await cmd(h, '目标B')
87
- let r = await report(h, { status: 'blocked', blocker: '等API' })
88
- assert.equal(r.goal.phase, 'active')
89
- assert.equal(r.goal.blockedStreak, 1)
90
- r = await report(h, { status: 'blocked', blocker: '等API' })
91
- assert.equal(r.goal.blockedStreak, 2)
92
- r = await report(h, { status: 'blocked', blocker: '等API' })
93
- assert.equal(r.goal.phase, 'blocked')
94
- await cmd(h, 'resume')
95
- r = await report(h, { status: 'blocked', blocker: '别的' })
96
- assert.equal(r.goal.blockedStreak, 1, '换原因重新计数')
97
- await report(h, { status: 'continue' })
98
- r = await report(h, { status: 'blocked', blocker: '别的' })
99
- assert.equal(r.goal.blockedStreak, 1, 'continue 清零 streak')
100
- })
101
-
102
- test('快照回显 goal 子对象', async () => {
103
- const h = await booted()
104
- await cmd(h, '目标C')
105
- await cmd(h, 'budget 7')
106
- const snap = await snapshotOf(h)
107
- assert.equal(snap.goal.objective, '目标C')
108
- assert.equal(snap.goal.maxRounds, 7)
109
- assert.equal(snap.goal.phase, 'active')
110
- })
1
+ /**
2
+ * /progress-goal 迷你目标域验收:
3
+ * - create/status/budget/pause/resume/clear 命令;
4
+ * - progress_goal_report 的 complete(证据+全板)/blocked(连续3次)/continue;
5
+ * - 预算到顶转 blocked;followup 续轮身份与注入避让。
6
+ */
7
+ import assert from 'node:assert/strict'
8
+ import fs from 'node:fs'
9
+ import os from 'node:os'
10
+ import path from 'node:path'
11
+ import test from 'node:test'
12
+
13
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-goal-test-'))
14
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
+
16
+ async function booted(config = {}) {
17
+ const harness = createHarness({ config })
18
+ await harness.run()
19
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
20
+ return harness
21
+ }
22
+
23
+ function cmd(harness, input) {
24
+ return harness.commandMap.get('progress-goal').handler({ agent: harness.agent, rawInput: input })
25
+ }
26
+
27
+ function report(harness, args) {
28
+ return harness.toolMap.get('progress_goal_report').definition.execute(args, { agent: harness.agent })
29
+ }
30
+
31
+ async function snapshotOf(harness) {
32
+ const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
33
+ return res.json()
34
+ }
35
+
36
+ test('create/status/budget/pause/resume/clear 全命令链', async () => {
37
+ const h = await booted()
38
+ let r = await cmd(h, '把插件改完并测试')
39
+ assert.equal(r.kind, 'success')
40
+ assert.match(r.text, /Status: active/)
41
+ assert.match(r.text, /Rounds: 0\/256/)
42
+
43
+ r = await cmd(h, 'budget 3')
44
+ assert.match(r.text, /Rounds: 0\/3/)
45
+
46
+ r = await cmd(h, 'status')
47
+ assert.match(r.text, /Objective: "把插件改完并测试"/)
48
+
49
+ r = await cmd(h, 'pause')
50
+ assert.match(r.text, /Status: paused/)
51
+ r = await cmd(h, 'resume')
52
+ assert.match(r.text, /Status: active/)
53
+
54
+ r = await cmd(h, 'clear')
55
+ assert.equal(r.text, '目标已清除。')
56
+ r = await cmd(h, 'status')
57
+ assert.match(r.text, /没有目标/)
58
+ })
59
+
60
+ test('progress_goal_report: complete 需证据 + 全板完成', async () => {
61
+ const h = await booted()
62
+ await cmd(h, '目标A')
63
+ // 无证据 → 拒
64
+ let err = null
65
+ try { await report(h, { status: 'complete' }) } catch (e) { err = e }
66
+ assert.ok(err && /evidence/.test(err.message))
67
+ // 建板但不全完成 → 拒
68
+ await h.toolMap.get('progress_update').definition.execute(
69
+ { changes: [{ title: 't1', status: 'doing', percent: 50 }, { title: 't2', status: 'todo' }] },
70
+ { agent: h.agent },
71
+ )
72
+ err = null
73
+ try { await report(h, { status: 'complete', evidence: ['x'] }) } catch (e) { err = e }
74
+ assert.ok(err && /全部完成/.test(err.message))
75
+ // 全部 done → 成功
76
+ await h.toolMap.get('progress_update').definition.execute(
77
+ { changes: [{ title: 't1', status: 'done' }, { title: 't2', status: 'done' }] },
78
+ { agent: h.agent },
79
+ )
80
+ const r = await report(h, { status: 'complete', evidence: ['测试通过'] })
81
+ assert.equal(r.goal.phase, 'complete')
82
+ })
83
+
84
+ test('blocked 连续 3 轮同因才落 phase,continue 清零', async () => {
85
+ const h = await booted()
86
+ await cmd(h, '目标B')
87
+ let r = await report(h, { status: 'blocked', blocker: '等API' })
88
+ assert.equal(r.goal.phase, 'active')
89
+ assert.equal(r.goal.blockedStreak, 1)
90
+ r = await report(h, { status: 'blocked', blocker: '等API' })
91
+ assert.equal(r.goal.blockedStreak, 2)
92
+ r = await report(h, { status: 'blocked', blocker: '等API' })
93
+ assert.equal(r.goal.phase, 'blocked')
94
+ await cmd(h, 'resume')
95
+ r = await report(h, { status: 'blocked', blocker: '别的' })
96
+ assert.equal(r.goal.blockedStreak, 1, '换原因重新计数')
97
+ await report(h, { status: 'continue' })
98
+ r = await report(h, { status: 'blocked', blocker: '别的' })
99
+ assert.equal(r.goal.blockedStreak, 1, 'continue 清零 streak')
100
+ })
101
+
102
+ test('快照回显 goal 子对象', async () => {
103
+ const h = await booted()
104
+ await cmd(h, '目标C')
105
+ await cmd(h, 'budget 7')
106
+ const snap = await snapshotOf(h)
107
+ assert.equal(snap.goal.objective, '目标C')
108
+ assert.equal(snap.goal.maxRounds, 7)
109
+ assert.equal(snap.goal.phase, 'active')
110
+ })
package/test/harness.mjs CHANGED
@@ -6,7 +6,7 @@ import { apply } from '../index.js'
6
6
 
7
7
  export const SESSION = 'session-union-test'
8
8
 
9
- export function createHarness({ seed = {}, config = {}, withProjection = true, withProvide = true, storageless = false, llm = undefined, settings = undefined } = {}) {
9
+ export function createHarness({ seed = {}, config = {}, withProjection = true, withProvide = true, storageless = false, llm = undefined, settings = undefined, cwd = '' } = {}) {
10
10
  const records = { ...seed }
11
11
  const routes = new Map()
12
12
  const toolMap = new Map()
@@ -64,8 +64,10 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
64
64
  const agent = {
65
65
  id: SESSION,
66
66
  // v0.3.0:todo 镜像写通道。默认记录调用;测试可覆写 append 注入失败。
67
+ // v0.5.0:cwd 放在 session **顶层**(实测 shape,不是 header.cwd)——plan 扫描靠它。
67
68
  session: {
68
69
  id: SESSION,
70
+ ...(cwd ? { cwd } : {}),
69
71
  append(type, data) { appends.push({ type, data }); return Promise.resolve() },
70
72
  },
71
73
  ctx: {
@@ -151,7 +153,9 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
151
153
  run: () => apply(ctx, config),
152
154
  /** 按 (session, {type, data}) 派发一条 session/event */
153
155
  emit(type, data, session) {
154
- for (const h of listeners.filter((l) => l.type === 'session/event')) h.handler(session ?? { id: SESSION }, { type, data })
156
+ // 默认 session 带顶层 cwd(实测 shape):plan 扫描靠事件流里的 session。
157
+ const target = session ?? (cwd ? { id: SESSION, cwd } : { id: SESSION })
158
+ for (const h of listeners.filter((l) => l.type === 'session/event')) h.handler(target, { type, data })
155
159
  },
156
160
  }
157
161
  }
@@ -92,6 +92,9 @@ test('历史重名数据歧义:按 title 更新报错要求 id', async () => {
92
92
  })
93
93
 
94
94
  test('批量全成全败:坏条目不得让前半批落盘', async () => {
95
+ // 注意「全成全败」只针对**真语义错误**(remove 找不到目标、新增缺 title、percent
96
+ // 非数字、歧义 title)。status 词表错已改为宽容跳过 + warnings(见下个用例)——
97
+ // 那些是 PTC 通道绕过 schema 导致的输入噪声,不该让整批丢失。
95
98
  const harness = await booted()
96
99
  const before = await execUpdate(harness, { changes: [{ title: '已有任务' }] })
97
100
  await assert.rejects(
@@ -103,6 +106,41 @@ test('批量全成全败:坏条目不得让前半批落盘', async () => {
103
106
  assert.equal(snapshot.board.summary.total, 1, '失败批次不得留下半应用条目')
104
107
  })
105
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
+
106
144
  test('409:expectedRevision 过期拒写并回快照', async () => {
107
145
  const harness = await booted()
108
146
  await execUpdate(harness, { changes: [{ title: 'A' }] })
@@ -176,6 +214,35 @@ test('面板卸载不关掉工具;/progress off(command 源)才关', async
176
214
  assert.equal(harness.contexts.get('progress-union-user-edits')(), '')
177
215
  })
178
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
+
179
246
  test('旧前缀别名 /progress-board/* 仍可用一版', async () => {
180
247
  const harness = await booted()
181
248
  const res = await callRoute(harness, '/progress-board/snapshot', { method: 'GET', url: `/progress-board/snapshot?sessionId=${SESSION}`, headers: {} })