dsh-progress-union 0.8.4 → 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.
@@ -1,174 +1,174 @@
1
- /**
2
- * 0.7.0 rc.3 验收:R4 任务板重大(结构性)变更 → 输入队列。
3
- * 只有 add/remove/order 触发;running 走 agent.steer(next-step 黄档),
4
- * idle 走 agent.followup(next-turn);消息 source.kind='user' 才过 isHumanSteer;
5
- * 同回合合并、同 rev 不重投;关掉开关或板未启用时一条都不发。
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
-
16
- /**
17
- * @param {{config?: object, detachAgent?: boolean}} [opts] detachAgent=true 让
18
- * 板已建好但 liveAgentOf 查不到活 agent(会话 id 从 agent 上挪走,两条查找路径同时落空)。
19
- */
20
- async function booted({ config = {}, detachAgent = false } = {}) {
21
- const harness = createHarness({ config })
22
- await harness.run()
23
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
24
- await harness.toolMap.get('progress_update').definition.execute(
25
- { changes: [{ title: '接数据面', status: 'doing' }, { title: '写面板' }] },
26
- { agent: harness.agent },
27
- )
28
- harness.steers = []
29
- harness.agent.steer = (message) => { harness.steers.push(message); harness.inbox.nextStep.push(message) }
30
- if (detachAgent) harness.agent.session.id = 'some-other-session'
31
- return harness
32
- }
33
-
34
- /** 走「用户在面板改板」这条真实入口(origin='user')。 */
35
- async function userEdit(harness, changes, expectedRevision) {
36
- const res = await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes, expectedRevision }))
37
- return res.json()
38
- }
39
-
40
- test('idle + 用户新增项 → followup 落队列,正文带 <progress-major-change rev="N">', async () => {
41
- const harness = await booted()
42
- const before = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} }).then((r) => r.json())
43
- const out = await userEdit(harness, [{ title: '补下载子条' }], before.revision)
44
- assert.equal(out.ok, true)
45
- assert.equal(out.notified, true, '/action 必须把服务端是否已落队列告知客户端')
46
- assert.equal(out.noticeMerged, false, '真的投了一条就不能标 merged')
47
- assert.equal(harness.followups.length, 1, 'idle 必须走 followup')
48
- const msg = harness.followups[0]
49
- assert.equal(msg.role, 'user')
50
- assert.deepEqual(msg.source, { kind: 'user', producer: 'dsh-progress-union', rev: out.revision })
51
- assert.equal(msg.content[0].type, 'text')
52
- const text = msg.content[0].text
53
- assert.match(text, new RegExp(`<progress-major-change rev="${out.revision}">`))
54
- assert.match(text, /<\/progress-major-change>/)
55
- assert.match(text, /\+ 新增:补下载子条/)
56
- assert.match(text, /- \[~\] 接数据面/, '正文要裹进当前清单,模型不用重新拉板')
57
- assert.match(text, /不要按旧顺序推进/)
58
- })
59
-
60
- test('running + agent.steer → 走 next-step 黄档,不排 followup', async () => {
61
- const harness = await booted()
62
- harness.agent.status = 'running'
63
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
64
- const out = await userEdit(harness, [{ id: before.items[1].id, remove: true }], before.revision)
65
- assert.equal(out.ok, true)
66
- assert.equal(harness.steers.length, 1, 'running 必须走 steer(本回合 next-step)')
67
- assert.equal(harness.followups.length, 0, 'running 时不该另起新回合')
68
- assert.match(harness.steers[0].content[0].text, /- 删除:写面板/)
69
- })
70
-
71
- test('只有非结构性改动(current/percent/status)时一条都不发', async () => {
72
- const harness = await booted()
73
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
74
- const out = await userEdit(harness, [
75
- { id: before.items[0].id, current: '手工补的当前', percent: 60, status: 'doing' },
76
- ], before.revision)
77
- assert.equal(out.ok, true)
78
- assert.equal(out.changed.length, 1)
79
- assert.equal(harness.followups.length + harness.steers.length, 0, '改字段不算重大变更')
80
- })
81
-
82
- test('同回合连续两次结构性改板 → 合并成一条(同 rev 不重投)', async () => {
83
- const harness = await booted()
84
- let rev = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().revision
85
- const first = await userEdit(harness, [{ title: 'A' }], rev)
86
- assert.equal(first.notified, true, '首次结构性改板必须回执 notified=true,客户端据此不再另发 wake 消息')
87
- rev = first.revision
88
- const second = await userEdit(harness, [{ title: 'B' }], rev)
89
- assert.equal(second.notified, false, '同回合第两次被合并,不得假装已投递')
90
- // 但必须告知客户端「本回合已经提醒过了」——否则客户端会另发一条 wake,
91
- // 队列里就同时有 R4 提醒与客户端 wake 两条(真机实测偏差)。
92
- assert.equal(second.noticeMerged, true, '同回合被合并必须回执 noticeMerged=true')
93
- rev = second.revision
94
- const third = await userEdit(harness, [{ title: 'C' }], rev)
95
- assert.equal(third.notified, false)
96
- assert.equal(third.noticeMerged, true)
97
- rev = third.revision
98
- assert.equal(harness.followups.length, 1, '同一回合只提一次')
99
- // 已发的那条对应第一次的 rev;后续 rev 不再补投
100
- assert.equal(harness.followups.filter((m) => m.source && m.source.producer === 'dsh-progress-union').length, 1)
101
- })
102
-
103
- test('开新回合后可以再提(提醒窗口按回合走)', async () => {
104
- const harness = await booted()
105
- let rev = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().revision
106
- rev = (await userEdit(harness, [{ title: 'A' }], rev)).revision
107
- assert.equal(harness.followups.length, 1)
108
- rev = (await userEdit(harness, [{ title: 'B' }], rev)).revision
109
- assert.equal(harness.followups.length, 1, '同回合仍只一条')
110
- harness.emit('turn/start', {})
111
- rev = (await userEdit(harness, [{ title: 'C' }], rev)).revision
112
- assert.equal(harness.followups.length, 2, '新回合必须能再提醒')
113
- const revs = harness.followups.map((m) => m.source.rev)
114
- assert.equal(new Set(revs).size, 2, '同 rev 绝不重投')
115
- })
116
-
117
- test('notifyMajorChanges:false 一条都不发(逐字退回 0.6.x 行为)', async () => {
118
- const harness = await booted({ config: { notifyMajorChanges: false } })
119
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
120
- const out = await userEdit(harness, [{ title: '关掉提醒' }], before.revision)
121
- assert.equal(out.ok, true, '改板本身必须照常成功')
122
- assert.equal(out.notified, false, '开关关掉时 notified 必为 false,客户端 wake 行为退回 0.6.x')
123
- assert.equal(out.noticeMerged, false, '开关关掉不算「已合并」')
124
- assert.equal(harness.followups.length + harness.steers.length, 0)
125
- })
126
-
127
- test('板未启用(关板)时不发;主模型自己写板(origin=agent)也不发', async () => {
128
- const harness = await booted()
129
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: false, source: 'command' }))
130
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
131
- const out = await userEdit(harness, [{ title: '关板后新增' }], before.revision)
132
- assert.equal(out.ok, true, '关板后改板本身仍要照常落盘')
133
- assert.equal(out.notified, false)
134
- assert.equal(out.noticeMerged, false, '关板是“没递”,不是“已合并”,客户端仍应保留 wake')
135
- assert.equal(out.items.some((i) => i.title === '关板后新增'), true)
136
- assert.equal(harness.followups.length + harness.steers.length, 0, '关板不该往队列里丢东西')
137
-
138
- const h2 = await booted()
139
- await h2.toolMap.get('progress_update').definition.execute({ changes: [{ title: '模型自己新增的项' }] }, { agent: h2.agent })
140
- assert.equal(h2.followups.length + h2.steers.length, 0, '主模型知道刚写了什么,不要回灌给它')
141
- })
142
-
143
- test('没有活着的 agent / steer 抛错:只吞不炸,改板照常落盘', async () => {
144
- const harness = await booted({ detachAgent: true })
145
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
146
- const out = await userEdit(harness, [{ title: '无 agent 也要能改板' }], before.revision)
147
- assert.equal(out.ok, true)
148
- assert.equal(out.items.some((i) => i.title === '无 agent 也要能改板'), true)
149
- assert.equal(harness.followups.length, 0)
150
-
151
- const h2 = await booted()
152
- h2.agent.status = 'running'
153
- h2.agent.steer = () => { throw new Error('inbox 满了') }
154
- const b2 = (await callRoute(h2, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
155
- const r2 = await userEdit(h2, [{ title: '派发失败也要落盘' }], b2.revision)
156
- assert.equal(r2.ok, true, '提醒失败绝不能连带让改板失败')
157
- assert.equal(r2.items.some((i) => i.title === '派发失败也要落盘'), true)
158
- assert.equal(h2.followups.length, 0, 'steer 抛错后不得退回 followup 补发(避免同一变更两条队列消息)')
159
- })
160
-
161
- test('提醒只占一条队列消息,不叠加催办也不接管滞后面板计时', async () => {
162
- const harness = await booted()
163
- for (let i = 0; i < 3; i += 1) harness.emit('step/start', {})
164
- const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
165
- assert.match(harness.contexts.get('progress-union-observer')(), /synced="3 步前"/)
166
-
167
- const out = await userEdit(harness, [{ title: '用户插入一项' }], before.revision)
168
- assert.equal(out.ok, true)
169
- assert.equal(harness.followups.length, 1, '只那一条重大变更提醒,不得叠加自动催办')
170
- assert.equal(harness.inbox.nextTurn.length, 1, '提醒之外不另起轮次')
171
- // 用户写板本身把 stepsSinceModel 归零(origin='user' 算一次同步),提醒不能再额外减步
172
- harness.emit('step/start', {})
173
- assert.match(harness.contexts.get('progress-union-observer')(), /synced="1 步前"/)
174
- })
1
+ /**
2
+ * 0.7.0 rc.3 验收:R4 任务板重大(结构性)变更 → 输入队列。
3
+ * 只有 add/remove/order 触发;running 走 agent.steer(next-step 黄档),
4
+ * idle 走 agent.followup(next-turn);消息 source.kind='user' 才过 isHumanSteer;
5
+ * 同回合合并、同 rev 不重投;关掉开关或板未启用时一条都不发。
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
+
16
+ /**
17
+ * @param {{config?: object, detachAgent?: boolean}} [opts] detachAgent=true 让
18
+ * 板已建好但 liveAgentOf 查不到活 agent(会话 id 从 agent 上挪走,两条查找路径同时落空)。
19
+ */
20
+ async function booted({ config = {}, detachAgent = false } = {}) {
21
+ const harness = createHarness({ config })
22
+ await harness.run()
23
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
24
+ await harness.toolMap.get('progress_update').definition.execute(
25
+ { changes: [{ title: '接数据面', status: 'doing' }, { title: '写面板' }] },
26
+ { agent: harness.agent },
27
+ )
28
+ harness.steers = []
29
+ harness.agent.steer = (message) => { harness.steers.push(message); harness.inbox.nextStep.push(message) }
30
+ if (detachAgent) harness.agent.session.id = 'some-other-session'
31
+ return harness
32
+ }
33
+
34
+ /** 走「用户在面板改板」这条真实入口(origin='user')。 */
35
+ async function userEdit(harness, changes, expectedRevision) {
36
+ const res = await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes, expectedRevision }))
37
+ return res.json()
38
+ }
39
+
40
+ test('idle + 用户新增项 → followup 落队列,正文带 <progress-major-change rev="N">', async () => {
41
+ const harness = await booted()
42
+ const before = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} }).then((r) => r.json())
43
+ const out = await userEdit(harness, [{ title: '补下载子条' }], before.revision)
44
+ assert.equal(out.ok, true)
45
+ assert.equal(out.notified, true, '/action 必须把服务端是否已落队列告知客户端')
46
+ assert.equal(out.noticeMerged, false, '真的投了一条就不能标 merged')
47
+ assert.equal(harness.followups.length, 1, 'idle 必须走 followup')
48
+ const msg = harness.followups[0]
49
+ assert.equal(msg.role, 'user')
50
+ assert.deepEqual(msg.source, { kind: 'user', producer: 'dsh-progress-union', rev: out.revision })
51
+ assert.equal(msg.content[0].type, 'text')
52
+ const text = msg.content[0].text
53
+ assert.match(text, new RegExp(`<progress-major-change rev="${out.revision}">`))
54
+ assert.match(text, /<\/progress-major-change>/)
55
+ assert.match(text, /\+ 新增:补下载子条/)
56
+ assert.match(text, /- \[~\] 接数据面/, '正文要裹进当前清单,模型不用重新拉板')
57
+ assert.match(text, /不要按旧顺序推进/)
58
+ })
59
+
60
+ test('running + agent.steer → 走 next-step 黄档,不排 followup', async () => {
61
+ const harness = await booted()
62
+ harness.agent.status = 'running'
63
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
64
+ const out = await userEdit(harness, [{ id: before.items[1].id, remove: true }], before.revision)
65
+ assert.equal(out.ok, true)
66
+ assert.equal(harness.steers.length, 1, 'running 必须走 steer(本回合 next-step)')
67
+ assert.equal(harness.followups.length, 0, 'running 时不该另起新回合')
68
+ assert.match(harness.steers[0].content[0].text, /- 删除:写面板/)
69
+ })
70
+
71
+ test('只有非结构性改动(current/percent/status)时一条都不发', async () => {
72
+ const harness = await booted()
73
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
74
+ const out = await userEdit(harness, [
75
+ { id: before.items[0].id, current: '手工补的当前', percent: 60, status: 'doing' },
76
+ ], before.revision)
77
+ assert.equal(out.ok, true)
78
+ assert.equal(out.changed.length, 1)
79
+ assert.equal(harness.followups.length + harness.steers.length, 0, '改字段不算重大变更')
80
+ })
81
+
82
+ test('同回合连续两次结构性改板 → 合并成一条(同 rev 不重投)', async () => {
83
+ const harness = await booted()
84
+ let rev = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().revision
85
+ const first = await userEdit(harness, [{ title: 'A' }], rev)
86
+ assert.equal(first.notified, true, '首次结构性改板必须回执 notified=true,客户端据此不再另发 wake 消息')
87
+ rev = first.revision
88
+ const second = await userEdit(harness, [{ title: 'B' }], rev)
89
+ assert.equal(second.notified, false, '同回合第两次被合并,不得假装已投递')
90
+ // 但必须告知客户端「本回合已经提醒过了」——否则客户端会另发一条 wake,
91
+ // 队列里就同时有 R4 提醒与客户端 wake 两条(真机实测偏差)。
92
+ assert.equal(second.noticeMerged, true, '同回合被合并必须回执 noticeMerged=true')
93
+ rev = second.revision
94
+ const third = await userEdit(harness, [{ title: 'C' }], rev)
95
+ assert.equal(third.notified, false)
96
+ assert.equal(third.noticeMerged, true)
97
+ rev = third.revision
98
+ assert.equal(harness.followups.length, 1, '同一回合只提一次')
99
+ // 已发的那条对应第一次的 rev;后续 rev 不再补投
100
+ assert.equal(harness.followups.filter((m) => m.source && m.source.producer === 'dsh-progress-union').length, 1)
101
+ })
102
+
103
+ test('开新回合后可以再提(提醒窗口按回合走)', async () => {
104
+ const harness = await booted()
105
+ let rev = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().revision
106
+ rev = (await userEdit(harness, [{ title: 'A' }], rev)).revision
107
+ assert.equal(harness.followups.length, 1)
108
+ rev = (await userEdit(harness, [{ title: 'B' }], rev)).revision
109
+ assert.equal(harness.followups.length, 1, '同回合仍只一条')
110
+ harness.emit('turn/start', {})
111
+ rev = (await userEdit(harness, [{ title: 'C' }], rev)).revision
112
+ assert.equal(harness.followups.length, 2, '新回合必须能再提醒')
113
+ const revs = harness.followups.map((m) => m.source.rev)
114
+ assert.equal(new Set(revs).size, 2, '同 rev 绝不重投')
115
+ })
116
+
117
+ test('notifyMajorChanges:false 一条都不发(逐字退回 0.6.x 行为)', async () => {
118
+ const harness = await booted({ config: { notifyMajorChanges: false } })
119
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
120
+ const out = await userEdit(harness, [{ title: '关掉提醒' }], before.revision)
121
+ assert.equal(out.ok, true, '改板本身必须照常成功')
122
+ assert.equal(out.notified, false, '开关关掉时 notified 必为 false,客户端 wake 行为退回 0.6.x')
123
+ assert.equal(out.noticeMerged, false, '开关关掉不算「已合并」')
124
+ assert.equal(harness.followups.length + harness.steers.length, 0)
125
+ })
126
+
127
+ test('板未启用(关板)时不发;主模型自己写板(origin=agent)也不发', async () => {
128
+ const harness = await booted()
129
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: false, source: 'command' }))
130
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
131
+ const out = await userEdit(harness, [{ title: '关板后新增' }], before.revision)
132
+ assert.equal(out.ok, true, '关板后改板本身仍要照常落盘')
133
+ assert.equal(out.notified, false)
134
+ assert.equal(out.noticeMerged, false, '关板是“没递”,不是“已合并”,客户端仍应保留 wake')
135
+ assert.equal(out.items.some((i) => i.title === '关板后新增'), true)
136
+ assert.equal(harness.followups.length + harness.steers.length, 0, '关板不该往队列里丢东西')
137
+
138
+ const h2 = await booted()
139
+ await h2.toolMap.get('progress_update').definition.execute({ changes: [{ title: '模型自己新增的项' }] }, { agent: h2.agent })
140
+ assert.equal(h2.followups.length + h2.steers.length, 0, '主模型知道刚写了什么,不要回灌给它')
141
+ })
142
+
143
+ test('没有活着的 agent / steer 抛错:只吞不炸,改板照常落盘', async () => {
144
+ const harness = await booted({ detachAgent: true })
145
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
146
+ const out = await userEdit(harness, [{ title: '无 agent 也要能改板' }], before.revision)
147
+ assert.equal(out.ok, true)
148
+ assert.equal(out.items.some((i) => i.title === '无 agent 也要能改板'), true)
149
+ assert.equal(harness.followups.length, 0)
150
+
151
+ const h2 = await booted()
152
+ h2.agent.status = 'running'
153
+ h2.agent.steer = () => { throw new Error('inbox 满了') }
154
+ const b2 = (await callRoute(h2, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
155
+ const r2 = await userEdit(h2, [{ title: '派发失败也要落盘' }], b2.revision)
156
+ assert.equal(r2.ok, true, '提醒失败绝不能连带让改板失败')
157
+ assert.equal(r2.items.some((i) => i.title === '派发失败也要落盘'), true)
158
+ assert.equal(h2.followups.length, 0, 'steer 抛错后不得退回 followup 补发(避免同一变更两条队列消息)')
159
+ })
160
+
161
+ test('提醒只占一条队列消息,不叠加催办也不接管滞后面板计时', async () => {
162
+ const harness = await booted()
163
+ for (let i = 0; i < 3; i += 1) harness.emit('step/start', {})
164
+ const before = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
165
+ assert.match(harness.contexts.get('progress-union-observer')(), /synced="3 步前"/)
166
+
167
+ const out = await userEdit(harness, [{ title: '用户插入一项' }], before.revision)
168
+ assert.equal(out.ok, true)
169
+ assert.equal(harness.followups.length, 1, '只那一条重大变更提醒,不得叠加自动催办')
170
+ assert.equal(harness.inbox.nextTurn.length, 1, '提醒之外不另起轮次')
171
+ // 用户写板本身把 stepsSinceModel 归零(origin='user' 算一次同步),提醒不能再额外减步
172
+ harness.emit('step/start', {})
173
+ assert.match(harness.contexts.get('progress-union-observer')(), /synced="1 步前"/)
174
+ })