dsh-dev-plan-presets 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +341 -2
- package/client.js +1096 -0
- package/cordis.patch.yml +22 -0
- package/detail.md +192 -0
- package/docs/flow-redesign.md +403 -0
- package/guard.js +364 -0
- package/icon.svg +12 -0
- package/index.js +703 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -4
- package/preset.js +485 -0
- package/scripts/test-harness.mjs +290 -0
- package/scripts/verify-presets.mjs +1650 -0
- package/settings.js +174 -0
- package/test/plugin.test.mjs +1468 -0
|
@@ -0,0 +1,1468 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
+
import {
|
|
7
|
+
callRoute,
|
|
8
|
+
createFakeAgent,
|
|
9
|
+
createFakeConfigEditor,
|
|
10
|
+
createFakeContext,
|
|
11
|
+
createFakeRegistry,
|
|
12
|
+
createFakeWebServer,
|
|
13
|
+
loadModules,
|
|
14
|
+
} from '../scripts/test-harness.mjs'
|
|
15
|
+
|
|
16
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
17
|
+
const { settings: S, preset: P, index, guard } = await loadModules(ROOT)
|
|
18
|
+
|
|
19
|
+
const base = () => ({ ...S.DEFAULT_SETTINGS })
|
|
20
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
21
|
+
|
|
22
|
+
async function loadClientTestApi() {
|
|
23
|
+
const previousWindow = globalThis.window
|
|
24
|
+
const previousFlag = globalThis.__DSH_DEV_PLAN_PRESETS_TEST__
|
|
25
|
+
const captured = { module: null }
|
|
26
|
+
globalThis.window = {
|
|
27
|
+
__ModuleLoader__: {
|
|
28
|
+
load(module) {
|
|
29
|
+
captured.module = module
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
globalThis.__DSH_DEV_PLAN_PRESETS_TEST__ = true
|
|
34
|
+
try {
|
|
35
|
+
const url =
|
|
36
|
+
pathToFileURL(join(ROOT, 'client.js')).href +
|
|
37
|
+
'?client-test=' +
|
|
38
|
+
Date.now() +
|
|
39
|
+
Math.random().toString(36).slice(2)
|
|
40
|
+
await import(url)
|
|
41
|
+
assert.ok(captured.module, 'client.js 没有调用 __ModuleLoader__.load')
|
|
42
|
+
const fakeReact = {
|
|
43
|
+
createElement: (...args) => ({ args }),
|
|
44
|
+
useState: (initial) => [initial, () => {}],
|
|
45
|
+
useEffect: () => {},
|
|
46
|
+
useRef: (initial) => ({ current: initial }),
|
|
47
|
+
useCallback: (fn) => fn,
|
|
48
|
+
cloneElement: (element) => element,
|
|
49
|
+
Fragment: 'Fragment',
|
|
50
|
+
}
|
|
51
|
+
const api = captured.module.factory(() => fakeReact)
|
|
52
|
+
assert.ok(api.__test, 'client 没有暴露测试用纯选择函数')
|
|
53
|
+
return api.__test
|
|
54
|
+
} finally {
|
|
55
|
+
globalThis.window = previousWindow
|
|
56
|
+
globalThis.__DSH_DEV_PLAN_PRESETS_TEST__ = previousFlag
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test('默认设置:standard + pin,零 deep-ptc 依赖', () => {
|
|
61
|
+
const value = S.normalizeSettings(undefined)
|
|
62
|
+
assert.equal(value.developMode, 'standard')
|
|
63
|
+
assert.equal(value.modelGuardMode, 'pin')
|
|
64
|
+
assert.equal(value.killOnViolation, true)
|
|
65
|
+
assert.equal(value.honorExplicit, false)
|
|
66
|
+
assert.equal(value.audit, true)
|
|
67
|
+
assert.equal(value.guardAllSubagents, false)
|
|
68
|
+
assert.equal(value.childProvider, 'dsh-opencode-go')
|
|
69
|
+
assert.equal(value.childModel, 'deepseek-v4.1-flash')
|
|
70
|
+
assert.equal(value.childReasoningEffort, '')
|
|
71
|
+
assert.deepEqual(S.routeOf(value), { provider: 'dsh-opencode-go', model: 'deepseek-v4.1-flash' })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('Config 严格校验:默认值通过,非法枚举/空路由被拒绝', () => {
|
|
75
|
+
const ok = S.Config['~standard'].validate({})
|
|
76
|
+
assert.deepEqual(ok.value, base())
|
|
77
|
+
// 任意非空 preset id 都合法;只有空值被拒绝。
|
|
78
|
+
const customMode = S.Config['~standard'].validate({ developMode: 'my-preset' })
|
|
79
|
+
assert.equal(customMode.value.developMode, 'my-preset')
|
|
80
|
+
const emptyMode = S.Config['~standard'].validate({ developMode: ' ' })
|
|
81
|
+
assert.ok(emptyMode.issues.some((issue) => issue.path[0] === 'developMode'))
|
|
82
|
+
const badGuardAll = S.Config['~standard'].validate({ guardAllSubagents: 'yes' })
|
|
83
|
+
assert.ok(badGuardAll.issues.some((issue) => issue.path[0] === 'guardAllSubagents'))
|
|
84
|
+
const goodGuardAll = S.Config['~standard'].validate({ guardAllSubagents: true })
|
|
85
|
+
assert.equal(goodGuardAll.value.guardAllSubagents, true)
|
|
86
|
+
const badGuard = S.Config['~standard'].validate({ modelGuardMode: 'kill' })
|
|
87
|
+
assert.ok(badGuard.issues.some((issue) => issue.path[0] === 'modelGuardMode'))
|
|
88
|
+
const badRoute = S.Config['~standard'].validate({ childProvider: ' ' })
|
|
89
|
+
assert.ok(badRoute.issues.some((issue) => issue.path[0] === 'childProvider'))
|
|
90
|
+
const badEffort = S.Config['~standard'].validate({ childReasoningEffort: 1 })
|
|
91
|
+
assert.ok(badEffort.issues.some((issue) => issue.path[0] === 'childReasoningEffort'))
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('standard 定义:四个委派工具、develop=standard、主窗无施工工具', () => {
|
|
95
|
+
const definition = P.buildPresetDefinition({
|
|
96
|
+
settings: base(),
|
|
97
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
98
|
+
})
|
|
99
|
+
assert.equal(definition.id, 'dev-plan')
|
|
100
|
+
assert.equal(definition.name, '开发规划与交付')
|
|
101
|
+
assert.equal(P.PRESET_NAME, '开发规划与交付')
|
|
102
|
+
assert.equal(definition.order, 10)
|
|
103
|
+
|
|
104
|
+
const rows = []
|
|
105
|
+
const walk = (plugins) => {
|
|
106
|
+
for (const row of plugins ?? []) {
|
|
107
|
+
rows.push(row)
|
|
108
|
+
if (Array.isArray(row?.config)) walk(row.config)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
walk(definition.plugins)
|
|
112
|
+
for (const forbidden of P.FORBIDDEN_MAIN_PLUGINS) {
|
|
113
|
+
assert.ok(!rows.some((row) => row?.name === forbidden), `主窗不应挂 ${forbidden}`)
|
|
114
|
+
}
|
|
115
|
+
const subagents = rows.filter((row) => row?.name === '@deepseek-ai/dsh-tool-subagent')
|
|
116
|
+
assert.equal(subagents.length, 4)
|
|
117
|
+
assert.deepEqual(
|
|
118
|
+
subagents.map((row) => row.config.toolName).sort(),
|
|
119
|
+
['develop', 'recon', 'review', 'scribe'],
|
|
120
|
+
)
|
|
121
|
+
for (const row of subagents) {
|
|
122
|
+
const cfg = row.config
|
|
123
|
+
assert.equal(cfg.provider, 'spawn')
|
|
124
|
+
assert.equal(cfg.maxDepth, 1)
|
|
125
|
+
assert.equal(cfg.modelSelection, false)
|
|
126
|
+
assert.equal(cfg.modelDiscovery, false)
|
|
127
|
+
assert.equal(cfg.allowedAgentPresets, undefined)
|
|
128
|
+
assert.deepEqual(cfg.agentOptions, { provider: 'dsh-opencode-go', model: 'deepseek-v4.1-flash' })
|
|
129
|
+
assert.equal(cfg.agentPreset, 'standard')
|
|
130
|
+
}
|
|
131
|
+
assert.equal(subagents.find((row) => row.config.toolName === 'develop').config.agentPreset, 'standard')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('deep-ptc 定义:只有 develop 切到 deep-ptc,其余仍是 standard', () => {
|
|
135
|
+
const mode = P.resolveDevelopMode({
|
|
136
|
+
requestedMode: 'deep-ptc',
|
|
137
|
+
presets: [{ id: 'deep-ptc', name: '深度 PTC' }],
|
|
138
|
+
catalogChecked: true,
|
|
139
|
+
})
|
|
140
|
+
const definition = P.buildPresetDefinition({ settings: base(), mode })
|
|
141
|
+
const rows = []
|
|
142
|
+
const walk = (plugins) => {
|
|
143
|
+
for (const row of plugins ?? []) {
|
|
144
|
+
rows.push(row)
|
|
145
|
+
if (Array.isArray(row?.config)) walk(row.config)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
walk(definition.plugins)
|
|
149
|
+
const byName = Object.fromEntries(
|
|
150
|
+
rows
|
|
151
|
+
.filter((row) => row?.name === '@deepseek-ai/dsh-tool-subagent')
|
|
152
|
+
.map((row) => [row.config.toolName, row.config.agentPreset]),
|
|
153
|
+
)
|
|
154
|
+
assert.deepEqual(byName, {
|
|
155
|
+
recon: 'standard',
|
|
156
|
+
review: 'standard',
|
|
157
|
+
scribe: 'standard',
|
|
158
|
+
develop: 'deep-ptc',
|
|
159
|
+
})
|
|
160
|
+
assert.match(definition.description, /deep-ptc/)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test('回退显式可见:standard + 原因,写进 description 与 persona', () => {
|
|
164
|
+
const mode = P.resolveDevelopMode({ requestedMode: 'deep-ptc', presets: [], catalogChecked: true })
|
|
165
|
+
assert.equal(mode.effective, 'standard')
|
|
166
|
+
assert.equal(mode.fallback, true)
|
|
167
|
+
assert.match(mode.reason, /没有可用的施工方式|未安装|未启用|已被移除/)
|
|
168
|
+
const definition = P.buildPresetDefinition({ settings: base(), mode })
|
|
169
|
+
assert.match(definition.description, /已回退 standard/)
|
|
170
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
171
|
+
assert.match(persona, /已回退 standard/)
|
|
172
|
+
assert.match(persona, /不是静默降级/)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('deep-ptc 已注册但激活失败也回退', () => {
|
|
176
|
+
const mode = P.resolveDevelopMode({
|
|
177
|
+
requestedMode: 'deep-ptc',
|
|
178
|
+
presets: [{ id: 'deep-ptc', broken: 'row 3 failed to import' }],
|
|
179
|
+
catalogChecked: true,
|
|
180
|
+
})
|
|
181
|
+
assert.equal(mode.effective, 'standard')
|
|
182
|
+
assert.equal(mode.fallback, true)
|
|
183
|
+
assert.match(mode.reason, /加载失败/)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('apply 动态注册 preset,并在 dispose 时交还 disposer', async () => {
|
|
187
|
+
const registry = createFakeRegistry()
|
|
188
|
+
const ctx = createFakeContext({ registry })
|
|
189
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
190
|
+
await ctx.flush()
|
|
191
|
+
assert.equal(registry.definitions.length, 1)
|
|
192
|
+
assert.equal(registry.definitions[0].id, 'dev-plan')
|
|
193
|
+
const stateRoute = null
|
|
194
|
+
assert.equal(stateRoute, null)
|
|
195
|
+
await ctx.dispose()
|
|
196
|
+
assert.deepEqual(registry.released, ['dev-plan'])
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('state 路由:默认 standard、preset 描述可用', async () => {
|
|
200
|
+
const registry = createFakeRegistry()
|
|
201
|
+
const webServer = createFakeWebServer()
|
|
202
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
203
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
204
|
+
await ctx.flush()
|
|
205
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
|
|
206
|
+
assert.equal(typeof handler, 'function')
|
|
207
|
+
const response = await callRoute(handler, 'GET')
|
|
208
|
+
assert.equal(response.code, 200)
|
|
209
|
+
assert.equal(response.body.version, '0.3.0')
|
|
210
|
+
assert.equal(response.body.effectiveMode, 'standard')
|
|
211
|
+
assert.equal(response.body.fallback.active, false)
|
|
212
|
+
assert.equal(response.body.preset.id, 'dev-plan')
|
|
213
|
+
assert.equal(response.body.config.guardAllSubagents, false)
|
|
214
|
+
assert.equal(response.body.presets.selfId, 'dev-plan')
|
|
215
|
+
assert.match(response.body.preset.description, /standard/)
|
|
216
|
+
await ctx.dispose()
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
test('state 路由:请求 deep-ptc 但宿主没有时显式回退', async () => {
|
|
220
|
+
const registry = createFakeRegistry()
|
|
221
|
+
const webServer = createFakeWebServer()
|
|
222
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
223
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
|
|
224
|
+
await ctx.flush()
|
|
225
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
|
|
226
|
+
const response = await callRoute(handler, 'GET')
|
|
227
|
+
assert.equal(response.body.effectiveMode, 'standard')
|
|
228
|
+
assert.equal(response.body.fallback.active, true)
|
|
229
|
+
assert.match(response.body.fallback.reason, /没有可用的施工方式|未安装|未启用|已被移除/)
|
|
230
|
+
assert.equal(response.body.presets.checked, true)
|
|
231
|
+
assert.deepEqual(response.body.presets.rows, [])
|
|
232
|
+
assert.match(response.body.preset.description, /已回退 standard/)
|
|
233
|
+
assert.ok(ctx.loggerCalls.warn.some((line) => line.includes('已回退 standard')))
|
|
234
|
+
assert.equal(registry.definitions[0].plugins.at(-1).config.agentPreset, 'standard')
|
|
235
|
+
await ctx.dispose()
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('registry 中实际存在 deep-ptc 时,develop 使用 deep-ptc', async () => {
|
|
239
|
+
const registry = createFakeRegistry({ rows: [{ id: 'deep-ptc' }] })
|
|
240
|
+
const ctx = createFakeContext({
|
|
241
|
+
registry,
|
|
242
|
+
entries: [{ id: 'deep-ptc-settings', options: { name: 'dsh-deep-ptc-mode' }, fiber: { state: 1 } }],
|
|
243
|
+
})
|
|
244
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
|
|
245
|
+
await ctx.flush()
|
|
246
|
+
const definition = registry.definitions[0]
|
|
247
|
+
const develop = definition.plugins.find((row) => row.id === 'tool-subagent-develop')
|
|
248
|
+
assert.equal(develop.config.agentPreset, 'deep-ptc')
|
|
249
|
+
assert.equal(definition.plugins.find((row) => row.id === 'tool-subagent-recon').config.agentPreset, 'standard')
|
|
250
|
+
await ctx.dispose()
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('目录中没有目标 preset 时回退,不把 loader entry 当可用证据', async () => {
|
|
254
|
+
const registry = createFakeRegistry({ rows: [] })
|
|
255
|
+
const webServer = createFakeWebServer()
|
|
256
|
+
const ctx = createFakeContext({
|
|
257
|
+
registry,
|
|
258
|
+
webServer,
|
|
259
|
+
// LOADING:深度 PTC 已安装并开始加载,但 preset 还没注册,不能据 entry 推断可用。
|
|
260
|
+
entries: [{ id: 'deep-ptc-settings', options: { name: 'dsh-deep-ptc-mode' }, fiber: { state: 1 } }],
|
|
261
|
+
})
|
|
262
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
|
|
263
|
+
await ctx.flush()
|
|
264
|
+
const definition = registry.definitions[0]
|
|
265
|
+
assert.equal(definition.plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset, 'standard')
|
|
266
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
267
|
+
assert.equal(state.body.effectiveMode, 'standard')
|
|
268
|
+
assert.equal(state.body.fallback.active, true)
|
|
269
|
+
assert.match(state.body.fallback.reason, /没有可用的施工方式|未安装|未启用|已被移除/)
|
|
270
|
+
assert.match(state.body.preset.description, /已回退 standard/)
|
|
271
|
+
await ctx.dispose()
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
test('延迟复检可以在 registry 出现 deep-ptc 后把 develop 从 standard 提升到 deep-ptc', async () => {
|
|
275
|
+
const registry = createFakeRegistry({ rows: [] })
|
|
276
|
+
let listCalls = 0
|
|
277
|
+
// 第一次探测时 registry 还没有 deep-ptc;延迟复检时已注册。
|
|
278
|
+
registry.list = async () => {
|
|
279
|
+
listCalls += 1
|
|
280
|
+
return listCalls === 1 ? [] : [{ id: 'deep-ptc' }]
|
|
281
|
+
}
|
|
282
|
+
const webServer = createFakeWebServer()
|
|
283
|
+
const ctx = createFakeContext({
|
|
284
|
+
registry,
|
|
285
|
+
webServer,
|
|
286
|
+
entries: [{ id: 'deep-ptc-settings', options: { name: 'dsh-deep-ptc-mode' }, fiber: { state: 1 } }],
|
|
287
|
+
})
|
|
288
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 300 })
|
|
289
|
+
await ctx.flush()
|
|
290
|
+
assert.equal(registry.definitions.length, 1)
|
|
291
|
+
assert.equal(
|
|
292
|
+
registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
|
|
293
|
+
'standard',
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
// 深度 PTC 完成动态注册后,下一次延迟复检应释放旧定义并注册 deep-ptc 版本。
|
|
297
|
+
await sleep(600)
|
|
298
|
+
await ctx.flush()
|
|
299
|
+
assert.ok(registry.definitions.length >= 2)
|
|
300
|
+
const latest = registry.definitions.at(-1)
|
|
301
|
+
assert.equal(latest.plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset, 'deep-ptc')
|
|
302
|
+
assert.equal(latest.plugins.find((row) => row.id === 'tool-subagent-recon').config.agentPreset, 'standard')
|
|
303
|
+
assert.ok(registry.released.includes('dev-plan'))
|
|
304
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
305
|
+
assert.equal(state.body.effectiveMode, 'deep-ptc')
|
|
306
|
+
assert.equal(state.body.fallback.active, false)
|
|
307
|
+
await ctx.dispose()
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
test('同 effective/fallback 但回退原因变化时,重新发布 preset 描述', async () => {
|
|
311
|
+
const registry = createFakeRegistry({ rows: [] })
|
|
312
|
+
let listCalls = 0
|
|
313
|
+
registry.list = async () => {
|
|
314
|
+
listCalls += 1
|
|
315
|
+
return [{ id: 'deep-ptc', broken: listCalls === 1 ? 'first failure' : 'second failure' }]
|
|
316
|
+
}
|
|
317
|
+
const webServer = createFakeWebServer()
|
|
318
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
319
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 300 })
|
|
320
|
+
await ctx.flush()
|
|
321
|
+
assert.equal(registry.definitions.length, 1)
|
|
322
|
+
assert.match(registry.definitions[0].description, /first failure/)
|
|
323
|
+
|
|
324
|
+
await sleep(600)
|
|
325
|
+
await ctx.flush()
|
|
326
|
+
assert.ok(registry.definitions.length >= 2)
|
|
327
|
+
const latest = registry.definitions.at(-1)
|
|
328
|
+
assert.match(latest.description, /second failure/)
|
|
329
|
+
assert.doesNotMatch(latest.description, /first failure/)
|
|
330
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
331
|
+
assert.equal(state.body.effectiveMode, 'standard')
|
|
332
|
+
assert.equal(state.body.fallback.active, true)
|
|
333
|
+
assert.match(state.body.fallback.reason, /second failure/)
|
|
334
|
+
assert.match(state.body.preset.description, /second failure/)
|
|
335
|
+
await ctx.dispose()
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
test('config 路由:用 configEditor 写回,非法值 400 且不写', async () => {
|
|
339
|
+
const registry = createFakeRegistry()
|
|
340
|
+
const webServer = createFakeWebServer()
|
|
341
|
+
const configEditor = createFakeConfigEditor()
|
|
342
|
+
const ctx = createFakeContext({ registry, webServer, configEditor })
|
|
343
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
344
|
+
await ctx.flush()
|
|
345
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/config')
|
|
346
|
+
|
|
347
|
+
const invalid = await callRoute(handler, 'POST', { modelGuardMode: 'kill' })
|
|
348
|
+
assert.equal(invalid.code, 400)
|
|
349
|
+
assert.equal(configEditor.edits.length, 0)
|
|
350
|
+
|
|
351
|
+
const ok = await callRoute(handler, 'POST', {
|
|
352
|
+
developMode: 'deep-ptc',
|
|
353
|
+
childProvider: 'p',
|
|
354
|
+
childModel: 'm',
|
|
355
|
+
childReasoningEffort: 'high',
|
|
356
|
+
modelGuardMode: 'audit',
|
|
357
|
+
killOnViolation: false,
|
|
358
|
+
honorExplicit: true,
|
|
359
|
+
audit: false,
|
|
360
|
+
guardAllSubagents: true,
|
|
361
|
+
})
|
|
362
|
+
assert.equal(ok.code, 200)
|
|
363
|
+
assert.equal(configEditor.edits.length, 1)
|
|
364
|
+
assert.deepEqual(configEditor.edits[0].next, {
|
|
365
|
+
developMode: 'deep-ptc',
|
|
366
|
+
childProvider: 'p',
|
|
367
|
+
childModel: 'm',
|
|
368
|
+
childReasoningEffort: 'high',
|
|
369
|
+
modelGuardMode: 'audit',
|
|
370
|
+
killOnViolation: false,
|
|
371
|
+
honorExplicit: true,
|
|
372
|
+
audit: false,
|
|
373
|
+
guardAllSubagents: true,
|
|
374
|
+
})
|
|
375
|
+
assert.equal(ok.body.ok, true)
|
|
376
|
+
await ctx.dispose()
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
test('模型守门 pin:子代理被 select,主会话完全不动', async () => {
|
|
380
|
+
const registry = createFakeRegistry()
|
|
381
|
+
const child = createFakeAgent({ id: 'child-1', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
382
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'expensive', model: 'big' } })
|
|
383
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
384
|
+
const ctx = createFakeContext({ registry, agents })
|
|
385
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
386
|
+
await ctx.flush()
|
|
387
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
388
|
+
assert.equal(typeof listener, 'function')
|
|
389
|
+
|
|
390
|
+
listener({ agent: child.agent })
|
|
391
|
+
assert.deepEqual(child.selects, [{ provider: 'dsh-opencode-go', model: 'deepseek-v4.1-flash' }])
|
|
392
|
+
assert.equal(child.stepHandlers.length, 1)
|
|
393
|
+
|
|
394
|
+
listener({ agent: parent.agent })
|
|
395
|
+
assert.deepEqual(parent.selects, [])
|
|
396
|
+
assert.equal(parent.stepHandlers.length, 0)
|
|
397
|
+
await ctx.dispose()
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
test('模型守门 pin:pre-step 越界在请求前 reject + cancel + 通知父会话', async () => {
|
|
401
|
+
const registry = createFakeRegistry()
|
|
402
|
+
const child = createFakeAgent({ id: 'child-2', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
403
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'expensive', model: 'big' } })
|
|
404
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
405
|
+
const webServer = createFakeWebServer()
|
|
406
|
+
const ctx = createFakeContext({ registry, agents, webServer })
|
|
407
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
408
|
+
await ctx.flush()
|
|
409
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
410
|
+
listener({ agent: child.agent })
|
|
411
|
+
|
|
412
|
+
const next = async () => ({ kind: 'enter', messages: [] })
|
|
413
|
+
const decision = await child.stepHandlers[0](
|
|
414
|
+
{ modelSelection: { provider: 'other', model: 'expensive' } },
|
|
415
|
+
next,
|
|
416
|
+
)
|
|
417
|
+
assert.deepEqual(decision, { kind: 'reject' })
|
|
418
|
+
assert.equal(child.cancelled.length, 1)
|
|
419
|
+
assert.equal(parent.injected.length, 1)
|
|
420
|
+
assert.match(parent.injected[0].content[0].text, /已中止/)
|
|
421
|
+
|
|
422
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
423
|
+
assert.equal(state.body.violations.length, 1)
|
|
424
|
+
assert.match(state.body.violations[0].text, /越界/)
|
|
425
|
+
await ctx.dispose()
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
test('模型守门 audit:只记录,不 select、不打断', async () => {
|
|
429
|
+
const registry = createFakeRegistry()
|
|
430
|
+
const child = createFakeAgent({ id: 'child-3', parentSession: 'main', origin: 'subagent', current: { provider: 'x', model: 'y' } })
|
|
431
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
432
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
433
|
+
const webServer = createFakeWebServer()
|
|
434
|
+
const ctx = createFakeContext({ registry, agents, webServer })
|
|
435
|
+
index.apply(ctx.ctx, { ...base(), modelGuardMode: 'audit' }, { verificationDelayMs: 0 })
|
|
436
|
+
await ctx.flush()
|
|
437
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
438
|
+
listener({ agent: child.agent })
|
|
439
|
+
assert.deepEqual(child.selects, [])
|
|
440
|
+
assert.equal(child.stepHandlers.length, 1)
|
|
441
|
+
const decision = await child.stepHandlers[0](
|
|
442
|
+
{ modelSelection: { provider: 'x', model: 'y' } },
|
|
443
|
+
async () => ({ kind: 'enter', messages: [] }),
|
|
444
|
+
)
|
|
445
|
+
assert.equal(decision.kind, 'enter')
|
|
446
|
+
assert.equal(child.cancelled.length, 0)
|
|
447
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
448
|
+
assert.equal(state.body.violations.length, 1)
|
|
449
|
+
await ctx.dispose()
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
test('模型守门 off:不注册监听、不 select、不检查', async () => {
|
|
453
|
+
const registry = createFakeRegistry()
|
|
454
|
+
const child = createFakeAgent({ id: 'child-4', parentSession: 'main', origin: 'subagent' })
|
|
455
|
+
const ctx = createFakeContext({ registry })
|
|
456
|
+
index.apply(ctx.ctx, { ...base(), modelGuardMode: 'off' }, { verificationDelayMs: 0 })
|
|
457
|
+
await ctx.flush()
|
|
458
|
+
assert.equal(ctx.listeners.get('agent/created'), undefined)
|
|
459
|
+
assert.deepEqual(child.selects, [])
|
|
460
|
+
assert.equal(child.stepHandlers.length, 0)
|
|
461
|
+
await ctx.dispose()
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
test('config 路由:拒绝 text/plain、cross-site、错误 Origin,且 configEditor 零写入', async () => {
|
|
465
|
+
const registry = createFakeRegistry()
|
|
466
|
+
const webServer = createFakeWebServer()
|
|
467
|
+
const configEditor = createFakeConfigEditor()
|
|
468
|
+
const ctx = createFakeContext({ registry, webServer, configEditor })
|
|
469
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
470
|
+
await ctx.flush()
|
|
471
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/config')
|
|
472
|
+
|
|
473
|
+
const textPlain = await callRoute(handler, 'POST', { modelGuardMode: 'audit' }, { 'content-type': 'text/plain' })
|
|
474
|
+
assert.equal(textPlain.code, 415)
|
|
475
|
+
assert.equal(textPlain.body.code, 'unsupported-media-type')
|
|
476
|
+
|
|
477
|
+
const crossSite = await callRoute(
|
|
478
|
+
handler,
|
|
479
|
+
'POST',
|
|
480
|
+
{ modelGuardMode: 'audit' },
|
|
481
|
+
{ 'content-type': 'application/json', 'sec-fetch-site': 'cross-site' },
|
|
482
|
+
)
|
|
483
|
+
assert.equal(crossSite.code, 403)
|
|
484
|
+
assert.equal(crossSite.body.code, 'forbidden-origin')
|
|
485
|
+
|
|
486
|
+
const badOrigin = await callRoute(
|
|
487
|
+
handler,
|
|
488
|
+
'POST',
|
|
489
|
+
{ modelGuardMode: 'audit' },
|
|
490
|
+
{ 'content-type': 'application/json', origin: 'https://evil.example', host: '127.0.0.1:1162' },
|
|
491
|
+
)
|
|
492
|
+
assert.equal(badOrigin.code, 403)
|
|
493
|
+
assert.equal(badOrigin.body.code, 'forbidden-origin')
|
|
494
|
+
|
|
495
|
+
// DNS rebinding 形状:Origin 与 Host 同为攻击者域名,但不在实际监听 origin 上。
|
|
496
|
+
const rebinding = await callRoute(
|
|
497
|
+
handler,
|
|
498
|
+
'POST',
|
|
499
|
+
{ modelGuardMode: 'audit' },
|
|
500
|
+
{ 'content-type': 'application/json', origin: 'http://evil.example:1162', host: 'evil.example:1162' },
|
|
501
|
+
)
|
|
502
|
+
assert.equal(rebinding.code, 403)
|
|
503
|
+
assert.equal(rebinding.body.reason, 'origin-not-authoritative')
|
|
504
|
+
|
|
505
|
+
const wrongPort = await callRoute(
|
|
506
|
+
handler,
|
|
507
|
+
'POST',
|
|
508
|
+
{ modelGuardMode: 'audit' },
|
|
509
|
+
{ 'content-type': 'application/json', origin: 'http://127.0.0.1:9999', host: '127.0.0.1:9999' },
|
|
510
|
+
)
|
|
511
|
+
assert.equal(wrongPort.code, 403)
|
|
512
|
+
assert.equal(wrongPort.body.reason, 'origin-not-authoritative')
|
|
513
|
+
|
|
514
|
+
const nonListening = await callRoute(
|
|
515
|
+
handler,
|
|
516
|
+
'POST',
|
|
517
|
+
{ modelGuardMode: 'audit' },
|
|
518
|
+
{ 'content-type': 'application/json', origin: 'http://10.1.2.3:1162', host: '10.1.2.3:1162' },
|
|
519
|
+
)
|
|
520
|
+
assert.equal(nonListening.code, 403)
|
|
521
|
+
assert.equal(nonListening.body.reason, 'origin-not-authoritative')
|
|
522
|
+
|
|
523
|
+
assert.equal(configEditor.edits.length, 0, '被拒绝的请求不得调用 configEditor')
|
|
524
|
+
await ctx.dispose()
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
test('config 路由:允许同源、localhost/[::1] 同端口别名与无 Origin', async () => {
|
|
528
|
+
const registry = createFakeRegistry()
|
|
529
|
+
const webServer = createFakeWebServer()
|
|
530
|
+
const configEditor = createFakeConfigEditor()
|
|
531
|
+
const ctx = createFakeContext({ registry, webServer, configEditor })
|
|
532
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
533
|
+
await ctx.flush()
|
|
534
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/config')
|
|
535
|
+
|
|
536
|
+
const sameOrigin = await callRoute(
|
|
537
|
+
handler,
|
|
538
|
+
'POST',
|
|
539
|
+
{ modelGuardMode: 'audit' },
|
|
540
|
+
{
|
|
541
|
+
'content-type': 'application/json; charset=utf-8',
|
|
542
|
+
origin: 'http://127.0.0.1:1162',
|
|
543
|
+
host: '127.0.0.1:1162',
|
|
544
|
+
'sec-fetch-site': 'same-origin',
|
|
545
|
+
},
|
|
546
|
+
)
|
|
547
|
+
assert.equal(sameOrigin.code, 200)
|
|
548
|
+
assert.equal(configEditor.edits.length, 1)
|
|
549
|
+
|
|
550
|
+
const localhostAlias = await callRoute(
|
|
551
|
+
handler,
|
|
552
|
+
'POST',
|
|
553
|
+
{ modelGuardMode: 'audit' },
|
|
554
|
+
{
|
|
555
|
+
'content-type': 'application/json',
|
|
556
|
+
origin: 'http://localhost:1162',
|
|
557
|
+
host: 'localhost:1162',
|
|
558
|
+
'sec-fetch-site': 'same-origin',
|
|
559
|
+
},
|
|
560
|
+
)
|
|
561
|
+
assert.equal(localhostAlias.code, 200)
|
|
562
|
+
assert.equal(configEditor.edits.length, 2)
|
|
563
|
+
|
|
564
|
+
const ipv6Alias = await callRoute(
|
|
565
|
+
handler,
|
|
566
|
+
'POST',
|
|
567
|
+
{ modelGuardMode: 'audit' },
|
|
568
|
+
{
|
|
569
|
+
'content-type': 'application/json',
|
|
570
|
+
origin: 'http://[::1]:1162',
|
|
571
|
+
host: '[::1]:1162',
|
|
572
|
+
'sec-fetch-site': 'same-origin',
|
|
573
|
+
},
|
|
574
|
+
)
|
|
575
|
+
assert.equal(ipv6Alias.code, 200)
|
|
576
|
+
assert.equal(configEditor.edits.length, 3)
|
|
577
|
+
|
|
578
|
+
const noOrigin = await callRoute(handler, 'POST', { modelGuardMode: 'audit' }, { 'content-type': 'application/json' })
|
|
579
|
+
assert.equal(noOrigin.code, 200)
|
|
580
|
+
assert.equal(configEditor.edits.length, 4)
|
|
581
|
+
await ctx.dispose()
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
test('插件卸载时 guard 总 disposer 真正移除 child 的 pre-step handler', async () => {
|
|
585
|
+
const registry = createFakeRegistry()
|
|
586
|
+
const child = createFakeAgent({ id: 'child-dispose', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
587
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
588
|
+
const ctx = createFakeContext({
|
|
589
|
+
registry,
|
|
590
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
591
|
+
})
|
|
592
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
593
|
+
await ctx.flush()
|
|
594
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
595
|
+
assert.equal(child.stepHandlers.length, 1)
|
|
596
|
+
await ctx.dispose()
|
|
597
|
+
assert.equal(child.stepHandlers.length, 0, '插件卸载后旧 guard 必须被移除')
|
|
598
|
+
})
|
|
599
|
+
|
|
600
|
+
test('agent/disposed 清理 guard,随后插件卸载保持幂等', async () => {
|
|
601
|
+
const registry = createFakeRegistry()
|
|
602
|
+
const child = createFakeAgent({ id: 'child-agent-disposed', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
603
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
604
|
+
const ctx = createFakeContext({
|
|
605
|
+
registry,
|
|
606
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
607
|
+
})
|
|
608
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
609
|
+
await ctx.flush()
|
|
610
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
611
|
+
assert.equal(child.stepHandlers.length, 1)
|
|
612
|
+
const disposed = ctx.listeners.get('agent/disposed')?.[0]
|
|
613
|
+
assert.equal(typeof disposed, 'function')
|
|
614
|
+
disposed({ agent: child.agent })
|
|
615
|
+
assert.equal(child.stepHandlers.length, 0)
|
|
616
|
+
await ctx.dispose()
|
|
617
|
+
assert.equal(child.stepHandlers.length, 0)
|
|
618
|
+
})
|
|
619
|
+
|
|
620
|
+
test('modelGuardMode=off 不注册 agent/disposed', async () => {
|
|
621
|
+
const ctx = createFakeContext({ registry: createFakeRegistry() })
|
|
622
|
+
index.apply(ctx.ctx, { ...base(), modelGuardMode: 'off' }, { verificationDelayMs: 0 })
|
|
623
|
+
await ctx.flush()
|
|
624
|
+
assert.equal(ctx.listeners.get('agent/created'), undefined)
|
|
625
|
+
assert.equal(ctx.listeners.get('agent/disposed'), undefined)
|
|
626
|
+
await ctx.dispose()
|
|
627
|
+
})
|
|
628
|
+
|
|
629
|
+
test('模型守门 honorExplicit:显式路由不钉也不挂守卫', async () => {
|
|
630
|
+
const registry = createFakeRegistry()
|
|
631
|
+
const child = createFakeAgent({
|
|
632
|
+
id: 'child-5',
|
|
633
|
+
parentSession: 'main', origin: 'subagent',
|
|
634
|
+
current: { provider: 'explicit', model: 'route' },
|
|
635
|
+
})
|
|
636
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
637
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
638
|
+
const ctx = createFakeContext({ registry, agents })
|
|
639
|
+
index.apply(ctx.ctx, { ...base(), honorExplicit: true }, { verificationDelayMs: 0 })
|
|
640
|
+
await ctx.flush()
|
|
641
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
642
|
+
listener({ agent: child.agent })
|
|
643
|
+
assert.deepEqual(child.selects, [])
|
|
644
|
+
// 尊重显式路由时不应再挂一个会立刻打断它的守卫。
|
|
645
|
+
assert.equal(child.stepHandlers.length, 0)
|
|
646
|
+
await ctx.dispose()
|
|
647
|
+
})
|
|
648
|
+
|
|
649
|
+
test('模型守门 pin + select 缺失 + kill=false:不 cancel,但保留守卫并记录后续越界', async () => {
|
|
650
|
+
const registry = createFakeRegistry()
|
|
651
|
+
const child = createFakeAgent({
|
|
652
|
+
id: 'child-no-select',
|
|
653
|
+
parentSession: 'main', origin: 'subagent',
|
|
654
|
+
current: undefined,
|
|
655
|
+
select: null,
|
|
656
|
+
})
|
|
657
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
658
|
+
const webServer = createFakeWebServer()
|
|
659
|
+
const ctx = createFakeContext({
|
|
660
|
+
registry,
|
|
661
|
+
webServer,
|
|
662
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
663
|
+
})
|
|
664
|
+
index.apply(ctx.ctx, { ...base(), killOnViolation: false }, { verificationDelayMs: 0 })
|
|
665
|
+
await ctx.flush()
|
|
666
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
667
|
+
listener({ agent: child.agent })
|
|
668
|
+
assert.equal(child.cancelled.length, 0)
|
|
669
|
+
assert.equal(child.stepHandlers.length, 1, 'select 不可用时仍要装 pre-step 守卫')
|
|
670
|
+
|
|
671
|
+
const decision = await child.stepHandlers[0](
|
|
672
|
+
{ modelSelection: { provider: 'other', model: 'expensive' } },
|
|
673
|
+
async () => ({ kind: 'enter', messages: [] }),
|
|
674
|
+
)
|
|
675
|
+
assert.equal(decision.kind, 'enter')
|
|
676
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
677
|
+
assert.ok(state.body.violations.some((entry) => /越界/.test(entry.text)))
|
|
678
|
+
assert.ok(state.body.violations.some((entry) => /model\.select/.test(entry.text)))
|
|
679
|
+
|
|
680
|
+
// 主会话仍然完全不受影响。
|
|
681
|
+
listener({ agent: parent.agent })
|
|
682
|
+
assert.equal(parent.selects.length, 0)
|
|
683
|
+
assert.equal(parent.stepHandlers.length, 0)
|
|
684
|
+
await ctx.dispose()
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
test('模型守门 pin + select 抛错 + kill=false:不 cancel,但保留守卫并记录后续越界', async () => {
|
|
688
|
+
const registry = createFakeRegistry()
|
|
689
|
+
const child = createFakeAgent({
|
|
690
|
+
id: 'child-select-throws',
|
|
691
|
+
parentSession: 'main', origin: 'subagent',
|
|
692
|
+
current: undefined,
|
|
693
|
+
select: () => {
|
|
694
|
+
throw new Error('boom')
|
|
695
|
+
},
|
|
696
|
+
})
|
|
697
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
698
|
+
const webServer = createFakeWebServer()
|
|
699
|
+
const ctx = createFakeContext({
|
|
700
|
+
registry,
|
|
701
|
+
webServer,
|
|
702
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
703
|
+
})
|
|
704
|
+
index.apply(ctx.ctx, { ...base(), killOnViolation: false }, { verificationDelayMs: 0 })
|
|
705
|
+
await ctx.flush()
|
|
706
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
707
|
+
assert.equal(child.cancelled.length, 0)
|
|
708
|
+
assert.equal(child.stepHandlers.length, 1, 'select 抛错时仍要装 pre-step 守卫')
|
|
709
|
+
|
|
710
|
+
const decision = await child.stepHandlers[0](
|
|
711
|
+
{ modelSelection: { provider: 'other', model: 'expensive' } },
|
|
712
|
+
async () => ({ kind: 'enter', messages: [] }),
|
|
713
|
+
)
|
|
714
|
+
assert.equal(decision.kind, 'enter')
|
|
715
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
716
|
+
assert.ok(state.body.violations.some((entry) => /钉住子代理路由失败/.test(entry.text)))
|
|
717
|
+
assert.ok(state.body.violations.some((entry) => /越界/.test(entry.text)))
|
|
718
|
+
await ctx.dispose()
|
|
719
|
+
})
|
|
720
|
+
|
|
721
|
+
test('模型守门 pin + select 抛错 + kill=true:仍 cancel 并通知父会话', async () => {
|
|
722
|
+
const registry = createFakeRegistry()
|
|
723
|
+
const child = createFakeAgent({
|
|
724
|
+
id: 'child-select-throws-kill',
|
|
725
|
+
parentSession: 'main', origin: 'subagent',
|
|
726
|
+
current: undefined,
|
|
727
|
+
select: () => {
|
|
728
|
+
throw new Error('boom')
|
|
729
|
+
},
|
|
730
|
+
})
|
|
731
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
732
|
+
const ctx = createFakeContext({
|
|
733
|
+
registry,
|
|
734
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
735
|
+
})
|
|
736
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
737
|
+
await ctx.flush()
|
|
738
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
739
|
+
assert.equal(child.cancelled.length, 1)
|
|
740
|
+
assert.equal(parent.injected.length, 1)
|
|
741
|
+
assert.equal(child.stepHandlers.length, 1, 'cancel 前已装守卫,但子代理已被中止')
|
|
742
|
+
await ctx.dispose()
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
test('childReasoningEffort 非空时进入 agentOptions 与守门目标', async () => {
|
|
746
|
+
const settings = { ...base(), childReasoningEffort: 'high' }
|
|
747
|
+
const definition = P.buildPresetDefinition({
|
|
748
|
+
settings,
|
|
749
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
750
|
+
})
|
|
751
|
+
const develop = definition.plugins.find((row) => row.id === 'tool-subagent-develop')
|
|
752
|
+
assert.deepEqual(develop.config.agentOptions, {
|
|
753
|
+
provider: 'dsh-opencode-go',
|
|
754
|
+
model: 'deepseek-v4.1-flash',
|
|
755
|
+
reasoningEffort: 'high',
|
|
756
|
+
})
|
|
757
|
+
|
|
758
|
+
const registry = createFakeRegistry()
|
|
759
|
+
const child = createFakeAgent({ id: 'child-6', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
760
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
761
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
762
|
+
const ctx = createFakeContext({ registry, agents })
|
|
763
|
+
index.apply(ctx.ctx, settings, { verificationDelayMs: 0 })
|
|
764
|
+
await ctx.flush()
|
|
765
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
766
|
+
assert.deepEqual(child.selects, [
|
|
767
|
+
{ provider: 'dsh-opencode-go', model: 'deepseek-v4.1-flash', reasoningEffort: 'high' },
|
|
768
|
+
])
|
|
769
|
+
const next = async () => ({ kind: 'enter', messages: [] })
|
|
770
|
+
const wrongEffort = await child.stepHandlers[0](
|
|
771
|
+
{ modelSelection: { provider: 'dsh-opencode-go', model: 'deepseek-v4.1-flash' } },
|
|
772
|
+
next,
|
|
773
|
+
)
|
|
774
|
+
assert.deepEqual(wrongEffort, { kind: 'reject' })
|
|
775
|
+
await ctx.dispose()
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
test('audit=false 不写审计日志,但越界仍进入 UI 记录', async () => {
|
|
779
|
+
const registry = createFakeRegistry()
|
|
780
|
+
const child = createFakeAgent({ id: 'child-7', parentSession: 'main', origin: 'subagent' })
|
|
781
|
+
const parent = createFakeAgent({ id: 'main', agentPreset: 'dev-plan', current: { provider: 'p', model: 'm' } })
|
|
782
|
+
const agents = { get: (id) => (id === 'main' ? parent.agent : child.agent) }
|
|
783
|
+
const webServer = createFakeWebServer()
|
|
784
|
+
const ctx = createFakeContext({ registry, agents, webServer })
|
|
785
|
+
index.apply(ctx.ctx, { ...base(), audit: false }, { verificationDelayMs: 0 })
|
|
786
|
+
await ctx.flush()
|
|
787
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
788
|
+
await child.stepHandlers[0](
|
|
789
|
+
{ modelSelection: { provider: 'x', model: 'y' } },
|
|
790
|
+
async () => ({ kind: 'enter', messages: [] }),
|
|
791
|
+
)
|
|
792
|
+
assert.ok(!ctx.loggerCalls.info.some((line) => line.includes('audit')))
|
|
793
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
794
|
+
assert.equal(state.body.violations.length, 1)
|
|
795
|
+
await ctx.dispose()
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
test('probePresets 返回真实目录:id/name/description/broken,并区分超时', async () => {
|
|
799
|
+
const registry = createFakeRegistry({
|
|
800
|
+
rows: [
|
|
801
|
+
{ id: 'standard', name: 'Standard' },
|
|
802
|
+
{ id: 'deep-ptc', name: '深度 PTC', description: 'PTC', broken: 'load failed' },
|
|
803
|
+
{ nonsense: true },
|
|
804
|
+
],
|
|
805
|
+
})
|
|
806
|
+
const ctx = createFakeContext({
|
|
807
|
+
registry,
|
|
808
|
+
entries: [{ id: 'ptc-row', options: { name: 'dsh-deep-ptc-mode' }, fiber: { state: 1 } }],
|
|
809
|
+
})
|
|
810
|
+
const probe = await index.probePresets(ctx.ctx, registry)
|
|
811
|
+
assert.equal(probe.checked, true)
|
|
812
|
+
assert.equal(probe.timedOut, false)
|
|
813
|
+
assert.deepEqual(probe.rows.map((row) => row.id), ['standard', 'deep-ptc'])
|
|
814
|
+
assert.equal(probe.rows[1].name, '深度 PTC')
|
|
815
|
+
assert.equal(probe.rows[1].description, 'PTC')
|
|
816
|
+
assert.equal(probe.rows[1].broken, 'load failed')
|
|
817
|
+
|
|
818
|
+
const hanging = createFakeRegistry()
|
|
819
|
+
hanging.list = () => new Promise(() => {})
|
|
820
|
+
const timeoutCtx = createFakeContext({ registry: hanging })
|
|
821
|
+
const timedOut = await index.probePresets(timeoutCtx.ctx, hanging)
|
|
822
|
+
assert.equal(timedOut.checked, false)
|
|
823
|
+
assert.equal(timedOut.timedOut, true)
|
|
824
|
+
assert.deepEqual(timedOut.rows, [])
|
|
825
|
+
})
|
|
826
|
+
|
|
827
|
+
test('P0-1 风险分级:快速/标准/高风险 + 四维判定 + 快速路径不取消必做项', () => {
|
|
828
|
+
const definition = P.buildPresetDefinition({
|
|
829
|
+
settings: base(),
|
|
830
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
831
|
+
})
|
|
832
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
833
|
+
for (const marker of ['快速路径', '标准路径', '高风险路径', '歧义', '影响面', '可逆性', '可验证性']) {
|
|
834
|
+
assert.ok(persona.includes(marker), `缺 P0-1 标记:${marker}`)
|
|
835
|
+
}
|
|
836
|
+
assert.match(persona, /快速路径不取消用户开工批准、developer 自验和主窗审查/)
|
|
837
|
+
assert.match(persona, /只选一条最短安全路径,不固定跑瀑布/)
|
|
838
|
+
// 证据不足只能升级风险/补证据,不能反向降级。
|
|
839
|
+
assert.match(persona, /提高风险等级|升级到能补足证据/)
|
|
840
|
+
assert.match(persona, /绝不因验证困难降低路径等级/)
|
|
841
|
+
assert.doesNotMatch(persona, /降低路径等级并补验收/)
|
|
842
|
+
})
|
|
843
|
+
|
|
844
|
+
test('P0-2 一次性开工契约:字段齐全且普通实现不反复批准', () => {
|
|
845
|
+
const definition = P.buildPresetDefinition({
|
|
846
|
+
settings: base(),
|
|
847
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
848
|
+
})
|
|
849
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
850
|
+
for (const marker of [
|
|
851
|
+
'一次性开工契约',
|
|
852
|
+
'范围:',
|
|
853
|
+
'非目标:',
|
|
854
|
+
'允许路径:',
|
|
855
|
+
'接口/依赖:',
|
|
856
|
+
'验收条件:',
|
|
857
|
+
'检查命令:',
|
|
858
|
+
'风险/回退:',
|
|
859
|
+
]) {
|
|
860
|
+
assert.ok(persona.includes(marker), `缺 P0-2 标记:${marker}`)
|
|
861
|
+
}
|
|
862
|
+
assert.match(persona, /普通文件编辑和实现细节不反复等待批准/)
|
|
863
|
+
assert.match(persona, /只有范围扩大、风险变化或宿主权限要求/)
|
|
864
|
+
})
|
|
865
|
+
|
|
866
|
+
test('P0-3 验收前置:最小切片→语法/静态契约→针对性测试→必要运行/GUI,且静态不冒充真实验证', () => {
|
|
867
|
+
const definition = P.buildPresetDefinition({
|
|
868
|
+
settings: base(),
|
|
869
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
870
|
+
})
|
|
871
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
872
|
+
const ordered = ['最小切片', '语法/静态契约', '针对性测试', '必要运行/GUI 验收']
|
|
873
|
+
let cursor = -1
|
|
874
|
+
for (const marker of ordered) {
|
|
875
|
+
const index = persona.indexOf(marker)
|
|
876
|
+
assert.ok(index > cursor, `P0-3 顺序错误或缺标记:${marker}`)
|
|
877
|
+
cursor = index
|
|
878
|
+
}
|
|
879
|
+
assert.match(persona, /静态检查不等于真实验证/)
|
|
880
|
+
assert.match(persona, /verified \/ partial \/ failed \/ 未验证/)
|
|
881
|
+
})
|
|
882
|
+
|
|
883
|
+
test('P0-4 非阻塞协作:不轮询/不忙等/不重复施工/不重复读文件,developer 打断边界明确', () => {
|
|
884
|
+
const definition = P.buildPresetDefinition({
|
|
885
|
+
settings: base(),
|
|
886
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
887
|
+
})
|
|
888
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
889
|
+
for (const marker of ['非阻塞协作', '不轮询', '不忙等', '不重复施工', '不重复读取']) {
|
|
890
|
+
assert.ok(persona.includes(marker), `缺 P0-4 标记:${marker}`)
|
|
891
|
+
}
|
|
892
|
+
assert.match(persona, /developer 只在阻塞、范围冲突或关键契约需要决策时打断主窗/)
|
|
893
|
+
assert.match(persona, /验收准备、审查基线、资料研究、独立任务/)
|
|
894
|
+
})
|
|
895
|
+
|
|
896
|
+
test('P0-5 证据化审查与严重度返工:实际 diff、阻塞/非阻塞、最终责任不外包', () => {
|
|
897
|
+
const definition = P.buildPresetDefinition({
|
|
898
|
+
settings: base(),
|
|
899
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
900
|
+
})
|
|
901
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
902
|
+
for (const marker of ['实际 diff 和关键证据', '阻塞问题', '非阻塞建议', '主窗最终审查责任不外包']) {
|
|
903
|
+
assert.ok(persona.includes(marker), `缺 P0-5 标记:${marker}`)
|
|
904
|
+
}
|
|
905
|
+
assert.match(persona, /send_message 续派同一 developer/)
|
|
906
|
+
assert.match(persona, /不为一两条风格建议无限打磨/)
|
|
907
|
+
assert.match(persona, /recon:只在缺少事实/)
|
|
908
|
+
assert.match(persona, /review:只在高风险/)
|
|
909
|
+
assert.match(persona, /scribe:只在文档属于验收范围/)
|
|
910
|
+
// 实际变更证据闭环:摘要/文件清单不等于 diff 审查。
|
|
911
|
+
for (const marker of ['实际变更证据', '不能只给文件清单', '不得声称审过实际 diff', '补证据']) {
|
|
912
|
+
assert.ok(persona.includes(marker), `缺实际变更证据标记:${marker}`)
|
|
913
|
+
}
|
|
914
|
+
assert.match(persona, /git diff.*等价|等价.*git diff/s)
|
|
915
|
+
assert.match(persona, /修改前后内容/)
|
|
916
|
+
assert.doesNotMatch(persona, /只有改动摘要也算证据|只给文件清单(?:也)?可以/)
|
|
917
|
+
})
|
|
918
|
+
|
|
919
|
+
test('client 回退横幅涵盖不可用原因(中英文)', () => {
|
|
920
|
+
const source = readFileSync(join(ROOT, 'client.js'), 'utf8')
|
|
921
|
+
for (const marker of ['已回退 standard', '未安装', '未启用', '已被移除', '加载失败']) {
|
|
922
|
+
assert.ok(source.includes(marker), `client 回退横幅缺标记:${marker}`)
|
|
923
|
+
}
|
|
924
|
+
for (const marker of ['Fell back to standard', 'not installed', 'failed to load']) {
|
|
925
|
+
assert.ok(source.includes(marker), `client 英文回退横幅缺标记:${marker}`)
|
|
926
|
+
}
|
|
927
|
+
// 目录超时同样要有可理解状态,而不是伪装成正常。
|
|
928
|
+
for (const marker of ['施工方式列表读取超时', 'setup list timed out']) {
|
|
929
|
+
assert.ok(source.includes(marker), `client 缺少目录超时状态:${marker}`)
|
|
930
|
+
}
|
|
931
|
+
})
|
|
932
|
+
|
|
933
|
+
test('派工事实:实际 develop/send_message 工具调用才是派工,文本不算', () => {
|
|
934
|
+
const definition = P.buildPresetDefinition({
|
|
935
|
+
settings: base(),
|
|
936
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
937
|
+
})
|
|
938
|
+
const personaRow = definition.plugins.find((row) => row.id === 'persona')
|
|
939
|
+
const persona = `${personaRow.config.prefix}${personaRow.config.suffix}`
|
|
940
|
+
for (const marker of [
|
|
941
|
+
'文本不是派工',
|
|
942
|
+
'必须实际调用 develop',
|
|
943
|
+
'只有工具接受后才可说“已派出 developer”',
|
|
944
|
+
'未派工',
|
|
945
|
+
'任务书是 develop 的 prompt 参数',
|
|
946
|
+
'不得停在计划、前言或任务书文本',
|
|
947
|
+
'实际调用 send_message',
|
|
948
|
+
]) {
|
|
949
|
+
assert.ok(persona.includes(marker), `缺派工事实标记:${marker}`)
|
|
950
|
+
}
|
|
951
|
+
assert.doesNotMatch(persona, /文本也能算派工|没有调用也可以说已派出|文本任务书即视为已派工/)
|
|
952
|
+
})
|
|
953
|
+
|
|
954
|
+
test('插件显示名带模式,预设名保持开发规划与交付', () => {
|
|
955
|
+
const zh = JSON.parse(readFileSync(join(ROOT, 'locale/zh.json'), 'utf8'))
|
|
956
|
+
const en = JSON.parse(readFileSync(join(ROOT, 'locale/en.json'), 'utf8'))
|
|
957
|
+
assert.equal(zh.meta.title, '开发规划与交付模式')
|
|
958
|
+
assert.equal(en.meta.title, 'Development planning & delivery Mode')
|
|
959
|
+
assert.ok(zh.meta.title.endsWith('模式'))
|
|
960
|
+
assert.ok(en.meta.title.endsWith('Mode'))
|
|
961
|
+
assert.equal(P.PRESET_NAME, '开发规划与交付')
|
|
962
|
+
|
|
963
|
+
const client = readFileSync(join(ROOT, 'client.js'), 'utf8')
|
|
964
|
+
assert.ok(client.includes('开发规划与交付 · 施工设置'))
|
|
965
|
+
assert.ok(!client.includes('开发规划与交付模式 · 施工设置'), '设置页标题应继续使用 preset 名')
|
|
966
|
+
|
|
967
|
+
const readme = readFileSync(join(ROOT, 'README.md'), 'utf8')
|
|
968
|
+
assert.ok(readme.includes('开发规划与交付模式'))
|
|
969
|
+
assert.ok(readme.includes('preset 名称仍是「开发规划与交付」'))
|
|
970
|
+
assert.ok(readme.includes('显示名已定'))
|
|
971
|
+
assert.ok(!readme.includes('显示名未定'))
|
|
972
|
+
assert.ok(!readme.includes('界面名称仍是「开发规划」'))
|
|
973
|
+
})
|
|
974
|
+
|
|
975
|
+
test('guard 只认子代理 header:fork 主对话(parentSession + depth 0)不算', () => {
|
|
976
|
+
assert.equal(guard.isSubagentHeader(undefined), false)
|
|
977
|
+
assert.equal(guard.isSubagentHeader({}), false)
|
|
978
|
+
assert.equal(guard.isSubagentHeader({ origin: 'user' }), false)
|
|
979
|
+
// 宿主真实 fork 主对话形状:有 parentSession、isSeeded、delegationDepth:0、无 origin。
|
|
980
|
+
assert.equal(guard.isSubagentHeader({ parentSession: 'main' }), false)
|
|
981
|
+
assert.equal(guard.isSubagentHeader({ parentSession: 'main', isSeeded: true, delegationDepth: 0 }), false)
|
|
982
|
+
assert.equal(guard.isSubagentHeader({ origin: 'subagent' }), true)
|
|
983
|
+
assert.equal(guard.isSubagentHeader({ parentSession: 'main', delegationDepth: 1 }), true)
|
|
984
|
+
assert.equal(guard.isSubagentHeader({ delegationDepth: 0, origin: 'subagent' }), true)
|
|
985
|
+
assert.equal(guard.isSubagentHeader({ delegationDepth: '1' }), false)
|
|
986
|
+
})
|
|
987
|
+
|
|
988
|
+
test('fork 形主对话在 guardAllSubagents true/false 下都不 select、不挂 pre-step', async () => {
|
|
989
|
+
for (const global of [false, true]) {
|
|
990
|
+
const registry = createFakeRegistry()
|
|
991
|
+
const fork = createFakeAgent({
|
|
992
|
+
id: 'fork-main',
|
|
993
|
+
parentSession: 'main',
|
|
994
|
+
isSeeded: true,
|
|
995
|
+
delegationDepth: 0,
|
|
996
|
+
current: undefined,
|
|
997
|
+
})
|
|
998
|
+
const parent = createFakeAgent({
|
|
999
|
+
id: 'main',
|
|
1000
|
+
agentPreset: 'dev-plan',
|
|
1001
|
+
current: { provider: 'p', model: 'm' },
|
|
1002
|
+
})
|
|
1003
|
+
const ctx = createFakeContext({
|
|
1004
|
+
registry,
|
|
1005
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : fork.agent) },
|
|
1006
|
+
})
|
|
1007
|
+
index.apply(ctx.ctx, { ...base(), guardAllSubagents: global }, { verificationDelayMs: 0 })
|
|
1008
|
+
await ctx.flush()
|
|
1009
|
+
const listener = ctx.listeners.get('agent/created')[0]
|
|
1010
|
+
listener({ agent: fork.agent })
|
|
1011
|
+
assert.deepEqual(fork.selects, [], 'fork 主对话不得被 select(global=' + global + ')')
|
|
1012
|
+
assert.equal(fork.stepHandlers.length, 0, 'fork 主对话不得挂 pre-step(global=' + global + ')')
|
|
1013
|
+
listener({ agent: parent.agent })
|
|
1014
|
+
assert.equal(parent.stepHandlers.length, 0, '主会话永不守门')
|
|
1015
|
+
await ctx.dispose()
|
|
1016
|
+
}
|
|
1017
|
+
})
|
|
1018
|
+
|
|
1019
|
+
test('delegationDepth>0 的真正子代理仍按 dev-plan 范围守门', async () => {
|
|
1020
|
+
const registry = createFakeRegistry()
|
|
1021
|
+
const child = createFakeAgent({
|
|
1022
|
+
id: 'child-depth',
|
|
1023
|
+
parentSession: 'main',
|
|
1024
|
+
delegationDepth: 1,
|
|
1025
|
+
current: undefined,
|
|
1026
|
+
})
|
|
1027
|
+
const parent = createFakeAgent({
|
|
1028
|
+
id: 'main',
|
|
1029
|
+
agentPreset: 'dev-plan',
|
|
1030
|
+
current: { provider: 'p', model: 'm' },
|
|
1031
|
+
})
|
|
1032
|
+
const ctx = createFakeContext({
|
|
1033
|
+
registry,
|
|
1034
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
1035
|
+
})
|
|
1036
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
1037
|
+
await ctx.flush()
|
|
1038
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
1039
|
+
assert.equal(child.selects.length, 1)
|
|
1040
|
+
assert.equal(child.stepHandlers.length, 1)
|
|
1041
|
+
await ctx.dispose()
|
|
1042
|
+
})
|
|
1043
|
+
|
|
1044
|
+
test('任意有效 develop preset:不再限于 standard/deep-ptc', () => {
|
|
1045
|
+
const mode = P.resolveDevelopMode({
|
|
1046
|
+
requestedMode: 'team-builder',
|
|
1047
|
+
presets: [{ id: 'team-builder', name: '团队施工' }],
|
|
1048
|
+
catalogChecked: true,
|
|
1049
|
+
})
|
|
1050
|
+
assert.equal(mode.effective, 'team-builder')
|
|
1051
|
+
assert.equal(mode.fallback, false)
|
|
1052
|
+
const definition = P.buildPresetDefinition({ settings: base(), mode })
|
|
1053
|
+
const develop = definition.plugins.find((row) => row.id === 'tool-subagent-develop')
|
|
1054
|
+
assert.equal(develop.config.agentPreset, 'team-builder')
|
|
1055
|
+
assert.match(definition.description, /团队施工/)
|
|
1056
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
1057
|
+
assert.match(persona, /当前施工子代理模式:团队施工(team-builder)/)
|
|
1058
|
+
})
|
|
1059
|
+
|
|
1060
|
+
test('自引用与缺失/超时:保留配置原值,运行期回退 standard', async () => {
|
|
1061
|
+
const selfMode = P.resolveDevelopMode({
|
|
1062
|
+
requestedMode: 'dev-plan',
|
|
1063
|
+
presets: [{ id: 'dev-plan', name: '开发规划与交付' }],
|
|
1064
|
+
catalogChecked: true,
|
|
1065
|
+
})
|
|
1066
|
+
assert.equal(selfMode.fallback, true)
|
|
1067
|
+
assert.match(selfMode.reason, /递归派工/)
|
|
1068
|
+
|
|
1069
|
+
const missing = P.resolveDevelopMode({
|
|
1070
|
+
requestedMode: 'removed-preset',
|
|
1071
|
+
presets: [],
|
|
1072
|
+
catalogChecked: true,
|
|
1073
|
+
})
|
|
1074
|
+
assert.equal(missing.requested, 'removed-preset')
|
|
1075
|
+
assert.equal(missing.effective, 'standard')
|
|
1076
|
+
assert.equal(missing.fallback, true)
|
|
1077
|
+
|
|
1078
|
+
const registry = createFakeRegistry({ rows: [] })
|
|
1079
|
+
const webServer = createFakeWebServer()
|
|
1080
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
1081
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'removed-preset' }, { verificationDelayMs: 0 })
|
|
1082
|
+
await ctx.flush()
|
|
1083
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
1084
|
+
// 配置原值不被静默改写;只有运行期 effective 回退。
|
|
1085
|
+
assert.equal(state.body.config.developMode, 'removed-preset')
|
|
1086
|
+
assert.equal(state.body.requestedMode, 'removed-preset')
|
|
1087
|
+
assert.equal(state.body.effectiveMode, 'standard')
|
|
1088
|
+
assert.equal(state.body.fallback.active, true)
|
|
1089
|
+
assert.equal(
|
|
1090
|
+
registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
|
|
1091
|
+
'standard',
|
|
1092
|
+
)
|
|
1093
|
+
await ctx.dispose()
|
|
1094
|
+
})
|
|
1095
|
+
|
|
1096
|
+
test('预设目录超时:显式回退并保留 timedOut,供 UI 提示', async () => {
|
|
1097
|
+
const registry = createFakeRegistry()
|
|
1098
|
+
registry.list = () => new Promise(() => {})
|
|
1099
|
+
const webServer = createFakeWebServer()
|
|
1100
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
1101
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
|
|
1102
|
+
await ctx.flush()
|
|
1103
|
+
// probe 会等满 MAX_PROBE_MS,再发布回退结果。
|
|
1104
|
+
await sleep(1400)
|
|
1105
|
+
await ctx.flush()
|
|
1106
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
1107
|
+
assert.equal(state.body.effectiveMode, 'standard')
|
|
1108
|
+
assert.equal(state.body.fallback.active, true)
|
|
1109
|
+
assert.equal(state.body.presets.checked, false)
|
|
1110
|
+
assert.equal(state.body.presets.timedOut, true)
|
|
1111
|
+
assert.match(state.body.fallback.reason, /尚未就绪|读取超时/)
|
|
1112
|
+
await ctx.dispose()
|
|
1113
|
+
})
|
|
1114
|
+
|
|
1115
|
+
test('模型目录:枚举 provider/model,单个 provider 失败只局部降级', async () => {
|
|
1116
|
+
const registry = createFakeRegistry()
|
|
1117
|
+
const webServer = createFakeWebServer()
|
|
1118
|
+
const llm = {
|
|
1119
|
+
listProviders: () => [
|
|
1120
|
+
{ id: 'alpha', name: 'Alpha 服务商' },
|
|
1121
|
+
{ id: 'broken', name: 'Broken 服务商' },
|
|
1122
|
+
],
|
|
1123
|
+
listModels: async (id) => {
|
|
1124
|
+
if (id === 'broken') throw new Error('missing credentials')
|
|
1125
|
+
return [
|
|
1126
|
+
{ id: 'alpha-1', name: 'Alpha 一号' },
|
|
1127
|
+
{ id: 'alpha-2' },
|
|
1128
|
+
]
|
|
1129
|
+
},
|
|
1130
|
+
}
|
|
1131
|
+
const ctx = createFakeContext({ registry, webServer, llm })
|
|
1132
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
1133
|
+
await ctx.flush()
|
|
1134
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
|
|
1135
|
+
// 第一次 /state 只返回快照并启动后台刷新;第二次读到刷新结果。
|
|
1136
|
+
const first = await callRoute(handler, 'GET')
|
|
1137
|
+
assert.equal(first.body.modelCatalog.checked, false)
|
|
1138
|
+
await sleep(0)
|
|
1139
|
+
await ctx.flush()
|
|
1140
|
+
const state = await callRoute(handler, 'GET')
|
|
1141
|
+
assert.equal(state.body.modelCatalog.checked, true)
|
|
1142
|
+
assert.deepEqual(
|
|
1143
|
+
state.body.modelCatalog.providers.map((item) => [item.provider, item.models.map((m) => m.model)]),
|
|
1144
|
+
[
|
|
1145
|
+
['alpha', ['alpha-1', 'alpha-2']],
|
|
1146
|
+
['broken', []],
|
|
1147
|
+
],
|
|
1148
|
+
)
|
|
1149
|
+
assert.deepEqual(state.body.modelCatalog.failures.map((item) => item.provider), ['broken'])
|
|
1150
|
+
assert.match(state.body.modelCatalog.failures[0].message, /missing credentials/)
|
|
1151
|
+
assert.equal(state.body.modelCatalog.providers[0].models[0].name, 'Alpha 一号')
|
|
1152
|
+
await ctx.dispose()
|
|
1153
|
+
})
|
|
1154
|
+
|
|
1155
|
+
test('模型目录失败与旧路由:目录不可用时不改旧值,也不伪装成目录正常', async () => {
|
|
1156
|
+
const registry = createFakeRegistry()
|
|
1157
|
+
const webServer = createFakeWebServer()
|
|
1158
|
+
const configEditor = createFakeConfigEditor()
|
|
1159
|
+
const llm = {
|
|
1160
|
+
listProviders: () => {
|
|
1161
|
+
throw new Error('catalog exploded')
|
|
1162
|
+
},
|
|
1163
|
+
listModels: async () => [],
|
|
1164
|
+
}
|
|
1165
|
+
const ctx = createFakeContext({ registry, webServer, configEditor, llm })
|
|
1166
|
+
index.apply(
|
|
1167
|
+
ctx.ctx,
|
|
1168
|
+
{ ...base(), childProvider: 'legacy-provider', childModel: 'legacy-model' },
|
|
1169
|
+
{ verificationDelayMs: 0 },
|
|
1170
|
+
)
|
|
1171
|
+
await ctx.flush()
|
|
1172
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
|
|
1173
|
+
await callRoute(handler, 'GET')
|
|
1174
|
+
await sleep(0)
|
|
1175
|
+
await ctx.flush()
|
|
1176
|
+
const state = await callRoute(handler, 'GET')
|
|
1177
|
+
assert.equal(state.body.modelCatalog.checked, false)
|
|
1178
|
+
assert.match(state.body.modelCatalog.error, /catalog exploded/)
|
|
1179
|
+
assert.equal(state.body.config.childProvider, 'legacy-provider')
|
|
1180
|
+
assert.equal(state.body.config.childModel, 'legacy-model')
|
|
1181
|
+
assert.equal(state.body.route.provider, 'legacy-provider')
|
|
1182
|
+
assert.equal(state.body.route.model, 'legacy-model')
|
|
1183
|
+
|
|
1184
|
+
// 目录失败不会把旧值改成默认值:原样提交视为 unchanged,不触发写回。
|
|
1185
|
+
const unchanged = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/config'), 'POST', {
|
|
1186
|
+
childProvider: 'legacy-provider',
|
|
1187
|
+
childModel: 'legacy-model',
|
|
1188
|
+
childReasoningEffort: '',
|
|
1189
|
+
})
|
|
1190
|
+
assert.equal(unchanged.code, 200)
|
|
1191
|
+
assert.equal(unchanged.body.unchanged, true)
|
|
1192
|
+
assert.equal(configEditor.edits.length, 0)
|
|
1193
|
+
|
|
1194
|
+
// 用户明确改成另一组值时仍可保存,且不会因目录失败被拒绝或改写。
|
|
1195
|
+
const saved = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/config'), 'POST', {
|
|
1196
|
+
childProvider: 'other-provider',
|
|
1197
|
+
childModel: 'other-model',
|
|
1198
|
+
childReasoningEffort: '',
|
|
1199
|
+
})
|
|
1200
|
+
assert.equal(saved.code, 200)
|
|
1201
|
+
assert.equal(configEditor.edits.length, 1)
|
|
1202
|
+
assert.equal(configEditor.edits[0].next.childProvider, 'other-provider')
|
|
1203
|
+
await ctx.dispose()
|
|
1204
|
+
})
|
|
1205
|
+
|
|
1206
|
+
test('守门范围矩阵:默认只守 dev-plan 父会话,global 开关恢复全局,主会话永不守', async () => {
|
|
1207
|
+
const scenarios = [
|
|
1208
|
+
{ name: 'dev-plan 父会话', parentPreset: 'dev-plan', global: false, guarded: true },
|
|
1209
|
+
{ name: '非 dev-plan 父会话', parentPreset: 'standard', global: false, guarded: false },
|
|
1210
|
+
{ name: '父会话 preset 未知', parentPreset: undefined, global: false, guarded: false },
|
|
1211
|
+
{ name: '非 dev-plan + global', parentPreset: 'standard', global: true, guarded: true },
|
|
1212
|
+
{ name: 'dev-plan + global', parentPreset: 'dev-plan', global: true, guarded: true },
|
|
1213
|
+
]
|
|
1214
|
+
for (const scenario of scenarios) {
|
|
1215
|
+
const registry = createFakeRegistry()
|
|
1216
|
+
const child = createFakeAgent({ id: 'child', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
1217
|
+
const parent = createFakeAgent({
|
|
1218
|
+
id: 'main',
|
|
1219
|
+
agentPreset: scenario.parentPreset,
|
|
1220
|
+
current: { provider: 'p', model: 'm' },
|
|
1221
|
+
})
|
|
1222
|
+
const ctx = createFakeContext({
|
|
1223
|
+
registry,
|
|
1224
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
1225
|
+
})
|
|
1226
|
+
index.apply(ctx.ctx, { ...base(), guardAllSubagents: scenario.global }, { verificationDelayMs: 0 })
|
|
1227
|
+
await ctx.flush()
|
|
1228
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
1229
|
+
assert.equal(
|
|
1230
|
+
child.stepHandlers.length,
|
|
1231
|
+
scenario.guarded ? 1 : 0,
|
|
1232
|
+
`${scenario.name} 的守门范围错误`,
|
|
1233
|
+
)
|
|
1234
|
+
await ctx.dispose()
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// registry.presetForSession 优先于 header,且主会话即使 global 也不守。
|
|
1238
|
+
const registry = createFakeRegistry({ presetForSession: () => 'dev-plan' })
|
|
1239
|
+
const child = createFakeAgent({
|
|
1240
|
+
id: 'child-priority',
|
|
1241
|
+
parentSession: 'main', origin: 'subagent',
|
|
1242
|
+
current: undefined,
|
|
1243
|
+
})
|
|
1244
|
+
const parent = createFakeAgent({
|
|
1245
|
+
id: 'main',
|
|
1246
|
+
agentPreset: 'standard',
|
|
1247
|
+
current: { provider: 'p', model: 'm' },
|
|
1248
|
+
})
|
|
1249
|
+
const ctx = createFakeContext({
|
|
1250
|
+
registry,
|
|
1251
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
1252
|
+
})
|
|
1253
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
1254
|
+
await ctx.flush()
|
|
1255
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
1256
|
+
assert.equal(child.stepHandlers.length, 1, 'presetForSession 应优先于 header')
|
|
1257
|
+
assert.equal(parent.stepHandlers.length, 0, '主会话永不守门')
|
|
1258
|
+
await ctx.dispose()
|
|
1259
|
+
})
|
|
1260
|
+
|
|
1261
|
+
test('施工目录/权限规则写入主代理 persona', () => {
|
|
1262
|
+
const definition = P.buildPresetDefinition({
|
|
1263
|
+
settings: base(),
|
|
1264
|
+
mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
|
|
1265
|
+
})
|
|
1266
|
+
const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
|
|
1267
|
+
for (const marker of [
|
|
1268
|
+
'施工目录与权限',
|
|
1269
|
+
'工具创建参数',
|
|
1270
|
+
'cwd',
|
|
1271
|
+
'可写工作区',
|
|
1272
|
+
'不得先以其他目录 spawn',
|
|
1273
|
+
'working_directory / cd',
|
|
1274
|
+
'不假设已有子代理权限会随之扩大',
|
|
1275
|
+
'沙箱模式',
|
|
1276
|
+
'真实错误原文',
|
|
1277
|
+
]) {
|
|
1278
|
+
assert.ok(persona.includes(marker), `缺权限防护标记:${marker}`)
|
|
1279
|
+
}
|
|
1280
|
+
assert.match(persona, /目标目录不在可写范围/)
|
|
1281
|
+
assert.match(persona, /停止派工/)
|
|
1282
|
+
})
|
|
1283
|
+
|
|
1284
|
+
test('设置页契约:动态预设/模型下拉、原生控件、label 关联与守门范围开关', () => {
|
|
1285
|
+
const source = readFileSync(join(ROOT, 'client.js'), 'utf8')
|
|
1286
|
+
for (const marker of [
|
|
1287
|
+
'state.presets',
|
|
1288
|
+
'presetRows',
|
|
1289
|
+
'state.modelCatalog',
|
|
1290
|
+
'providers',
|
|
1291
|
+
'guardAllSubagents',
|
|
1292
|
+
'htmlFor',
|
|
1293
|
+
'aria-describedby',
|
|
1294
|
+
'fieldset',
|
|
1295
|
+
'legend',
|
|
1296
|
+
"type: 'button'",
|
|
1297
|
+
'同时管理其他插件的子代理',
|
|
1298
|
+
'服务商',
|
|
1299
|
+
'模型',
|
|
1300
|
+
]) {
|
|
1301
|
+
assert.ok(source.includes(marker), `设置页缺契约标记:${marker}`)
|
|
1302
|
+
}
|
|
1303
|
+
// 不再硬编码 deep-ptc 选项,也不再使用自由文本 provider/model 输入。
|
|
1304
|
+
assert.ok(!source.includes("value: 'deep-ptc'"), '不应硬编码 deep-ptc 选项')
|
|
1305
|
+
assert.ok(!/childProvider:\s*'\s*'/.test(source), '不应把 provider 当自由文本初始化')
|
|
1306
|
+
assert.ok(!source.includes('configEditor'), '普通文案不应出现 configEditor')
|
|
1307
|
+
assert.ok(!source.includes('reasoningEffort(可空)'), '不应把 reasoningEffort 当主标签')
|
|
1308
|
+
assert.ok(!/onChange:\s*save/.test(source), '选择变化不得自动保存')
|
|
1309
|
+
})
|
|
1310
|
+
|
|
1311
|
+
test('state 返回真实预设目录:名称、broken 与自定义预设生效', async () => {
|
|
1312
|
+
const registry = createFakeRegistry({
|
|
1313
|
+
rows: [
|
|
1314
|
+
{ id: 'dev-plan', name: '开发规划与交付' },
|
|
1315
|
+
{ id: 'team-builder', name: '团队施工', description: '团队预设' },
|
|
1316
|
+
{ id: 'broken-preset', name: '损坏预设', broken: 'import failed' },
|
|
1317
|
+
],
|
|
1318
|
+
})
|
|
1319
|
+
const webServer = createFakeWebServer()
|
|
1320
|
+
const ctx = createFakeContext({ registry, webServer })
|
|
1321
|
+
index.apply(ctx.ctx, { ...base(), developMode: 'team-builder' }, { verificationDelayMs: 0 })
|
|
1322
|
+
await ctx.flush()
|
|
1323
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
1324
|
+
assert.equal(state.body.effectiveMode, 'team-builder')
|
|
1325
|
+
assert.equal(state.body.modeName, '团队施工')
|
|
1326
|
+
assert.deepEqual(state.body.presets.rows.map((row) => row.id), ['dev-plan', 'team-builder', 'broken-preset'])
|
|
1327
|
+
assert.equal(state.body.presets.rows[1].name, '团队施工')
|
|
1328
|
+
assert.equal(state.body.presets.rows[2].broken, 'import failed')
|
|
1329
|
+
assert.equal(
|
|
1330
|
+
registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
|
|
1331
|
+
'team-builder',
|
|
1332
|
+
)
|
|
1333
|
+
await ctx.dispose()
|
|
1334
|
+
|
|
1335
|
+
const brokenRegistry = createFakeRegistry({
|
|
1336
|
+
rows: [{ id: 'broken-preset', name: '损坏预设', broken: 'import failed' }],
|
|
1337
|
+
})
|
|
1338
|
+
const brokenWeb = createFakeWebServer()
|
|
1339
|
+
const brokenCtx = createFakeContext({ registry: brokenRegistry, webServer: brokenWeb })
|
|
1340
|
+
index.apply(brokenCtx.ctx, { ...base(), developMode: 'broken-preset' }, { verificationDelayMs: 0 })
|
|
1341
|
+
await brokenCtx.flush()
|
|
1342
|
+
const brokenState = await callRoute(brokenWeb.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
1343
|
+
assert.equal(brokenState.body.effectiveMode, 'standard')
|
|
1344
|
+
assert.equal(brokenState.body.fallback.active, true)
|
|
1345
|
+
assert.match(brokenState.body.fallback.reason, /加载失败/)
|
|
1346
|
+
assert.equal(brokenState.body.config.developMode, 'broken-preset')
|
|
1347
|
+
await brokenCtx.dispose()
|
|
1348
|
+
})
|
|
1349
|
+
|
|
1350
|
+
test('presetForSession 返回 null 时回退 header.agentPreset 判断守门范围', async () => {
|
|
1351
|
+
const registry = createFakeRegistry({ presetForSession: () => null })
|
|
1352
|
+
const child = createFakeAgent({ id: 'child-fallback', parentSession: 'main', origin: 'subagent', current: undefined })
|
|
1353
|
+
const parent = createFakeAgent({
|
|
1354
|
+
id: 'main',
|
|
1355
|
+
agentPreset: 'dev-plan',
|
|
1356
|
+
current: { provider: 'p', model: 'm' },
|
|
1357
|
+
})
|
|
1358
|
+
const ctx = createFakeContext({
|
|
1359
|
+
registry,
|
|
1360
|
+
agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
|
|
1361
|
+
})
|
|
1362
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
1363
|
+
await ctx.flush()
|
|
1364
|
+
ctx.listeners.get('agent/created')[0]({ agent: child.agent })
|
|
1365
|
+
assert.equal(child.stepHandlers.length, 1, 'header.agentPreset=dev-plan 时应守门')
|
|
1366
|
+
await ctx.dispose()
|
|
1367
|
+
})
|
|
1368
|
+
|
|
1369
|
+
test('模型目录刷新不阻塞 /state:慢 provider 下状态立即返回快照', async () => {
|
|
1370
|
+
const registry = createFakeRegistry()
|
|
1371
|
+
const webServer = createFakeWebServer()
|
|
1372
|
+
const llm = {
|
|
1373
|
+
listProviders: () => [{ id: 'slow', name: 'Slow' }],
|
|
1374
|
+
listModels: () => new Promise(() => {}),
|
|
1375
|
+
}
|
|
1376
|
+
const ctx = createFakeContext({ registry, webServer, llm })
|
|
1377
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
|
|
1378
|
+
await ctx.flush()
|
|
1379
|
+
const started = Date.now()
|
|
1380
|
+
const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
|
|
1381
|
+
const elapsed = Date.now() - started
|
|
1382
|
+
assert.ok(elapsed < 500, `/state 不应等待 listModels,实际 ${elapsed}ms`)
|
|
1383
|
+
assert.equal(state.body.modelCatalog.checked, false)
|
|
1384
|
+
assert.equal(state.body.modelCatalog.providers.length, 0)
|
|
1385
|
+
await ctx.dispose()
|
|
1386
|
+
})
|
|
1387
|
+
|
|
1388
|
+
test('设置页静置 60s:模型全量枚举至多 2 次(初始 + 一次刷新)', async () => {
|
|
1389
|
+
let clock = 0
|
|
1390
|
+
let listCalls = 0
|
|
1391
|
+
const registry = createFakeRegistry()
|
|
1392
|
+
const webServer = createFakeWebServer()
|
|
1393
|
+
const llm = {
|
|
1394
|
+
listProviders: () => [{ id: 'p', name: 'P' }],
|
|
1395
|
+
listModels: async () => {
|
|
1396
|
+
listCalls += 1
|
|
1397
|
+
return [{ id: 'm', name: 'M' }]
|
|
1398
|
+
},
|
|
1399
|
+
}
|
|
1400
|
+
const ctx = createFakeContext({ registry, webServer, llm })
|
|
1401
|
+
index.apply(ctx.ctx, base(), { verificationDelayMs: 0, now: () => clock })
|
|
1402
|
+
await ctx.flush()
|
|
1403
|
+
const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
|
|
1404
|
+
|
|
1405
|
+
await callRoute(handler, 'GET')
|
|
1406
|
+
await sleep(0)
|
|
1407
|
+
await ctx.flush()
|
|
1408
|
+
assert.equal(listCalls, 1, '首次 /state 应触发一次初始枚举')
|
|
1409
|
+
|
|
1410
|
+
for (let t = 4000; t <= 56000; t += 4000) {
|
|
1411
|
+
clock = t
|
|
1412
|
+
await callRoute(handler, 'GET')
|
|
1413
|
+
await sleep(0)
|
|
1414
|
+
await ctx.flush()
|
|
1415
|
+
assert.equal(listCalls, 1, `t=${t}ms 时不应重复全量枚举`)
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
clock = 60000
|
|
1419
|
+
await callRoute(handler, 'GET')
|
|
1420
|
+
await sleep(0)
|
|
1421
|
+
await ctx.flush()
|
|
1422
|
+
assert.equal(listCalls, 2, '60s 时应至多刷新一次')
|
|
1423
|
+
await ctx.dispose()
|
|
1424
|
+
})
|
|
1425
|
+
|
|
1426
|
+
test('client 行为:broken/自身/旧值禁用,确实来自真实 client 纯函数', async () => {
|
|
1427
|
+
const api = await loadClientTestApi()
|
|
1428
|
+
const T = (cn) => cn
|
|
1429
|
+
const choices = api.presetChoices(
|
|
1430
|
+
[
|
|
1431
|
+
{ id: 'dev-plan', name: '开发规划与交付' },
|
|
1432
|
+
{ id: 'broken-preset', name: '损坏方式', broken: 'import failed' },
|
|
1433
|
+
{ id: 'team-builder', name: '团队施工' },
|
|
1434
|
+
],
|
|
1435
|
+
'broken-preset',
|
|
1436
|
+
'dev-plan',
|
|
1437
|
+
T,
|
|
1438
|
+
)
|
|
1439
|
+
const byValue = Object.fromEntries(choices.map((choice) => [choice.value, choice]))
|
|
1440
|
+
assert.equal(byValue.standard.disabled, undefined)
|
|
1441
|
+
assert.equal(byValue['dev-plan'].disabled, true, 'dev-plan 自身必须禁用')
|
|
1442
|
+
assert.equal(byValue['broken-preset'].disabled, true, 'broken 项必须禁用')
|
|
1443
|
+
assert.equal(byValue['team-builder'].disabled, undefined)
|
|
1444
|
+
assert.match(byValue['broken-preset'].label, /不可用/)
|
|
1445
|
+
assert.match(byValue['dev-plan'].label, /不能选自己/)
|
|
1446
|
+
|
|
1447
|
+
const legacy = api.presetChoices([{ id: 'team-builder', name: '团队施工' }], 'removed-preset', 'dev-plan', T)
|
|
1448
|
+
assert.equal(legacy.find((choice) => choice.value === 'removed-preset').disabled, true)
|
|
1449
|
+
})
|
|
1450
|
+
|
|
1451
|
+
test('client 行为:provider→model 联动取首个模型,旧 provider/model 禁用', async () => {
|
|
1452
|
+
const api = await loadClientTestApi()
|
|
1453
|
+
const T = (cn) => cn
|
|
1454
|
+
const providers = [
|
|
1455
|
+
{ provider: 'alpha', name: 'Alpha', models: [{ model: 'a1', name: 'A1' }, { model: 'a2' }] },
|
|
1456
|
+
{ provider: 'beta', name: 'Beta', models: [{ model: 'b1' }] },
|
|
1457
|
+
]
|
|
1458
|
+
assert.equal(api.firstModelOf(providers, 'beta'), 'b1')
|
|
1459
|
+
assert.equal(api.firstModelOf(providers, 'missing'), '')
|
|
1460
|
+
|
|
1461
|
+
const providerOptions = api.providerChoices(providers, 'legacy', T)
|
|
1462
|
+
assert.equal(providerOptions.find((choice) => choice.value === 'legacy').disabled, true)
|
|
1463
|
+
assert.equal(providerOptions.find((choice) => choice.value === 'alpha').label, 'Alpha(alpha)')
|
|
1464
|
+
|
|
1465
|
+
const modelOptions = api.modelChoices(providers[0].models, 'gone', T)
|
|
1466
|
+
assert.equal(modelOptions.find((choice) => choice.value === 'gone').disabled, true)
|
|
1467
|
+
assert.equal(modelOptions.find((choice) => choice.value === 'a1').label, 'A1(a1)')
|
|
1468
|
+
})
|