dsh-progress-union 0.7.8 → 0.8.0

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/test/ops.test.mjs CHANGED
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * 0.7.0 rc.3 验收:R3 侧边栏 LLM 任务操作。
3
- * validateBoard 纯函数 + /ops/providers + /ops 四操作(refine/mutate/ask/validate)。
4
- * 硬约束:不新开顶级标签、零新增依赖;模型返回非法数据一律不落盘;
5
- * origin='ops' 不得让主模型看起来「刚刚同步过板」(stepsSinceModel 不归零)。
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 不归零)。
6
10
  */
7
11
  import assert from 'node:assert/strict'
8
12
  import fs from 'node:fs'
@@ -12,7 +16,7 @@ import test from 'node:test'
12
16
 
13
17
  process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
14
18
  const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
- const { validateBoard } = await import('../index.js')
19
+ const { validateBoard, validateProposal, isLocalRouteName, buildOpsChain, withOpsFeedback } = await import('../index.js')
16
20
 
17
21
  const OPS = '/progress-union/ops'
18
22
 
@@ -29,7 +33,13 @@ function llmMock(reply, calls) {
29
33
  async function booted({ config = {}, reply = '{}', calls = [], providers = undefined } = {}) {
30
34
  const llm = { ...llmMock(reply, calls), ...(providers ? { listProviders: async () => providers } : {}) }
31
35
  const harness = createHarness({
32
- config: { assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 }, ...config },
36
+ config: {
37
+ assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 },
38
+ // v0.8.0:ops 的介入范围 = 白名单。默认钉一条 local/qwen(与 llmMock 对得上),
39
+ // 需要测「未钉定」的用例自己把 routeProvider/routeModel 清空。
40
+ ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] },
41
+ ...config,
42
+ },
33
43
  llm,
34
44
  })
35
45
  await harness.run()
@@ -85,22 +95,108 @@ test('validateBoard:可疑但可写的只进 warnings(空板/重复 title/or
85
95
  assert.match(dup.warnings.join(' '), /同时 doing 2 项/)
86
96
  })
87
97
 
98
+ // ── validateProposal(模型输出格式门)────────────────────────────────
99
+
100
+ test('validateProposal:合规输出直接过;thinking 只是展示字段,缺了不打回', () => {
101
+ const state = { items: [{ id: 'a', title: '甲' }, { id: 'b', title: '乙' }] }
102
+ assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'doing' }], answer: 'ok' }, 'refine').ok, true)
103
+ assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }] }, 'mutate').ok, true, '无 thinking 也必须过')
104
+ assert.equal(validateProposal(state, { board: { changes: [{ kind: 'remove', id: 'b' }] } }, 'mutate').ok, true, '兼容 {board:{changes}} 旧形状')
105
+ assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'done' }], answer: '完成' }, 'mutate').ok, true, 'done 不强制带 percent:落盘时由 applyOneChange 补 100')
106
+ })
107
+
108
+ test('validateProposal:吃不下的一律打回(非对象/缺 changes/kind 非枚举/幽灵 id/缺 title/edit 空转/percent 越界)', () => {
109
+ const state = { items: [{ id: 'a', title: '甲' }] }
110
+ const none = validateProposal(state, null, 'refine')
111
+ assert.equal(none.ok, false)
112
+ assert.match(none.errors[0], /不是可解析的 JSON 对象/)
113
+ assert.match(validateProposal(state, { answer: 'x' }, 'refine').errors.join(' '), /缺少 changes 数组/)
114
+ assert.match(validateProposal(state, { changes: ['nope'] }, 'refine').errors.join(' '), /不是对象/)
115
+ assert.match(validateProposal(state, { changes: [{ kind: 'teleport', id: 'a' }] }, 'refine').errors.join(' '), /kind 非法/)
116
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'ghost', status: 'done' }] }, 'refine').errors.join(' '), /不在板上/)
117
+ assert.match(validateProposal(state, { changes: [{ kind: 'remove', id: 'ghost' }] }, 'mutate').errors.join(' '), /不在板上/)
118
+ assert.match(validateProposal(state, { changes: [{ kind: 'add', title: ' ' }] }, 'refine').errors.join(' '), /缺少 title/)
119
+ assert.match(validateProposal(state, { changes: [{ kind: 'add', title: '很长的'.repeat(70) }] }, 'refine').errors.join(' '), /title 过长/)
120
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a' }] }, 'refine').errors.join(' '), /没有任何要改的字段/)
121
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'pending-ish' }] }, 'refine').errors.join(' '), /status 非法/)
122
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', percent: 140 }] }, 'refine').errors.join(' '), /percent 越界/)
123
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', order: 'x' }] }, 'refine').errors.join(' '), /order 不是数字/)
124
+ })
125
+
126
+ test('validateProposal:条数超上限只截断不打回;ask 只硬要求 answer', () => {
127
+ const state = { items: [{ id: 'a', title: '甲' }] }
128
+ const many = { changes: Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i })) }
129
+ assert.equal(validateProposal(state, many, 'refine').ok, true, '超上限走截断(可部分交付),不因此烧 token 重问')
130
+ assert.equal(validateProposal(state, { changes: [], answer: ' ' }, 'ask').ok, false, 'ask 没 answer 等于没回答')
131
+ assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }], answer: '好' }, 'ask').ok, true, 'ask 硬塞 changes 由路由丢弃,不算格式错')
132
+ })
133
+
134
+ // ── 路由链纯函数(v0.8.0 白名单)───────────────────────────────
135
+
136
+ test('buildOpsChain:主路由在前、条目按序在后,缺 provider/model 剔除、同串去重', () => {
137
+ const chain = buildOpsChain(
138
+ { provider: 'local-35', model: 'Qwen3.6-35B-A3B' },
139
+ [{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, { provider: '', model: 'x' }, { provider: 'strata', model: 'qwen3.8-flash-iq2_xs' }],
140
+ false,
141
+ )
142
+ assert.deepEqual(chain.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'strata/qwen3.8-flash-iq2_xs'], '重复与缺 provider 的条目不占位')
143
+ assert.deepEqual(buildOpsChain({ provider: '', model: '' }, [], true), [], '主路由缺失 = 空链(未钉定)')
144
+ assert.deepEqual(buildOpsChain(null, undefined, true), [], '配置形状不对也不抛错')
145
+ })
146
+
147
+ test('buildOpsChain:preferLocal 只重排不删;关掉则严格按配置顺序', () => {
148
+ const primary = { provider: 'deepseek-account', model: 'deepseek-v4-pro' }
149
+ const fallbacks = [{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }]
150
+ const on = buildOpsChain(primary, fallbacks, true)
151
+ assert.deepEqual(on.map((r) => r.provider), ['local-35', 'deepseek-account'], '本地候选排到链首')
152
+ assert.equal(on.length, 2, '重排不得丢条目')
153
+ assert.deepEqual(buildOpsChain(primary, fallbacks, false).map((r) => r.provider), ['deepseek-account', 'local-35'], '关掉后按配置顺序')
154
+ })
155
+
156
+ test('isLocalRouteName:provider 命名与量化后缀都能命中,云端旗舰不算本地', () => {
157
+ assert.equal(isLocalRouteName('local-35', 'Qwen3.6-35B-A3B'), true, 'provider 名命中')
158
+ assert.equal(isLocalRouteName('strata', 'qwen3.8-flash-iq2_xs'), true, '量化后缀命中')
159
+ assert.equal(isLocalRouteName('ollama', 'llama3.1:8b'), true)
160
+ assert.equal(isLocalRouteName('deepseek-account', 'deepseek-v4-pro'), false, '付费旗舰不得误标为本地')
161
+ })
162
+
163
+ test('withOpsFeedback:无错误时原提示逐字不动,有错误时把原因清单贴回后面', () => {
164
+ assert.equal(withOpsFeedback('BASE', null), 'BASE', '首轮不许改写提示')
165
+ assert.equal(withOpsFeedback('BASE', []), 'BASE')
166
+ const fed = withOpsFeedback('BASE', ['第 1 条 不是对象', '第 2 条 kind 非法'])
167
+ assert.match(fed, /^BASE/, '原提示必须逐字保留在前')
168
+ assert.match(fed, /- 第 1 条 不是对象/)
169
+ assert.match(fed, /- 第 2 条 kind 非法/)
170
+ })
171
+
88
172
  // ── /ops/providers ──────────────────────────────────────────────────────
89
173
 
90
- test('providers:llm.listProviders 有值就列出来;服务缺失退回空数组不报错', async () => {
91
- const harness = await booted({ providers: [{ id: 'local', models: [{ id: 'qwen', label: 'Qwen 3' }, 'deepseek'] }, { name: 'other' }] })
174
+ test('providers:候选只来自配置白名单,不再枚举宿主 listProviders', async () => {
175
+ let listed = 0
176
+ const harness = await booted({
177
+ providers: [{ id: 'deepseek-official', models: ['deepseek-v4-pro'] }],
178
+ config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-account', model: 'deepseek-v4-pro' }] } },
179
+ })
180
+ const src = harness.ctx.get('llm')
181
+ const origin = src.listProviders
182
+ src.listProviders = async () => { listed += 1; return origin() }
92
183
  const res = await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })
93
184
  const json = res.json()
94
185
  assert.equal(json.ok, true)
95
- assert.equal(json.disabled, false, '默认开关下 providers 必须报 disabled=false')
96
- assert.deepEqual(json.providers.map((p) => p.id), ['local', 'other'])
97
- assert.deepEqual(json.providers[0].models.map((m) => m.id), ['qwen', 'deepseek'])
98
- assert.equal(json.default.provider, 'local', '无宿主默认选择时退回设置页')
186
+ assert.equal(json.disabled, false)
187
+ assert.equal(json.unconfigured, false, '钉了主路由就不是未钉定')
188
+ assert.equal(listed, 0, '白名单为准:一个宿主 provider 都不去枚举')
189
+ assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-account/deepseek-v4-pro'])
190
+ assert.deepEqual(json.routes.map((r) => r.local), [true, false], '本地/云端标记要随链给出')
191
+ assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-account'], 'providers 仍按 provider 聚合(旧客户端兼容)')
192
+ assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B'])
193
+ assert.deepEqual(json.default, { provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, '默认就是链首')
194
+ assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示')
99
195
 
100
- const bare = await booted({ reply: '{}' })
196
+ const bare = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
101
197
  const j2 = (await callRoute(bare, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
102
- assert.deepEqual(j2.providers, [], 'listProviders 不存在必须给空数组')
103
- assert.equal(j2.configured.mode, 'registered')
198
+ assert.equal(j2.unconfigured, true, '链空必须报 unconfigured,而不是只给空数组')
199
+ assert.deepEqual(j2.providers, [])
104
200
 
105
201
  const wrong = await callRoute(harness, `${OPS}/providers`, { method: 'POST', url: `${OPS}/providers`, headers: {} })
106
202
  assert.equal(wrong.status, 405)
@@ -144,26 +240,30 @@ test('op=validate 纯本地跑,一次 llm 调用都不发', async () => {
144
240
 
145
241
  // ── /ops refine / mutate:落盘 + 护栏 ──────────────────────────────────
146
242
 
147
- test('op=refine 落盘 add+edit(order),并回 snapshot;updatedBy 走 ops 通道', async () => {
243
+ test('op=refine 合规输出落盘 add+edit(order):thinking / attempts / 自动体检一并回给客户端', async () => {
244
+ let reply = '{}'
148
245
  const calls = []
149
- const harness = await booted({
150
- calls,
151
- reply: JSON.stringify({
152
- changes: [
153
- { kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
154
- { kind: 'edit', id: 'not-a-real-id', status: 'done' },
155
- { kind: 'add', title: '' },
156
- ],
157
- answer: '已按数据面拆成两步',
158
- }),
159
- })
246
+ const harness = await booted({ calls, reply: () => reply })
160
247
  const before = await snapshot(harness)
248
+ const target = before.items.find((i) => i.title === '写面板')
249
+ assert.ok(target, '种子板必须有「写面板」项')
250
+ reply = JSON.stringify({
251
+ thinking: '「写面板」偏粗,拆成数据面与展示面两步',
252
+ changes: [
253
+ { kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
254
+ { kind: 'edit', id: target.id, status: 'doing', percent: 40 },
255
+ ],
256
+ answer: '已按数据面拆成两步',
257
+ })
161
258
  const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
162
259
  assert.equal(r.json.ok, true)
163
260
  assert.equal(r.json.applied, true)
164
- assert.equal(r.json.changes.length, 1, '假 id 与空 title 必须被丢掉')
165
- assert.equal(r.json.changes[0].change, 'add')
261
+ assert.equal(r.json.changes.length, 2)
166
262
  assert.equal(r.json.answer, '已按数据面拆成两步')
263
+ assert.equal(r.json.thinking, '「写面板」偏粗,拆成数据面与展示面两步', '思考区要原样透出')
264
+ assert.equal(r.json.attempts, 1, '一次就合规不应重试')
265
+ assert.equal(r.json.validation.ok, true, '落盘后的体检结论随回执自动带回')
266
+ assert.deepEqual(r.json.validation.errors, [])
167
267
  assert.equal(calls.length, 1)
168
268
  assert.equal(calls[0].provider, 'local')
169
269
  assert.equal(calls[0].model, 'qwen')
@@ -172,15 +272,62 @@ test('op=refine 落盘 add+edit(order),并回 snapshot;updatedBy 走 ops 通
172
272
  assert.equal(after.revision, before.revision + 1)
173
273
  })
174
274
 
275
+ test('输出不符格式(幽灵 id + 空 title)→ 打回重问,第两轮合规才落盘', async () => {
276
+ const seq = [
277
+ JSON.stringify({ changes: [{ kind: 'edit', id: 'not-a-real-id', status: 'done' }, { kind: 'add', title: '' }], answer: 'x' }),
278
+ JSON.stringify({ thinking: '上一条用了板上没有的 id', changes: [{ kind: 'add', title: '拆:校验回写' }], answer: '重新给一版' }),
279
+ ]
280
+ const calls = []
281
+ const harness = await booted({ calls, reply: () => seq.shift() })
282
+ const before = await snapshot(harness)
283
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
284
+ assert.equal(r.json.applied, true)
285
+ assert.equal(r.json.attempts, 2, '第一轮必须被打回')
286
+ assert.equal(r.json.changes.length, 1)
287
+ assert.equal(r.json.answer, '重新给一版')
288
+ assert.equal(calls.length, 2, '打回要真的再问一次')
289
+ const second = calls[1].messages[0].content[0].text
290
+ assert.match(second, /不符合校验格式/, '打回时要把原提示与错误清单一起喂回')
291
+ assert.match(second, /不在板上/)
292
+ assert.match(second, /缺少 title/)
293
+ const after = await snapshot(harness)
294
+ assert.equal(after.revision, before.revision + 1, '不允许半应用:只在合规那一轮落盘')
295
+ })
296
+
297
+ test('三轮都不合规 → 502,一次板都未动', async () => {
298
+ const calls = []
299
+ const harness = await booted({ calls, reply: '{"changes":[{"kind":"teleport","id":"x"}]}' })
300
+ const before = await snapshot(harness)
301
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
302
+ assert.equal(r.status, 502)
303
+ assert.match(r.json.error, /路由链上没有一条给出可用输出/)
304
+ assert.match(r.json.error, /kind 非法/)
305
+ assert.equal(calls.length, 3, '一次原始 + 两次打回')
306
+ assert.equal((await snapshot(harness)).revision, before.revision, '打回失败不许留痕')
307
+ })
308
+
309
+ test('op=ask 没给 answer 也算不合格,打回一轮后取到回答', async () => {
310
+ const seq = ['{"changes":[]}', '{"thinking":"板上只有一项 doing","changes":[],"answer":"只有「接数据面」在做"}']
311
+ const calls = []
312
+ const harness = await booted({ calls, reply: () => seq.shift() })
313
+ const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
314
+ assert.equal(r.json.ok, true)
315
+ assert.equal(r.json.attempts, 2)
316
+ assert.match(r.json.answer, /只有「接数据面」/)
317
+ assert.equal(r.json.thinking, '板上只有一项 doing')
318
+ assert.equal(calls.length, 2)
319
+ })
320
+
175
321
  test('op=mutate 能把指令翻成删除(只认板上真 id),并触发 R4 队列提醒', async () => {
176
322
  let reply = '{}'
177
323
  const harness = await booted({ reply: () => reply })
178
324
  const snap = await snapshot(harness)
179
325
  const last = snap.items.find((i) => i.title === '补测试')
180
- reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }, { kind: 'remove', id: 'ghost-id' }], answer: '删掉了' })
326
+ reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }], answer: '删掉了' })
181
327
  const r = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '把补测试删掉' })
182
328
  assert.equal(r.json.applied, true)
183
- assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }], '不存在的 id 必须被丢掉')
329
+ assert.equal(r.json.attempts, 1, '只给板上真 id 就是一次过')
330
+ assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }])
184
331
  const after = await snapshot(harness)
185
332
  assert.equal(after.items.some((i) => i.title === '补测试'), false)
186
333
  // R4:删除是结构性变更 → idle 走 followup 落队列
@@ -209,22 +356,75 @@ test('op=mutate/ask 缺 question、未知 op、缺 sessionId 一律 400', async
209
356
  assert.equal((await ops(harness, { sessionId: '', op: 'validate' })).status, 400)
210
357
  })
211
358
 
212
- test('未配置辅助模型 → 400,且不落任何改动', async () => {
213
- const harness = await booted({ config: { assistant: { mode: '' } }, reply: '{"changes":[{"kind":"add","title":"x"}]}' })
359
+ test('未钉定模型路由 → 403,一帧 token 都不发', async () => {
360
+ const calls = []
361
+ const harness = await booted({ calls, config: { ops: { enabled: true, routeProvider: '', routeModel: '' } }, reply: '{"changes":[{"kind":"add","title":"x"}]}' })
362
+ const before = await snapshot(harness)
363
+ for (const op of ['refine', 'mutate', 'ask']) {
364
+ const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
365
+ assert.equal(r.status, 403, `${op} 在未钉定路由时必须 403`)
366
+ assert.match(r.json.error, /未钉定模型路由|ops\.fallbacks/)
367
+ }
368
+ assert.equal(calls.length, 0, '未钉定不得发出任何一次模型调用')
369
+ assert.equal((await snapshot(harness)).revision, before.revision, '没钉路由就不许动板')
370
+ // 体检不花 token,与路由无关,仍照常可用
371
+ const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
372
+ assert.equal(v.status, 200)
373
+ })
374
+
375
+ test('选了链外的 provider/model → 403,并把链上候选告知回去', async () => {
376
+ const calls = []
377
+ const harness = await booted({ calls, reply: '{"changes":[]}' })
378
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine', provider: 'deepseek-account', model: 'deepseek-v4-pro' })
379
+ assert.equal(r.status, 403)
380
+ assert.match(r.json.error, /不在 ops 允许范围内/)
381
+ assert.match(r.json.error, /local\/qwen/, '必须把链上真值告知回去,否则用户无从改配置')
382
+ assert.equal(calls.length, 0)
383
+ })
384
+
385
+ test('主路由传输失败 → 沿链降级到下一条,routeIndex 告知降级位次', async () => {
386
+ const calls = []
387
+ const harness = await booted({
388
+ calls,
389
+ config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
390
+ reply: () => (calls.length === 1 ? (() => { throw new Error('assistant-empty') })() : JSON.stringify({ thinking: '主路由挂了,这条顶上', changes: [{ kind: 'add', title: '拆项' }], answer: '已落盘' })),
391
+ })
214
392
  const before = await snapshot(harness)
215
393
  const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
216
- assert.equal(r.status, 400)
217
- assert.match(r.json.error, /辅助模型未配置/)
218
- const after = await snapshot(harness)
219
- assert.equal(after.revision, before.revision, '拿不到模型就不许动板')
394
+ assert.equal(r.json.applied, true, '主路由传输失败不得直接放弃,要沿链降级')
395
+ assert.equal(r.json.routeIndex, 1, '服务的是链上第二条')
396
+ assert.deepEqual(r.json.route, { provider: 'backup', model: 'small', local: false })
397
+ assert.equal(calls.length, 2)
398
+ assert.equal(calls[1].provider, 'backup')
399
+ assert.equal(calls[1].model, 'small')
400
+ assert.equal((await snapshot(harness)).revision, before.revision + 1)
401
+ })
402
+
403
+ test('全链都拉不出可用输出 → 502,逐条路由的失败原因都告知', async () => {
404
+ const calls = []
405
+ const harness = await booted({
406
+ calls,
407
+ config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
408
+ reply: '纯文本,不是 JSON',
409
+ })
410
+ const before = await snapshot(harness)
411
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
412
+ assert.equal(r.status, 502)
413
+ assert.match(r.json.error, /路由链上没有一条给出可用输出/)
414
+ assert.match(r.json.error, /local\/qwen:/)
415
+ assert.match(r.json.error, /backup\/small:/)
416
+ assert.equal(calls.length, 6, '两条路由各走满三轮格式打回')
417
+ assert.equal((await snapshot(harness)).revision, before.revision)
220
418
  })
221
419
 
222
- test('模型乱答(无 JSON)→ 502,板不变', async () => {
223
- const harness = await booted({ reply: '我觉得可以拆成三步,你先看看代码' })
420
+ test('模型乱答(无 JSON)→ 三轮都拉不回来,502 且板不变', async () => {
421
+ const calls = []
422
+ const harness = await booted({ calls, reply: '我觉得可以拆成三步,你先看看代码' })
224
423
  const before = await snapshot(harness)
225
424
  const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
226
425
  assert.equal(r.status, 502)
227
- assert.match(r.json.error, /无法解析|没有返回/)
426
+ assert.match(r.json.error, /无法解析|没有返回|不是可解析/)
427
+ assert.equal(calls.length, 3, '纯文本回答同样走打回,不是一次就放弃')
228
428
  assert.equal((await snapshot(harness)).revision, before.revision)
229
429
  })
230
430