dsh-progress-union 0.6.3 → 0.7.0-rc.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/test/e2e.test.mjs CHANGED
@@ -1,77 +1,77 @@
1
- /**
2
- * Phase 5 端到端冒烟(task_22):建板 → 用户改 → 不 ack 读锚点 → ack 后再读 →
3
- * 时钟推进 12 分钟读 staleMin;另验 KV 缺席时锚点仍出且 persistent=false。
4
- */
5
- import assert from 'node:assert/strict'
6
- import fs from 'node:fs'
7
- import os from 'node:os'
8
- import path from 'node:path'
9
- import test from 'node:test'
10
-
11
- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
- const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
13
-
14
- function execUpdate(harness, args) {
15
- return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
16
- }
17
-
18
- test('端到端:建板→用户改→ack→陈旧推进,锚点各阶段状态正确迁移', async () => {
19
- const harness = createHarness()
20
- await harness.run()
21
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
22
- const anchor = () => harness.provided.get('progressAnchor').get(SESSION)
23
-
24
- // 阶段 0:启用但空板
25
- assert.equal(anchor().board.summary.total, 0)
26
- assert.match(harness.contexts.get('progress-union-kickoff')(), /第一个工具调用必须是 progress_update/)
27
-
28
- // 阶段 1:建板(3 项,1 doing)
29
- const added = await execUpdate(harness, {
30
- changes: [{ title: '抓帧', status: 'doing', current: '渲染第 1/900 帧' }, { title: '合成' }, { title: '字幕' }],
31
- })
32
- assert.equal(added.summary.total, 3)
33
- assert.equal(anchor().board.inFlight.length, 1)
34
- assert.equal(anchor().board.inFlight[0].title, '抓帧')
35
-
36
- // 阶段 2:用户面板改"合成"备注 → pending=1,userEdits 出现,时间戳推进
37
- const itemId = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().items[1].id
38
- await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: '用 4K' }] }))
39
- const pending = anchor()
40
- assert.equal(pending.board.pendingUserChanges, 1)
41
- assert.equal(pending.userEdits[0].fields[0].field, 'note')
42
- assert.ok(pending.revision > added.revision)
43
-
44
- // 阶段 3:agent ack → pending=0,锚点 revision 不因确认增长
45
- const acked = await execUpdate(harness, { changes: [], ackUserRevision: pending.revision })
46
- assert.equal(acked.revision, pending.revision)
47
- assert.equal(anchor().board.pendingUserChanges, 0)
48
- assert.equal(anchor().userEdits.length, 0)
49
-
50
- // 阶段 4:真实时钟推进 12 分钟无更新 → staleMin=12 且 kickoff 提醒复现
51
- const clock = withClock()
52
- try {
53
- clock.advance(12 * 60 * 1000)
54
- const later = harness.provided.get('progressAnchor').get(SESSION)
55
- assert.equal(later.time.staleMin, 12)
56
- assert.match(harness.contexts.get('progress-union-kickoff')(), /12 分钟没有更新/)
57
- } finally {
58
- clock.restore()
59
- }
60
-
61
- // 阶段 5:完成推进 → percent 迁移
62
- await execUpdate(harness, { changes: [{ id: added.changed[0].id, status: 'done' }] })
63
- const afterDone = anchor()
64
- assert.equal(afterDone.board.summary.done, 1)
65
- assert.equal(afterDone.board.summary.percent, 33) // (100+0+0)/3
66
- })
67
-
68
- test('KV 缺席:内存态可用,锚点照出且 persistent=false', async () => {
69
- const harness = createHarness({ storageless: true })
70
- await harness.run()
71
- await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
72
- await execUpdate(harness, { changes: [{ title: '仅内存', status: 'doing' }] })
73
- const anchor = harness.provided.get('progressAnchor').get(SESSION)
74
- assert.equal(anchor.persistent, false)
75
- assert.equal(anchor.board.summary.total, 1)
76
- assert.equal(anchor.board.inFlight[0].title, '仅内存')
77
- })
1
+ /**
2
+ * Phase 5 端到端冒烟(task_22):建板 → 用户改 → 不 ack 读锚点 → ack 后再读 →
3
+ * 时钟推进 12 分钟读 staleMin;另验 KV 缺席时锚点仍出且 persistent=false。
4
+ */
5
+ import assert from 'node:assert/strict'
6
+ import fs from 'node:fs'
7
+ import os from 'node:os'
8
+ import path from 'node:path'
9
+ import test from 'node:test'
10
+
11
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
+ const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
13
+
14
+ function execUpdate(harness, args) {
15
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
16
+ }
17
+
18
+ test('端到端:建板→用户改→ack→陈旧推进,锚点各阶段状态正确迁移', async () => {
19
+ const harness = createHarness()
20
+ await harness.run()
21
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
22
+ const anchor = () => harness.provided.get('progressAnchor').get(SESSION)
23
+
24
+ // 阶段 0:启用但空板
25
+ assert.equal(anchor().board.summary.total, 0)
26
+ assert.match(harness.contexts.get('progress-union-kickoff')(), /第一个工具调用必须是 progress_update/)
27
+
28
+ // 阶段 1:建板(3 项,1 doing)
29
+ const added = await execUpdate(harness, {
30
+ changes: [{ title: '抓帧', status: 'doing', current: '渲染第 1/900 帧' }, { title: '合成' }, { title: '字幕' }],
31
+ })
32
+ assert.equal(added.summary.total, 3)
33
+ assert.equal(anchor().board.inFlight.length, 1)
34
+ assert.equal(anchor().board.inFlight[0].title, '抓帧')
35
+
36
+ // 阶段 2:用户面板改"合成"备注 → pending=1,userEdits 出现,时间戳推进
37
+ const itemId = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().items[1].id
38
+ await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: '用 4K' }] }))
39
+ const pending = anchor()
40
+ assert.equal(pending.board.pendingUserChanges, 1)
41
+ assert.equal(pending.userEdits[0].fields[0].field, 'note')
42
+ assert.ok(pending.revision > added.revision)
43
+
44
+ // 阶段 3:agent ack → pending=0,锚点 revision 不因确认增长
45
+ const acked = await execUpdate(harness, { changes: [], ackUserRevision: pending.revision })
46
+ assert.equal(acked.revision, pending.revision)
47
+ assert.equal(anchor().board.pendingUserChanges, 0)
48
+ assert.equal(anchor().userEdits.length, 0)
49
+
50
+ // 阶段 4:真实时钟推进 12 分钟无更新 → staleMin=12 且 kickoff 提醒复现
51
+ const clock = withClock()
52
+ try {
53
+ clock.advance(12 * 60 * 1000)
54
+ const later = harness.provided.get('progressAnchor').get(SESSION)
55
+ assert.equal(later.time.staleMin, 12)
56
+ assert.match(harness.contexts.get('progress-union-kickoff')(), /12 分钟没有更新/)
57
+ } finally {
58
+ clock.restore()
59
+ }
60
+
61
+ // 阶段 5:完成推进 → percent 迁移
62
+ await execUpdate(harness, { changes: [{ id: added.changed[0].id, status: 'done' }] })
63
+ const afterDone = anchor()
64
+ assert.equal(afterDone.board.summary.done, 1)
65
+ assert.equal(afterDone.board.summary.percent, 33) // (100+0+0)/3
66
+ })
67
+
68
+ test('KV 缺席:内存态可用,锚点照出且 persistent=false', async () => {
69
+ const harness = createHarness({ storageless: true })
70
+ await harness.run()
71
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
72
+ await execUpdate(harness, { changes: [{ title: '仅内存', status: 'doing' }] })
73
+ const anchor = harness.provided.get('progressAnchor').get(SESSION)
74
+ assert.equal(anchor.persistent, false)
75
+ assert.equal(anchor.board.summary.total, 1)
76
+ assert.equal(anchor.board.inFlight[0].title, '仅内存')
77
+ })
@@ -176,23 +176,23 @@ test('重启自愈:armed 目标在会话重新挂载时自动补点火(无
176
176
  assert.equal(restarted.agent.followups[0].source.round, 2)
177
177
  })
178
178
 
179
- test('重启自愈:上一次进程遗留的排队轮次被清掉并重排(否则它既不跑又挡新轮)', async () => {
180
- const h = await booted()
181
- await update(h, [{ title: 't1', status: 'doing' }])
182
- await goalCmd(h, '目标S')
183
- const stranded = h.claim(h.agent.followups[0]) // 崩在「已排队、未执行」之间
184
-
185
- // 用同一份持久化记录重开宿主:attempt 空,但 inbox 里还留着上一轮
186
- const restarted = await booted({}, { seed: h.records })
187
- restarted.agent.inbox.nextTurn.push(stranded)
188
- await new Promise((resolve) => setTimeout(resolve, 2800))
189
-
190
- assert.equal(restarted.agent.followups.length, 1, '重启后必须重排一轮')
191
- assert.equal(restarted.agent.inbox.nextTurn.includes(stranded), false, '孤儿轮次必须被撤掉')
192
- assert.equal(restarted.agent.inbox.nextTurn.length, 1)
193
- assert.notEqual(restarted.agent.inbox.nextTurn[0].id, stranded.id)
194
- })
195
-
179
+ test('重启自愈:上一次进程遗留的排队轮次被清掉并重排(否则它既不跑又挡新轮)', async () => {
180
+ const h = await booted()
181
+ await update(h, [{ title: 't1', status: 'doing' }])
182
+ await goalCmd(h, '目标S')
183
+ const stranded = h.claim(h.agent.followups[0]) // 崩在「已排队、未执行」之间
184
+
185
+ // 用同一份持久化记录重开宿主:attempt 空,但 inbox 里还留着上一轮
186
+ const restarted = await booted({}, { seed: h.records })
187
+ restarted.agent.inbox.nextTurn.push(stranded)
188
+ await new Promise((resolve) => setTimeout(resolve, 2800))
189
+
190
+ assert.equal(restarted.agent.followups.length, 1, '重启后必须重排一轮')
191
+ assert.equal(restarted.agent.inbox.nextTurn.includes(stranded), false, '孤儿轮次必须被撤掉')
192
+ assert.equal(restarted.agent.inbox.nextTurn.length, 1)
193
+ assert.notEqual(restarted.agent.inbox.nextTurn[0].id, stranded.id)
194
+ })
195
+
196
196
  test('resume 接受 active:重新武装 + 点火', async () => {
197
197
  const h = await booted()
198
198
  await update(h, [{ title: 't1', status: 'doing' }])