dsh-progress-union 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +628 -628
- package/LICENSE +21 -21
- package/README.md +395 -395
- package/anchor.js +39 -39
- package/client.js +3828 -3828
- 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 +6165 -6119
- package/package.json +16 -6
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +479 -479
- package/test/download-classify.test.mjs +284 -284
- 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/major-change-notice.test.mjs +174 -174
- package/test/observer.test.mjs +170 -170
- package/test/ops.test.mjs +638 -638
- package/test/parse-progress.test.mjs +78 -78
- package/test/restore-hydrate.test.mjs +185 -185
- package/test/settings.test.mjs +253 -253
- 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 -137
package/test/ops.test.mjs
CHANGED
|
@@ -1,638 +1,638 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0.7.0 rc.3 验收:R3 侧边栏 LLM 任务操作。
|
|
3
|
-
* validateBoard / validateProposal / buildOpsChain 纯函数 + /ops/providers
|
|
4
|
-
* + /ops 三操作(refine/mutate/ask;validate 只留路由,面板不再放按钮)。
|
|
5
|
-
* 0.7.9 硬约束:模型输出不符格式一律打回重问(最多三轮),绕开半应用;
|
|
6
|
-
* 0.8.0 硬约束:介入范围 = 配置白名单(主路由 + ops.fallbacks),链外一律 403,
|
|
7
|
-
* 未钉定也一律 403,绝不退回宿主主模型;传输失败按链降级。
|
|
8
|
-
* 不新开顶级标签、零新增依赖;
|
|
9
|
-
* origin='ops' 不得让主模型看起来「同步过板」(stepsSinceModel 不归零)。
|
|
10
|
-
*/
|
|
11
|
-
import assert from 'node:assert/strict'
|
|
12
|
-
import fs from 'node:fs'
|
|
13
|
-
import os from 'node:os'
|
|
14
|
-
import path from 'node:path'
|
|
15
|
-
import test from 'node:test'
|
|
16
|
-
|
|
17
|
-
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
18
|
-
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
19
|
-
const { validateBoard, validateProposal, isLocalRouteName, buildOpsChain, withOpsFeedback, planSlugFromText } = await import('../index.js')
|
|
20
|
-
|
|
21
|
-
const OPS = '/progress-union/ops'
|
|
22
|
-
|
|
23
|
-
function llmMock(reply, calls) {
|
|
24
|
-
return {
|
|
25
|
-
async *stream(options) {
|
|
26
|
-
if (calls) calls.push(options)
|
|
27
|
-
yield { type: 'text-delta', text: typeof reply === 'function' ? reply() : reply }
|
|
28
|
-
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function booted({ config = {}, reply = '{}', calls = [], providers = undefined, models = undefined, cwd = '' } = {}) {
|
|
34
|
-
const llm = {
|
|
35
|
-
...llmMock(reply, calls),
|
|
36
|
-
...(providers ? { listProviders: async () => providers } : {}),
|
|
37
|
-
...(models ? { listModels: typeof models === 'function' ? models : async () => models } : {}),
|
|
38
|
-
}
|
|
39
|
-
const harness = createHarness({
|
|
40
|
-
...(cwd ? { cwd } : {}),
|
|
41
|
-
config: {
|
|
42
|
-
assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 },
|
|
43
|
-
// v0.8.0:ops 的介入范围 = 白名单。默认钉一条 local/qwen(与 llmMock 对得上),
|
|
44
|
-
// 需要测「未钉定」的用例自己把 routeProvider/routeModel 清空。
|
|
45
|
-
ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] },
|
|
46
|
-
...config,
|
|
47
|
-
},
|
|
48
|
-
llm,
|
|
49
|
-
})
|
|
50
|
-
await harness.run()
|
|
51
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
52
|
-
await harness.toolMap.get('progress_update').definition.execute(
|
|
53
|
-
{ changes: [{ title: '接数据面', status: 'doing' }, { title: '写面板', percent: 30 }, { title: '补测试' }] },
|
|
54
|
-
{ agent: harness.agent },
|
|
55
|
-
)
|
|
56
|
-
return harness
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function snapshot(harness) {
|
|
60
|
-
const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
|
|
61
|
-
return res.json()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function ops(harness, body) {
|
|
65
|
-
const res = await callRoute(harness, OPS, jsonReq('POST', OPS, body))
|
|
66
|
-
return { status: res.status, json: res.json() }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ── validateBoard(纯函数)──────────────────────────────────────────────
|
|
70
|
-
|
|
71
|
-
test('validateBoard:合法板通过,接受数组或 {items}', () => {
|
|
72
|
-
const ok = validateBoard([{ id: 'a', title: '甲', status: 'doing', percent: 20, order: 0 }, { id: 'b', title: '乙', status: 'todo', order: 1 }])
|
|
73
|
-
assert.equal(ok.ok, true, ok.errors.join(';'))
|
|
74
|
-
assert.equal(ok.count, 2)
|
|
75
|
-
assert.deepEqual(ok.warnings, [])
|
|
76
|
-
assert.equal(validateBoard({ items: [{ title: '甲' }] }).ok, true)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('validateBoard:硬错逐项拦下(项数/title/status 枚举/done⇒100/percent 越界)', () => {
|
|
80
|
-
assert.equal(validateBoard('nope').ok, false, '非数组必须是硬错')
|
|
81
|
-
const tooMany = validateBoard(Array.from({ length: 61 }, (_, i) => ({ title: 't' + i })))
|
|
82
|
-
assert.match(tooMany.errors.join(' '), /项数 61 超过上限 60/)
|
|
83
|
-
assert.match(validateBoard([{ status: 'doing' }]).errors.join(' '), /缺少 title/)
|
|
84
|
-
assert.match(validateBoard([{ title: '很长的'.repeat(70) }]).errors.join(' '), /title 过长/)
|
|
85
|
-
assert.match(validateBoard([{ title: '甲', status: 'pending-ish' }]).errors.join(' '), /status 非法/)
|
|
86
|
-
assert.match(validateBoard([{ title: '甲', status: 'done', percent: 50 }]).errors.join(' '), /done 但 percent=50/)
|
|
87
|
-
assert.match(validateBoard([{ title: '甲', percent: 140 }]).errors.join(' '), /percent 越界/)
|
|
88
|
-
assert.match(validateBoard([{ title: '甲', order: 'x' }]).errors.join(' '), /order 不是数字/)
|
|
89
|
-
assert.match(validateBoard(['nope']).errors.join(' '), /不是对象/)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('validateBoard:可疑但可写的只进 warnings(空板/重复 title/order 重复/多 doing)', () => {
|
|
93
|
-
const empty = validateBoard([])
|
|
94
|
-
assert.equal(empty.ok, true)
|
|
95
|
-
assert.match(empty.warnings.join(' '), /空板/)
|
|
96
|
-
const dup = validateBoard([{ title: '甲', status: 'doing', order: 0 }, { title: '甲', status: 'doing', order: 0 }])
|
|
97
|
-
assert.equal(dup.ok, true)
|
|
98
|
-
assert.match(dup.warnings.join(' '), /title 与前面重复/)
|
|
99
|
-
assert.match(dup.warnings.join(' '), /order 重复:0/)
|
|
100
|
-
assert.match(dup.warnings.join(' '), /同时 doing 2 项/)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
// ── validateProposal(模型输出格式门)────────────────────────────────
|
|
104
|
-
|
|
105
|
-
test('validateProposal:合规输出直接过;thinking 只是展示字段,缺了不打回', () => {
|
|
106
|
-
const state = { items: [{ id: 'a', title: '甲' }, { id: 'b', title: '乙' }] }
|
|
107
|
-
assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'doing' }], answer: 'ok' }, 'refine').ok, true)
|
|
108
|
-
assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }] }, 'mutate').ok, true, '无 thinking 也必须过')
|
|
109
|
-
assert.equal(validateProposal(state, { board: { changes: [{ kind: 'remove', id: 'b' }] } }, 'mutate').ok, true, '兼容 {board:{changes}} 旧形状')
|
|
110
|
-
assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'done' }], answer: '完成' }, 'mutate').ok, true, 'done 不强制带 percent:落盘时由 applyOneChange 补 100')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('validateProposal:吃不下的一律打回(非对象/缺 changes/kind 非枚举/幽灵 id/缺 title/edit 空转/percent 越界)', () => {
|
|
114
|
-
const state = { items: [{ id: 'a', title: '甲' }] }
|
|
115
|
-
const none = validateProposal(state, null, 'refine')
|
|
116
|
-
assert.equal(none.ok, false)
|
|
117
|
-
assert.match(none.errors[0], /不是可解析的 JSON 对象/)
|
|
118
|
-
assert.match(validateProposal(state, { answer: 'x' }, 'refine').errors.join(' '), /缺少 changes 数组/)
|
|
119
|
-
assert.match(validateProposal(state, { changes: ['nope'] }, 'refine').errors.join(' '), /不是对象/)
|
|
120
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'teleport', id: 'a' }] }, 'refine').errors.join(' '), /kind 非法/)
|
|
121
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'ghost', status: 'done' }] }, 'refine').errors.join(' '), /不在板上/)
|
|
122
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'remove', id: 'ghost' }] }, 'mutate').errors.join(' '), /不在板上/)
|
|
123
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'add', title: ' ' }] }, 'refine').errors.join(' '), /缺少 title/)
|
|
124
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'add', title: '很长的'.repeat(70) }] }, 'refine').errors.join(' '), /title 过长/)
|
|
125
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a' }] }, 'refine').errors.join(' '), /没有任何要改的字段/)
|
|
126
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'pending-ish' }] }, 'refine').errors.join(' '), /status 非法/)
|
|
127
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', percent: 140 }] }, 'refine').errors.join(' '), /percent 越界/)
|
|
128
|
-
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', order: 'x' }] }, 'refine').errors.join(' '), /order 不是数字/)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('validateProposal:条数超上限只截断不打回;ask 只硬要求 answer', () => {
|
|
132
|
-
const state = { items: [{ id: 'a', title: '甲' }] }
|
|
133
|
-
const many = { changes: Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i })) }
|
|
134
|
-
assert.equal(validateProposal(state, many, 'refine').ok, true, '超上限走截断(可部分交付),不因此烧 token 重问')
|
|
135
|
-
assert.equal(validateProposal(state, { changes: [], answer: ' ' }, 'ask').ok, false, 'ask 没 answer 等于没回答')
|
|
136
|
-
assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }], answer: '好' }, 'ask').ok, true, 'ask 硬塞 changes 由路由丢弃,不算格式错')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
// ── 路由链纯函数(v0.8.0 白名单)───────────────────────────────
|
|
140
|
-
|
|
141
|
-
test('buildOpsChain:主路由在前、条目按序在后,缺 provider/model 剔除、同串去重', () => {
|
|
142
|
-
const chain = buildOpsChain(
|
|
143
|
-
{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' },
|
|
144
|
-
[{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, { provider: '', model: 'x' }, { provider: 'strata', model: 'qwen3.8-flash-iq2_xs' }],
|
|
145
|
-
false,
|
|
146
|
-
)
|
|
147
|
-
assert.deepEqual(chain.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'strata/qwen3.8-flash-iq2_xs'], '重复与缺 provider 的条目不占位')
|
|
148
|
-
assert.deepEqual(buildOpsChain({ provider: '', model: '' }, [], true), [], '主路由缺失 = 空链(未钉定)')
|
|
149
|
-
assert.deepEqual(buildOpsChain(null, undefined, true), [], '配置形状不对也不抛错')
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
test('buildOpsChain:preferLocal 只重排不删;关掉则严格按配置顺序', () => {
|
|
153
|
-
const primary = { provider: 'deepseek-account', model: 'deepseek-v4-pro' }
|
|
154
|
-
const fallbacks = [{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }]
|
|
155
|
-
const on = buildOpsChain(primary, fallbacks, true)
|
|
156
|
-
assert.deepEqual(on.map((r) => r.provider), ['local-35', 'deepseek-account'], '本地候选排到链首')
|
|
157
|
-
assert.equal(on.length, 2, '重排不得丢条目')
|
|
158
|
-
assert.deepEqual(buildOpsChain(primary, fallbacks, false).map((r) => r.provider), ['deepseek-account', 'local-35'], '关掉后按配置顺序')
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('isLocalRouteName:provider 命名与量化后缀都能命中,云端旗舰不算本地', () => {
|
|
162
|
-
assert.equal(isLocalRouteName('local-35', 'Qwen3.6-35B-A3B'), true, 'provider 名命中')
|
|
163
|
-
assert.equal(isLocalRouteName('strata', 'qwen3.8-flash-iq2_xs'), true, '量化后缀命中')
|
|
164
|
-
assert.equal(isLocalRouteName('ollama', 'llama3.1:8b'), true)
|
|
165
|
-
assert.equal(isLocalRouteName('deepseek-account', 'deepseek-v4-pro'), false, '付费旗舰不得误标为本地')
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test('withOpsFeedback:无错误时原提示逐字不动,有错误时把原因清单贴回后面', () => {
|
|
169
|
-
assert.equal(withOpsFeedback('BASE', null), 'BASE', '首轮不许改写提示')
|
|
170
|
-
assert.equal(withOpsFeedback('BASE', []), 'BASE')
|
|
171
|
-
const fed = withOpsFeedback('BASE', ['第 1 条 不是对象', '第 2 条 kind 非法'])
|
|
172
|
-
assert.match(fed, /^BASE/, '原提示必须逐字保留在前')
|
|
173
|
-
assert.match(fed, /- 第 1 条 不是对象/)
|
|
174
|
-
assert.match(fed, /- 第 2 条 kind 非法/)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
// ── /ops/providers ──────────────────────────────────────────────────────
|
|
178
|
-
|
|
179
|
-
test('providers:候选只来自配置白名单,不再枚举宿主 listProviders', async () => {
|
|
180
|
-
let listed = 0
|
|
181
|
-
const harness = await booted({
|
|
182
|
-
providers: [{ id: 'deepseek-official', models: ['deepseek-v4-pro'] }],
|
|
183
|
-
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-account', model: 'deepseek-v4-pro' }] } },
|
|
184
|
-
})
|
|
185
|
-
const src = harness.ctx.get('llm')
|
|
186
|
-
const origin = src.listProviders
|
|
187
|
-
src.listProviders = async () => { listed += 1; return origin() }
|
|
188
|
-
const res = await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })
|
|
189
|
-
const json = res.json()
|
|
190
|
-
assert.equal(json.ok, true)
|
|
191
|
-
assert.equal(json.disabled, false)
|
|
192
|
-
assert.equal(json.unconfigured, false, '钉了主路由就不是未钉定')
|
|
193
|
-
assert.equal(listed, 0, '白名单为准:一个宿主 provider 都不去枚举')
|
|
194
|
-
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-account/deepseek-v4-pro'])
|
|
195
|
-
assert.deepEqual(json.routes.map((r) => r.local), [true, false], '本地/云端标记要随链给出')
|
|
196
|
-
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-account'], 'providers 仍按 provider 聚合(旧客户端兼容)')
|
|
197
|
-
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B'])
|
|
198
|
-
assert.deepEqual(json.default, { provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, '默认就是链首')
|
|
199
|
-
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示')
|
|
200
|
-
|
|
201
|
-
const bare = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
202
|
-
const j2 = (await callRoute(bare, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
|
|
203
|
-
assert.equal(j2.unconfigured, true, '链空必须报 unconfigured,而不是只给空数组')
|
|
204
|
-
assert.deepEqual(j2.providers, [])
|
|
205
|
-
|
|
206
|
-
const wrong = await callRoute(harness, `${OPS}/providers`, { method: 'POST', url: `${OPS}/providers`, headers: {} })
|
|
207
|
-
assert.equal(wrong.status, 405)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
test('catalog:链编辑器数据源 = 宿主 provider 目录 + 逐家模型清单 + 已存链原串', async () => {
|
|
211
|
-
let listed = 0
|
|
212
|
-
const harness = await booted({
|
|
213
|
-
providers: [{ id: 'local-35', name: 'local-35' }, { id: 'deepseek-own', name: 'DeepSeek' }],
|
|
214
|
-
models: async (provider) => {
|
|
215
|
-
listed += 1
|
|
216
|
-
return provider === 'local-35'
|
|
217
|
-
? [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen 3.6 35B' }, { id: 'Qwen3.8-27B' }]
|
|
218
|
-
: [{ id: 'deepseek-flash', name: 'Flash' }]
|
|
219
|
-
},
|
|
220
|
-
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-own', model: 'deepseek-flash' }, { provider: '', model: 'ghost' }] } },
|
|
221
|
-
})
|
|
222
|
-
const get = async () => (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
223
|
-
const json = await get()
|
|
224
|
-
assert.equal(json.ok, true)
|
|
225
|
-
assert.equal(json.enabled, true)
|
|
226
|
-
assert.equal(json.maxChain, 6, '链长上限要随目录给出,客户端才能拿宿主口径截断')
|
|
227
|
-
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-own'])
|
|
228
|
-
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B', 'Qwen3.8-27B'])
|
|
229
|
-
assert.equal(json.providers[0].models[0].label, 'Qwen 3.6 35B', '无 name 时回退到 id,有 name 用 name')
|
|
230
|
-
assert.equal(json.providers[0].modelsAvailable, true)
|
|
231
|
-
// 回显的是已存配置原串,不是链构建结果:半成品行也要看得见、能修好
|
|
232
|
-
assert.equal(json.chain.fallbacks.length, 2)
|
|
233
|
-
assert.deepEqual(json.chain.fallbacks[1], { provider: '', model: 'ghost' })
|
|
234
|
-
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-own/deepseek-flash'], '生效链那侧仍剔除缺 provider 的行')
|
|
235
|
-
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示,不进候选')
|
|
236
|
-
|
|
237
|
-
await get()
|
|
238
|
-
assert.equal(listed, 2, '两家 provider 各查一次,第二次开卡命中 TTL 缓存不重打宿主')
|
|
239
|
-
const wrong = await callRoute(harness, `${OPS}/catalog`, { method: 'POST', url: `${OPS}/catalog`, headers: {} })
|
|
240
|
-
assert.equal(wrong.status, 405)
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
test('catalog:宿主不供模型清单或查询报错时回空表并标 modelsAvailable=false', async () => {
|
|
244
|
-
const bare = await booted({ providers: [{ id: 'local-35', name: 'local-35' }] })
|
|
245
|
-
const j1 = (await callRoute(bare, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
246
|
-
assert.equal(j1.providers.length, 1, 'provider 目录照常给')
|
|
247
|
-
assert.equal(j1.providers[0].modelsAvailable, false, '没 listModels 就得告知客户端降级手输')
|
|
248
|
-
assert.deepEqual(j1.providers[0].models, [])
|
|
249
|
-
|
|
250
|
-
let calls = 0
|
|
251
|
-
const boom = await booted({
|
|
252
|
-
providers: [{ id: 'x', name: 'x' }],
|
|
253
|
-
models: async () => { calls += 1; throw new Error('adapter-down') },
|
|
254
|
-
})
|
|
255
|
-
const getBoom = async () => (await callRoute(boom, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
256
|
-
const j2 = await getBoom()
|
|
257
|
-
assert.equal(j2.providers[0].modelsAvailable, false)
|
|
258
|
-
assert.equal(j2.providers[0].models.length, 0)
|
|
259
|
-
await getBoom()
|
|
260
|
-
assert.equal(calls, 2, '失败不进缓存:下次开卡重试,不把一次报错长挂一分钟')
|
|
261
|
-
|
|
262
|
-
const none = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
263
|
-
const j3 = (await callRoute(none, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
264
|
-
assert.deepEqual(j3.providers, [], '宿主没给 llm 目录面时回空集,客户端全行手输')
|
|
265
|
-
assert.deepEqual(j3.routes, [])
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
test('catalog:ops.enabled=false 时目录与已存链照常回(关闭态也要能编链)', async () => {
|
|
269
|
-
const harness = await booted({
|
|
270
|
-
providers: [{ id: 'local', name: 'local' }],
|
|
271
|
-
models: async () => [{ id: 'qwen', name: 'qwen' }],
|
|
272
|
-
config: { ops: { enabled: false, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] } },
|
|
273
|
-
})
|
|
274
|
-
const json = (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
275
|
-
assert.equal(json.enabled, false, '开关态单独告知,不影响目录')
|
|
276
|
-
assert.equal(json.providers.length, 1)
|
|
277
|
-
assert.equal(json.chain.routeProvider, 'local', '关闭态下已存链仍可回显可编辑')
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
test('ops.enabled=false:providers 报 disabled 且不枚举宿主、refine/mutate/ask 一律 403,validate 照常可用', async () => {
|
|
281
|
-
let listed = 0
|
|
282
|
-
const harness = await booted({
|
|
283
|
-
config: { ops: { enabled: false } },
|
|
284
|
-
providers: [{ id: 'local', models: ['qwen'] }],
|
|
285
|
-
})
|
|
286
|
-
const src = harness.ctx.get('llm')
|
|
287
|
-
const origin = src.listProviders
|
|
288
|
-
src.listProviders = async () => { listed += 1; return origin() }
|
|
289
|
-
const prov = (await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
|
|
290
|
-
assert.equal(prov.disabled, true, '开关关掉必须告知客户端,而不是只给空数组')
|
|
291
|
-
assert.deepEqual(prov.providers, [])
|
|
292
|
-
assert.equal(listed, 0, '关了就不再打宿主 listProviders')
|
|
293
|
-
for (const op of ['refine', 'mutate', 'ask']) {
|
|
294
|
-
const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
|
|
295
|
-
assert.equal(r.status, 403, `${op} 在 ops.enabled=false 时必须 403`)
|
|
296
|
-
assert.match(r.json.error, /关闭|ops\.enabled/)
|
|
297
|
-
}
|
|
298
|
-
const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
299
|
-
assert.equal(v.status, 200, 'validate 是零 token 的本地体检,不被开关封掉')
|
|
300
|
-
assert.equal(v.json.ok, true)
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
// ── /ops validate:本地活,不进 LLM ────────────────────────────────────
|
|
304
|
-
|
|
305
|
-
test('op=validate 纯本地跑,一次 llm 调用都不发', async () => {
|
|
306
|
-
const calls = []
|
|
307
|
-
const harness = await booted({ reply: '{"changes":[]}', calls })
|
|
308
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
309
|
-
assert.equal(r.status, 200)
|
|
310
|
-
assert.equal(r.json.ok, true)
|
|
311
|
-
assert.equal(r.json.applied, false)
|
|
312
|
-
assert.equal(r.json.validation.count, 3)
|
|
313
|
-
assert.equal(calls.length, 0, 'validate 不得花 token')
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
// ── /ops refine / mutate:落盘 + 护栏 ──────────────────────────────────
|
|
317
|
-
|
|
318
|
-
test('op=refine 合规输出落盘 add+edit(order):thinking / attempts / 自动体检一并回给客户端', async () => {
|
|
319
|
-
let reply = '{}'
|
|
320
|
-
const calls = []
|
|
321
|
-
const harness = await booted({ calls, reply: () => reply })
|
|
322
|
-
const before = await snapshot(harness)
|
|
323
|
-
const target = before.items.find((i) => i.title === '写面板')
|
|
324
|
-
assert.ok(target, '种子板必须有「写面板」项')
|
|
325
|
-
reply = JSON.stringify({
|
|
326
|
-
thinking: '「写面板」偏粗,拆成数据面与展示面两步',
|
|
327
|
-
changes: [
|
|
328
|
-
{ kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
|
|
329
|
-
{ kind: 'edit', id: target.id, status: 'doing', percent: 40 },
|
|
330
|
-
],
|
|
331
|
-
answer: '已按数据面拆成两步',
|
|
332
|
-
})
|
|
333
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
334
|
-
assert.equal(r.json.ok, true)
|
|
335
|
-
assert.equal(r.json.applied, true)
|
|
336
|
-
assert.equal(r.json.changes.length, 2)
|
|
337
|
-
assert.equal(r.json.answer, '已按数据面拆成两步')
|
|
338
|
-
assert.equal(r.json.thinking, '「写面板」偏粗,拆成数据面与展示面两步', '思考区要原样透出')
|
|
339
|
-
assert.equal(r.json.attempts, 1, '一次就合规不应重试')
|
|
340
|
-
assert.equal(r.json.validation.ok, true, '落盘后的体检结论随回执自动带回')
|
|
341
|
-
assert.deepEqual(r.json.validation.errors, [])
|
|
342
|
-
assert.equal(calls.length, 1)
|
|
343
|
-
assert.equal(calls[0].provider, 'local')
|
|
344
|
-
assert.equal(calls[0].model, 'qwen')
|
|
345
|
-
const after = await snapshot(harness)
|
|
346
|
-
assert.equal(after.items.length, before.items.length + 1)
|
|
347
|
-
assert.equal(after.revision, before.revision + 1)
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
test('输出不符格式(幽灵 id + 空 title)→ 打回重问,第两轮合规才落盘', async () => {
|
|
351
|
-
const seq = [
|
|
352
|
-
JSON.stringify({ changes: [{ kind: 'edit', id: 'not-a-real-id', status: 'done' }, { kind: 'add', title: '' }], answer: 'x' }),
|
|
353
|
-
JSON.stringify({ thinking: '上一条用了板上没有的 id', changes: [{ kind: 'add', title: '拆:校验回写' }], answer: '重新给一版' }),
|
|
354
|
-
]
|
|
355
|
-
const calls = []
|
|
356
|
-
const harness = await booted({ calls, reply: () => seq.shift() })
|
|
357
|
-
const before = await snapshot(harness)
|
|
358
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
359
|
-
assert.equal(r.json.applied, true)
|
|
360
|
-
assert.equal(r.json.attempts, 2, '第一轮必须被打回')
|
|
361
|
-
assert.equal(r.json.changes.length, 1)
|
|
362
|
-
assert.equal(r.json.answer, '重新给一版')
|
|
363
|
-
assert.equal(calls.length, 2, '打回要真的再问一次')
|
|
364
|
-
const second = calls[1].messages[0].content[0].text
|
|
365
|
-
assert.match(second, /不符合校验格式/, '打回时要把原提示与错误清单一起喂回')
|
|
366
|
-
assert.match(second, /不在板上/)
|
|
367
|
-
assert.match(second, /缺少 title/)
|
|
368
|
-
const after = await snapshot(harness)
|
|
369
|
-
assert.equal(after.revision, before.revision + 1, '不允许半应用:只在合规那一轮落盘')
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
test('三轮都不合规 → 502,一次板都未动', async () => {
|
|
373
|
-
const calls = []
|
|
374
|
-
const harness = await booted({ calls, reply: '{"changes":[{"kind":"teleport","id":"x"}]}' })
|
|
375
|
-
const before = await snapshot(harness)
|
|
376
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
377
|
-
assert.equal(r.status, 502)
|
|
378
|
-
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
379
|
-
assert.match(r.json.error, /kind 非法/)
|
|
380
|
-
assert.equal(calls.length, 3, '一次原始 + 两次打回')
|
|
381
|
-
assert.equal((await snapshot(harness)).revision, before.revision, '打回失败不许留痕')
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
test('op=ask 没给 answer 也算不合格,打回一轮后取到回答', async () => {
|
|
385
|
-
const seq = ['{"changes":[]}', '{"thinking":"板上只有一项 doing","changes":[],"answer":"只有「接数据面」在做"}']
|
|
386
|
-
const calls = []
|
|
387
|
-
const harness = await booted({ calls, reply: () => seq.shift() })
|
|
388
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
|
|
389
|
-
assert.equal(r.json.ok, true)
|
|
390
|
-
assert.equal(r.json.attempts, 2)
|
|
391
|
-
assert.match(r.json.answer, /只有「接数据面」/)
|
|
392
|
-
assert.equal(r.json.thinking, '板上只有一项 doing')
|
|
393
|
-
assert.equal(calls.length, 2)
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
test('op=mutate 能把指令翻成删除(只认板上真 id),并触发 R4 队列提醒', async () => {
|
|
397
|
-
let reply = '{}'
|
|
398
|
-
const harness = await booted({ reply: () => reply })
|
|
399
|
-
const snap = await snapshot(harness)
|
|
400
|
-
const last = snap.items.find((i) => i.title === '补测试')
|
|
401
|
-
reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }], answer: '删掉了' })
|
|
402
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '把补测试删掉' })
|
|
403
|
-
assert.equal(r.json.applied, true)
|
|
404
|
-
assert.equal(r.json.attempts, 1, '只给板上真 id 就是一次过')
|
|
405
|
-
assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }])
|
|
406
|
-
const after = await snapshot(harness)
|
|
407
|
-
assert.equal(after.items.some((i) => i.title === '补测试'), false)
|
|
408
|
-
// R4:删除是结构性变更 → idle 走 followup 落队列
|
|
409
|
-
const notice = harness.followups.at(-1)
|
|
410
|
-
assert.ok(notice, '结构性变更必须落输入队列')
|
|
411
|
-
assert.equal(notice.source.kind, 'user', 'isHumanSteer 只认 kind=user')
|
|
412
|
-
assert.match(notice.content[0].text, /<progress-major-change rev="\d+">/)
|
|
413
|
-
// 回执必须把「已落队列」告知客户端(/ops 与 /action 同一套门控语义)
|
|
414
|
-
assert.equal(r.json.notified, true, 'ops 落盘的结构性变更必须回执 notified=true')
|
|
415
|
-
assert.equal(r.json.noticeMerged, false)
|
|
416
|
-
const before2 = harness.followups.length
|
|
417
|
-
const other = after.items.find((i) => i.title !== '补测试')
|
|
418
|
-
reply = JSON.stringify({ changes: [{ kind: 'remove', id: other.id }] })
|
|
419
|
-
const r2 = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '再删一项' })
|
|
420
|
-
assert.equal(r2.json.applied, true)
|
|
421
|
-
assert.equal(r2.json.notified, false, '同回合第二次 ops 改板被合并,不得假装新投了一条')
|
|
422
|
-
assert.equal(r2.json.noticeMerged, true, '但必须让客户端知道“本回合已经提醒过”,否则它会另发 wake')
|
|
423
|
-
assert.equal(harness.followups.length, before2, '同回合仍只一条队列消息')
|
|
424
|
-
})
|
|
425
|
-
|
|
426
|
-
test('op=mutate/ask 缺 question、未知 op、缺 sessionId 一律 400', async () => {
|
|
427
|
-
const harness = await booted({ reply: '{"changes":[]}' })
|
|
428
|
-
assert.equal((await ops(harness, { sessionId: SESSION, op: 'mutate' })).status, 400)
|
|
429
|
-
assert.equal((await ops(harness, { sessionId: SESSION, op: 'ask' })).status, 400)
|
|
430
|
-
assert.equal((await ops(harness, { sessionId: SESSION, op: 'teleport' })).status, 400)
|
|
431
|
-
assert.equal((await ops(harness, { sessionId: '', op: 'validate' })).status, 400)
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
test('未钉定模型路由 → 403,一帧 token 都不发', async () => {
|
|
435
|
-
const calls = []
|
|
436
|
-
const harness = await booted({ calls, config: { ops: { enabled: true, routeProvider: '', routeModel: '' } }, reply: '{"changes":[{"kind":"add","title":"x"}]}' })
|
|
437
|
-
const before = await snapshot(harness)
|
|
438
|
-
for (const op of ['refine', 'mutate', 'ask']) {
|
|
439
|
-
const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
|
|
440
|
-
assert.equal(r.status, 403, `${op} 在未钉定路由时必须 403`)
|
|
441
|
-
assert.match(r.json.error, /未钉定模型路由|ops\.fallbacks/)
|
|
442
|
-
}
|
|
443
|
-
assert.equal(calls.length, 0, '未钉定不得发出任何一次模型调用')
|
|
444
|
-
assert.equal((await snapshot(harness)).revision, before.revision, '没钉路由就不许动板')
|
|
445
|
-
// 体检不花 token,与路由无关,仍照常可用
|
|
446
|
-
const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
447
|
-
assert.equal(v.status, 200)
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
test('选了链外的 provider/model → 403,并把链上候选告知回去', async () => {
|
|
451
|
-
const calls = []
|
|
452
|
-
const harness = await booted({ calls, reply: '{"changes":[]}' })
|
|
453
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine', provider: 'deepseek-account', model: 'deepseek-v4-pro' })
|
|
454
|
-
assert.equal(r.status, 403)
|
|
455
|
-
assert.match(r.json.error, /不在 ops 允许范围内/)
|
|
456
|
-
assert.match(r.json.error, /local\/qwen/, '必须把链上真值告知回去,否则用户无从改配置')
|
|
457
|
-
assert.equal(calls.length, 0)
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
test('主路由传输失败 → 沿链降级到下一条,routeIndex 告知降级位次', async () => {
|
|
461
|
-
const calls = []
|
|
462
|
-
const harness = await booted({
|
|
463
|
-
calls,
|
|
464
|
-
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
465
|
-
reply: () => (calls.length === 1 ? (() => { throw new Error('assistant-empty') })() : JSON.stringify({ thinking: '主路由挂了,这条顶上', changes: [{ kind: 'add', title: '拆项' }], answer: '已落盘' })),
|
|
466
|
-
})
|
|
467
|
-
const before = await snapshot(harness)
|
|
468
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
469
|
-
assert.equal(r.json.applied, true, '主路由传输失败不得直接放弃,要沿链降级')
|
|
470
|
-
assert.equal(r.json.routeIndex, 1, '服务的是链上第二条')
|
|
471
|
-
assert.deepEqual(r.json.route, { provider: 'backup', model: 'small', local: false })
|
|
472
|
-
assert.equal(calls.length, 2)
|
|
473
|
-
assert.equal(calls[1].provider, 'backup')
|
|
474
|
-
assert.equal(calls[1].model, 'small')
|
|
475
|
-
assert.equal((await snapshot(harness)).revision, before.revision + 1)
|
|
476
|
-
})
|
|
477
|
-
|
|
478
|
-
test('全链都拉不出可用输出 → 502,逐条路由的失败原因都告知', async () => {
|
|
479
|
-
const calls = []
|
|
480
|
-
const harness = await booted({
|
|
481
|
-
calls,
|
|
482
|
-
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
483
|
-
reply: '纯文本,不是 JSON',
|
|
484
|
-
})
|
|
485
|
-
const before = await snapshot(harness)
|
|
486
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
487
|
-
assert.equal(r.status, 502)
|
|
488
|
-
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
489
|
-
assert.match(r.json.error, /local\/qwen:/)
|
|
490
|
-
assert.match(r.json.error, /backup\/small:/)
|
|
491
|
-
assert.equal(calls.length, 6, '两条路由各走满三轮格式打回')
|
|
492
|
-
assert.equal((await snapshot(harness)).revision, before.revision)
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
test('模型乱答(无 JSON)→ 三轮都拉不回来,502 且板不变', async () => {
|
|
496
|
-
const calls = []
|
|
497
|
-
const harness = await booted({ calls, reply: '我觉得可以拆成三步,你先看看代码' })
|
|
498
|
-
const before = await snapshot(harness)
|
|
499
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
500
|
-
assert.equal(r.status, 502)
|
|
501
|
-
assert.match(r.json.error, /无法解析|没有返回|不是可解析/)
|
|
502
|
-
assert.equal(calls.length, 3, '纯文本回答同样走打回,不是一次就放弃')
|
|
503
|
-
assert.equal((await snapshot(harness)).revision, before.revision)
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
test('模型给超过 8 条改动只应用前 8 条', async () => {
|
|
507
|
-
const many = Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i }))
|
|
508
|
-
const harness = await booted({ reply: JSON.stringify({ changes: many, answer: 'ok' }) })
|
|
509
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
510
|
-
assert.equal(r.json.changes.length, 8)
|
|
511
|
-
assert.equal((await snapshot(harness)).items.length, 3 + 8)
|
|
512
|
-
})
|
|
513
|
-
|
|
514
|
-
// ── ask:只回文本 ──────────────────────────────────────────────────────
|
|
515
|
-
|
|
516
|
-
test('op=ask 只回文本:模型硬塞 changes 也不落盘', async () => {
|
|
517
|
-
const calls = []
|
|
518
|
-
const harness = await booted({
|
|
519
|
-
calls,
|
|
520
|
-
reply: JSON.stringify({ changes: [{ kind: 'add', title: '不该出现' }], answer: '三项里只有「接数据面」在做' }),
|
|
521
|
-
})
|
|
522
|
-
const before = await snapshot(harness)
|
|
523
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
|
|
524
|
-
assert.equal(r.json.ok, true)
|
|
525
|
-
assert.equal(r.json.applied, false)
|
|
526
|
-
assert.equal(r.json.changes.length, 0)
|
|
527
|
-
assert.match(r.json.answer, /只有「接数据面」/)
|
|
528
|
-
assert.equal(calls.length, 1)
|
|
529
|
-
const after = await snapshot(harness)
|
|
530
|
-
assert.equal(after.revision, before.revision, 'ask 绝不改板')
|
|
531
|
-
})
|
|
532
|
-
|
|
533
|
-
test('喂给模型的板必须带 id(否则它无法指认 edit/remove 哪一项)', async () => {
|
|
534
|
-
const calls = []
|
|
535
|
-
const harness = await booted({ calls, reply: '{"changes":[],"answer":"x"}' })
|
|
536
|
-
const snap = await snapshot(harness)
|
|
537
|
-
await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
538
|
-
const user = calls[0].messages[0].content[0].text
|
|
539
|
-
for (const item of snap.items) assert.ok(user.includes(item.id), `提示里必须含板上项 id ${item.id}`)
|
|
540
|
-
assert.match(user, /<progress-board ids="true">/)
|
|
541
|
-
})
|
|
542
|
-
|
|
543
|
-
// ── origin='ops' 不冒充主模型 ──────────────────────────────────────────
|
|
544
|
-
|
|
545
|
-
test('ops 落盘不重置 stepsSinceModel:催办仍按原步数报滞后', async () => {
|
|
546
|
-
const harness = await booted({ reply: JSON.stringify({ changes: [{ kind: 'add', title: '拆项' }], answer: 'ok' }) })
|
|
547
|
-
for (let i = 0; i < 4; i += 1) harness.emit('step/start', {})
|
|
548
|
-
const text = () => harness.contexts.get('progress-union-observer')()
|
|
549
|
-
assert.match(text(), /synced="4 步前"/)
|
|
550
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
551
|
-
assert.equal(r.json.applied, true)
|
|
552
|
-
assert.match(text(), /synced="4 步前"/, '侧边栏 LLM 操作不算「模型已同步」')
|
|
553
|
-
})
|
|
554
|
-
|
|
555
|
-
// ── v0.9.0:计划文档进 ops 原料 ────────────────────────────────────
|
|
556
|
-
// 真机反馈:用户写「是否可以对 …\.agents\plans\session-exclusion-gate\tasks.md 任务为纲再细化」,
|
|
557
|
-
// 模型答“这属于咨询、不执行”——它确实只拿到板子清单,没有任何文件面。
|
|
558
|
-
// 本仓早就有 scanPlan/parseChecklistMarkdown 这套原料机器(给观察者用),ops 必须接上。
|
|
559
|
-
|
|
560
|
-
test('planSlugFromText:只认 .agents/plans/<slug>/ 形态,反斜杠与正斜杠都吃', () => {
|
|
561
|
-
assert.equal(planSlugFromText('按 E:\\test\\repo\\.agents\\plans\\session-exclusion-gate\\tasks.md 为纲细化'), 'session-exclusion-gate')
|
|
562
|
-
assert.equal(planSlugFromText('看 /home/me/.agents/plans/demo-plan/checklist.md 的第 3 项'), 'demo-plan')
|
|
563
|
-
assert.equal(planSlugFromText('把「做点事」拆细一点'), '', '普通英文词不得被当 slug')
|
|
564
|
-
assert.equal(planSlugFromText('.agents/plans/ab/tasks.md'), 'ab')
|
|
565
|
-
})
|
|
566
|
-
|
|
567
|
-
function mkOpsPlan() {
|
|
568
|
-
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'union-ops-plan-'))
|
|
569
|
-
const dir = path.join(cwd, '.agents', 'plans', 'demo-plan')
|
|
570
|
-
fs.mkdirSync(dir, { recursive: true })
|
|
571
|
-
fs.writeFileSync(path.join(dir, 'tasks.md'), '## Phase 1: 做点事\n- [x] t01 第一件事\n- [ ] t02 第二件事\n\n## Phase 2: 收尾\n- [ ] t03 第三件事\n', 'utf8')
|
|
572
|
-
fs.writeFileSync(path.join(dir, 'spec.md'), '# Spec: 演示\n\n## 需求\n- 让 ops 读计划\n', 'utf8')
|
|
573
|
-
return cwd
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
test('v0.9.0:ops ask 把点名的计划未完项喂进助手,并在回执报 grounding', async () => {
|
|
577
|
-
const calls = []
|
|
578
|
-
const cwd = mkOpsPlan()
|
|
579
|
-
const harness = await booted({ cwd, calls, reply: '{"thinking":"按纲","changes":[],"answer":"t02 与 t03 还没做"}' })
|
|
580
|
-
const named = path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')
|
|
581
|
-
const { status, json } = await ops(harness, { sessionId: SESSION, op: 'ask', question: `按 ${named} 为纲,还剩哪些没做` })
|
|
582
|
-
assert.equal(status, 200, JSON.stringify(json))
|
|
583
|
-
const user = calls[0].messages[0].content[0].text
|
|
584
|
-
assert.ok(user.includes('<plan slug="demo-plan"'), '助手输入必须带计划段')
|
|
585
|
-
assert.ok(user.includes('t02 第二件事') && user.includes('t03 第三件事'), '未完项原文与编号必须进原料')
|
|
586
|
-
assert.ok(!user.includes('t01 第一件事'), '已勾选项不再当未完喂入')
|
|
587
|
-
assert.ok(user.includes('Phase 1: 做点事'), 'Phase 分组要在')
|
|
588
|
-
assert.ok(user.includes('spec 大纲'), 'spec 大纲也要在')
|
|
589
|
-
assert.equal(json.plan.ok, true)
|
|
590
|
-
assert.equal(json.plan.slug, 'demo-plan')
|
|
591
|
-
assert.equal(json.plan.asked, 'demo-plan', '点名要如实回报')
|
|
592
|
-
assert.equal(json.plan.pending, 2)
|
|
593
|
-
assert.equal(json.plan.listed, 2)
|
|
594
|
-
})
|
|
595
|
-
|
|
596
|
-
test('v0.9.0:refine 同样拿到计划段,且指令仍在尾部(模型重尾)', async () => {
|
|
597
|
-
const calls = []
|
|
598
|
-
const cwd = mkOpsPlan()
|
|
599
|
-
const harness = await booted({ cwd, calls, reply: '{"changes":[{"kind":"add","title":"Phase 2 · 拆 t03"}],"answer":"ok"}' })
|
|
600
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'refine', question: `以 ${path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')} 为纲拆分` })
|
|
601
|
-
assert.equal(r.json.applied, true)
|
|
602
|
-
const user = calls[0].messages[0].content[0].text
|
|
603
|
-
const atPlan = user.indexOf('<plan slug="demo-plan"')
|
|
604
|
-
const atCmd = user.indexOf('用户补充:')
|
|
605
|
-
assert.ok(atPlan > 0, '计划段必须在')
|
|
606
|
-
assert.ok(atCmd > atPlan, `指令要排在计划段之后(plan=${atPlan} cmd=${atCmd})`)
|
|
607
|
-
assert.ok(user.indexOf('<progress-board') < atPlan, '计划段在板子清单之后、指令之前')
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
test('v0.9.0:planSync=off 时不注入计划段,但动作照常并报 reason=disabled', async () => {
|
|
611
|
-
const calls = []
|
|
612
|
-
const cwd = mkOpsPlan()
|
|
613
|
-
const harness = await booted({
|
|
614
|
-
cwd,
|
|
615
|
-
calls,
|
|
616
|
-
config: { planSync: 'off' },
|
|
617
|
-
reply: '{"thinking":"","changes":[],"answer":"ok"}',
|
|
618
|
-
})
|
|
619
|
-
const named = path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')
|
|
620
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: `${named} 还剩什么` })
|
|
621
|
-
assert.equal(r.status, 200, '计划面关掉不能连带把 ops 动作打死')
|
|
622
|
-
assert.ok(!calls[0].messages[0].content[0].text.includes('<plan'), 'off 时不得注入计划段')
|
|
623
|
-
assert.equal(r.json.plan.ok, false)
|
|
624
|
-
assert.equal(r.json.plan.reason, 'disabled', '要区分“被关掉”与“点名落空”')
|
|
625
|
-
assert.equal(r.json.plan.asked, 'demo-plan')
|
|
626
|
-
})
|
|
627
|
-
|
|
628
|
-
test('v0.9.0:点名不存在的 slug 时回退自动选,不静默抛错', async () => {
|
|
629
|
-
const calls = []
|
|
630
|
-
const cwd = mkOpsPlan()
|
|
631
|
-
const harness = await booted({ cwd, calls, reply: '{"thinking":"","changes":[],"answer":"ok"}' })
|
|
632
|
-
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: `按 ${path.join(cwd, '.agents', 'plans', 'no-such-plan', 'tasks.md')} 细化` })
|
|
633
|
-
assert.equal(r.status, 200)
|
|
634
|
-
const user = calls[0].messages[0].content[0].text
|
|
635
|
-
assert.equal(r.json.plan.asked, 'no-such-plan', '点名原值要留着供面板报信')
|
|
636
|
-
assert.equal(r.json.plan.slug, 'demo-plan', '回退到自动选,不空转')
|
|
637
|
-
assert.ok(user.includes('<plan slug="demo-plan"'), '回退后的原料照样喂')
|
|
638
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* 0.7.0 rc.3 验收:R3 侧边栏 LLM 任务操作。
|
|
3
|
+
* validateBoard / validateProposal / buildOpsChain 纯函数 + /ops/providers
|
|
4
|
+
* + /ops 三操作(refine/mutate/ask;validate 只留路由,面板不再放按钮)。
|
|
5
|
+
* 0.7.9 硬约束:模型输出不符格式一律打回重问(最多三轮),绕开半应用;
|
|
6
|
+
* 0.8.0 硬约束:介入范围 = 配置白名单(主路由 + ops.fallbacks),链外一律 403,
|
|
7
|
+
* 未钉定也一律 403,绝不退回宿主主模型;传输失败按链降级。
|
|
8
|
+
* 不新开顶级标签、零新增依赖;
|
|
9
|
+
* origin='ops' 不得让主模型看起来「同步过板」(stepsSinceModel 不归零)。
|
|
10
|
+
*/
|
|
11
|
+
import assert from 'node:assert/strict'
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
import os from 'node:os'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import test from 'node:test'
|
|
16
|
+
|
|
17
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
18
|
+
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
19
|
+
const { validateBoard, validateProposal, isLocalRouteName, buildOpsChain, withOpsFeedback, planSlugFromText } = await import('../index.js')
|
|
20
|
+
|
|
21
|
+
const OPS = '/progress-union/ops'
|
|
22
|
+
|
|
23
|
+
function llmMock(reply, calls) {
|
|
24
|
+
return {
|
|
25
|
+
async *stream(options) {
|
|
26
|
+
if (calls) calls.push(options)
|
|
27
|
+
yield { type: 'text-delta', text: typeof reply === 'function' ? reply() : reply }
|
|
28
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function booted({ config = {}, reply = '{}', calls = [], providers = undefined, models = undefined, cwd = '' } = {}) {
|
|
34
|
+
const llm = {
|
|
35
|
+
...llmMock(reply, calls),
|
|
36
|
+
...(providers ? { listProviders: async () => providers } : {}),
|
|
37
|
+
...(models ? { listModels: typeof models === 'function' ? models : async () => models } : {}),
|
|
38
|
+
}
|
|
39
|
+
const harness = createHarness({
|
|
40
|
+
...(cwd ? { cwd } : {}),
|
|
41
|
+
config: {
|
|
42
|
+
assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 },
|
|
43
|
+
// v0.8.0:ops 的介入范围 = 白名单。默认钉一条 local/qwen(与 llmMock 对得上),
|
|
44
|
+
// 需要测「未钉定」的用例自己把 routeProvider/routeModel 清空。
|
|
45
|
+
ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] },
|
|
46
|
+
...config,
|
|
47
|
+
},
|
|
48
|
+
llm,
|
|
49
|
+
})
|
|
50
|
+
await harness.run()
|
|
51
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
52
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
53
|
+
{ changes: [{ title: '接数据面', status: 'doing' }, { title: '写面板', percent: 30 }, { title: '补测试' }] },
|
|
54
|
+
{ agent: harness.agent },
|
|
55
|
+
)
|
|
56
|
+
return harness
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function snapshot(harness) {
|
|
60
|
+
const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
|
|
61
|
+
return res.json()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function ops(harness, body) {
|
|
65
|
+
const res = await callRoute(harness, OPS, jsonReq('POST', OPS, body))
|
|
66
|
+
return { status: res.status, json: res.json() }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ── validateBoard(纯函数)──────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
test('validateBoard:合法板通过,接受数组或 {items}', () => {
|
|
72
|
+
const ok = validateBoard([{ id: 'a', title: '甲', status: 'doing', percent: 20, order: 0 }, { id: 'b', title: '乙', status: 'todo', order: 1 }])
|
|
73
|
+
assert.equal(ok.ok, true, ok.errors.join(';'))
|
|
74
|
+
assert.equal(ok.count, 2)
|
|
75
|
+
assert.deepEqual(ok.warnings, [])
|
|
76
|
+
assert.equal(validateBoard({ items: [{ title: '甲' }] }).ok, true)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('validateBoard:硬错逐项拦下(项数/title/status 枚举/done⇒100/percent 越界)', () => {
|
|
80
|
+
assert.equal(validateBoard('nope').ok, false, '非数组必须是硬错')
|
|
81
|
+
const tooMany = validateBoard(Array.from({ length: 61 }, (_, i) => ({ title: 't' + i })))
|
|
82
|
+
assert.match(tooMany.errors.join(' '), /项数 61 超过上限 60/)
|
|
83
|
+
assert.match(validateBoard([{ status: 'doing' }]).errors.join(' '), /缺少 title/)
|
|
84
|
+
assert.match(validateBoard([{ title: '很长的'.repeat(70) }]).errors.join(' '), /title 过长/)
|
|
85
|
+
assert.match(validateBoard([{ title: '甲', status: 'pending-ish' }]).errors.join(' '), /status 非法/)
|
|
86
|
+
assert.match(validateBoard([{ title: '甲', status: 'done', percent: 50 }]).errors.join(' '), /done 但 percent=50/)
|
|
87
|
+
assert.match(validateBoard([{ title: '甲', percent: 140 }]).errors.join(' '), /percent 越界/)
|
|
88
|
+
assert.match(validateBoard([{ title: '甲', order: 'x' }]).errors.join(' '), /order 不是数字/)
|
|
89
|
+
assert.match(validateBoard(['nope']).errors.join(' '), /不是对象/)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('validateBoard:可疑但可写的只进 warnings(空板/重复 title/order 重复/多 doing)', () => {
|
|
93
|
+
const empty = validateBoard([])
|
|
94
|
+
assert.equal(empty.ok, true)
|
|
95
|
+
assert.match(empty.warnings.join(' '), /空板/)
|
|
96
|
+
const dup = validateBoard([{ title: '甲', status: 'doing', order: 0 }, { title: '甲', status: 'doing', order: 0 }])
|
|
97
|
+
assert.equal(dup.ok, true)
|
|
98
|
+
assert.match(dup.warnings.join(' '), /title 与前面重复/)
|
|
99
|
+
assert.match(dup.warnings.join(' '), /order 重复:0/)
|
|
100
|
+
assert.match(dup.warnings.join(' '), /同时 doing 2 项/)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
// ── validateProposal(模型输出格式门)────────────────────────────────
|
|
104
|
+
|
|
105
|
+
test('validateProposal:合规输出直接过;thinking 只是展示字段,缺了不打回', () => {
|
|
106
|
+
const state = { items: [{ id: 'a', title: '甲' }, { id: 'b', title: '乙' }] }
|
|
107
|
+
assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'doing' }], answer: 'ok' }, 'refine').ok, true)
|
|
108
|
+
assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }] }, 'mutate').ok, true, '无 thinking 也必须过')
|
|
109
|
+
assert.equal(validateProposal(state, { board: { changes: [{ kind: 'remove', id: 'b' }] } }, 'mutate').ok, true, '兼容 {board:{changes}} 旧形状')
|
|
110
|
+
assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'done' }], answer: '完成' }, 'mutate').ok, true, 'done 不强制带 percent:落盘时由 applyOneChange 补 100')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('validateProposal:吃不下的一律打回(非对象/缺 changes/kind 非枚举/幽灵 id/缺 title/edit 空转/percent 越界)', () => {
|
|
114
|
+
const state = { items: [{ id: 'a', title: '甲' }] }
|
|
115
|
+
const none = validateProposal(state, null, 'refine')
|
|
116
|
+
assert.equal(none.ok, false)
|
|
117
|
+
assert.match(none.errors[0], /不是可解析的 JSON 对象/)
|
|
118
|
+
assert.match(validateProposal(state, { answer: 'x' }, 'refine').errors.join(' '), /缺少 changes 数组/)
|
|
119
|
+
assert.match(validateProposal(state, { changes: ['nope'] }, 'refine').errors.join(' '), /不是对象/)
|
|
120
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'teleport', id: 'a' }] }, 'refine').errors.join(' '), /kind 非法/)
|
|
121
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'ghost', status: 'done' }] }, 'refine').errors.join(' '), /不在板上/)
|
|
122
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'remove', id: 'ghost' }] }, 'mutate').errors.join(' '), /不在板上/)
|
|
123
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'add', title: ' ' }] }, 'refine').errors.join(' '), /缺少 title/)
|
|
124
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'add', title: '很长的'.repeat(70) }] }, 'refine').errors.join(' '), /title 过长/)
|
|
125
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a' }] }, 'refine').errors.join(' '), /没有任何要改的字段/)
|
|
126
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'pending-ish' }] }, 'refine').errors.join(' '), /status 非法/)
|
|
127
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', percent: 140 }] }, 'refine').errors.join(' '), /percent 越界/)
|
|
128
|
+
assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', order: 'x' }] }, 'refine').errors.join(' '), /order 不是数字/)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('validateProposal:条数超上限只截断不打回;ask 只硬要求 answer', () => {
|
|
132
|
+
const state = { items: [{ id: 'a', title: '甲' }] }
|
|
133
|
+
const many = { changes: Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i })) }
|
|
134
|
+
assert.equal(validateProposal(state, many, 'refine').ok, true, '超上限走截断(可部分交付),不因此烧 token 重问')
|
|
135
|
+
assert.equal(validateProposal(state, { changes: [], answer: ' ' }, 'ask').ok, false, 'ask 没 answer 等于没回答')
|
|
136
|
+
assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }], answer: '好' }, 'ask').ok, true, 'ask 硬塞 changes 由路由丢弃,不算格式错')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
// ── 路由链纯函数(v0.8.0 白名单)───────────────────────────────
|
|
140
|
+
|
|
141
|
+
test('buildOpsChain:主路由在前、条目按序在后,缺 provider/model 剔除、同串去重', () => {
|
|
142
|
+
const chain = buildOpsChain(
|
|
143
|
+
{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' },
|
|
144
|
+
[{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, { provider: '', model: 'x' }, { provider: 'strata', model: 'qwen3.8-flash-iq2_xs' }],
|
|
145
|
+
false,
|
|
146
|
+
)
|
|
147
|
+
assert.deepEqual(chain.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'strata/qwen3.8-flash-iq2_xs'], '重复与缺 provider 的条目不占位')
|
|
148
|
+
assert.deepEqual(buildOpsChain({ provider: '', model: '' }, [], true), [], '主路由缺失 = 空链(未钉定)')
|
|
149
|
+
assert.deepEqual(buildOpsChain(null, undefined, true), [], '配置形状不对也不抛错')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('buildOpsChain:preferLocal 只重排不删;关掉则严格按配置顺序', () => {
|
|
153
|
+
const primary = { provider: 'deepseek-account', model: 'deepseek-v4-pro' }
|
|
154
|
+
const fallbacks = [{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }]
|
|
155
|
+
const on = buildOpsChain(primary, fallbacks, true)
|
|
156
|
+
assert.deepEqual(on.map((r) => r.provider), ['local-35', 'deepseek-account'], '本地候选排到链首')
|
|
157
|
+
assert.equal(on.length, 2, '重排不得丢条目')
|
|
158
|
+
assert.deepEqual(buildOpsChain(primary, fallbacks, false).map((r) => r.provider), ['deepseek-account', 'local-35'], '关掉后按配置顺序')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('isLocalRouteName:provider 命名与量化后缀都能命中,云端旗舰不算本地', () => {
|
|
162
|
+
assert.equal(isLocalRouteName('local-35', 'Qwen3.6-35B-A3B'), true, 'provider 名命中')
|
|
163
|
+
assert.equal(isLocalRouteName('strata', 'qwen3.8-flash-iq2_xs'), true, '量化后缀命中')
|
|
164
|
+
assert.equal(isLocalRouteName('ollama', 'llama3.1:8b'), true)
|
|
165
|
+
assert.equal(isLocalRouteName('deepseek-account', 'deepseek-v4-pro'), false, '付费旗舰不得误标为本地')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('withOpsFeedback:无错误时原提示逐字不动,有错误时把原因清单贴回后面', () => {
|
|
169
|
+
assert.equal(withOpsFeedback('BASE', null), 'BASE', '首轮不许改写提示')
|
|
170
|
+
assert.equal(withOpsFeedback('BASE', []), 'BASE')
|
|
171
|
+
const fed = withOpsFeedback('BASE', ['第 1 条 不是对象', '第 2 条 kind 非法'])
|
|
172
|
+
assert.match(fed, /^BASE/, '原提示必须逐字保留在前')
|
|
173
|
+
assert.match(fed, /- 第 1 条 不是对象/)
|
|
174
|
+
assert.match(fed, /- 第 2 条 kind 非法/)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// ── /ops/providers ──────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
test('providers:候选只来自配置白名单,不再枚举宿主 listProviders', async () => {
|
|
180
|
+
let listed = 0
|
|
181
|
+
const harness = await booted({
|
|
182
|
+
providers: [{ id: 'deepseek-official', models: ['deepseek-v4-pro'] }],
|
|
183
|
+
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-account', model: 'deepseek-v4-pro' }] } },
|
|
184
|
+
})
|
|
185
|
+
const src = harness.ctx.get('llm')
|
|
186
|
+
const origin = src.listProviders
|
|
187
|
+
src.listProviders = async () => { listed += 1; return origin() }
|
|
188
|
+
const res = await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })
|
|
189
|
+
const json = res.json()
|
|
190
|
+
assert.equal(json.ok, true)
|
|
191
|
+
assert.equal(json.disabled, false)
|
|
192
|
+
assert.equal(json.unconfigured, false, '钉了主路由就不是未钉定')
|
|
193
|
+
assert.equal(listed, 0, '白名单为准:一个宿主 provider 都不去枚举')
|
|
194
|
+
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-account/deepseek-v4-pro'])
|
|
195
|
+
assert.deepEqual(json.routes.map((r) => r.local), [true, false], '本地/云端标记要随链给出')
|
|
196
|
+
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-account'], 'providers 仍按 provider 聚合(旧客户端兼容)')
|
|
197
|
+
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B'])
|
|
198
|
+
assert.deepEqual(json.default, { provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, '默认就是链首')
|
|
199
|
+
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示')
|
|
200
|
+
|
|
201
|
+
const bare = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
202
|
+
const j2 = (await callRoute(bare, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
|
|
203
|
+
assert.equal(j2.unconfigured, true, '链空必须报 unconfigured,而不是只给空数组')
|
|
204
|
+
assert.deepEqual(j2.providers, [])
|
|
205
|
+
|
|
206
|
+
const wrong = await callRoute(harness, `${OPS}/providers`, { method: 'POST', url: `${OPS}/providers`, headers: {} })
|
|
207
|
+
assert.equal(wrong.status, 405)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('catalog:链编辑器数据源 = 宿主 provider 目录 + 逐家模型清单 + 已存链原串', async () => {
|
|
211
|
+
let listed = 0
|
|
212
|
+
const harness = await booted({
|
|
213
|
+
providers: [{ id: 'local-35', name: 'local-35' }, { id: 'deepseek-own', name: 'DeepSeek' }],
|
|
214
|
+
models: async (provider) => {
|
|
215
|
+
listed += 1
|
|
216
|
+
return provider === 'local-35'
|
|
217
|
+
? [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen 3.6 35B' }, { id: 'Qwen3.8-27B' }]
|
|
218
|
+
: [{ id: 'deepseek-flash', name: 'Flash' }]
|
|
219
|
+
},
|
|
220
|
+
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-own', model: 'deepseek-flash' }, { provider: '', model: 'ghost' }] } },
|
|
221
|
+
})
|
|
222
|
+
const get = async () => (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
223
|
+
const json = await get()
|
|
224
|
+
assert.equal(json.ok, true)
|
|
225
|
+
assert.equal(json.enabled, true)
|
|
226
|
+
assert.equal(json.maxChain, 6, '链长上限要随目录给出,客户端才能拿宿主口径截断')
|
|
227
|
+
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-own'])
|
|
228
|
+
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B', 'Qwen3.8-27B'])
|
|
229
|
+
assert.equal(json.providers[0].models[0].label, 'Qwen 3.6 35B', '无 name 时回退到 id,有 name 用 name')
|
|
230
|
+
assert.equal(json.providers[0].modelsAvailable, true)
|
|
231
|
+
// 回显的是已存配置原串,不是链构建结果:半成品行也要看得见、能修好
|
|
232
|
+
assert.equal(json.chain.fallbacks.length, 2)
|
|
233
|
+
assert.deepEqual(json.chain.fallbacks[1], { provider: '', model: 'ghost' })
|
|
234
|
+
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-own/deepseek-flash'], '生效链那侧仍剔除缺 provider 的行')
|
|
235
|
+
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示,不进候选')
|
|
236
|
+
|
|
237
|
+
await get()
|
|
238
|
+
assert.equal(listed, 2, '两家 provider 各查一次,第二次开卡命中 TTL 缓存不重打宿主')
|
|
239
|
+
const wrong = await callRoute(harness, `${OPS}/catalog`, { method: 'POST', url: `${OPS}/catalog`, headers: {} })
|
|
240
|
+
assert.equal(wrong.status, 405)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
test('catalog:宿主不供模型清单或查询报错时回空表并标 modelsAvailable=false', async () => {
|
|
244
|
+
const bare = await booted({ providers: [{ id: 'local-35', name: 'local-35' }] })
|
|
245
|
+
const j1 = (await callRoute(bare, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
246
|
+
assert.equal(j1.providers.length, 1, 'provider 目录照常给')
|
|
247
|
+
assert.equal(j1.providers[0].modelsAvailable, false, '没 listModels 就得告知客户端降级手输')
|
|
248
|
+
assert.deepEqual(j1.providers[0].models, [])
|
|
249
|
+
|
|
250
|
+
let calls = 0
|
|
251
|
+
const boom = await booted({
|
|
252
|
+
providers: [{ id: 'x', name: 'x' }],
|
|
253
|
+
models: async () => { calls += 1; throw new Error('adapter-down') },
|
|
254
|
+
})
|
|
255
|
+
const getBoom = async () => (await callRoute(boom, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
256
|
+
const j2 = await getBoom()
|
|
257
|
+
assert.equal(j2.providers[0].modelsAvailable, false)
|
|
258
|
+
assert.equal(j2.providers[0].models.length, 0)
|
|
259
|
+
await getBoom()
|
|
260
|
+
assert.equal(calls, 2, '失败不进缓存:下次开卡重试,不把一次报错长挂一分钟')
|
|
261
|
+
|
|
262
|
+
const none = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
263
|
+
const j3 = (await callRoute(none, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
264
|
+
assert.deepEqual(j3.providers, [], '宿主没给 llm 目录面时回空集,客户端全行手输')
|
|
265
|
+
assert.deepEqual(j3.routes, [])
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
test('catalog:ops.enabled=false 时目录与已存链照常回(关闭态也要能编链)', async () => {
|
|
269
|
+
const harness = await booted({
|
|
270
|
+
providers: [{ id: 'local', name: 'local' }],
|
|
271
|
+
models: async () => [{ id: 'qwen', name: 'qwen' }],
|
|
272
|
+
config: { ops: { enabled: false, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] } },
|
|
273
|
+
})
|
|
274
|
+
const json = (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
275
|
+
assert.equal(json.enabled, false, '开关态单独告知,不影响目录')
|
|
276
|
+
assert.equal(json.providers.length, 1)
|
|
277
|
+
assert.equal(json.chain.routeProvider, 'local', '关闭态下已存链仍可回显可编辑')
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
test('ops.enabled=false:providers 报 disabled 且不枚举宿主、refine/mutate/ask 一律 403,validate 照常可用', async () => {
|
|
281
|
+
let listed = 0
|
|
282
|
+
const harness = await booted({
|
|
283
|
+
config: { ops: { enabled: false } },
|
|
284
|
+
providers: [{ id: 'local', models: ['qwen'] }],
|
|
285
|
+
})
|
|
286
|
+
const src = harness.ctx.get('llm')
|
|
287
|
+
const origin = src.listProviders
|
|
288
|
+
src.listProviders = async () => { listed += 1; return origin() }
|
|
289
|
+
const prov = (await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
|
|
290
|
+
assert.equal(prov.disabled, true, '开关关掉必须告知客户端,而不是只给空数组')
|
|
291
|
+
assert.deepEqual(prov.providers, [])
|
|
292
|
+
assert.equal(listed, 0, '关了就不再打宿主 listProviders')
|
|
293
|
+
for (const op of ['refine', 'mutate', 'ask']) {
|
|
294
|
+
const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
|
|
295
|
+
assert.equal(r.status, 403, `${op} 在 ops.enabled=false 时必须 403`)
|
|
296
|
+
assert.match(r.json.error, /关闭|ops\.enabled/)
|
|
297
|
+
}
|
|
298
|
+
const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
299
|
+
assert.equal(v.status, 200, 'validate 是零 token 的本地体检,不被开关封掉')
|
|
300
|
+
assert.equal(v.json.ok, true)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
// ── /ops validate:本地活,不进 LLM ────────────────────────────────────
|
|
304
|
+
|
|
305
|
+
test('op=validate 纯本地跑,一次 llm 调用都不发', async () => {
|
|
306
|
+
const calls = []
|
|
307
|
+
const harness = await booted({ reply: '{"changes":[]}', calls })
|
|
308
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
309
|
+
assert.equal(r.status, 200)
|
|
310
|
+
assert.equal(r.json.ok, true)
|
|
311
|
+
assert.equal(r.json.applied, false)
|
|
312
|
+
assert.equal(r.json.validation.count, 3)
|
|
313
|
+
assert.equal(calls.length, 0, 'validate 不得花 token')
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
// ── /ops refine / mutate:落盘 + 护栏 ──────────────────────────────────
|
|
317
|
+
|
|
318
|
+
test('op=refine 合规输出落盘 add+edit(order):thinking / attempts / 自动体检一并回给客户端', async () => {
|
|
319
|
+
let reply = '{}'
|
|
320
|
+
const calls = []
|
|
321
|
+
const harness = await booted({ calls, reply: () => reply })
|
|
322
|
+
const before = await snapshot(harness)
|
|
323
|
+
const target = before.items.find((i) => i.title === '写面板')
|
|
324
|
+
assert.ok(target, '种子板必须有「写面板」项')
|
|
325
|
+
reply = JSON.stringify({
|
|
326
|
+
thinking: '「写面板」偏粗,拆成数据面与展示面两步',
|
|
327
|
+
changes: [
|
|
328
|
+
{ kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
|
|
329
|
+
{ kind: 'edit', id: target.id, status: 'doing', percent: 40 },
|
|
330
|
+
],
|
|
331
|
+
answer: '已按数据面拆成两步',
|
|
332
|
+
})
|
|
333
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
334
|
+
assert.equal(r.json.ok, true)
|
|
335
|
+
assert.equal(r.json.applied, true)
|
|
336
|
+
assert.equal(r.json.changes.length, 2)
|
|
337
|
+
assert.equal(r.json.answer, '已按数据面拆成两步')
|
|
338
|
+
assert.equal(r.json.thinking, '「写面板」偏粗,拆成数据面与展示面两步', '思考区要原样透出')
|
|
339
|
+
assert.equal(r.json.attempts, 1, '一次就合规不应重试')
|
|
340
|
+
assert.equal(r.json.validation.ok, true, '落盘后的体检结论随回执自动带回')
|
|
341
|
+
assert.deepEqual(r.json.validation.errors, [])
|
|
342
|
+
assert.equal(calls.length, 1)
|
|
343
|
+
assert.equal(calls[0].provider, 'local')
|
|
344
|
+
assert.equal(calls[0].model, 'qwen')
|
|
345
|
+
const after = await snapshot(harness)
|
|
346
|
+
assert.equal(after.items.length, before.items.length + 1)
|
|
347
|
+
assert.equal(after.revision, before.revision + 1)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
test('输出不符格式(幽灵 id + 空 title)→ 打回重问,第两轮合规才落盘', async () => {
|
|
351
|
+
const seq = [
|
|
352
|
+
JSON.stringify({ changes: [{ kind: 'edit', id: 'not-a-real-id', status: 'done' }, { kind: 'add', title: '' }], answer: 'x' }),
|
|
353
|
+
JSON.stringify({ thinking: '上一条用了板上没有的 id', changes: [{ kind: 'add', title: '拆:校验回写' }], answer: '重新给一版' }),
|
|
354
|
+
]
|
|
355
|
+
const calls = []
|
|
356
|
+
const harness = await booted({ calls, reply: () => seq.shift() })
|
|
357
|
+
const before = await snapshot(harness)
|
|
358
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
359
|
+
assert.equal(r.json.applied, true)
|
|
360
|
+
assert.equal(r.json.attempts, 2, '第一轮必须被打回')
|
|
361
|
+
assert.equal(r.json.changes.length, 1)
|
|
362
|
+
assert.equal(r.json.answer, '重新给一版')
|
|
363
|
+
assert.equal(calls.length, 2, '打回要真的再问一次')
|
|
364
|
+
const second = calls[1].messages[0].content[0].text
|
|
365
|
+
assert.match(second, /不符合校验格式/, '打回时要把原提示与错误清单一起喂回')
|
|
366
|
+
assert.match(second, /不在板上/)
|
|
367
|
+
assert.match(second, /缺少 title/)
|
|
368
|
+
const after = await snapshot(harness)
|
|
369
|
+
assert.equal(after.revision, before.revision + 1, '不允许半应用:只在合规那一轮落盘')
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('三轮都不合规 → 502,一次板都未动', async () => {
|
|
373
|
+
const calls = []
|
|
374
|
+
const harness = await booted({ calls, reply: '{"changes":[{"kind":"teleport","id":"x"}]}' })
|
|
375
|
+
const before = await snapshot(harness)
|
|
376
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
377
|
+
assert.equal(r.status, 502)
|
|
378
|
+
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
379
|
+
assert.match(r.json.error, /kind 非法/)
|
|
380
|
+
assert.equal(calls.length, 3, '一次原始 + 两次打回')
|
|
381
|
+
assert.equal((await snapshot(harness)).revision, before.revision, '打回失败不许留痕')
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('op=ask 没给 answer 也算不合格,打回一轮后取到回答', async () => {
|
|
385
|
+
const seq = ['{"changes":[]}', '{"thinking":"板上只有一项 doing","changes":[],"answer":"只有「接数据面」在做"}']
|
|
386
|
+
const calls = []
|
|
387
|
+
const harness = await booted({ calls, reply: () => seq.shift() })
|
|
388
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
|
|
389
|
+
assert.equal(r.json.ok, true)
|
|
390
|
+
assert.equal(r.json.attempts, 2)
|
|
391
|
+
assert.match(r.json.answer, /只有「接数据面」/)
|
|
392
|
+
assert.equal(r.json.thinking, '板上只有一项 doing')
|
|
393
|
+
assert.equal(calls.length, 2)
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
test('op=mutate 能把指令翻成删除(只认板上真 id),并触发 R4 队列提醒', async () => {
|
|
397
|
+
let reply = '{}'
|
|
398
|
+
const harness = await booted({ reply: () => reply })
|
|
399
|
+
const snap = await snapshot(harness)
|
|
400
|
+
const last = snap.items.find((i) => i.title === '补测试')
|
|
401
|
+
reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }], answer: '删掉了' })
|
|
402
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '把补测试删掉' })
|
|
403
|
+
assert.equal(r.json.applied, true)
|
|
404
|
+
assert.equal(r.json.attempts, 1, '只给板上真 id 就是一次过')
|
|
405
|
+
assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }])
|
|
406
|
+
const after = await snapshot(harness)
|
|
407
|
+
assert.equal(after.items.some((i) => i.title === '补测试'), false)
|
|
408
|
+
// R4:删除是结构性变更 → idle 走 followup 落队列
|
|
409
|
+
const notice = harness.followups.at(-1)
|
|
410
|
+
assert.ok(notice, '结构性变更必须落输入队列')
|
|
411
|
+
assert.equal(notice.source.kind, 'user', 'isHumanSteer 只认 kind=user')
|
|
412
|
+
assert.match(notice.content[0].text, /<progress-major-change rev="\d+">/)
|
|
413
|
+
// 回执必须把「已落队列」告知客户端(/ops 与 /action 同一套门控语义)
|
|
414
|
+
assert.equal(r.json.notified, true, 'ops 落盘的结构性变更必须回执 notified=true')
|
|
415
|
+
assert.equal(r.json.noticeMerged, false)
|
|
416
|
+
const before2 = harness.followups.length
|
|
417
|
+
const other = after.items.find((i) => i.title !== '补测试')
|
|
418
|
+
reply = JSON.stringify({ changes: [{ kind: 'remove', id: other.id }] })
|
|
419
|
+
const r2 = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '再删一项' })
|
|
420
|
+
assert.equal(r2.json.applied, true)
|
|
421
|
+
assert.equal(r2.json.notified, false, '同回合第二次 ops 改板被合并,不得假装新投了一条')
|
|
422
|
+
assert.equal(r2.json.noticeMerged, true, '但必须让客户端知道“本回合已经提醒过”,否则它会另发 wake')
|
|
423
|
+
assert.equal(harness.followups.length, before2, '同回合仍只一条队列消息')
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
test('op=mutate/ask 缺 question、未知 op、缺 sessionId 一律 400', async () => {
|
|
427
|
+
const harness = await booted({ reply: '{"changes":[]}' })
|
|
428
|
+
assert.equal((await ops(harness, { sessionId: SESSION, op: 'mutate' })).status, 400)
|
|
429
|
+
assert.equal((await ops(harness, { sessionId: SESSION, op: 'ask' })).status, 400)
|
|
430
|
+
assert.equal((await ops(harness, { sessionId: SESSION, op: 'teleport' })).status, 400)
|
|
431
|
+
assert.equal((await ops(harness, { sessionId: '', op: 'validate' })).status, 400)
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
test('未钉定模型路由 → 403,一帧 token 都不发', async () => {
|
|
435
|
+
const calls = []
|
|
436
|
+
const harness = await booted({ calls, config: { ops: { enabled: true, routeProvider: '', routeModel: '' } }, reply: '{"changes":[{"kind":"add","title":"x"}]}' })
|
|
437
|
+
const before = await snapshot(harness)
|
|
438
|
+
for (const op of ['refine', 'mutate', 'ask']) {
|
|
439
|
+
const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
|
|
440
|
+
assert.equal(r.status, 403, `${op} 在未钉定路由时必须 403`)
|
|
441
|
+
assert.match(r.json.error, /未钉定模型路由|ops\.fallbacks/)
|
|
442
|
+
}
|
|
443
|
+
assert.equal(calls.length, 0, '未钉定不得发出任何一次模型调用')
|
|
444
|
+
assert.equal((await snapshot(harness)).revision, before.revision, '没钉路由就不许动板')
|
|
445
|
+
// 体检不花 token,与路由无关,仍照常可用
|
|
446
|
+
const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
447
|
+
assert.equal(v.status, 200)
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
test('选了链外的 provider/model → 403,并把链上候选告知回去', async () => {
|
|
451
|
+
const calls = []
|
|
452
|
+
const harness = await booted({ calls, reply: '{"changes":[]}' })
|
|
453
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine', provider: 'deepseek-account', model: 'deepseek-v4-pro' })
|
|
454
|
+
assert.equal(r.status, 403)
|
|
455
|
+
assert.match(r.json.error, /不在 ops 允许范围内/)
|
|
456
|
+
assert.match(r.json.error, /local\/qwen/, '必须把链上真值告知回去,否则用户无从改配置')
|
|
457
|
+
assert.equal(calls.length, 0)
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
test('主路由传输失败 → 沿链降级到下一条,routeIndex 告知降级位次', async () => {
|
|
461
|
+
const calls = []
|
|
462
|
+
const harness = await booted({
|
|
463
|
+
calls,
|
|
464
|
+
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
465
|
+
reply: () => (calls.length === 1 ? (() => { throw new Error('assistant-empty') })() : JSON.stringify({ thinking: '主路由挂了,这条顶上', changes: [{ kind: 'add', title: '拆项' }], answer: '已落盘' })),
|
|
466
|
+
})
|
|
467
|
+
const before = await snapshot(harness)
|
|
468
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
469
|
+
assert.equal(r.json.applied, true, '主路由传输失败不得直接放弃,要沿链降级')
|
|
470
|
+
assert.equal(r.json.routeIndex, 1, '服务的是链上第二条')
|
|
471
|
+
assert.deepEqual(r.json.route, { provider: 'backup', model: 'small', local: false })
|
|
472
|
+
assert.equal(calls.length, 2)
|
|
473
|
+
assert.equal(calls[1].provider, 'backup')
|
|
474
|
+
assert.equal(calls[1].model, 'small')
|
|
475
|
+
assert.equal((await snapshot(harness)).revision, before.revision + 1)
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
test('全链都拉不出可用输出 → 502,逐条路由的失败原因都告知', async () => {
|
|
479
|
+
const calls = []
|
|
480
|
+
const harness = await booted({
|
|
481
|
+
calls,
|
|
482
|
+
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
483
|
+
reply: '纯文本,不是 JSON',
|
|
484
|
+
})
|
|
485
|
+
const before = await snapshot(harness)
|
|
486
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
487
|
+
assert.equal(r.status, 502)
|
|
488
|
+
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
489
|
+
assert.match(r.json.error, /local\/qwen:/)
|
|
490
|
+
assert.match(r.json.error, /backup\/small:/)
|
|
491
|
+
assert.equal(calls.length, 6, '两条路由各走满三轮格式打回')
|
|
492
|
+
assert.equal((await snapshot(harness)).revision, before.revision)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
test('模型乱答(无 JSON)→ 三轮都拉不回来,502 且板不变', async () => {
|
|
496
|
+
const calls = []
|
|
497
|
+
const harness = await booted({ calls, reply: '我觉得可以拆成三步,你先看看代码' })
|
|
498
|
+
const before = await snapshot(harness)
|
|
499
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
500
|
+
assert.equal(r.status, 502)
|
|
501
|
+
assert.match(r.json.error, /无法解析|没有返回|不是可解析/)
|
|
502
|
+
assert.equal(calls.length, 3, '纯文本回答同样走打回,不是一次就放弃')
|
|
503
|
+
assert.equal((await snapshot(harness)).revision, before.revision)
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
test('模型给超过 8 条改动只应用前 8 条', async () => {
|
|
507
|
+
const many = Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i }))
|
|
508
|
+
const harness = await booted({ reply: JSON.stringify({ changes: many, answer: 'ok' }) })
|
|
509
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
510
|
+
assert.equal(r.json.changes.length, 8)
|
|
511
|
+
assert.equal((await snapshot(harness)).items.length, 3 + 8)
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
// ── ask:只回文本 ──────────────────────────────────────────────────────
|
|
515
|
+
|
|
516
|
+
test('op=ask 只回文本:模型硬塞 changes 也不落盘', async () => {
|
|
517
|
+
const calls = []
|
|
518
|
+
const harness = await booted({
|
|
519
|
+
calls,
|
|
520
|
+
reply: JSON.stringify({ changes: [{ kind: 'add', title: '不该出现' }], answer: '三项里只有「接数据面」在做' }),
|
|
521
|
+
})
|
|
522
|
+
const before = await snapshot(harness)
|
|
523
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
|
|
524
|
+
assert.equal(r.json.ok, true)
|
|
525
|
+
assert.equal(r.json.applied, false)
|
|
526
|
+
assert.equal(r.json.changes.length, 0)
|
|
527
|
+
assert.match(r.json.answer, /只有「接数据面」/)
|
|
528
|
+
assert.equal(calls.length, 1)
|
|
529
|
+
const after = await snapshot(harness)
|
|
530
|
+
assert.equal(after.revision, before.revision, 'ask 绝不改板')
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
test('喂给模型的板必须带 id(否则它无法指认 edit/remove 哪一项)', async () => {
|
|
534
|
+
const calls = []
|
|
535
|
+
const harness = await booted({ calls, reply: '{"changes":[],"answer":"x"}' })
|
|
536
|
+
const snap = await snapshot(harness)
|
|
537
|
+
await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
538
|
+
const user = calls[0].messages[0].content[0].text
|
|
539
|
+
for (const item of snap.items) assert.ok(user.includes(item.id), `提示里必须含板上项 id ${item.id}`)
|
|
540
|
+
assert.match(user, /<progress-board ids="true">/)
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
// ── origin='ops' 不冒充主模型 ──────────────────────────────────────────
|
|
544
|
+
|
|
545
|
+
test('ops 落盘不重置 stepsSinceModel:催办仍按原步数报滞后', async () => {
|
|
546
|
+
const harness = await booted({ reply: JSON.stringify({ changes: [{ kind: 'add', title: '拆项' }], answer: 'ok' }) })
|
|
547
|
+
for (let i = 0; i < 4; i += 1) harness.emit('step/start', {})
|
|
548
|
+
const text = () => harness.contexts.get('progress-union-observer')()
|
|
549
|
+
assert.match(text(), /synced="4 步前"/)
|
|
550
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
551
|
+
assert.equal(r.json.applied, true)
|
|
552
|
+
assert.match(text(), /synced="4 步前"/, '侧边栏 LLM 操作不算「模型已同步」')
|
|
553
|
+
})
|
|
554
|
+
|
|
555
|
+
// ── v0.9.0:计划文档进 ops 原料 ────────────────────────────────────
|
|
556
|
+
// 真机反馈:用户写「是否可以对 …\.agents\plans\session-exclusion-gate\tasks.md 任务为纲再细化」,
|
|
557
|
+
// 模型答“这属于咨询、不执行”——它确实只拿到板子清单,没有任何文件面。
|
|
558
|
+
// 本仓早就有 scanPlan/parseChecklistMarkdown 这套原料机器(给观察者用),ops 必须接上。
|
|
559
|
+
|
|
560
|
+
test('planSlugFromText:只认 .agents/plans/<slug>/ 形态,反斜杠与正斜杠都吃', () => {
|
|
561
|
+
assert.equal(planSlugFromText('按 E:\\test\\repo\\.agents\\plans\\session-exclusion-gate\\tasks.md 为纲细化'), 'session-exclusion-gate')
|
|
562
|
+
assert.equal(planSlugFromText('看 /home/me/.agents/plans/demo-plan/checklist.md 的第 3 项'), 'demo-plan')
|
|
563
|
+
assert.equal(planSlugFromText('把「做点事」拆细一点'), '', '普通英文词不得被当 slug')
|
|
564
|
+
assert.equal(planSlugFromText('.agents/plans/ab/tasks.md'), 'ab')
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
function mkOpsPlan() {
|
|
568
|
+
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'union-ops-plan-'))
|
|
569
|
+
const dir = path.join(cwd, '.agents', 'plans', 'demo-plan')
|
|
570
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
571
|
+
fs.writeFileSync(path.join(dir, 'tasks.md'), '## Phase 1: 做点事\n- [x] t01 第一件事\n- [ ] t02 第二件事\n\n## Phase 2: 收尾\n- [ ] t03 第三件事\n', 'utf8')
|
|
572
|
+
fs.writeFileSync(path.join(dir, 'spec.md'), '# Spec: 演示\n\n## 需求\n- 让 ops 读计划\n', 'utf8')
|
|
573
|
+
return cwd
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
test('v0.9.0:ops ask 把点名的计划未完项喂进助手,并在回执报 grounding', async () => {
|
|
577
|
+
const calls = []
|
|
578
|
+
const cwd = mkOpsPlan()
|
|
579
|
+
const harness = await booted({ cwd, calls, reply: '{"thinking":"按纲","changes":[],"answer":"t02 与 t03 还没做"}' })
|
|
580
|
+
const named = path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')
|
|
581
|
+
const { status, json } = await ops(harness, { sessionId: SESSION, op: 'ask', question: `按 ${named} 为纲,还剩哪些没做` })
|
|
582
|
+
assert.equal(status, 200, JSON.stringify(json))
|
|
583
|
+
const user = calls[0].messages[0].content[0].text
|
|
584
|
+
assert.ok(user.includes('<plan slug="demo-plan"'), '助手输入必须带计划段')
|
|
585
|
+
assert.ok(user.includes('t02 第二件事') && user.includes('t03 第三件事'), '未完项原文与编号必须进原料')
|
|
586
|
+
assert.ok(!user.includes('t01 第一件事'), '已勾选项不再当未完喂入')
|
|
587
|
+
assert.ok(user.includes('Phase 1: 做点事'), 'Phase 分组要在')
|
|
588
|
+
assert.ok(user.includes('spec 大纲'), 'spec 大纲也要在')
|
|
589
|
+
assert.equal(json.plan.ok, true)
|
|
590
|
+
assert.equal(json.plan.slug, 'demo-plan')
|
|
591
|
+
assert.equal(json.plan.asked, 'demo-plan', '点名要如实回报')
|
|
592
|
+
assert.equal(json.plan.pending, 2)
|
|
593
|
+
assert.equal(json.plan.listed, 2)
|
|
594
|
+
})
|
|
595
|
+
|
|
596
|
+
test('v0.9.0:refine 同样拿到计划段,且指令仍在尾部(模型重尾)', async () => {
|
|
597
|
+
const calls = []
|
|
598
|
+
const cwd = mkOpsPlan()
|
|
599
|
+
const harness = await booted({ cwd, calls, reply: '{"changes":[{"kind":"add","title":"Phase 2 · 拆 t03"}],"answer":"ok"}' })
|
|
600
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine', question: `以 ${path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')} 为纲拆分` })
|
|
601
|
+
assert.equal(r.json.applied, true)
|
|
602
|
+
const user = calls[0].messages[0].content[0].text
|
|
603
|
+
const atPlan = user.indexOf('<plan slug="demo-plan"')
|
|
604
|
+
const atCmd = user.indexOf('用户补充:')
|
|
605
|
+
assert.ok(atPlan > 0, '计划段必须在')
|
|
606
|
+
assert.ok(atCmd > atPlan, `指令要排在计划段之后(plan=${atPlan} cmd=${atCmd})`)
|
|
607
|
+
assert.ok(user.indexOf('<progress-board') < atPlan, '计划段在板子清单之后、指令之前')
|
|
608
|
+
})
|
|
609
|
+
|
|
610
|
+
test('v0.9.0:planSync=off 时不注入计划段,但动作照常并报 reason=disabled', async () => {
|
|
611
|
+
const calls = []
|
|
612
|
+
const cwd = mkOpsPlan()
|
|
613
|
+
const harness = await booted({
|
|
614
|
+
cwd,
|
|
615
|
+
calls,
|
|
616
|
+
config: { planSync: 'off' },
|
|
617
|
+
reply: '{"thinking":"","changes":[],"answer":"ok"}',
|
|
618
|
+
})
|
|
619
|
+
const named = path.join(cwd, '.agents', 'plans', 'demo-plan', 'tasks.md')
|
|
620
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: `${named} 还剩什么` })
|
|
621
|
+
assert.equal(r.status, 200, '计划面关掉不能连带把 ops 动作打死')
|
|
622
|
+
assert.ok(!calls[0].messages[0].content[0].text.includes('<plan'), 'off 时不得注入计划段')
|
|
623
|
+
assert.equal(r.json.plan.ok, false)
|
|
624
|
+
assert.equal(r.json.plan.reason, 'disabled', '要区分“被关掉”与“点名落空”')
|
|
625
|
+
assert.equal(r.json.plan.asked, 'demo-plan')
|
|
626
|
+
})
|
|
627
|
+
|
|
628
|
+
test('v0.9.0:点名不存在的 slug 时回退自动选,不静默抛错', async () => {
|
|
629
|
+
const calls = []
|
|
630
|
+
const cwd = mkOpsPlan()
|
|
631
|
+
const harness = await booted({ cwd, calls, reply: '{"thinking":"","changes":[],"answer":"ok"}' })
|
|
632
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: `按 ${path.join(cwd, '.agents', 'plans', 'no-such-plan', 'tasks.md')} 细化` })
|
|
633
|
+
assert.equal(r.status, 200)
|
|
634
|
+
const user = calls[0].messages[0].content[0].text
|
|
635
|
+
assert.equal(r.json.plan.asked, 'no-such-plan', '点名原值要留着供面板报信')
|
|
636
|
+
assert.equal(r.json.plan.slug, 'demo-plan', '回退到自动选,不空转')
|
|
637
|
+
assert.ok(user.includes('<plan slug="demo-plan"'), '回退后的原料照样喂')
|
|
638
|
+
})
|