dsh-progress-union 0.1.6 → 0.1.8
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 +77 -0
- package/README.md +25 -13
- package/client.js +14 -189
- package/dsh.plugin.json +1 -1
- package/index.js +51 -25
- package/package.json +9 -4
- package/test/anchor.test.mjs +139 -0
- package/test/assistant.test.mjs +215 -0
- package/test/client.test.mjs +54 -0
- package/test/e2e.test.mjs +77 -0
- package/test/goal.test.mjs +110 -0
- package/test/harness.mjs +210 -0
- package/test/host.test.mjs +184 -0
- package/test/observer.test.mjs +171 -0
- package/test/stats.test.mjs +54 -0
- package/test/time.test.mjs +147 -0
|
@@ -0,0 +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
|
+
})
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 8 验收:辅助 LLM(审查/监视)通道。
|
|
3
|
+
* - 直连端点、滞后触发、只改 current/next/percent(updatedBy=assistant);
|
|
4
|
+
* - 每回合配额 + 最小间隔节流;失败静默入 assistantError;
|
|
5
|
+
* - 快照只回非机密字段(apiKey 只回布尔);关着时零 fetch。
|
|
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
|
+
|
|
16
|
+
function stubFetch(handler) {
|
|
17
|
+
const calls = []
|
|
18
|
+
const original = globalThis.fetch
|
|
19
|
+
globalThis.fetch = async (url, init) => {
|
|
20
|
+
calls.push({ url: String(url), init })
|
|
21
|
+
return handler(url, init, calls.length)
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
calls,
|
|
25
|
+
restore: () => {
|
|
26
|
+
globalThis.fetch = original
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function proposal(content) {
|
|
32
|
+
return {
|
|
33
|
+
ok: true,
|
|
34
|
+
status: 200,
|
|
35
|
+
async json() {
|
|
36
|
+
return { choices: [{ message: { content } }] }
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function booted(config) {
|
|
42
|
+
const harness = createHarness({ config })
|
|
43
|
+
await harness.run()
|
|
44
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
45
|
+
return harness
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function execUpdate(harness, args) {
|
|
49
|
+
return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function settle(ms = 30) {
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, ms))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function snapshotOf(harness) {
|
|
57
|
+
const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
|
|
58
|
+
return res.json()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test('命中的提议落地:只改 current/percent,updatedBy=assistant,快照不含密钥明文', async () => {
|
|
62
|
+
const harness = await booted({
|
|
63
|
+
assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', apiKey: 'sekret', model: 'mini', minIntervalMs: 0, maxCallsPerTurn: 1, timeoutMs: 5000 },
|
|
64
|
+
})
|
|
65
|
+
const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', percent: 10, current: '热身' }] })
|
|
66
|
+
const itemId = added.changed[0].id
|
|
67
|
+
const stub = stubFetch(() => proposal('```json\n{"board":{"changes":[{"kind":"edit","id":"' + itemId + '","current":"审查:跑集成测试","percent":60},{"kind":"edit","id":"p_fake","current":"x"}]},"round":{"status":"continue","summary":"推进中"},"note":"滞后 6 步,已校准"}\n```'))
|
|
68
|
+
try {
|
|
69
|
+
harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
|
|
70
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
71
|
+
await settle()
|
|
72
|
+
assert.equal(stub.calls.length, 1, '滞后触发一次审查')
|
|
73
|
+
assert.ok(stub.calls[0].url.endsWith('/chat/completions'))
|
|
74
|
+
assert.equal(stub.calls[0].init.headers.authorization, 'Bearer sekret')
|
|
75
|
+
|
|
76
|
+
const snap = await snapshotOf(harness)
|
|
77
|
+
const item = snap.items.find((x) => x.id === itemId)
|
|
78
|
+
assert.equal(item.current, '审查:跑集成测试')
|
|
79
|
+
assert.equal(item.percent, 60)
|
|
80
|
+
assert.equal(item.status, 'doing', '审查不得改状态')
|
|
81
|
+
assert.equal(item.updatedBy, 'assistant')
|
|
82
|
+
assert.equal(snap.items.length, 1, '不存在的 id 被丢弃,不得新增任务')
|
|
83
|
+
|
|
84
|
+
assert.equal(snap.assistant.enabled, true)
|
|
85
|
+
assert.equal(snap.assistant.hasApiKey, true)
|
|
86
|
+
assert.equal('apiKey' in snap.assistant, false, '密钥不得回传')
|
|
87
|
+
assert.match(harness.contexts.get('progress-union-observer')(), /助手审查:滞后 6 步,已校准/)
|
|
88
|
+
} finally {
|
|
89
|
+
stub.restore()
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('关着时零 fetch;autoApply=false 只记录建议不落地', async () => {
|
|
94
|
+
const off = await booted()
|
|
95
|
+
await execUpdate(off, { changes: [{ title: '任务', status: 'doing' }] })
|
|
96
|
+
const stubOff = stubFetch(() => proposal('{"changes":[],"note":"x"}'))
|
|
97
|
+
try {
|
|
98
|
+
for (let i = 0; i < 6; i++) off.emit('step/start', {})
|
|
99
|
+
await settle()
|
|
100
|
+
assert.equal(stubOff.calls.length, 0, '未启用不得发起请求')
|
|
101
|
+
assert.equal((await snapshotOf(off)).assistant.enabled, false)
|
|
102
|
+
} finally {
|
|
103
|
+
stubOff.restore()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const dry = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 0, autoApply: false } })
|
|
107
|
+
const added = await execUpdate(dry, { changes: [{ title: '任务', status: 'doing', percent: 10, current: '原样' }] })
|
|
108
|
+
const itemId = added.changed[0].id
|
|
109
|
+
const stubDry = stubFetch(() => proposal('{"board":{"changes":[{"kind":"edit","id":"' + itemId + '","percent":90}]},"round":{"status":"continue"},"note":"建议 90%"}'))
|
|
110
|
+
try {
|
|
111
|
+
for (let i = 0; i < 6; i++) dry.emit('step/start', {})
|
|
112
|
+
await settle()
|
|
113
|
+
const snap = await snapshotOf(dry)
|
|
114
|
+
assert.equal(snap.items[0].percent, 10, 'autoApply=false 不落地')
|
|
115
|
+
assert.match(dry.contexts.get('progress-union-observer')(), /助手审查:建议 90%/)
|
|
116
|
+
} finally {
|
|
117
|
+
stubDry.restore()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('失败静默:HTTP 错误/坏 JSON 只进 assistantError,不阻断板', async () => {
|
|
122
|
+
const harness = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 0 } })
|
|
123
|
+
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
|
|
124
|
+
const stub = stubFetch(() => ({ ok: false, status: 503, async json() { return {} } }))
|
|
125
|
+
try {
|
|
126
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
127
|
+
await settle()
|
|
128
|
+
const text = harness.contexts.get('progress-union-observer')()
|
|
129
|
+
assert.match(text, /助手审查失败:HTTP 503/)
|
|
130
|
+
assert.equal((await snapshotOf(harness)).items[0].status, 'doing', '板本体不受影响')
|
|
131
|
+
} finally {
|
|
132
|
+
stub.restore()
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('节流与每回合配额:minIntervalMs 内不再发;新回合重置配额', async () => {
|
|
137
|
+
const harness = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 60_000, maxCallsPerTurn: 1 } })
|
|
138
|
+
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
|
|
139
|
+
const stub = stubFetch(() => proposal('{"changes":[],"note":"ok"}'))
|
|
140
|
+
try {
|
|
141
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
142
|
+
await settle()
|
|
143
|
+
assert.equal(stub.calls.length, 1)
|
|
144
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
145
|
+
await settle()
|
|
146
|
+
assert.equal(stub.calls.length, 1, '最小间隔内不得重发')
|
|
147
|
+
} finally {
|
|
148
|
+
stub.restore()
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('assistant 逐叶子 volatile:live ref 每回合重读,改值不需重启', async () => {
|
|
153
|
+
const ref = (getter) => ({ get: getter })
|
|
154
|
+
const live = { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini' }
|
|
155
|
+
const harness = createHarness({
|
|
156
|
+
config: {
|
|
157
|
+
assistant: {
|
|
158
|
+
mode: ref(() => live.mode),
|
|
159
|
+
baseUrl: ref(() => live.baseUrl),
|
|
160
|
+
model: ref(() => live.model),
|
|
161
|
+
minIntervalMs: ref(() => 0),
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
await harness.run()
|
|
166
|
+
const on = await snapshotOf(harness)
|
|
167
|
+
assert.equal(on.assistant.mode, 'direct')
|
|
168
|
+
assert.equal(on.assistant.enabled, true)
|
|
169
|
+
live.mode = ''
|
|
170
|
+
const off = await snapshotOf(harness)
|
|
171
|
+
assert.equal(off.assistant.enabled, false, '设置页关掉后下一次读即生效')
|
|
172
|
+
})
|
|
173
|
+
test('registered 模式:走宿主 llm.stream(system 走 options.system,content 为块数组),消费 text-delta + 槽位管理 + 轮次草案', async () => {
|
|
174
|
+
const streamCalls = []
|
|
175
|
+
const llm = {
|
|
176
|
+
async *stream(options) {
|
|
177
|
+
streamCalls.push(options)
|
|
178
|
+
yield { type: 'text-delta', text: '{}' }
|
|
179
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
const harness = createHarness({
|
|
183
|
+
config: { assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0, maxCallsPerTurn: 1 } },
|
|
184
|
+
llm,
|
|
185
|
+
})
|
|
186
|
+
await harness.run()
|
|
187
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
188
|
+
const added = await execUpdate(harness, { changes: [{ title: '任务', status: 'doing', percent: 10 }] })
|
|
189
|
+
const itemId = added.changed[0].id
|
|
190
|
+
llm.stream = async function* (options) {
|
|
191
|
+
streamCalls.push(options)
|
|
192
|
+
yield { type: 'text-delta', text: '{"board":{"changes":[' }
|
|
193
|
+
yield { type: 'text-delta', text: `{"kind":"edit","id":"${itemId}","percent":75}` }
|
|
194
|
+
yield { type: 'text-delta', text: ']},"round":{"status":"continue","summary":"推进中"},"note":"registered 校准"}' }
|
|
195
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
196
|
+
}
|
|
197
|
+
for (let i = 0; i < 6; i++) harness.emit('step/start', {})
|
|
198
|
+
await settle()
|
|
199
|
+
assert.equal(streamCalls.length, 1, 'registered 走 llm.stream 而非 fetch')
|
|
200
|
+
assert.equal(streamCalls[0].provider, 'local')
|
|
201
|
+
assert.equal(streamCalls[0].model, 'qwen')
|
|
202
|
+
// 契约守卫(2026-11-26 事故回归):system 必须在 options.system,不能藏在 messages 里,
|
|
203
|
+
// 否则 adapter 不映射 system 槽 → DeepSeek 回落到内置 "You are a helpful assistant."
|
|
204
|
+
assert.equal(typeof streamCalls[0].system, 'string')
|
|
205
|
+
assert.match(streamCalls[0].system, /progress assistant/, 'system 必须是 ASSISTANT_SYSTEM 正文')
|
|
206
|
+
assert.deepEqual(streamCalls[0].messages.map((m) => m.role), ['user'], 'messages 里不得出现 role:system')
|
|
207
|
+
const blocks = streamCalls[0].messages[0].content
|
|
208
|
+
assert.ok(Array.isArray(blocks), 'content 必须是 ContentBlock[],不能是裸字符串')
|
|
209
|
+
assert.equal(blocks[0].type, 'text')
|
|
210
|
+
assert.match(blocks[0].text, /目标|\[~\]/, '输入正文必须带上板清单')
|
|
211
|
+
const snap = await snapshotOf(harness)
|
|
212
|
+
assert.equal(snap.items[0].percent, 75, '助手改了槽位')
|
|
213
|
+
assert.equal(snap.items[0].updatedBy, 'assistant')
|
|
214
|
+
assert.match(harness.contexts.get('progress-union-observer')(), /助手轮次草案.*推进中/)
|
|
215
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 4 验收:client 契约守卫。
|
|
3
|
+
* 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
|
|
4
|
+
* 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
|
|
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-test-'))
|
|
13
|
+
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
14
|
+
|
|
15
|
+
const clientFile = new URL('../client.js', import.meta.url).pathname.replace(/^\//, '')
|
|
16
|
+
|
|
17
|
+
test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
|
|
18
|
+
const src = fs.readFileSync(clientFile, 'utf8')
|
|
19
|
+
assert.match(src, /id: 'dsh-progress-union'/)
|
|
20
|
+
assert.match(src, /const API = '\/progress-union'/)
|
|
21
|
+
assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
|
|
22
|
+
assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
|
|
23
|
+
assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
|
|
27
|
+
const harness = createHarness()
|
|
28
|
+
await harness.run()
|
|
29
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
30
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
31
|
+
{ changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
|
|
32
|
+
{ agent: harness.agent },
|
|
33
|
+
)
|
|
34
|
+
harness.emit('turn/start', {})
|
|
35
|
+
harness.emit('step/start', {})
|
|
36
|
+
|
|
37
|
+
const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
|
|
38
|
+
assert.equal(snap.ok, true)
|
|
39
|
+
assert.equal(snap.enabled, true)
|
|
40
|
+
assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
|
|
41
|
+
assert.equal(typeof snap.summary.percent, 'number')
|
|
42
|
+
assert.equal('pendingUserChanges' in snap, true)
|
|
43
|
+
|
|
44
|
+
const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
|
|
45
|
+
assert.equal(status.ok, true)
|
|
46
|
+
assert.equal(status.config.pollMs, 1000)
|
|
47
|
+
assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
|
|
48
|
+
assert.equal(String(status.task.id), String(SESSION))
|
|
49
|
+
// 板开:阶段直接取板 items,不再走关键词猜测
|
|
50
|
+
assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
|
|
51
|
+
assert.equal(status.task.boardDriven, true)
|
|
52
|
+
assert.equal(status.task.current, 0)
|
|
53
|
+
assert.ok(Array.isArray(status.tasks))
|
|
54
|
+
})
|
|
@@ -0,0 +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
|
+
})
|
|
@@ -0,0 +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
|
+
})
|