dsh-progress-union 0.6.3 → 0.7.0-rc.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 +401 -373
- package/LICENSE +21 -21
- package/README.md +286 -286
- package/anchor.js +39 -39
- package/client.js +3078 -2993
- 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 +1 -1
- package/icon.svg +7 -7
- package/index.js +5206 -4568
- package/package.json +93 -79
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +274 -190
- package/test/download-classify.test.mjs +199 -0
- 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/parse-progress.test.mjs +78 -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/tool-gloss.test.mjs +137 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.7.0 R1 验收:下载识别(classifyDownload)与板项标记(isDownloadItem)。
|
|
3
|
+
* 口径与 spec 一致:**软感知** —— 词表命中才记,猜不出返回 null;
|
|
4
|
+
* 绝不把 npm test / git status / pip list 这类无网络拉取的动作误判成下载。
|
|
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
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-dl-test-'))
|
|
13
|
+
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
14
|
+
const { classifyDownload, isDownloadItem, unwrapAct } = await import('../index.js')
|
|
15
|
+
|
|
16
|
+
const sh = (command) => ['bash', JSON.stringify({ command })]
|
|
17
|
+
|
|
18
|
+
test('classifyDownload:安装类命中并取到包名', () => {
|
|
19
|
+
assert.deepEqual(classifyDownload(...sh('npm install lodash'))?.kind, 'install')
|
|
20
|
+
assert.equal(classifyDownload(...sh('npm install lodash')).target, 'lodash')
|
|
21
|
+
assert.equal(classifyDownload(...sh('pnpm add -D vite')).target, 'vite')
|
|
22
|
+
assert.equal(classifyDownload(...sh('yarn add react')).kind, 'install')
|
|
23
|
+
assert.equal(classifyDownload(...sh('pip install requests')).target, 'requests')
|
|
24
|
+
assert.equal(classifyDownload(...sh('uv pip install httpx')).kind, 'install')
|
|
25
|
+
assert.equal(classifyDownload(...sh('brew install ripgrep')).target, 'ripgrep')
|
|
26
|
+
assert.equal(classifyDownload(...sh('cargo add serde')).target, 'serde')
|
|
27
|
+
assert.equal(classifyDownload(...sh('npx create-vite app')).target, 'create-vite')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('classifyDownload:clone / pull / 单一下载器', () => {
|
|
31
|
+
const clone = classifyDownload(...sh('git clone https://github.com/acme/widget.git'))
|
|
32
|
+
assert.equal(clone.kind, 'clone')
|
|
33
|
+
assert.equal(clone.target, 'widget.git')
|
|
34
|
+
assert.equal(classifyDownload(...sh('git pull')).kind, 'clone')
|
|
35
|
+
const pull = classifyDownload(...sh('docker pull nginx:latest'))
|
|
36
|
+
assert.equal(pull.kind, 'pull')
|
|
37
|
+
assert.equal(pull.target, 'nginx:latest')
|
|
38
|
+
assert.equal(classifyDownload(...sh('wget https://host/big.zip')).target, 'big.zip')
|
|
39
|
+
assert.equal(classifyDownload(...sh('curl -O https://mirror/x.tar.gz')).target, 'x.tar.gz')
|
|
40
|
+
assert.equal(classifyDownload(...sh('curl -L https://api.dev/pkg.tgz -o pkg.tgz')).target, 'pkg.tgz')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('classifyDownload:不误判(无网络拉取的动作一律 null)', () => {
|
|
44
|
+
for (const cmd of [
|
|
45
|
+
'npm test', 'npm run dev', 'npm ls', 'npm view foo', 'npm ci --dry-run',
|
|
46
|
+
'git status', 'git log --oneline -5', 'git diff', 'ls -la', 'echo hi',
|
|
47
|
+
'pip list', 'pip show requests', 'pip freeze', 'conda info', 'brew list',
|
|
48
|
+
'cargo build', 'cargo test', 'dotnet test', 'node build.mjs', 'python train.py',
|
|
49
|
+
'grep -rn todo src', 'cat package.json',
|
|
50
|
+
]) {
|
|
51
|
+
assert.equal(classifyDownload(...sh(cmd)), null, `不得把「${cmd}」当下载`)
|
|
52
|
+
}
|
|
53
|
+
assert.equal(classifyDownload('todo_write', JSON.stringify({ todos: [] })), null)
|
|
54
|
+
assert.equal(classifyDownload('read', JSON.stringify({ file_path: 'a.md' })), null)
|
|
55
|
+
assert.equal(classifyDownload('bash', JSON.stringify({})), null)
|
|
56
|
+
assert.equal(classifyDownload(undefined, undefined), null)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('classifyDownload:后台线索(工具名 / & / nohup / --detach / detached 参数)', () => {
|
|
60
|
+
assert.equal(classifyDownload(...sh('npm install heavy-dep &')).background, true)
|
|
61
|
+
assert.equal(classifyDownload(...sh('nohup pip install torch > log.txt 2>&1 &')).background, true)
|
|
62
|
+
assert.equal(classifyDownload(...sh('docker pull big/image --detach')).background, true)
|
|
63
|
+
assert.equal(classifyDownload('exec_background', JSON.stringify({ command: 'wget https://h/f.bin' })).background, true)
|
|
64
|
+
assert.equal(classifyDownload('bash', JSON.stringify({ command: 'wget https://h/f.bin', detached: true })).background, true)
|
|
65
|
+
// 前台的 & 只在该段真是命令时才生效:`a && b` 不得判成后台
|
|
66
|
+
assert.equal(classifyDownload(...sh('npm ci && npm test')).background, false)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('classifyDownload + unwrapAct:act 包装透传到内层工具', () => {
|
|
70
|
+
const wrapped = ['act', JSON.stringify({ tool: 'bash', input: { command: 'npm i left-pad' } })]
|
|
71
|
+
const hit = classifyDownload(...wrapped)
|
|
72
|
+
assert.equal(hit?.kind, 'install')
|
|
73
|
+
assert.equal(hit.target, 'left-pad')
|
|
74
|
+
assert.deepEqual(unwrapAct('act', JSON.stringify({ tool: 'read', input: { file_path: 'x' } })), {
|
|
75
|
+
name: 'read', argsRaw: JSON.stringify({ file_path: 'x' }),
|
|
76
|
+
})
|
|
77
|
+
// 非 act 工具原样返回,不做二次展开
|
|
78
|
+
assert.deepEqual(unwrapAct('bash', '{"command":"ls"}'), { name: 'bash', argsRaw: '{"command":"ls"}' })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('classifyDownload:非 shell 通道的下载工具名', () => {
|
|
82
|
+
const hit = classifyDownload('download_file', JSON.stringify({ url: 'https://cdn/a.iso' }))
|
|
83
|
+
assert.equal(hit.kind, 'download')
|
|
84
|
+
assert.equal(hit.target, 'a.iso')
|
|
85
|
+
assert.equal(classifyDownload('download', JSON.stringify({})), null, '拿不到目标就不记')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('isDownloadItem:分组词与标题动词命中', () => {
|
|
89
|
+
assert.equal(isDownloadItem({ group: 'download', title: '拉模型' }), true)
|
|
90
|
+
assert.equal(isDownloadItem({ group: 'deps-install', title: '装依赖' }), true)
|
|
91
|
+
assert.equal(isDownloadItem({ title: 'git clone 主仓' }), true)
|
|
92
|
+
assert.equal(isDownloadItem({ title: 'Install python deps' }), true)
|
|
93
|
+
assert.equal(isDownloadItem({ title: '渲染截图' }), false)
|
|
94
|
+
assert.equal(isDownloadItem({ group: 'release', title: '发包到 npm' }), false)
|
|
95
|
+
assert.equal(isDownloadItem(null), false)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// —— 接线面:recordTool 命中 → 观察块出 ⬇ 行 + 快照 download 字段 ——
|
|
99
|
+
|
|
100
|
+
async function booted() {
|
|
101
|
+
const harness = createHarness()
|
|
102
|
+
await harness.run()
|
|
103
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
104
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
105
|
+
{ changes: [{ title: '拉取素材', status: 'doing' }, { title: '合成音轨', status: 'todo' }] },
|
|
106
|
+
{ agent: harness.agent },
|
|
107
|
+
)
|
|
108
|
+
return harness
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function observerText(harness) {
|
|
112
|
+
return harness.contexts.get('progress-union-observer')()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function snapshot(harness) {
|
|
116
|
+
const res = await callRoute(harness, '/progress-union/snapshot', {
|
|
117
|
+
method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {},
|
|
118
|
+
})
|
|
119
|
+
return res.json()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
test('观察块:下载中出现一行,板无下载项时追催办子句', async () => {
|
|
123
|
+
const harness = await booted()
|
|
124
|
+
// 板上的 doing 项是「拉取素材」→ 标题不含下载动词,仍算没挂上:催办子句应出现
|
|
125
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
126
|
+
const text = observerText(harness)
|
|
127
|
+
assert.match(text, /⬇ 下载中:x\.zip/, text)
|
|
128
|
+
assert.match(text, /板上没有对应的 doing 下载项/, text)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('观察块:板上有 doing 下载项时不催办', async () => {
|
|
132
|
+
const harness = await booted()
|
|
133
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
134
|
+
{ changes: [{ title: 'wget 拉取素材包', status: 'doing' }] },
|
|
135
|
+
{ agent: harness.agent },
|
|
136
|
+
)
|
|
137
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
138
|
+
const text = observerText(harness)
|
|
139
|
+
assert.match(text, /⬇ 下载中:x\.zip/, text)
|
|
140
|
+
assert.doesNotMatch(text, /板上没有对应的 doing 下载项/, text)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('观察块:download.enabled=false 时整行消失(逐字退回 0.6.x)', async () => {
|
|
144
|
+
const harness = createHarness({ config: { download: { enabled: false } } })
|
|
145
|
+
await harness.run()
|
|
146
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
147
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
148
|
+
const text = observerText(harness)
|
|
149
|
+
assert.doesNotMatch(text, /⬇/, 'download.enabled=false 必须逐字退回 0.6.x 观察块')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('快照 download:elapsed 档(只有动作记录时 percent 为 null,不假扮进度)', async () => {
|
|
153
|
+
const harness = await booted()
|
|
154
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c9', arguments: JSON.stringify({ command: 'git clone https://github.com/a/b.git' }) })
|
|
155
|
+
const dl = (await snapshot(harness)).download
|
|
156
|
+
assert.equal(dl.active, true)
|
|
157
|
+
assert.equal(dl.basis, 'elapsed')
|
|
158
|
+
assert.equal(dl.kind, 'clone')
|
|
159
|
+
assert.equal(dl.target, 'b.git')
|
|
160
|
+
assert.equal(dl.percent, null)
|
|
161
|
+
assert.equal(dl.background, false)
|
|
162
|
+
assert.deepEqual(Object.keys(dl).sort(), ['active', 'basis', 'bytes', 'elapsedSec', 'kind', 'percent', 'target', 'background'].sort())
|
|
163
|
+
assert.ok(Object.keys(dl).length <= 8, 'download 键数必须 ≤8')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('快照 download:stdout 档优先于板项(tool/result 带真值)', async () => {
|
|
167
|
+
const harness = await booted()
|
|
168
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c2', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
169
|
+
harness.emit('tool/result', {
|
|
170
|
+
callId: 'c2',
|
|
171
|
+
message: { toolCallId: 'c2', toolName: 'bash', content: [{ type: 'text', text: 'x.zip 45% [====> ] 12.3MB/27.8MB 4.1MB/s' }] },
|
|
172
|
+
})
|
|
173
|
+
const dl = (await snapshot(harness)).download
|
|
174
|
+
assert.equal(dl.basis, 'stdout')
|
|
175
|
+
assert.equal(dl.percent, 45)
|
|
176
|
+
assert.equal(dl.bytes, '12.3MB/27.8MB')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('快照 download:无下载时是稳定的非激活对象(前端可无条件读)', async () => {
|
|
180
|
+
const harness = await booted()
|
|
181
|
+
const dl = (await snapshot(harness)).download
|
|
182
|
+
assert.deepEqual(dl, { active: false, basis: '', kind: '', target: '', percent: null, bytes: '', background: false, elapsedSec: 0 })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('快照 items 追加 isDownload(老字段不动)', async () => {
|
|
186
|
+
const harness = await booted()
|
|
187
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
188
|
+
{ changes: [{ title: 'npm install 依赖', status: 'todo', group: 'deps' }] },
|
|
189
|
+
{ agent: harness.agent },
|
|
190
|
+
)
|
|
191
|
+
const snap = await snapshot(harness)
|
|
192
|
+
const byTitle = new Map(snap.items.map((i) => [i.title, i]))
|
|
193
|
+
assert.equal(byTitle.get('npm install 依赖').isDownload, true)
|
|
194
|
+
assert.equal(byTitle.get('拉取素材').isDownload, false, '中文标题不靠语义猜,只认词表')
|
|
195
|
+
assert.ok(Object.keys(byTitle.get('拉取素材')).includes('isDownload'), '只追加字段')
|
|
196
|
+
for (const key of ['id', 'title', 'status', 'percent', 'current', 'next', 'approach', 'note', 'group', 'order', 'updatedAt', 'updatedBy']) {
|
|
197
|
+
assert.ok(Object.keys(snap.items[0]).includes(key), `老字段 ${key} 不得丢`)
|
|
198
|
+
}
|
|
199
|
+
})
|
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-drive.test.mjs
CHANGED
|
@@ -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' }])
|