dsh-progress-union 0.7.9 → 0.8.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 +29 -0
- package/README.md +36 -3
- package/client.js +310 -43
- package/dsh.plugin.json +1 -1
- package/index.js +277 -76
- package/package.json +1 -1
- package/test/client.test.mjs +39 -1
- package/test/ops.test.mjs +207 -24
- package/test/settings.test.mjs +27 -1
package/test/ops.test.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 0.7.0 rc.3 验收:R3 侧边栏 LLM 任务操作。
|
|
3
|
-
* validateBoard / validateProposal 纯函数 + /ops/providers
|
|
4
|
-
*
|
|
5
|
-
* 0.7.9
|
|
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,绝不退回宿主主模型;传输失败按链降级。
|
|
6
8
|
* 不新开顶级标签、零新增依赖;
|
|
7
9
|
* origin='ops' 不得让主模型看起来「同步过板」(stepsSinceModel 不归零)。
|
|
8
10
|
*/
|
|
@@ -14,7 +16,7 @@ import test from 'node:test'
|
|
|
14
16
|
|
|
15
17
|
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
16
18
|
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
17
|
-
const { validateBoard, validateProposal } = await import('../index.js')
|
|
19
|
+
const { validateBoard, validateProposal, isLocalRouteName, buildOpsChain, withOpsFeedback } = await import('../index.js')
|
|
18
20
|
|
|
19
21
|
const OPS = '/progress-union/ops'
|
|
20
22
|
|
|
@@ -28,10 +30,20 @@ function llmMock(reply, calls) {
|
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
async function booted({ config = {}, reply = '{}', calls = [], providers = undefined } = {}) {
|
|
32
|
-
const llm = {
|
|
33
|
+
async function booted({ config = {}, reply = '{}', calls = [], providers = undefined, models = undefined } = {}) {
|
|
34
|
+
const llm = {
|
|
35
|
+
...llmMock(reply, calls),
|
|
36
|
+
...(providers ? { listProviders: async () => providers } : {}),
|
|
37
|
+
...(models ? { listModels: typeof models === 'function' ? models : async () => models } : {}),
|
|
38
|
+
}
|
|
33
39
|
const harness = createHarness({
|
|
34
|
-
config: {
|
|
40
|
+
config: {
|
|
41
|
+
assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 },
|
|
42
|
+
// v0.8.0:ops 的介入范围 = 白名单。默认钉一条 local/qwen(与 llmMock 对得上),
|
|
43
|
+
// 需要测「未钉定」的用例自己把 routeProvider/routeModel 清空。
|
|
44
|
+
ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] },
|
|
45
|
+
...config,
|
|
46
|
+
},
|
|
35
47
|
llm,
|
|
36
48
|
})
|
|
37
49
|
await harness.run()
|
|
@@ -123,27 +135,147 @@ test('validateProposal:条数超上限只截断不打回;ask 只硬要求 an
|
|
|
123
135
|
assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }], answer: '好' }, 'ask').ok, true, 'ask 硬塞 changes 由路由丢弃,不算格式错')
|
|
124
136
|
})
|
|
125
137
|
|
|
138
|
+
// ── 路由链纯函数(v0.8.0 白名单)───────────────────────────────
|
|
139
|
+
|
|
140
|
+
test('buildOpsChain:主路由在前、条目按序在后,缺 provider/model 剔除、同串去重', () => {
|
|
141
|
+
const chain = buildOpsChain(
|
|
142
|
+
{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' },
|
|
143
|
+
[{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, { provider: '', model: 'x' }, { provider: 'strata', model: 'qwen3.8-flash-iq2_xs' }],
|
|
144
|
+
false,
|
|
145
|
+
)
|
|
146
|
+
assert.deepEqual(chain.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'strata/qwen3.8-flash-iq2_xs'], '重复与缺 provider 的条目不占位')
|
|
147
|
+
assert.deepEqual(buildOpsChain({ provider: '', model: '' }, [], true), [], '主路由缺失 = 空链(未钉定)')
|
|
148
|
+
assert.deepEqual(buildOpsChain(null, undefined, true), [], '配置形状不对也不抛错')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('buildOpsChain:preferLocal 只重排不删;关掉则严格按配置顺序', () => {
|
|
152
|
+
const primary = { provider: 'deepseek-account', model: 'deepseek-v4-pro' }
|
|
153
|
+
const fallbacks = [{ provider: 'local-35', model: 'Qwen3.6-35B-A3B' }]
|
|
154
|
+
const on = buildOpsChain(primary, fallbacks, true)
|
|
155
|
+
assert.deepEqual(on.map((r) => r.provider), ['local-35', 'deepseek-account'], '本地候选排到链首')
|
|
156
|
+
assert.equal(on.length, 2, '重排不得丢条目')
|
|
157
|
+
assert.deepEqual(buildOpsChain(primary, fallbacks, false).map((r) => r.provider), ['deepseek-account', 'local-35'], '关掉后按配置顺序')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('isLocalRouteName:provider 命名与量化后缀都能命中,云端旗舰不算本地', () => {
|
|
161
|
+
assert.equal(isLocalRouteName('local-35', 'Qwen3.6-35B-A3B'), true, 'provider 名命中')
|
|
162
|
+
assert.equal(isLocalRouteName('strata', 'qwen3.8-flash-iq2_xs'), true, '量化后缀命中')
|
|
163
|
+
assert.equal(isLocalRouteName('ollama', 'llama3.1:8b'), true)
|
|
164
|
+
assert.equal(isLocalRouteName('deepseek-account', 'deepseek-v4-pro'), false, '付费旗舰不得误标为本地')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('withOpsFeedback:无错误时原提示逐字不动,有错误时把原因清单贴回后面', () => {
|
|
168
|
+
assert.equal(withOpsFeedback('BASE', null), 'BASE', '首轮不许改写提示')
|
|
169
|
+
assert.equal(withOpsFeedback('BASE', []), 'BASE')
|
|
170
|
+
const fed = withOpsFeedback('BASE', ['第 1 条 不是对象', '第 2 条 kind 非法'])
|
|
171
|
+
assert.match(fed, /^BASE/, '原提示必须逐字保留在前')
|
|
172
|
+
assert.match(fed, /- 第 1 条 不是对象/)
|
|
173
|
+
assert.match(fed, /- 第 2 条 kind 非法/)
|
|
174
|
+
})
|
|
175
|
+
|
|
126
176
|
// ── /ops/providers ──────────────────────────────────────────────────────
|
|
127
177
|
|
|
128
|
-
test('providers
|
|
129
|
-
|
|
178
|
+
test('providers:候选只来自配置白名单,不再枚举宿主 listProviders', async () => {
|
|
179
|
+
let listed = 0
|
|
180
|
+
const harness = await booted({
|
|
181
|
+
providers: [{ id: 'deepseek-official', models: ['deepseek-v4-pro'] }],
|
|
182
|
+
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-account', model: 'deepseek-v4-pro' }] } },
|
|
183
|
+
})
|
|
184
|
+
const src = harness.ctx.get('llm')
|
|
185
|
+
const origin = src.listProviders
|
|
186
|
+
src.listProviders = async () => { listed += 1; return origin() }
|
|
130
187
|
const res = await callRoute(harness, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })
|
|
131
188
|
const json = res.json()
|
|
132
189
|
assert.equal(json.ok, true)
|
|
133
|
-
assert.equal(json.disabled, false
|
|
134
|
-
assert.
|
|
135
|
-
assert.
|
|
136
|
-
assert.
|
|
137
|
-
|
|
138
|
-
|
|
190
|
+
assert.equal(json.disabled, false)
|
|
191
|
+
assert.equal(json.unconfigured, false, '钉了主路由就不是未钉定')
|
|
192
|
+
assert.equal(listed, 0, '白名单为准:一个宿主 provider 都不去枚举')
|
|
193
|
+
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-account/deepseek-v4-pro'])
|
|
194
|
+
assert.deepEqual(json.routes.map((r) => r.local), [true, false], '本地/云端标记要随链给出')
|
|
195
|
+
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-account'], 'providers 仍按 provider 聚合(旧客户端兼容)')
|
|
196
|
+
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B'])
|
|
197
|
+
assert.deepEqual(json.default, { provider: 'local-35', model: 'Qwen3.6-35B-A3B' }, '默认就是链首')
|
|
198
|
+
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示')
|
|
199
|
+
|
|
200
|
+
const bare = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
139
201
|
const j2 = (await callRoute(bare, `${OPS}/providers`, { method: 'GET', url: `${OPS}/providers`, headers: {} })).json()
|
|
140
|
-
assert.
|
|
141
|
-
assert.
|
|
202
|
+
assert.equal(j2.unconfigured, true, '链空必须报 unconfigured,而不是只给空数组')
|
|
203
|
+
assert.deepEqual(j2.providers, [])
|
|
142
204
|
|
|
143
205
|
const wrong = await callRoute(harness, `${OPS}/providers`, { method: 'POST', url: `${OPS}/providers`, headers: {} })
|
|
144
206
|
assert.equal(wrong.status, 405)
|
|
145
207
|
})
|
|
146
208
|
|
|
209
|
+
test('catalog:链编辑器数据源 = 宿主 provider 目录 + 逐家模型清单 + 已存链原串', async () => {
|
|
210
|
+
let listed = 0
|
|
211
|
+
const harness = await booted({
|
|
212
|
+
providers: [{ id: 'local-35', name: 'local-35' }, { id: 'deepseek-own', name: 'DeepSeek' }],
|
|
213
|
+
models: async (provider) => {
|
|
214
|
+
listed += 1
|
|
215
|
+
return provider === 'local-35'
|
|
216
|
+
? [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen 3.6 35B' }, { id: 'Qwen3.8-27B' }]
|
|
217
|
+
: [{ id: 'deepseek-flash', name: 'Flash' }]
|
|
218
|
+
},
|
|
219
|
+
config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-own', model: 'deepseek-flash' }, { provider: '', model: 'ghost' }] } },
|
|
220
|
+
})
|
|
221
|
+
const get = async () => (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
222
|
+
const json = await get()
|
|
223
|
+
assert.equal(json.ok, true)
|
|
224
|
+
assert.equal(json.enabled, true)
|
|
225
|
+
assert.equal(json.maxChain, 6, '链长上限要随目录给出,客户端才能拿宿主口径截断')
|
|
226
|
+
assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-own'])
|
|
227
|
+
assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B', 'Qwen3.8-27B'])
|
|
228
|
+
assert.equal(json.providers[0].models[0].label, 'Qwen 3.6 35B', '无 name 时回退到 id,有 name 用 name')
|
|
229
|
+
assert.equal(json.providers[0].modelsAvailable, true)
|
|
230
|
+
// 回显的是已存配置原串,不是链构建结果:半成品行也要看得见、能修好
|
|
231
|
+
assert.equal(json.chain.fallbacks.length, 2)
|
|
232
|
+
assert.deepEqual(json.chain.fallbacks[1], { provider: '', model: 'ghost' })
|
|
233
|
+
assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-own/deepseek-flash'], '生效链那侧仍剔除缺 provider 的行')
|
|
234
|
+
assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示,不进候选')
|
|
235
|
+
|
|
236
|
+
await get()
|
|
237
|
+
assert.equal(listed, 2, '两家 provider 各查一次,第二次开卡命中 TTL 缓存不重打宿主')
|
|
238
|
+
const wrong = await callRoute(harness, `${OPS}/catalog`, { method: 'POST', url: `${OPS}/catalog`, headers: {} })
|
|
239
|
+
assert.equal(wrong.status, 405)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('catalog:宿主不供模型清单或查询报错时回空表并标 modelsAvailable=false', async () => {
|
|
243
|
+
const bare = await booted({ providers: [{ id: 'local-35', name: 'local-35' }] })
|
|
244
|
+
const j1 = (await callRoute(bare, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
245
|
+
assert.equal(j1.providers.length, 1, 'provider 目录照常给')
|
|
246
|
+
assert.equal(j1.providers[0].modelsAvailable, false, '没 listModels 就得告知客户端降级手输')
|
|
247
|
+
assert.deepEqual(j1.providers[0].models, [])
|
|
248
|
+
|
|
249
|
+
let calls = 0
|
|
250
|
+
const boom = await booted({
|
|
251
|
+
providers: [{ id: 'x', name: 'x' }],
|
|
252
|
+
models: async () => { calls += 1; throw new Error('adapter-down') },
|
|
253
|
+
})
|
|
254
|
+
const getBoom = async () => (await callRoute(boom, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
255
|
+
const j2 = await getBoom()
|
|
256
|
+
assert.equal(j2.providers[0].modelsAvailable, false)
|
|
257
|
+
assert.equal(j2.providers[0].models.length, 0)
|
|
258
|
+
await getBoom()
|
|
259
|
+
assert.equal(calls, 2, '失败不进缓存:下次开卡重试,不把一次报错长挂一分钟')
|
|
260
|
+
|
|
261
|
+
const none = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
|
|
262
|
+
const j3 = (await callRoute(none, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
263
|
+
assert.deepEqual(j3.providers, [], '宿主没给 llm 目录面时回空集,客户端全行手输')
|
|
264
|
+
assert.deepEqual(j3.routes, [])
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
test('catalog:ops.enabled=false 时目录与已存链照常回(关闭态也要能编链)', async () => {
|
|
268
|
+
const harness = await booted({
|
|
269
|
+
providers: [{ id: 'local', name: 'local' }],
|
|
270
|
+
models: async () => [{ id: 'qwen', name: 'qwen' }],
|
|
271
|
+
config: { ops: { enabled: false, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] } },
|
|
272
|
+
})
|
|
273
|
+
const json = (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
|
|
274
|
+
assert.equal(json.enabled, false, '开关态单独告知,不影响目录')
|
|
275
|
+
assert.equal(json.providers.length, 1)
|
|
276
|
+
assert.equal(json.chain.routeProvider, 'local', '关闭态下已存链仍可回显可编辑')
|
|
277
|
+
})
|
|
278
|
+
|
|
147
279
|
test('ops.enabled=false:providers 报 disabled 且不枚举宿主、refine/mutate/ask 一律 403,validate 照常可用', async () => {
|
|
148
280
|
let listed = 0
|
|
149
281
|
const harness = await booted({
|
|
@@ -242,7 +374,7 @@ test('三轮都不合规 → 502,一次板都未动', async () => {
|
|
|
242
374
|
const before = await snapshot(harness)
|
|
243
375
|
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
244
376
|
assert.equal(r.status, 502)
|
|
245
|
-
assert.match(r.json.error,
|
|
377
|
+
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
246
378
|
assert.match(r.json.error, /kind 非法/)
|
|
247
379
|
assert.equal(calls.length, 3, '一次原始 + 两次打回')
|
|
248
380
|
assert.equal((await snapshot(harness)).revision, before.revision, '打回失败不许留痕')
|
|
@@ -298,14 +430,65 @@ test('op=mutate/ask 缺 question、未知 op、缺 sessionId 一律 400', async
|
|
|
298
430
|
assert.equal((await ops(harness, { sessionId: '', op: 'validate' })).status, 400)
|
|
299
431
|
})
|
|
300
432
|
|
|
301
|
-
test('
|
|
302
|
-
const
|
|
433
|
+
test('未钉定模型路由 → 403,一帧 token 都不发', async () => {
|
|
434
|
+
const calls = []
|
|
435
|
+
const harness = await booted({ calls, config: { ops: { enabled: true, routeProvider: '', routeModel: '' } }, reply: '{"changes":[{"kind":"add","title":"x"}]}' })
|
|
436
|
+
const before = await snapshot(harness)
|
|
437
|
+
for (const op of ['refine', 'mutate', 'ask']) {
|
|
438
|
+
const r = await ops(harness, { sessionId: SESSION, op, question: '拆一下' })
|
|
439
|
+
assert.equal(r.status, 403, `${op} 在未钉定路由时必须 403`)
|
|
440
|
+
assert.match(r.json.error, /未钉定模型路由|ops\.fallbacks/)
|
|
441
|
+
}
|
|
442
|
+
assert.equal(calls.length, 0, '未钉定不得发出任何一次模型调用')
|
|
443
|
+
assert.equal((await snapshot(harness)).revision, before.revision, '没钉路由就不许动板')
|
|
444
|
+
// 体检不花 token,与路由无关,仍照常可用
|
|
445
|
+
const v = await ops(harness, { sessionId: SESSION, op: 'validate' })
|
|
446
|
+
assert.equal(v.status, 200)
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
test('选了链外的 provider/model → 403,并把链上候选告知回去', async () => {
|
|
450
|
+
const calls = []
|
|
451
|
+
const harness = await booted({ calls, reply: '{"changes":[]}' })
|
|
452
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine', provider: 'deepseek-account', model: 'deepseek-v4-pro' })
|
|
453
|
+
assert.equal(r.status, 403)
|
|
454
|
+
assert.match(r.json.error, /不在 ops 允许范围内/)
|
|
455
|
+
assert.match(r.json.error, /local\/qwen/, '必须把链上真值告知回去,否则用户无从改配置')
|
|
456
|
+
assert.equal(calls.length, 0)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test('主路由传输失败 → 沿链降级到下一条,routeIndex 告知降级位次', async () => {
|
|
460
|
+
const calls = []
|
|
461
|
+
const harness = await booted({
|
|
462
|
+
calls,
|
|
463
|
+
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
464
|
+
reply: () => (calls.length === 1 ? (() => { throw new Error('assistant-empty') })() : JSON.stringify({ thinking: '主路由挂了,这条顶上', changes: [{ kind: 'add', title: '拆项' }], answer: '已落盘' })),
|
|
465
|
+
})
|
|
466
|
+
const before = await snapshot(harness)
|
|
467
|
+
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
468
|
+
assert.equal(r.json.applied, true, '主路由传输失败不得直接放弃,要沿链降级')
|
|
469
|
+
assert.equal(r.json.routeIndex, 1, '服务的是链上第二条')
|
|
470
|
+
assert.deepEqual(r.json.route, { provider: 'backup', model: 'small', local: false })
|
|
471
|
+
assert.equal(calls.length, 2)
|
|
472
|
+
assert.equal(calls[1].provider, 'backup')
|
|
473
|
+
assert.equal(calls[1].model, 'small')
|
|
474
|
+
assert.equal((await snapshot(harness)).revision, before.revision + 1)
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
test('全链都拉不出可用输出 → 502,逐条路由的失败原因都告知', async () => {
|
|
478
|
+
const calls = []
|
|
479
|
+
const harness = await booted({
|
|
480
|
+
calls,
|
|
481
|
+
config: { ops: { enabled: true, routeProvider: 'local', routeModel: 'qwen', preferLocal: false, fallbacks: [{ provider: 'backup', model: 'small' }] } },
|
|
482
|
+
reply: '纯文本,不是 JSON',
|
|
483
|
+
})
|
|
303
484
|
const before = await snapshot(harness)
|
|
304
485
|
const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
|
|
305
|
-
assert.equal(r.status,
|
|
306
|
-
assert.match(r.json.error,
|
|
307
|
-
|
|
308
|
-
assert.
|
|
486
|
+
assert.equal(r.status, 502)
|
|
487
|
+
assert.match(r.json.error, /路由链上没有一条给出可用输出/)
|
|
488
|
+
assert.match(r.json.error, /local\/qwen:/)
|
|
489
|
+
assert.match(r.json.error, /backup\/small:/)
|
|
490
|
+
assert.equal(calls.length, 6, '两条路由各走满三轮格式打回')
|
|
491
|
+
assert.equal((await snapshot(harness)).revision, before.revision)
|
|
309
492
|
})
|
|
310
493
|
|
|
311
494
|
test('模型乱答(无 JSON)→ 三轮都拉不回来,502 且板不变', async () => {
|
package/test/settings.test.mjs
CHANGED
|
@@ -150,14 +150,40 @@ test('设置卡:每条写路径必须是 Config 里的 volatile 叶子', () =>
|
|
|
150
150
|
const paths = new Set()
|
|
151
151
|
for (const m of src.matchAll(/(?:switchInput|segmentInput)\('(\w+)',\s*\w+,\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
152
152
|
for (const m of src.matchAll(/(?:numberInput|textInput|secretInput)\('(\w+)',\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
153
|
+
// v0.8.1:路由链编辑器直接拼 mutate 的 path 字面量,这类写点以前扫不到——
|
|
154
|
+
// 不补上就等于开了个绕过本闸的后门(新写点必须同样落在 volatile 叶子上)。
|
|
155
|
+
for (const m of src.matchAll(/path:\s*\['(\w+)',\s*'(\w+)'\]/g)) paths.add(`${m[1]}.${m[2]}`)
|
|
153
156
|
for (const m of src.matchAll(/void commit\('(\w+)'/g)) paths.add(m[1])
|
|
154
|
-
assert.ok(paths.size >=
|
|
157
|
+
assert.ok(paths.size >= 27, `扫到的写路径只有 ${paths.size} 条,正则可能失效`)
|
|
155
158
|
for (const p of [...paths].sort()) {
|
|
156
159
|
assert.ok(p in leaves, `设置卡要写 ${p},但 Config 里没这个键`)
|
|
157
160
|
assert.equal(leaves[p], true, `设置卡要写 ${p},但它不是 volatile 叶子 → 宿主 settings/rejected`)
|
|
158
161
|
}
|
|
159
162
|
})
|
|
160
163
|
|
|
164
|
+
/**
|
|
165
|
+
* v0.8.1:降级链从「只能手写 yml」改成面板可编。本闸钉住四件事:
|
|
166
|
+
* fallbacks 必须是 volatile 叶子(否则编辑器拨了不落盘);整链一次提交
|
|
167
|
+
* 三个键;不得再开整组铺回的分支;目录拉不到时要能降级手输。
|
|
168
|
+
*/
|
|
169
|
+
test('v0.8.1:路由链编辑器的写面与降级形态', () => {
|
|
170
|
+
const leaves = volatileLeaves(Config)
|
|
171
|
+
assert.equal(leaves['ops.fallbacks'], true, 'ops.fallbacks 必须是 volatile 叶子,否则面板编不了链')
|
|
172
|
+
assert.equal(leaves['ops'], undefined, 'ops 节本身不得被标 volatile(嵌套 volatile 宿主直接拒)')
|
|
173
|
+
|
|
174
|
+
const src = fs.readFileSync(fileURLToPath(new URL('../client.js', import.meta.url)), 'utf8').replace(/\r\n/g, '\n')
|
|
175
|
+
for (const key of ['routeProvider', 'routeModel', 'fallbacks']) {
|
|
176
|
+
assert.ok(src.includes(`path: ['ops', '${key}']`), `整链提交必须含 ${key} 这一键,不留半截状态`)
|
|
177
|
+
}
|
|
178
|
+
assert.ok(!/void commit\('ops'/.test(src), '嵌套组不得整组铺回(0.7.5 实测会被 settings/rejected 拒)')
|
|
179
|
+
assert.match(src, /fetch\(`\$\{API\}\/ops\/catalog`/, '编辑器必须从宿主目录拉 provider/模型')
|
|
180
|
+
assert.match(src, /bucket\.modelsAvailable === true/, '该家不供模型清单时要降级为手输,不能给一个填不了的空下拉')
|
|
181
|
+
assert.match(src, /rows\.length >= maxChain/, '添加按钮到链长上限要禁用')
|
|
182
|
+
assert.match(src, /const move = \(index, delta\) =>/, '行序必须能在面板调(降级链语义就是顺序)')
|
|
183
|
+
assert.match(src, /chainRowsOf\(props\.ops\)/, '行初值必须从已存配置回显,不能从空表开始')
|
|
184
|
+
assert.ok(!src.includes('setOpsFallbackNote'), '「fallbacks 只能改 yml」的旧说法必须从文案里消失')
|
|
185
|
+
})
|
|
186
|
+
|
|
161
187
|
/**
|
|
162
188
|
* v0.7.7 真机回灌:0.7.6 修好写面后,页脚出现「已保存」与「有未保存的改动」并存
|
|
163
189
|
* —— 开关拨完即落盘,但乐观草稿仍按「键存在」计脏。脏位必须按值比对。
|