dsh-progress-union 0.6.1 → 0.6.2
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 +363 -340
- package/LICENSE +21 -21
- package/README.md +282 -272
- package/anchor.js +39 -39
- package/client.js +2990 -2973
- 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/icon.svg +7 -7
- package/index.js +4568 -4466
- package/package.json +79 -79
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +181 -172
- package/test/e2e.test.mjs +77 -77
- package/test/goal-drive.test.mjs +17 -17
- package/test/harness.mjs +249 -249
- package/test/host.test.mjs +251 -251
- package/test/observer.test.mjs +170 -170
- package/test/restore-hydrate.test.mjs +185 -0
- package/test/settings.test.mjs +81 -81
- package/test/star-panel.test.mjs +181 -181
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/observer.test.mjs
CHANGED
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 7 验收:观察者(辅助观察最近输出/清单;板滞后及时补与催办)。
|
|
3
|
-
*/
|
|
4
|
-
import assert from 'node:assert/strict'
|
|
5
|
-
import fs from 'node:fs'
|
|
6
|
-
import os from 'node:os'
|
|
7
|
-
import path from 'node:path'
|
|
8
|
-
import test from 'node:test'
|
|
9
|
-
|
|
10
|
-
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
11
|
-
const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
|
|
12
|
-
|
|
13
|
-
async function booted() {
|
|
14
|
-
const harness = createHarness()
|
|
15
|
-
await harness.run()
|
|
16
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
17
|
-
return harness
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function execUpdate(harness, args) {
|
|
21
|
-
return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function observerText(harness) {
|
|
25
|
-
const fn = harness.contexts.get('progress-union-observer')
|
|
26
|
-
assert.ok(fn, 'progress-union-observer 上下文必须注册')
|
|
27
|
-
return fn()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
test('观察块:清单标记 + 最近输出 + 最近动作 + 官方 todo 行', async () => {
|
|
31
|
-
const harness = await booted()
|
|
32
|
-
await execUpdate(harness, {
|
|
33
|
-
changes: [
|
|
34
|
-
{ title: '接口改造', status: 'done' },
|
|
35
|
-
{ title: '补集成测试', status: 'doing', current: '写 observer 用例', next: '跑全量' },
|
|
36
|
-
{ title: '发版', status: 'todo' },
|
|
37
|
-
],
|
|
38
|
-
})
|
|
39
|
-
harness.emit('assistant/message', { message: { content: [{ type: 'text', text: '接口改造已完成,接下来补测试。' }] } })
|
|
40
|
-
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
|
|
41
|
-
harness.emit('todo/write', { todos: [
|
|
42
|
-
{ content: '接口改造', status: 'completed' },
|
|
43
|
-
{ content: '补集成测试', status: 'in_progress' },
|
|
44
|
-
{ content: '发版', status: 'pending' },
|
|
45
|
-
] })
|
|
46
|
-
|
|
47
|
-
const text = observerText(harness)
|
|
48
|
-
assert.match(text, /<progress-observer revision="1"/)
|
|
49
|
-
assert.match(text, /\[x\] 接口改造/)
|
|
50
|
-
assert.match(text, /\[~\] 补集成测试(0%) · 当前:写 observer 用例 · 下一步:跑全量/)
|
|
51
|
-
assert.match(text, /\[ \] 发版/)
|
|
52
|
-
assert.match(text, /最近输出:「接口改造已完成,接下来补测试。/)
|
|
53
|
-
assert.match(text, /最近动作:Bash/)
|
|
54
|
-
assert.match(text, /\[官方todo\] 完成 1\/3,未完:补集成测试、发版/)
|
|
55
|
-
assert.doesNotMatch(text, /滞后/, '未超阈值不得催办')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('滞后刚需:超 N 步未写板 → 催办出现;模型写板后消失', async () => {
|
|
59
|
-
const harness = await booted()
|
|
60
|
-
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'doing' }] })
|
|
61
|
-
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
62
|
-
const text = observerText(harness)
|
|
63
|
-
assert.match(text, /⚠ 进度已滞后(6 步前)/)
|
|
64
|
-
assert.match(text, /先调用 progress_update 同步再继续/)
|
|
65
|
-
|
|
66
|
-
// 模型自己同步(无变化确认也算)→ 催办消失
|
|
67
|
-
await execUpdate(harness, { changes: [] })
|
|
68
|
-
assert.doesNotMatch(observerText(harness), /滞后/)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('观察者自动补 current:事实性最近动作写入 doing 项(updatedBy=observer),不抵消催办', async () => {
|
|
72
|
-
const harness = await booted()
|
|
73
|
-
const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
|
|
74
|
-
const itemId = added.changed[0].id
|
|
75
|
-
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render --frames 900' }) })
|
|
76
|
-
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
77
|
-
await flush()
|
|
78
|
-
|
|
79
|
-
const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
|
|
80
|
-
const item = snap.items.find((x) => x.id === itemId)
|
|
81
|
-
assert.match(item.current, /^自动同步:Bash · command=render --frames 900/)
|
|
82
|
-
assert.equal(item.updatedBy, 'observer')
|
|
83
|
-
assert.equal(item.status, 'doing', '观察者不得改状态')
|
|
84
|
-
assert.ok(snap.revision >= 2)
|
|
85
|
-
|
|
86
|
-
// 自动补不重置\"模型同步\"计数:催办仍在(状态/百分比仍需模型确认)
|
|
87
|
-
assert.match(observerText(harness), /⚠ 进度已滞后/)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('progress_update 拉通道:返回 inFlight 明细 + time 字段', async () => {
|
|
91
|
-
const harness = await booted()
|
|
92
|
-
const r = await execUpdate(harness, {
|
|
93
|
-
changes: [
|
|
94
|
-
{ title: '甲', status: 'done' },
|
|
95
|
-
{ title: '乙', status: 'doing', current: '做乙', next: '做丙' },
|
|
96
|
-
{ title: '丙', status: 'blocked', note: '等确认' },
|
|
97
|
-
],
|
|
98
|
-
})
|
|
99
|
-
assert.equal(r.inFlight.length, 2)
|
|
100
|
-
assert.deepEqual(r.inFlight.map((x) => x.status), ['doing', 'blocked'])
|
|
101
|
-
assert.equal(typeof r.time.etaBasis, 'string')
|
|
102
|
-
assert.equal(typeof r.time.steps, 'number')
|
|
103
|
-
assert.equal(typeof r.time.staleMin, 'number')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('最近改动:带路径的工具调用入块,同路径去重、只留最近 4 个', async () => {
|
|
107
|
-
const harness = await booted()
|
|
108
|
-
await execUpdate(harness, { changes: [{ title: '改代码', status: 'doing' }] })
|
|
109
|
-
const call = (file, tool = 'Edit') => harness.emit('tool/call', { name: tool, arguments: JSON.stringify({ file_path: file }) })
|
|
110
|
-
call('E:\\proj\\src\\a.ts')
|
|
111
|
-
call('E:\\proj\\src\\b.ts', 'Write')
|
|
112
|
-
call('E:\\proj\\src\\a.ts') // 同路径去重,留最新
|
|
113
|
-
call('E:\\proj\\src\\c.ts')
|
|
114
|
-
call('E:\\proj\\src\\d.ts')
|
|
115
|
-
call('E:\\proj\\src\\e.ts')
|
|
116
|
-
|
|
117
|
-
const text = observerText(harness)
|
|
118
|
-
const line = text.split('\n').find((l) => l.startsWith('最近改动:'))
|
|
119
|
-
assert.ok(line, '最近改动行必须存在')
|
|
120
|
-
assert.equal((line.match(/(/g) || []).length, 4, '最多 4 条')
|
|
121
|
-
assert.doesNotMatch(line, /b\.ts/, '被后 4 条挤出(上限保留最近)')
|
|
122
|
-
assert.match(line, /a\.ts(Edit)/, '同路径重写后保留最新一条')
|
|
123
|
-
assert.equal((line.match(/a\.ts/g) || []).length, 1, '同路径只出现一次(去重)')
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
test('清单对比:todo 与板完成数漂移才出对比行(算术,非语义)', async () => {
|
|
127
|
-
const harness = await booted()
|
|
128
|
-
await execUpdate(harness, {
|
|
129
|
-
changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }, { title: '丙', status: 'todo' }],
|
|
130
|
-
})
|
|
131
|
-
harness.emit('todo/write', { todos: [
|
|
132
|
-
{ content: '甲', status: 'completed' },
|
|
133
|
-
{ content: '乙', status: 'completed' },
|
|
134
|
-
{ content: '丙', status: 'pending' },
|
|
135
|
-
] })
|
|
136
|
-
const drifted = observerText(harness)
|
|
137
|
-
assert.match(drifted, /对比:官方 todo 完成 2\/3 · 板完成 1\/3(进度不一致/)
|
|
138
|
-
|
|
139
|
-
// 对齐后不再出对比行
|
|
140
|
-
await execUpdate(harness, { changes: [{ title: '乙', status: 'done' }] })
|
|
141
|
-
assert.doesNotMatch(observerText(harness), /对比:/)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('观察者自补的 current 在块里标注待确认', async () => {
|
|
145
|
-
const harness = await booted()
|
|
146
|
-
await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
|
|
147
|
-
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render' }) })
|
|
148
|
-
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
149
|
-
await flush()
|
|
150
|
-
assert.match(observerText(harness), /当前:自动同步:Bash · command=render(观察者补,待确认)/)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
test('门控:关板/全完成/空板时观察块为空(0 token)', async () => {
|
|
154
|
-
const harness = createHarness()
|
|
155
|
-
await harness.run()
|
|
156
|
-
assert.equal(observerText(harness), '', '未启用不得注入')
|
|
157
|
-
|
|
158
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
159
|
-
assert.equal(observerText(harness), '', '空板不注入(kickoff 负责)')
|
|
160
|
-
|
|
161
|
-
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
|
|
162
|
-
assert.equal(observerText(harness), '', '全完成不打扰')
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
test('可关:observer.enabled=false 时零注入', async () => {
|
|
166
|
-
const harness = createHarness({ config: { observer: { enabled: false } } })
|
|
167
|
-
await harness.run()
|
|
168
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
169
|
-
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
|
|
170
|
-
assert.equal(observerText(harness), '')
|
|
1
|
+
/**
|
|
2
|
+
* Phase 7 验收:观察者(辅助观察最近输出/清单;板滞后及时补与催办)。
|
|
3
|
+
*/
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import test from 'node:test'
|
|
9
|
+
|
|
10
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
11
|
+
const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
|
|
12
|
+
|
|
13
|
+
async function booted() {
|
|
14
|
+
const harness = createHarness()
|
|
15
|
+
await harness.run()
|
|
16
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
17
|
+
return harness
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function execUpdate(harness, args) {
|
|
21
|
+
return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function observerText(harness) {
|
|
25
|
+
const fn = harness.contexts.get('progress-union-observer')
|
|
26
|
+
assert.ok(fn, 'progress-union-observer 上下文必须注册')
|
|
27
|
+
return fn()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test('观察块:清单标记 + 最近输出 + 最近动作 + 官方 todo 行', async () => {
|
|
31
|
+
const harness = await booted()
|
|
32
|
+
await execUpdate(harness, {
|
|
33
|
+
changes: [
|
|
34
|
+
{ title: '接口改造', status: 'done' },
|
|
35
|
+
{ title: '补集成测试', status: 'doing', current: '写 observer 用例', next: '跑全量' },
|
|
36
|
+
{ title: '发版', status: 'todo' },
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
harness.emit('assistant/message', { message: { content: [{ type: 'text', text: '接口改造已完成,接下来补测试。' }] } })
|
|
40
|
+
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
|
|
41
|
+
harness.emit('todo/write', { todos: [
|
|
42
|
+
{ content: '接口改造', status: 'completed' },
|
|
43
|
+
{ content: '补集成测试', status: 'in_progress' },
|
|
44
|
+
{ content: '发版', status: 'pending' },
|
|
45
|
+
] })
|
|
46
|
+
|
|
47
|
+
const text = observerText(harness)
|
|
48
|
+
assert.match(text, /<progress-observer revision="1"/)
|
|
49
|
+
assert.match(text, /\[x\] 接口改造/)
|
|
50
|
+
assert.match(text, /\[~\] 补集成测试(0%) · 当前:写 observer 用例 · 下一步:跑全量/)
|
|
51
|
+
assert.match(text, /\[ \] 发版/)
|
|
52
|
+
assert.match(text, /最近输出:「接口改造已完成,接下来补测试。/)
|
|
53
|
+
assert.match(text, /最近动作:Bash/)
|
|
54
|
+
assert.match(text, /\[官方todo\] 完成 1\/3,未完:补集成测试、发版/)
|
|
55
|
+
assert.doesNotMatch(text, /滞后/, '未超阈值不得催办')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('滞后刚需:超 N 步未写板 → 催办出现;模型写板后消失', async () => {
|
|
59
|
+
const harness = await booted()
|
|
60
|
+
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'doing' }] })
|
|
61
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
62
|
+
const text = observerText(harness)
|
|
63
|
+
assert.match(text, /⚠ 进度已滞后(6 步前)/)
|
|
64
|
+
assert.match(text, /先调用 progress_update 同步再继续/)
|
|
65
|
+
|
|
66
|
+
// 模型自己同步(无变化确认也算)→ 催办消失
|
|
67
|
+
await execUpdate(harness, { changes: [] })
|
|
68
|
+
assert.doesNotMatch(observerText(harness), /滞后/)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('观察者自动补 current:事实性最近动作写入 doing 项(updatedBy=observer),不抵消催办', async () => {
|
|
72
|
+
const harness = await booted()
|
|
73
|
+
const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
|
|
74
|
+
const itemId = added.changed[0].id
|
|
75
|
+
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render --frames 900' }) })
|
|
76
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
77
|
+
await flush()
|
|
78
|
+
|
|
79
|
+
const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
|
|
80
|
+
const item = snap.items.find((x) => x.id === itemId)
|
|
81
|
+
assert.match(item.current, /^自动同步:Bash · command=render --frames 900/)
|
|
82
|
+
assert.equal(item.updatedBy, 'observer')
|
|
83
|
+
assert.equal(item.status, 'doing', '观察者不得改状态')
|
|
84
|
+
assert.ok(snap.revision >= 2)
|
|
85
|
+
|
|
86
|
+
// 自动补不重置\"模型同步\"计数:催办仍在(状态/百分比仍需模型确认)
|
|
87
|
+
assert.match(observerText(harness), /⚠ 进度已滞后/)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('progress_update 拉通道:返回 inFlight 明细 + time 字段', async () => {
|
|
91
|
+
const harness = await booted()
|
|
92
|
+
const r = await execUpdate(harness, {
|
|
93
|
+
changes: [
|
|
94
|
+
{ title: '甲', status: 'done' },
|
|
95
|
+
{ title: '乙', status: 'doing', current: '做乙', next: '做丙' },
|
|
96
|
+
{ title: '丙', status: 'blocked', note: '等确认' },
|
|
97
|
+
],
|
|
98
|
+
})
|
|
99
|
+
assert.equal(r.inFlight.length, 2)
|
|
100
|
+
assert.deepEqual(r.inFlight.map((x) => x.status), ['doing', 'blocked'])
|
|
101
|
+
assert.equal(typeof r.time.etaBasis, 'string')
|
|
102
|
+
assert.equal(typeof r.time.steps, 'number')
|
|
103
|
+
assert.equal(typeof r.time.staleMin, 'number')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('最近改动:带路径的工具调用入块,同路径去重、只留最近 4 个', async () => {
|
|
107
|
+
const harness = await booted()
|
|
108
|
+
await execUpdate(harness, { changes: [{ title: '改代码', status: 'doing' }] })
|
|
109
|
+
const call = (file, tool = 'Edit') => harness.emit('tool/call', { name: tool, arguments: JSON.stringify({ file_path: file }) })
|
|
110
|
+
call('E:\\proj\\src\\a.ts')
|
|
111
|
+
call('E:\\proj\\src\\b.ts', 'Write')
|
|
112
|
+
call('E:\\proj\\src\\a.ts') // 同路径去重,留最新
|
|
113
|
+
call('E:\\proj\\src\\c.ts')
|
|
114
|
+
call('E:\\proj\\src\\d.ts')
|
|
115
|
+
call('E:\\proj\\src\\e.ts')
|
|
116
|
+
|
|
117
|
+
const text = observerText(harness)
|
|
118
|
+
const line = text.split('\n').find((l) => l.startsWith('最近改动:'))
|
|
119
|
+
assert.ok(line, '最近改动行必须存在')
|
|
120
|
+
assert.equal((line.match(/(/g) || []).length, 4, '最多 4 条')
|
|
121
|
+
assert.doesNotMatch(line, /b\.ts/, '被后 4 条挤出(上限保留最近)')
|
|
122
|
+
assert.match(line, /a\.ts(Edit)/, '同路径重写后保留最新一条')
|
|
123
|
+
assert.equal((line.match(/a\.ts/g) || []).length, 1, '同路径只出现一次(去重)')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('清单对比:todo 与板完成数漂移才出对比行(算术,非语义)', async () => {
|
|
127
|
+
const harness = await booted()
|
|
128
|
+
await execUpdate(harness, {
|
|
129
|
+
changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }, { title: '丙', status: 'todo' }],
|
|
130
|
+
})
|
|
131
|
+
harness.emit('todo/write', { todos: [
|
|
132
|
+
{ content: '甲', status: 'completed' },
|
|
133
|
+
{ content: '乙', status: 'completed' },
|
|
134
|
+
{ content: '丙', status: 'pending' },
|
|
135
|
+
] })
|
|
136
|
+
const drifted = observerText(harness)
|
|
137
|
+
assert.match(drifted, /对比:官方 todo 完成 2\/3 · 板完成 1\/3(进度不一致/)
|
|
138
|
+
|
|
139
|
+
// 对齐后不再出对比行
|
|
140
|
+
await execUpdate(harness, { changes: [{ title: '乙', status: 'done' }] })
|
|
141
|
+
assert.doesNotMatch(observerText(harness), /对比:/)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('观察者自补的 current 在块里标注待确认', async () => {
|
|
145
|
+
const harness = await booted()
|
|
146
|
+
await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', current: '热身' }] })
|
|
147
|
+
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'render' }) })
|
|
148
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
149
|
+
await flush()
|
|
150
|
+
assert.match(observerText(harness), /当前:自动同步:Bash · command=render(观察者补,待确认)/)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('门控:关板/全完成/空板时观察块为空(0 token)', async () => {
|
|
154
|
+
const harness = createHarness()
|
|
155
|
+
await harness.run()
|
|
156
|
+
assert.equal(observerText(harness), '', '未启用不得注入')
|
|
157
|
+
|
|
158
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
159
|
+
assert.equal(observerText(harness), '', '空板不注入(kickoff 负责)')
|
|
160
|
+
|
|
161
|
+
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
|
|
162
|
+
assert.equal(observerText(harness), '', '全完成不打扰')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('可关:observer.enabled=false 时零注入', async () => {
|
|
166
|
+
const harness = createHarness({ config: { observer: { enabled: false } } })
|
|
167
|
+
await harness.run()
|
|
168
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
169
|
+
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
|
|
170
|
+
assert.equal(observerText(harness), '')
|
|
171
171
|
})
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.6.2 验收(R1/R2):冷启动从会话归档回灌板。
|
|
3
|
+
* 全部用 archive.js 写盘 + harness 的空 seed / 老 seed 模拟「KV 丢失」「KV 落后于归档」,
|
|
4
|
+
* 不起真宿主;每条都可独立复现。
|
|
5
|
+
*/
|
|
6
|
+
import assert from 'node:assert/strict'
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import os from 'node:os'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import test from 'node:test'
|
|
11
|
+
|
|
12
|
+
// index.js 模块求值时即读 DSH_HOME,必须先钉死再动态引入。
|
|
13
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-hydrate-home-'))
|
|
14
|
+
const { archiveDir, writeArchiveVersion, readIndex, archiveVersionPath } = await import('../archive.js')
|
|
15
|
+
const { SESSION, createHarness, callRoute, jsonReq, flush } = await import('./harness.mjs')
|
|
16
|
+
|
|
17
|
+
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'union-hydrate-root-'))
|
|
18
|
+
const KEY = Buffer.from(SESSION, 'utf8').toString('base64url')
|
|
19
|
+
let rootSeq = 0
|
|
20
|
+
const root = () => path.join(TMP, 'case-' + ++rootSeq)
|
|
21
|
+
|
|
22
|
+
function mkItem(i, over = {}) {
|
|
23
|
+
return {
|
|
24
|
+
id: 'p_' + i, title: '任务' + i, status: 'todo', percent: 0, current: '', next: '',
|
|
25
|
+
approach: '', note: '', order: i, unit: '', targetTurns: 2, closedAt: 0, startedTurn: 0, ...over,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function makeEntry(rev, items) {
|
|
30
|
+
const n = items.length
|
|
31
|
+
const done = items.filter((i) => i.status === 'done').length
|
|
32
|
+
return {
|
|
33
|
+
version: 1, sessionId: SESSION, seq: 0, revision: rev, at: Date.now(), reason: 'turn',
|
|
34
|
+
task: { title: '回灌测试', goal: { objective: '回灌目标', phase: 'active', roundsStarted: 0 } },
|
|
35
|
+
board: { enabled: true, summary: { total: n, done, doing: 0, todo: n - done, blocked: 0, percent: 0 }, items },
|
|
36
|
+
handoff: { objective: '回灌目标', doneSoFar: [], inFlight: [], nextItems: [], filesTouched: [], openUnits: [], lastTurn: { turn: rev, startSeq: 0, endSeq: 0, summary: '' }, generatedBy: 'rules' },
|
|
37
|
+
truncated: false,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function seedVersions(dirRoot, revs, items = [mkItem(0), mkItem(1), mkItem(2)]) {
|
|
42
|
+
const d = archiveDir(dirRoot, SESSION)
|
|
43
|
+
fs.rmSync(d, { recursive: true, force: true })
|
|
44
|
+
const seqs = revs.map((rev) => writeArchiveVersion(d, makeEntry(rev, items.map((i) => ({ ...i })))).seq)
|
|
45
|
+
return { dir: d, seqs }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function seedRecord(rev, items) {
|
|
49
|
+
return {
|
|
50
|
+
[KEY]: {
|
|
51
|
+
record: {
|
|
52
|
+
version: 1, sessionId: SESSION, revision: rev, userRevision: 0, agentSeenRevision: 0,
|
|
53
|
+
enabled: true, createdAt: 1, updatedAt: 1, items, userChanges: [], archiveSeq: 0, archiveError: '',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function boot(config = {}) {
|
|
60
|
+
const harness = createHarness({ config })
|
|
61
|
+
await harness.run()
|
|
62
|
+
return harness
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function snapshot(harness) {
|
|
66
|
+
return callRoute(harness, '/progress-union/snapshot', {
|
|
67
|
+
method: 'GET', url: '/progress-union/snapshot?sessionId=' + SESSION, headers: {},
|
|
68
|
+
}).then((res) => res.json())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const execUpdate = (harness, args) => harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
72
|
+
|
|
73
|
+
test('KV 缺失 + 归档 rev 7(3 项)→ 快照回灌到 rev 7 / 3 项 / restoredFrom.seq 是 head', async () => {
|
|
74
|
+
const r = root()
|
|
75
|
+
const { seqs } = seedVersions(r, [5, 6, 7])
|
|
76
|
+
const harness = await boot({ archiveRoot: r })
|
|
77
|
+
const snap = await snapshot(harness)
|
|
78
|
+
assert.equal(snap.revision, 7, '版本号从归档 rev 继续,不回到 0')
|
|
79
|
+
assert.equal(snap.items.length, 3)
|
|
80
|
+
assert.equal(snap.items[0].title, '任务0')
|
|
81
|
+
assert.equal(snap.restoredFrom.seq, seqs.at(-1))
|
|
82
|
+
assert.equal(snap.restoredFrom.revision, 7)
|
|
83
|
+
assert.deepEqual(Object.keys(snap.restoredFrom).sort(), ['at', 'degraded', 'items', 'reason', 'revision', 'seq'])
|
|
84
|
+
assert.equal(snap.restoredFrom.items, 3)
|
|
85
|
+
assert.equal(snap.restoredFrom.degraded, false)
|
|
86
|
+
// 回灌必须立刻落盘:下一次重启直接从 KV 拿到接续板
|
|
87
|
+
await flush()
|
|
88
|
+
assert.equal(harness.records[KEY].revision, 7)
|
|
89
|
+
assert.equal(harness.records[KEY].items.length, 3)
|
|
90
|
+
assert.equal(harness.records[KEY].archiveSeq, seqs.at(-1))
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('回灌后再写一次板 → revision 8(不从 0 重开)', async () => {
|
|
94
|
+
const r = root()
|
|
95
|
+
seedVersions(r, [7])
|
|
96
|
+
const harness = await boot({ archiveRoot: r })
|
|
97
|
+
assert.equal((await snapshot(harness)).revision, 7)
|
|
98
|
+
await execUpdate(harness, { changes: [{ title: '对账后的新任务', status: 'doing', current: '继续做' }] })
|
|
99
|
+
const snap = await snapshot(harness)
|
|
100
|
+
assert.equal(snap.revision, 8)
|
|
101
|
+
assert.equal(snap.items.length, 4)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('seed rev 3(2 项)+ 归档 rev 9 → 采用归档、revision 9', async () => {
|
|
105
|
+
const r = root()
|
|
106
|
+
seedVersions(r, [9])
|
|
107
|
+
const harness = createHarness({ config: { archiveRoot: r }, seed: seedRecord(3, [mkItem(0), mkItem(1)]) })
|
|
108
|
+
await harness.run()
|
|
109
|
+
const snap = await snapshot(harness)
|
|
110
|
+
assert.equal(snap.revision, 9)
|
|
111
|
+
assert.equal(snap.items.length, 3)
|
|
112
|
+
assert.equal(snap.restoredFrom.revision, 9)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('seed rev 5(2 项)+ 归档 rev 5 → 不回灌,items 保持 seed 内容', async () => {
|
|
116
|
+
const r = root()
|
|
117
|
+
seedVersions(r, [5])
|
|
118
|
+
const items = [mkItem(0, { title: 'seed甲' }), mkItem(1, { title: 'seed乙' })]
|
|
119
|
+
const harness = createHarness({ config: { archiveRoot: r }, seed: seedRecord(5, items) })
|
|
120
|
+
await harness.run()
|
|
121
|
+
const snap = await snapshot(harness)
|
|
122
|
+
assert.equal(snap.revision, 5)
|
|
123
|
+
assert.equal(snap.items.length, 2)
|
|
124
|
+
assert.equal(snap.items[0].title, 'seed甲')
|
|
125
|
+
assert.equal(snap.restoredFrom, null, 'KV 不落后时不得回灌')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('archiveEnabled=false + 归档存在 → 不回灌、不写盘', async () => {
|
|
129
|
+
const r = root()
|
|
130
|
+
seedVersions(r, [7])
|
|
131
|
+
const harness = await boot({ archiveRoot: r, archiveEnabled: false })
|
|
132
|
+
const snap = await snapshot(harness)
|
|
133
|
+
assert.equal(snap.revision, 0)
|
|
134
|
+
assert.equal(snap.items.length, 0)
|
|
135
|
+
assert.equal(snap.restoredFrom, null)
|
|
136
|
+
await flush()
|
|
137
|
+
assert.equal(harness.records[KEY], undefined, '关档时不得写盘')
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('head 版 checksum 坏 + head-1 可读 → 回灌 head-1 且 degraded=true', async () => {
|
|
141
|
+
const r = root()
|
|
142
|
+
const { dir, seqs } = seedVersions(r, [11, 12])
|
|
143
|
+
// 破坏 head 的 checksum:改字段但保留旧 checksum
|
|
144
|
+
const headFile = archiveVersionPath(dir, seqs.at(-1))
|
|
145
|
+
const head = JSON.parse(fs.readFileSync(headFile, 'utf8'))
|
|
146
|
+
head.revision = 99
|
|
147
|
+
fs.writeFileSync(headFile, JSON.stringify(head))
|
|
148
|
+
const harness = await boot({ archiveRoot: r })
|
|
149
|
+
const snap = await snapshot(harness)
|
|
150
|
+
assert.equal(snap.revision, 11, 'head 坏则用 head-1 的 revision')
|
|
151
|
+
assert.equal(snap.restoredFrom.seq, seqs.at(-2))
|
|
152
|
+
assert.equal(snap.restoredFrom.degraded, true)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('kickoff:恢复态含「已从上一版会话归档接续」且不含「当前为空」,同进程只催一次', async () => {
|
|
156
|
+
const r = root()
|
|
157
|
+
seedVersions(r, [7])
|
|
158
|
+
const harness = await boot({ archiveRoot: r })
|
|
159
|
+
const kickoff = harness.contexts.get('progress-union-kickoff')
|
|
160
|
+
const first = kickoff()
|
|
161
|
+
assert.match(first, /已从上一版会话归档接续/)
|
|
162
|
+
assert.match(first, /不要从 0 重建计划/)
|
|
163
|
+
assert.doesNotMatch(first, /当前为空/)
|
|
164
|
+
assert.equal(kickoff(), '', '同进程不重复催办')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('captureArchive 之后 KV 的 archiveSeq === index.headSeq', async () => {
|
|
168
|
+
const r = root()
|
|
169
|
+
const harness = createHarness({ config: { archiveRoot: r }, seed: seedRecord(2, [mkItem(0)]) })
|
|
170
|
+
await harness.run()
|
|
171
|
+
harness.emit('turn/end', {})
|
|
172
|
+
await flush()
|
|
173
|
+
const index = readIndex(archiveDir(r, SESSION))
|
|
174
|
+
assert.ok(index && index.headSeq >= 1, '归档已写入')
|
|
175
|
+
await flush()
|
|
176
|
+
assert.equal(harness.records[KEY].archiveSeq, index.headSeq, 'archiveSeq 必须落盘(0.6.1 只写内存)')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('老记录无 restoredFrom 字段:归一不报错,快照回 null', async () => {
|
|
180
|
+
const harness = createHarness({ seed: seedRecord(2, [mkItem(0)]) })
|
|
181
|
+
await harness.run()
|
|
182
|
+
const snap = await snapshot(harness)
|
|
183
|
+
assert.equal(snap.restoredFrom, null)
|
|
184
|
+
assert.equal(snap.revision, 2)
|
|
185
|
+
})
|