dsh-progress-union 0.5.2 → 0.5.4
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 +47 -16
- package/LICENSE +21 -21
- package/README.md +220 -201
- package/anchor.js +39 -39
- package/client.js +3040 -2956
- 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 +3833 -3625
- package/package.json +77 -77
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +74 -58
- package/test/e2e.test.mjs +77 -77
- package/test/goal-control.test.mjs +147 -0
- package/test/goal-drive.test.mjs +130 -25
- package/test/goal.test.mjs +3 -2
- package/test/harness.mjs +249 -225
- 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/package.json
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-progress-union",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"registry": "https://registry.npmjs.org",
|
|
9
|
-
"access": "public",
|
|
10
|
-
"tag": "latest"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@deepseek-ai/schemastery": "~3.18.4"
|
|
14
|
-
},
|
|
15
|
-
"main": "./index.js",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": "./index.js",
|
|
18
|
-
"./client": "./client.js",
|
|
19
|
-
"./anchor": "./anchor.js",
|
|
20
|
-
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
21
|
-
"./package.json": "./package.json"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"README.md",
|
|
25
|
-
"LICENSE",
|
|
26
|
-
"index.js",
|
|
27
|
-
"anchor.js",
|
|
28
|
-
"client.js",
|
|
29
|
-
"cordis.patch.yml",
|
|
30
|
-
"dsh.plugin.json",
|
|
31
|
-
"icon.svg",
|
|
32
|
-
"docs/",
|
|
33
|
-
"test/",
|
|
34
|
-
"CHANGELOG.md"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"test": "node --test test/*.test.mjs"
|
|
38
|
-
},
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=22.19.0",
|
|
41
|
-
"dsh": ">=0.2.0-0 <0.3.0-0"
|
|
42
|
-
},
|
|
43
|
-
"dsh": {
|
|
44
|
-
"bundle": {
|
|
45
|
-
"patch": "./cordis.patch.yml"
|
|
46
|
-
},
|
|
47
|
-
"client": {
|
|
48
|
-
"platform": "web",
|
|
49
|
-
"immediately": true,
|
|
50
|
-
"inject": [
|
|
51
|
-
"@deepseek-ai/dsh-client-locale",
|
|
52
|
-
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
53
|
-
"@deepseek-ai/dsh-client-ui-layout",
|
|
54
|
-
"@deepseek-ai/dsh-client-ui-conversation",
|
|
55
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"keywords": [
|
|
60
|
-
"deepseek-harness",
|
|
61
|
-
"dsh",
|
|
62
|
-
"dsh-plugin",
|
|
63
|
-
"progress-board",
|
|
64
|
-
"progress-anchor",
|
|
65
|
-
"compaction",
|
|
66
|
-
"progress-tracking",
|
|
67
|
-
"eta"
|
|
68
|
-
],
|
|
69
|
-
"repository": {
|
|
70
|
-
"type": "git",
|
|
71
|
-
"url": "git+https://github.com/drscrewdriver/dsh-progress-union.git"
|
|
72
|
-
},
|
|
73
|
-
"homepage": "https://github.com/drscrewdriver/dsh-progress-union#readme",
|
|
74
|
-
"bugs": {
|
|
75
|
-
"url": "https://github.com/drscrewdriver/dsh-progress-union/issues"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-progress-union",
|
|
3
|
+
"version": "0.5.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org",
|
|
9
|
+
"access": "public",
|
|
10
|
+
"tag": "latest"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@deepseek-ai/schemastery": "~3.18.4"
|
|
14
|
+
},
|
|
15
|
+
"main": "./index.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./index.js",
|
|
18
|
+
"./client": "./client.js",
|
|
19
|
+
"./anchor": "./anchor.js",
|
|
20
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"index.js",
|
|
27
|
+
"anchor.js",
|
|
28
|
+
"client.js",
|
|
29
|
+
"cordis.patch.yml",
|
|
30
|
+
"dsh.plugin.json",
|
|
31
|
+
"icon.svg",
|
|
32
|
+
"docs/",
|
|
33
|
+
"test/",
|
|
34
|
+
"CHANGELOG.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "node --test test/*.test.mjs"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22.19.0",
|
|
41
|
+
"dsh": ">=0.2.0-0 <0.3.0-0"
|
|
42
|
+
},
|
|
43
|
+
"dsh": {
|
|
44
|
+
"bundle": {
|
|
45
|
+
"patch": "./cordis.patch.yml"
|
|
46
|
+
},
|
|
47
|
+
"client": {
|
|
48
|
+
"platform": "web",
|
|
49
|
+
"immediately": true,
|
|
50
|
+
"inject": [
|
|
51
|
+
"@deepseek-ai/dsh-client-locale",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
53
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
54
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
55
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"deepseek-harness",
|
|
61
|
+
"dsh",
|
|
62
|
+
"dsh-plugin",
|
|
63
|
+
"progress-board",
|
|
64
|
+
"progress-anchor",
|
|
65
|
+
"compaction",
|
|
66
|
+
"progress-tracking",
|
|
67
|
+
"eta"
|
|
68
|
+
],
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "git+https://github.com/drscrewdriver/dsh-progress-union.git"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/drscrewdriver/dsh-progress-union#readme",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/drscrewdriver/dsh-progress-union/issues"
|
|
76
|
+
}
|
|
77
|
+
}
|
package/test/anchor.test.mjs
CHANGED
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 3 验收:progressAnchor 锚点——schema 全集 / 双平面字节同形 / 同态 /
|
|
3
|
-
* rev 对账 / userEdits 硬约束可见 / projection 判脏。
|
|
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 } = await import('./harness.mjs')
|
|
13
|
-
|
|
14
|
-
async function booted() {
|
|
15
|
-
const harness = createHarness()
|
|
16
|
-
await harness.run()
|
|
17
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
18
|
-
return harness
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function execUpdate(harness, args) {
|
|
22
|
-
return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function anchorOf(harness, atMs) {
|
|
26
|
-
return harness.provided.get('progressAnchor').get(SESSION, atMs)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test('schema 全集:version=1 字段齐、类型对、slotTrail 预留为 null', async () => {
|
|
30
|
-
const harness = await booted()
|
|
31
|
-
await execUpdate(harness, { changes: [{ title: '甲', status: 'doing', current: '写代码', next: '测试' }] })
|
|
32
|
-
harness.emit('turn/start', {})
|
|
33
|
-
const anchor = anchorOf(harness)
|
|
34
|
-
assert.equal(anchor.version, 1)
|
|
35
|
-
assert.equal(anchor.sessionId, SESSION)
|
|
36
|
-
assert.equal(typeof anchor.revision, 'number')
|
|
37
|
-
assert.equal(typeof anchor.updatedAt, 'number')
|
|
38
|
-
assert.deepEqual(Object.keys(anchor.board).sort(), ['enabled', 'inFlight', 'pendingUserChanges', 'summary'])
|
|
39
|
-
assert.deepEqual(Object.keys(anchor.board.summary).sort(), ['blocked', 'doing', 'done', 'percent', 'todo', 'total'])
|
|
40
|
-
assert.deepEqual(Object.keys(anchor.board.inFlight[0]).sort(), ['current', 'id', 'next', 'percent', 'status', 'title'])
|
|
41
|
-
assert.deepEqual(Object.keys(anchor.time).sort(), ['elapsedSec', 'etaBasis', 'etaMin', 'etaP75Min', 'overMin', 'staleMin', 'startedAt', 'steps', 'todoDone', 'todoTotal'])
|
|
42
|
-
assert.equal(typeof anchor.persistent, 'boolean')
|
|
43
|
-
assert.equal(anchor.slotTrail, null)
|
|
44
|
-
assert.ok(Array.isArray(anchor.userEdits))
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('双平面字节同形 + 同态:同 (revision, now) service 与 HTTP 输出逐字节相等', async () => {
|
|
48
|
-
const harness = await booted()
|
|
49
|
-
await execUpdate(harness, { changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }] })
|
|
50
|
-
harness.emit('turn/start', {})
|
|
51
|
-
const started = anchorOf(harness).time.startedAt
|
|
52
|
-
const fixed = started + 45_000
|
|
53
|
-
|
|
54
|
-
const viaService = JSON.stringify(anchorOf(harness, fixed))
|
|
55
|
-
const again = JSON.stringify(anchorOf(harness, fixed))
|
|
56
|
-
assert.equal(viaService, again, '同 now 两次读取必须同字节(同态)')
|
|
57
|
-
|
|
58
|
-
const res = await callRoute(harness, '/progress-union/anchor', {
|
|
59
|
-
method: 'GET',
|
|
60
|
-
url: `/progress-union/anchor?sessionId=${SESSION}&now=${fixed}`,
|
|
61
|
-
headers: {},
|
|
62
|
-
})
|
|
63
|
-
assert.equal(res.status, 200)
|
|
64
|
-
assert.equal(JSON.stringify(res.json().anchor), viaService, 'HTTP 与 service 双平面同形')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('rev 对账:历史 progress_update 返回 rev < 当前锚点 rev ⇒ 该段已兑现可剪', async () => {
|
|
68
|
-
const harness = await booted()
|
|
69
|
-
const first = await execUpdate(harness, { changes: [{ title: '步骤一' }] })
|
|
70
|
-
const second = await execUpdate(harness, { changes: [{ id: first.changed[0].id, status: 'done' }] })
|
|
71
|
-
const anchor = anchorOf(harness)
|
|
72
|
-
assert.equal(anchor.revision, second.revision)
|
|
73
|
-
assert.ok(first.revision < anchor.revision, '第一段工具返回 rev 已被锚点覆盖(可安全剪)')
|
|
74
|
-
assert.ok(second.changed.length >= 1)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
test('userEdits 硬约束:pending>0 必出条目;超 20 条封顶;长值压缩 240+…', async () => {
|
|
78
|
-
const harness = await booted()
|
|
79
|
-
const added = await execUpdate(harness, { changes: [{ title: '任务', approach: 'x'.repeat(600) }] })
|
|
80
|
-
const itemId = added.changed[0].id
|
|
81
|
-
for (let i = 0; i < 25; i++) {
|
|
82
|
-
await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: `改动 ${i}` }] }))
|
|
83
|
-
}
|
|
84
|
-
const anchor = anchorOf(harness)
|
|
85
|
-
assert.equal(anchor.board.pendingUserChanges, 25)
|
|
86
|
-
assert.equal(anchor.userEdits.length, 20, '注入体积有界(最近 20 条)')
|
|
87
|
-
assert.equal(anchor.userEdits[anchor.userEdits.length - 1].kind, 'edit')
|
|
88
|
-
const longField = anchor.userEdits.flatMap((e) => e.fields).find((f) => typeof f.to === 'string' && f.to.length > 200)
|
|
89
|
-
assert.equal(longField, undefined, 'userEdits 只含用户改动;agent 建立的长 approach 不在其中')
|
|
90
|
-
|
|
91
|
-
// ack 后清空
|
|
92
|
-
await execUpdate(harness, { changes: [], ackUserRevision: anchor.revision })
|
|
93
|
-
const after = anchorOf(harness)
|
|
94
|
-
assert.equal(after.board.pendingUserChanges, 0)
|
|
95
|
-
assert.equal(after.userEdits.length, 0)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test('空会话锚点:revision=0、board 关闭、etaBasis=none、userEdits 空', () => {
|
|
99
|
-
const fresh = createHarness()
|
|
100
|
-
return fresh.run().then(() => {
|
|
101
|
-
const anchor = fresh.provided.get('progressAnchor').get('session-nope')
|
|
102
|
-
assert.equal(anchor.revision, 0)
|
|
103
|
-
assert.equal(anchor.board.enabled, false)
|
|
104
|
-
assert.equal(anchor.board.summary.total, 0)
|
|
105
|
-
assert.equal(anchor.time.etaBasis, 'none')
|
|
106
|
-
assert.deepEqual(anchor.board.inFlight, [])
|
|
107
|
-
assert.deepEqual(anchor.userEdits, [])
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('projection progressAnchor:注册、init 形状、未变同引用、板写后重建', async () => {
|
|
112
|
-
const harness = await booted()
|
|
113
|
-
const proj = harness.projections.get('progressAnchor')
|
|
114
|
-
assert.ok(proj, 'sessionProjections 可得时必须注册 progressAnchor')
|
|
115
|
-
const state0 = proj.init()
|
|
116
|
-
assert.equal(state0.version, 1)
|
|
117
|
-
assert.ok(state0.sessions.some((s) => s.sessionId === SESSION && s.enabled === true))
|
|
118
|
-
|
|
119
|
-
const state1 = proj.apply(state0, { type: 'user/message', data: {} })
|
|
120
|
-
assert.equal(state1, state0, 'agg 未变必须返回同引用(不 republish)')
|
|
121
|
-
|
|
122
|
-
await execUpdate(harness, { changes: [{ title: '新任务', status: 'doing' }] })
|
|
123
|
-
const state2 = proj.apply(state1, { type: 'tool/result', data: {} })
|
|
124
|
-
assert.notEqual(state2, state1, '板写入后 agg 变,必须重建')
|
|
125
|
-
const row = state2.sessions.find((s) => s.sessionId === SESSION)
|
|
126
|
-
assert.equal(row.revision, 1)
|
|
127
|
-
assert.equal(row.summary.doing, 1)
|
|
128
|
-
assert.doesNotThrow(() => proj.stateSchema.parse(state2))
|
|
129
|
-
assert.doesNotThrow(() => proj.wire.viewSchema.parse(state2))
|
|
130
|
-
assert.throws(() => proj.stateSchema.parse({ version: 1, agg: 'bad', sessions: [] }))
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test('list() 面:多会话聚合可用', async () => {
|
|
134
|
-
const harness = await booted()
|
|
135
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: 'session-other', active: true, source: 'command' }))
|
|
136
|
-
const list = harness.provided.get('progressAnchor').list(Date.now())
|
|
137
|
-
assert.ok(Array.isArray(list))
|
|
138
|
-
assert.deepEqual(list.map((a) => a.sessionId).sort(), [SESSION, 'session-other'].sort())
|
|
139
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* Phase 3 验收:progressAnchor 锚点——schema 全集 / 双平面字节同形 / 同态 /
|
|
3
|
+
* rev 对账 / userEdits 硬约束可见 / projection 判脏。
|
|
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 } = await import('./harness.mjs')
|
|
13
|
+
|
|
14
|
+
async function booted() {
|
|
15
|
+
const harness = createHarness()
|
|
16
|
+
await harness.run()
|
|
17
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
18
|
+
return harness
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function execUpdate(harness, args) {
|
|
22
|
+
return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function anchorOf(harness, atMs) {
|
|
26
|
+
return harness.provided.get('progressAnchor').get(SESSION, atMs)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('schema 全集:version=1 字段齐、类型对、slotTrail 预留为 null', async () => {
|
|
30
|
+
const harness = await booted()
|
|
31
|
+
await execUpdate(harness, { changes: [{ title: '甲', status: 'doing', current: '写代码', next: '测试' }] })
|
|
32
|
+
harness.emit('turn/start', {})
|
|
33
|
+
const anchor = anchorOf(harness)
|
|
34
|
+
assert.equal(anchor.version, 1)
|
|
35
|
+
assert.equal(anchor.sessionId, SESSION)
|
|
36
|
+
assert.equal(typeof anchor.revision, 'number')
|
|
37
|
+
assert.equal(typeof anchor.updatedAt, 'number')
|
|
38
|
+
assert.deepEqual(Object.keys(anchor.board).sort(), ['enabled', 'inFlight', 'pendingUserChanges', 'summary'])
|
|
39
|
+
assert.deepEqual(Object.keys(anchor.board.summary).sort(), ['blocked', 'doing', 'done', 'percent', 'todo', 'total'])
|
|
40
|
+
assert.deepEqual(Object.keys(anchor.board.inFlight[0]).sort(), ['current', 'id', 'next', 'percent', 'status', 'title'])
|
|
41
|
+
assert.deepEqual(Object.keys(anchor.time).sort(), ['elapsedSec', 'etaBasis', 'etaMin', 'etaP75Min', 'overMin', 'staleMin', 'startedAt', 'steps', 'todoDone', 'todoTotal'])
|
|
42
|
+
assert.equal(typeof anchor.persistent, 'boolean')
|
|
43
|
+
assert.equal(anchor.slotTrail, null)
|
|
44
|
+
assert.ok(Array.isArray(anchor.userEdits))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('双平面字节同形 + 同态:同 (revision, now) service 与 HTTP 输出逐字节相等', async () => {
|
|
48
|
+
const harness = await booted()
|
|
49
|
+
await execUpdate(harness, { changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }] })
|
|
50
|
+
harness.emit('turn/start', {})
|
|
51
|
+
const started = anchorOf(harness).time.startedAt
|
|
52
|
+
const fixed = started + 45_000
|
|
53
|
+
|
|
54
|
+
const viaService = JSON.stringify(anchorOf(harness, fixed))
|
|
55
|
+
const again = JSON.stringify(anchorOf(harness, fixed))
|
|
56
|
+
assert.equal(viaService, again, '同 now 两次读取必须同字节(同态)')
|
|
57
|
+
|
|
58
|
+
const res = await callRoute(harness, '/progress-union/anchor', {
|
|
59
|
+
method: 'GET',
|
|
60
|
+
url: `/progress-union/anchor?sessionId=${SESSION}&now=${fixed}`,
|
|
61
|
+
headers: {},
|
|
62
|
+
})
|
|
63
|
+
assert.equal(res.status, 200)
|
|
64
|
+
assert.equal(JSON.stringify(res.json().anchor), viaService, 'HTTP 与 service 双平面同形')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('rev 对账:历史 progress_update 返回 rev < 当前锚点 rev ⇒ 该段已兑现可剪', async () => {
|
|
68
|
+
const harness = await booted()
|
|
69
|
+
const first = await execUpdate(harness, { changes: [{ title: '步骤一' }] })
|
|
70
|
+
const second = await execUpdate(harness, { changes: [{ id: first.changed[0].id, status: 'done' }] })
|
|
71
|
+
const anchor = anchorOf(harness)
|
|
72
|
+
assert.equal(anchor.revision, second.revision)
|
|
73
|
+
assert.ok(first.revision < anchor.revision, '第一段工具返回 rev 已被锚点覆盖(可安全剪)')
|
|
74
|
+
assert.ok(second.changed.length >= 1)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('userEdits 硬约束:pending>0 必出条目;超 20 条封顶;长值压缩 240+…', async () => {
|
|
78
|
+
const harness = await booted()
|
|
79
|
+
const added = await execUpdate(harness, { changes: [{ title: '任务', approach: 'x'.repeat(600) }] })
|
|
80
|
+
const itemId = added.changed[0].id
|
|
81
|
+
for (let i = 0; i < 25; i++) {
|
|
82
|
+
await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: `改动 ${i}` }] }))
|
|
83
|
+
}
|
|
84
|
+
const anchor = anchorOf(harness)
|
|
85
|
+
assert.equal(anchor.board.pendingUserChanges, 25)
|
|
86
|
+
assert.equal(anchor.userEdits.length, 20, '注入体积有界(最近 20 条)')
|
|
87
|
+
assert.equal(anchor.userEdits[anchor.userEdits.length - 1].kind, 'edit')
|
|
88
|
+
const longField = anchor.userEdits.flatMap((e) => e.fields).find((f) => typeof f.to === 'string' && f.to.length > 200)
|
|
89
|
+
assert.equal(longField, undefined, 'userEdits 只含用户改动;agent 建立的长 approach 不在其中')
|
|
90
|
+
|
|
91
|
+
// ack 后清空
|
|
92
|
+
await execUpdate(harness, { changes: [], ackUserRevision: anchor.revision })
|
|
93
|
+
const after = anchorOf(harness)
|
|
94
|
+
assert.equal(after.board.pendingUserChanges, 0)
|
|
95
|
+
assert.equal(after.userEdits.length, 0)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('空会话锚点:revision=0、board 关闭、etaBasis=none、userEdits 空', () => {
|
|
99
|
+
const fresh = createHarness()
|
|
100
|
+
return fresh.run().then(() => {
|
|
101
|
+
const anchor = fresh.provided.get('progressAnchor').get('session-nope')
|
|
102
|
+
assert.equal(anchor.revision, 0)
|
|
103
|
+
assert.equal(anchor.board.enabled, false)
|
|
104
|
+
assert.equal(anchor.board.summary.total, 0)
|
|
105
|
+
assert.equal(anchor.time.etaBasis, 'none')
|
|
106
|
+
assert.deepEqual(anchor.board.inFlight, [])
|
|
107
|
+
assert.deepEqual(anchor.userEdits, [])
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('projection progressAnchor:注册、init 形状、未变同引用、板写后重建', async () => {
|
|
112
|
+
const harness = await booted()
|
|
113
|
+
const proj = harness.projections.get('progressAnchor')
|
|
114
|
+
assert.ok(proj, 'sessionProjections 可得时必须注册 progressAnchor')
|
|
115
|
+
const state0 = proj.init()
|
|
116
|
+
assert.equal(state0.version, 1)
|
|
117
|
+
assert.ok(state0.sessions.some((s) => s.sessionId === SESSION && s.enabled === true))
|
|
118
|
+
|
|
119
|
+
const state1 = proj.apply(state0, { type: 'user/message', data: {} })
|
|
120
|
+
assert.equal(state1, state0, 'agg 未变必须返回同引用(不 republish)')
|
|
121
|
+
|
|
122
|
+
await execUpdate(harness, { changes: [{ title: '新任务', status: 'doing' }] })
|
|
123
|
+
const state2 = proj.apply(state1, { type: 'tool/result', data: {} })
|
|
124
|
+
assert.notEqual(state2, state1, '板写入后 agg 变,必须重建')
|
|
125
|
+
const row = state2.sessions.find((s) => s.sessionId === SESSION)
|
|
126
|
+
assert.equal(row.revision, 1)
|
|
127
|
+
assert.equal(row.summary.doing, 1)
|
|
128
|
+
assert.doesNotThrow(() => proj.stateSchema.parse(state2))
|
|
129
|
+
assert.doesNotThrow(() => proj.wire.viewSchema.parse(state2))
|
|
130
|
+
assert.throws(() => proj.stateSchema.parse({ version: 1, agg: 'bad', sessions: [] }))
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('list() 面:多会话聚合可用', async () => {
|
|
134
|
+
const harness = await booted()
|
|
135
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: 'session-other', active: true, source: 'command' }))
|
|
136
|
+
const list = harness.provided.get('progressAnchor').list(Date.now())
|
|
137
|
+
assert.ok(Array.isArray(list))
|
|
138
|
+
assert.deepEqual(list.map((a) => a.sessionId).sort(), [SESSION, 'session-other'].sort())
|
|
139
|
+
})
|