dsh-progress-union 0.4.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 +157 -119
- package/LICENSE +21 -21
- package/README.md +201 -173
- package/anchor.js +39 -39
- package/client.js +2959 -2894
- package/cordis.patch.yml +4 -4
- package/docs/consumer-guide.md +210 -210
- 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 -3106
- 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 -54
- package/test/consumer.test.mjs +101 -101
- package/test/e2e.test.mjs +77 -77
- package/test/goal.test.mjs +110 -110
- package/test/harness.mjs +220 -216
- package/test/host.test.mjs +251 -184
- package/test/observer.test.mjs +170 -170
- package/test/plan.test.mjs +274 -0
- package/test/settings.test.mjs +81 -78
- package/test/stats.test.mjs +54 -54
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/consumer.test.mjs
CHANGED
|
@@ -1,101 +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
|
+
/**
|
|
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
|
+
})
|
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
|
+
})
|
package/test/goal.test.mjs
CHANGED
|
@@ -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
|
+
})
|