feat(models): 角色卡模型切换;修复配置原子性与跨项目缓存(v0.2.2)
- 角色卡显示模型下拉(/sansheng/state 返回 rt.catalog 可用模型) - Q11:模型先全部解析校验,失败零修改/回滚 runtime - Q12:项目切换失败不把旧项目缓存配到新上下文 - 测试 127/127 pass
This commit is contained in:
parent
7c79de3023
commit
f0361cabeb
|
|
@ -49,7 +49,7 @@
|
|||
## 验证
|
||||
|
||||
```sh
|
||||
node --test --test-isolation=none sansheng/test/*.test.js # 123 tests
|
||||
node --test --test-isolation=none sansheng/test/*.test.js # 127 tests
|
||||
node --check sansheng/client.js && node --check sansheng/index.js
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# WP0 基线、接口与发布路线
|
||||
# WP0 基线、接口与发布路线
|
||||
|
||||
日期:2026-11-13(Asia/Shanghai)
|
||||
状态:实施前核对记录。后续验证结果按测试 ID 写入本目录其他文件。
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
| 基准提交 | `3f20f89`(工作树在开工时仅多出交接方案文档) |
|
||||
| 远端 | `origin https://git.qyhhh.top/newbie/dsh-sansheng-liubu.git` |
|
||||
| 根工作区 | `workspaces: ["sansheng", "ds-bot"]`,根 `package.json` 不是 DSH 插件 |
|
||||
| 治理包 | `sansheng/` = `dsh-sansheng-sansheng@0.2.1`(本次发布候选) |
|
||||
| 治理包 | `sansheng/` = `dsh-sansheng-sansheng@0.2.2`(本次发布候选) |
|
||||
| 团队底座 | `ds-bot/` = `ds-bot@0.3.2-sansheng.2`(上游 `Fei2411/DS-Bot@84c3cb8` + 本地 M-01–M-06) |
|
||||
| Node | v24.21.0(DSH 随附 `~/.dsh/dsh-runtimes/dsh-primary-runtime/dependencies/node/bin/node.exe`) |
|
||||
| 桌面宿主 | DeepSeek Harness 0.2.2-rc.3(`resources/runtime/primary-runtime/runtime.json`) |
|
||||
|
|
@ -108,3 +108,4 @@ ds-bot 侧只在服务存在时执行检查;不存在时保持上游行为。
|
|||
- [x] 项目树入口无公开项目动作 API → 采用宿主原生 `contextMenus` workspace/session 菜单 + 右栏页签;不使用私有 DOM。
|
||||
- [x] 不依赖直接修改宿主才能成立的功能;ds-bot 必要补丁均记录在 PATCHES。
|
||||
- [x] 旧数据保留策略明确,无自动迁移。
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,11 @@ node --check sansheng/index.js
|
|||
| U03 右栏重复点击聚焦 | 组件级通过 | `openRolesTab` 优先 better-sidebar/openTabIn;现有测试覆盖回退 |
|
||||
| U04 Better Sidebar 缺失/失败 | 真实宿主冒烟通过(回退入口) | 测试 profile 无 better-sidebar:左栏底部「三省」按钮可打开右栏「角色」页签;见 `03-host-smoke.md` |
|
||||
| U05 小窗口/宽屏/主题 | 部分验证 | 1440×900 浅色截图;深色/窄屏未测 |
|
||||
| U06 A/B 切换旧响应不覆盖 | 组件级通过 | client 请求序号丢弃过期响应(UI 测试) |
|
||||
| U06 A/B 切换旧响应不覆盖 | 通过(client 测试) | 请求序号丢弃旧响应;Q12:跨项目失败不再把 A 缓存配上 B 上下文 |
|
||||
| U07 新目标不显示旧验收 | 通过(api-v3) | 按 goalId 过滤 + 历史折叠 |
|
||||
| U08 先 reject 后 pass 不显示旧返工 | 通过(api-v3) | 当前阶段最新判决决定卡片 |
|
||||
| U09 断连/过期/配置失败提示 | 组件级通过 | 保留上次数据但显示“连接中断”;配置表单错误就地显示 |
|
||||
| U10 模型切换 | 组件级通过 / 真实有模型未测 | 角色卡模型下拉调用 `/sansheng/config`;无可用模型目录时显示默认模型;真实 API Key 环境待测 |
|
||||
|
||||
## 3. 隔离
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ node --check sansheng/index.js
|
|||
| I01 默认参数创建 A/B 成功且身份独立 | 通过(isolation I01) | 全局 Bot 名唯一算法 + 项目绑定互斥 |
|
||||
| I02 A 尚书绑 B 拒绝 | 通过(isolation I02) | `bot-taken` 校验,无半绑定 |
|
||||
| I03 B 会话显式 A / 私聊跨项目 | 通过(isolation I03/I03b + ds-bot M-04) | `resolveProjectForCall` 冲突拒绝;`checkDelivery` 覆盖 message_bot 私聊与 rt.deliver |
|
||||
| I04 修改 A 模型不影响 B | 通过(isolation I04) | `updateProjectConfig` 只更新 A 的 Bot 与绑定 |
|
||||
| I04 修改 A 模型不影响 B | 通过(isolation I04 + Q11) | `updateProjectConfig` 先解析全部模型再应用;无效模型零修改,中途失败回滚 runtime 模型 |
|
||||
| I05 A 记忆不注入 B | 源码级通过 / 真实宿主未验证 | M-05:team 作用域写入、读取、系统提示、autoRecall、memoryUpdate 全部按项目拒绝;无 ds-bot 测试框架,仅语法/静态检查 |
|
||||
| I06 跨项目自动投递拒绝 | 通过(isolation I05/I06) | governance.checkDelivery + ds-bot delivery 补丁 |
|
||||
| I07 并行写入与工作根 | 部分通过 | 写租约测试通过;`workDir` 通过 `rt.createBot/updateBot` 落到 Bot;同根并发仍以单写租约为准,未做真实文件系统越界测试 |
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ profile `web-test` 的 bundles:`@deepseek-ai/dsh-base`、`@deepseek-ai/dsh-web
|
|||
| 原生聊天布局 | 输入框保持在底部,右栏展开/收起不影响输入框几何(1440×900 截图) | `evidence/host-right-roles.png` |
|
||||
| 左侧栏保持宿主项目树 | 安装 M-06 后,DS Bot 不再 shadow `sidebar.workspaces`;左栏显示「工作区 / DS Bot / New Session」项目树,不再换成 Bot 列表 | `evidence/host-project-tree-bot-switch.png` |
|
||||
| Bot 切换在右栏 | 右栏角色卡下方新增折叠「Bot 切换 · 4」,列出丞相/工部/尚书/Chief 与项目群,点击打开对应真实会话 | `evidence/host-project-tree-bot-switch.png` |
|
||||
| 模型切换 | 组件/服务端测试通过;测试 profile 没有 API Key,`/sansheng/state` 的 `models` 为空,角色卡显示「默认模型」,未能真实切换 | `client.test.js`、Q11 测试 |
|
||||
|
||||
HTTP 响应原文(初始空状态):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# 发布说明(候选版本 v0.2.1 / ds-bot 0.3.2-sansheng.2)
|
||||
# 发布说明(候选版本 v0.2.2 / ds-bot 0.3.2-sansheng.2)
|
||||
|
||||
日期:2026-11-14
|
||||
状态:**候选版本**。可用于隔离测试环境;用户日常 desktop profile 未由实施者修改。
|
||||
|
|
@ -7,10 +7,16 @@
|
|||
|
||||
| 包 | 版本 | 文件 |
|
||||
| --- | --- | --- |
|
||||
| `dsh-sansheng-sansheng` | 0.2.1 | `dist/dsh-sansheng-sansheng-0.2.1.tgz` |
|
||||
| `dsh-sansheng-sansheng` | 0.2.2 | `dist/dsh-sansheng-sansheng-0.2.2.tgz` |
|
||||
| `ds-bot`(上游 0.3.2 + M-01–M-06) | 0.3.2-sansheng.2 | `dist/ds-bot-0.3.2-sansheng.2.tgz` |
|
||||
|
||||
云端预发布:`v0.2.1-sansheng`,https://git.qyhhh.top/DeepsSeekHarness/dsh-sansheng-liubu/releases/tag/v0.2.1-sansheng (两个 tarball 已作为 release assets 上传)。
|
||||
云端预发布:`v0.2.2-sansheng`,https://git.qyhhh.top/DeepsSeekHarness/dsh-sansheng-liubu/releases/tag/v0.2.2-sansheng (两个 tarball 已作为 release assets 上传)。
|
||||
|
||||
### v0.2.2 变更
|
||||
|
||||
- 角色卡模型下拉:`/sansheng/state` 返回可用模型目录,角色卡直接切换本项目该角色模型(无 API Key 时显示默认模型,不伪造可选项)。
|
||||
- Q11:模型配置先全部解析校验,再应用;任一无效零修改,中途失败/保存失败回滚 runtime 模型。
|
||||
- Q12:项目切换请求按上下文签名缓存,切到 B 后失败不会显示 A 的旧卡片与可操作内容。
|
||||
|
||||
构建命令(在包目录运行):
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ window.__ModuleLoader__.load({
|
|||
.ss-card[data-tone="warn"] .ss-dot{background:var(--dsw-alias-state-error-primary,#dc2626)}
|
||||
.ss-card[data-tone="attention"] .ss-dot{background:#c9871f}
|
||||
.ss-duty{font-size:11px;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.ss-model-select{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#5b616b);font:inherit;font-size:11px;max-width:55%;padding:0 14px 0 0;margin:0;cursor:pointer;text-overflow:ellipsis}
|
||||
.ss-model-select:hover,.ss-model-select:focus-visible{color:var(--dsw-alias-label-primary,#1f2329)}
|
||||
.ss-model-text{color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||||
.ss-main{font-size:12.5px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.ss-sub{font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary,#5b616b);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word}
|
||||
.ss-foot{display:flex;align-items:center;gap:6px;font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a8f98);min-width:0}
|
||||
|
|
@ -324,6 +327,7 @@ window.__ModuleLoader__.load({
|
|||
let timer = null
|
||||
let lastData = null
|
||||
let lastUpdatedAt = 0
|
||||
let lastSignature = null
|
||||
const schedule = delay => {
|
||||
if (stopped) return
|
||||
if (timer) clearTimeout(timer)
|
||||
|
|
@ -349,11 +353,21 @@ window.__ModuleLoader__.load({
|
|||
}
|
||||
lastData = data
|
||||
lastUpdatedAt = Date.now()
|
||||
lastSignature = signature
|
||||
rememberState(data, context)
|
||||
onChange({ loading: false, error: null, data, updatedAt: lastUpdatedAt, context })
|
||||
} catch (error) {
|
||||
if (stopped || isStale(requestId, latestRequestId)) return
|
||||
onChange({ loading: false, error: messageOf(error), data: lastData, updatedAt: lastUpdatedAt, context })
|
||||
// 只有同一项目断连才展示上次数据;切到 B 后失败不能把 A 的卡片
|
||||
// 配上 B 的上下文(Q12)。
|
||||
const sameProject = signature === lastSignature
|
||||
onChange({
|
||||
loading: false,
|
||||
error: messageOf(error),
|
||||
data: sameProject ? lastData : null,
|
||||
updatedAt: sameProject ? lastUpdatedAt : 0,
|
||||
context,
|
||||
})
|
||||
} finally {
|
||||
if (!stopped && !isStale(requestId, latestRequestId)) schedule(retryImmediately ? 0 : intervalMs)
|
||||
}
|
||||
|
|
@ -657,11 +671,27 @@ window.__ModuleLoader__.load({
|
|||
}
|
||||
}
|
||||
|
||||
function RoleCard({ ctx, project, card }) {
|
||||
function RoleCard({ ctx, project, card, models, onRefresh }) {
|
||||
const model = card.model ? String(card.model) : '默认模型'
|
||||
const exists = card.exists === true ? '存在' : card.exists === false ? '不存在' : ''
|
||||
const phase = card.phase || phaseOf(project)
|
||||
const clickable = Boolean(card.sessionId)
|
||||
const modelOptions = Array.isArray(models) ? models : []
|
||||
const [savingModel, setSavingModel] = React.useState(false)
|
||||
const [modelError, setModelError] = React.useState(null)
|
||||
const changeModel = async value => {
|
||||
if (!value || savingModel) return
|
||||
setSavingModel(true)
|
||||
setModelError(null)
|
||||
try {
|
||||
await postJson('/sansheng/config', { projectId: project.id, models: { [card.role]: value } })
|
||||
if (typeof onRefresh === 'function') onRefresh()
|
||||
} catch (error) {
|
||||
setModelError(messageOf(error))
|
||||
} finally {
|
||||
setSavingModel(false)
|
||||
}
|
||||
}
|
||||
const activate = () => { openRoleSession(ctx, card) }
|
||||
const props = {
|
||||
className: 'ss-card',
|
||||
|
|
@ -681,13 +711,39 @@ window.__ModuleLoader__.load({
|
|||
}
|
||||
}
|
||||
}
|
||||
const modelControl = modelOptions.length > 0
|
||||
? h('select', {
|
||||
key: 'model',
|
||||
className: 'ss-model-select',
|
||||
value: card.model || '',
|
||||
disabled: savingModel,
|
||||
'aria-label': (card.label || card.role) + '模型',
|
||||
onClick: event => { if (event && event.stopPropagation) event.stopPropagation() },
|
||||
onKeyDown: event => { if (event && event.stopPropagation) event.stopPropagation() },
|
||||
onChange: event => {
|
||||
if (event && event.stopPropagation) event.stopPropagation()
|
||||
void changeModel(event.target.value)
|
||||
},
|
||||
}, [
|
||||
!card.model ? h('option', { key: 'default', value: '', children: '默认模型' }) : null,
|
||||
card.model && !modelOptions.some(item => item.ref === card.model)
|
||||
? h('option', { key: 'current', value: card.model, children: card.model })
|
||||
: null,
|
||||
...modelOptions.map(item => h('option', { key: item.ref, value: item.ref, children: item.name || item.ref })),
|
||||
].filter(Boolean))
|
||||
: h('span', { key: 'model', className: 'ss-model-text', children: model })
|
||||
return h('div', props, [
|
||||
h('div', { key: 'head', className: 'ss-card-head' }, [
|
||||
h('span', { key: 'mark', className: 'ss-mark', 'aria-hidden': 'true', children: ROLE_MARK[card.role] || '省' }),
|
||||
h('strong', { key: 'label', children: card.label || ROLE_LABEL[card.role] || card.role }),
|
||||
h('span', { key: 'dot', className: 'ss-dot', 'aria-hidden': 'true' }),
|
||||
]),
|
||||
h('div', { key: 'duty', className: 'ss-duty', children: `${card.name || '未就绪'} · ${model}` }),
|
||||
h('div', { key: 'duty', className: 'ss-duty' }, [
|
||||
h('span', { key: 'name', children: card.name || '未就绪' }),
|
||||
h('span', { key: 'sep', children: ' · ' }),
|
||||
modelControl,
|
||||
]),
|
||||
modelError ? h('div', { key: 'model-error', className: 'ss-error', children: '模型切换失败:' + modelError }) : null,
|
||||
h('div', { key: 'main', className: 'ss-main', children: card.line || card.next || '暂无状态' }),
|
||||
card.detail ? h('div', { key: 'sub', className: 'ss-sub', children: card.detail }) : null,
|
||||
h('div', { key: 'foot', className: 'ss-foot' }, [
|
||||
|
|
@ -952,7 +1008,7 @@ window.__ModuleLoader__.load({
|
|||
} else if (project) {
|
||||
const roles = rolesOf(project)
|
||||
body = [
|
||||
...roles.map(card => h(RoleCard, { key: card.role || card.label, ctx, project, card })),
|
||||
...roles.map(card => h(RoleCard, { key: card.role || card.label, ctx, project, card, models: data && data.models, onRefresh })),
|
||||
h(BotSwitcher, { key: 'bots', ctx, data }),
|
||||
h(HistoryPanel, { key: 'history', project }),
|
||||
h(ConfigPanel, { key: 'config', ctx, project, onRefresh }),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsh-sansheng-sansheng",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"private": true,
|
||||
"description": "三省六部:在 DS Bot 团队上提供丞相/尚书/工部三角色、目标门禁与审查记录。",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -276,10 +276,12 @@ export async function updateProjectConfig({ ctx, store, args }) {
|
|||
const rt = ctx.get('dsbot-runtime', false)
|
||||
const patch = {}
|
||||
const changed = []
|
||||
let rollbackModels = []
|
||||
|
||||
if (args.models && typeof args.models === 'object') {
|
||||
const models = { ...project.models }
|
||||
const applied = []
|
||||
const resolvedModels = []
|
||||
// 先解析校验全部模型,任何一个不可用就零修改(Q11)。
|
||||
for (const role of ROLE_IDS) {
|
||||
const raw = args.models[role]
|
||||
if (raw === undefined || raw === null || String(raw).trim() === '') continue
|
||||
|
|
@ -287,24 +289,46 @@ export async function updateProjectConfig({ ctx, store, args }) {
|
|||
try {
|
||||
if (rt && typeof rt.resolveModel === 'function') resolved = await rt.resolveModel(resolved)
|
||||
} catch (error) {
|
||||
return { ok: false, text: `${ROLE_LABEL[role]}的模型“${raw}”不可用:${error?.message ?? error}` }
|
||||
return { ok: false, text: `${ROLE_LABEL[role]}的模型“${raw}”不可用:${error?.message ?? error}。本次没有修改任何模型。` }
|
||||
}
|
||||
const botId = project.bots?.[role]
|
||||
if (rt && typeof rt.updateBot === 'function' && botId) {
|
||||
const bot = rt && typeof rt.botOf === 'function' && botId ? rt.botOf(botId) : undefined
|
||||
resolvedModels.push({
|
||||
role,
|
||||
botId,
|
||||
resolved,
|
||||
previousRuntime: bot?.model ?? bot?.appliedModel ?? null,
|
||||
previousConfig: project.models?.[role] ?? null,
|
||||
})
|
||||
}
|
||||
const applied = []
|
||||
for (const item of resolvedModels) {
|
||||
if (rt && typeof rt.updateBot === 'function' && item.botId) {
|
||||
try {
|
||||
await rt.updateBot(botId, { model: resolved }, undefined)
|
||||
await rt.updateBot(item.botId, { model: item.resolved }, undefined)
|
||||
applied.push(item)
|
||||
} catch (error) {
|
||||
for (const undo of applied) {
|
||||
try { await rt.updateBot(undo.botId, { model: undo.previous }, undefined) } catch { /* 尽力回滚 */ }
|
||||
const rollback = []
|
||||
for (const undo of applied.reverse()) {
|
||||
try {
|
||||
await rt.updateBot(undo.botId, { model: undo.previousRuntime }, undefined)
|
||||
} catch (undoError) {
|
||||
rollback.push(`${ROLE_LABEL[undo.role]}(${undoError?.message ?? undoError})`)
|
||||
}
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
text: `更新${ROLE_LABEL[item.role]}模型失败:${error?.message ?? error}。`
|
||||
+ (rollback.length > 0 ? `已回滚其余角色,但${rollback.join('、')}回滚失败,请检查实际模型配置。` : '已回滚本次已修改的模型。'),
|
||||
}
|
||||
return { ok: false, text: `更新${ROLE_LABEL[role]}模型失败:${error?.message ?? error}` }
|
||||
}
|
||||
applied.push({ botId, previous: project.models?.[role] ?? null })
|
||||
}
|
||||
models[role] = resolved
|
||||
changed.push(`${ROLE_LABEL[role]}模型=${resolved}`)
|
||||
models[item.role] = item.resolved
|
||||
changed.push(`${ROLE_LABEL[item.role]}模型=${item.resolved}`)
|
||||
}
|
||||
patch.models = models
|
||||
// 保存失败时也要把 runtime 恢复,不能只回滚 Store。
|
||||
rollbackModels = applied
|
||||
}
|
||||
if (args.maxReworks !== undefined) {
|
||||
patch.maxReworks = clampInt(args.maxReworks, project.maxReworks ?? 3, 1, 10)
|
||||
|
|
@ -325,7 +349,19 @@ export async function updateProjectConfig({ ctx, store, args }) {
|
|||
try {
|
||||
await store.updateProject(project.id, patch)
|
||||
} catch (error) {
|
||||
return { ok: false, text: `保存配置失败:${error?.message ?? error}` }
|
||||
const rollback = []
|
||||
for (const undo of rollbackModels.reverse()) {
|
||||
try {
|
||||
if (rt && typeof rt.updateBot === 'function') await rt.updateBot(undo.botId, { model: undo.previousRuntime }, undefined)
|
||||
} catch (undoError) {
|
||||
rollback.push(`${ROLE_LABEL[undo.role]}(${undoError?.message ?? undoError})`)
|
||||
}
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
text: `保存配置失败:${error?.message ?? error}。`
|
||||
+ (rollback.length > 0 ? `模型回滚失败:${rollback.join('、')},请检查实际模型配置。` : '已回滚运行时模型。'),
|
||||
}
|
||||
}
|
||||
return { ok: true, text: `已更新项目「${project.name}」(${project.id}):${changed.join(',')}。只影响本项目,其他项目与正在运行的会话不受影响。` }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,9 +108,23 @@ export function installRoute({ ctx, store, dsbot }) {
|
|||
const payload = buildStatePayload({ store, dsbot })
|
||||
const current = resolveCurrentProject(payload, { workspaceId: params.workspaceId, sessionId: params.sessionId })
|
||||
const health = typeof store.health === 'function' ? store.health() : { status: 'ok' }
|
||||
let models = []
|
||||
try {
|
||||
const rt = ctx.get('dsbot-runtime', false)
|
||||
if (rt && typeof rt.catalog === 'function') {
|
||||
models = (await rt.catalog()).map(entry => ({
|
||||
ref: entry.ref,
|
||||
provider: entry.provider,
|
||||
providerName: entry.providerName,
|
||||
model: entry.id,
|
||||
name: entry.name,
|
||||
}))
|
||||
}
|
||||
} catch { /* 模型目录不可用时仍返回项目状态 */ }
|
||||
send(res, 200, {
|
||||
...payload,
|
||||
...listBots({ dsbot, store }),
|
||||
models,
|
||||
current: current.project ?? null,
|
||||
currentMatch: current.matchedBy,
|
||||
health: { status: health.status, error: health.error ?? null },
|
||||
|
|
|
|||
|
|
@ -562,3 +562,53 @@ test('Bot 切换列表在右栏渲染并可打开对应会话', async () => {
|
|||
buttons[0].props.onClick()
|
||||
assert.deepEqual(opened, ['sess-b1'])
|
||||
})
|
||||
|
||||
test('角色卡模型下拉调用 /sansheng/config,只改当前角色模型', async () => {
|
||||
const calls = []
|
||||
const fetch = async (url, options) => {
|
||||
calls.push({ url, options })
|
||||
return { ok: true, status: 200, json: async () => ({ ok: true }) }
|
||||
}
|
||||
const { module } = await loadClient({ fetch })
|
||||
const project = projectFixture()
|
||||
const tree = module.__test.RoleCard({
|
||||
ctx: fakeCtx(),
|
||||
project,
|
||||
card: project.roles[0],
|
||||
models: [{ ref: 'provider/new-model', name: 'New Model' }],
|
||||
})
|
||||
const select = findAll(tree, node => node.type === 'select')[0]
|
||||
assert.ok(select, '有可用模型时渲染下拉')
|
||||
await select.props.onChange({ target: { value: 'provider/new-model' }, stopPropagation() {} })
|
||||
assert.equal(calls[0].url, '/sansheng/config')
|
||||
const body = JSON.parse(calls[0].options.body)
|
||||
assert.deepEqual(body, { projectId: 'prj-1', models: { lead: 'provider/new-model' } })
|
||||
})
|
||||
|
||||
test('切到 B 后请求失败,不把 A 的缓存配上 B 的上下文', async () => {
|
||||
const workspaces = { items: [{ workspaceId: 'ws-A', sessionIds: ['sess-A'] }] }
|
||||
const sessions = { byId: { 'sess-A': { id: 'sess-A', retainedBy: { mainView: 1 } } } }
|
||||
const ctx = fakeCtx({ workspaces, sessions })
|
||||
let failing = false
|
||||
const fetch = async () => {
|
||||
if (failing) throw new Error('网络断了')
|
||||
return { ok: true, status: 200, json: async () => ({ generatedAt: 1, current: { id: 'prj-A', name: 'A' }, projects: [] }) }
|
||||
}
|
||||
const states = []
|
||||
const poller = (await loadClient()).module.__test.createStatePoller({ ctx, fetchImpl: fetch, onChange: state => states.push(state), intervalMs: 60000 })
|
||||
poller.start()
|
||||
await flush()
|
||||
assert.equal(states.at(-1).data.current.name, 'A')
|
||||
|
||||
sessions.byId['sess-A'].retainedBy.mainView = 0
|
||||
sessions.byId['sess-B'] = { id: 'sess-B', retainedBy: { mainView: 1 } }
|
||||
workspaces.items = [{ workspaceId: 'ws-B', sessionIds: ['sess-B'] }]
|
||||
failing = true
|
||||
poller.refresh()
|
||||
await flush()
|
||||
const last = states.at(-1)
|
||||
assert.equal(last.context.workspaceId, 'ws-B')
|
||||
assert.equal(last.data, null, '跨项目失败不显示旧项目数据')
|
||||
assert.match(last.error, /网络断了/)
|
||||
poller.stop()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -297,3 +297,48 @@ test('写租约:同项目第二个写任务被拒绝,释放后可获取', as
|
|||
await env.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test('Q11:模型配置先全部校验,任一无效时零修改', async () => {
|
||||
const env = await setup()
|
||||
try {
|
||||
await env.tool('sansheng_provision').execute({ project: '项目A', workDir: 'C:/work/a' }, userExec)
|
||||
await env.reload()
|
||||
const project = Object.values(env.store.peek().projects)[0]
|
||||
const before = env.calls.updated.length
|
||||
const result = await env.tool('sansheng_config').execute({
|
||||
project: project.id,
|
||||
models: { lead: 'provider/ok', shangshu: 'bad' },
|
||||
}, userExec)
|
||||
assert.match(result, /不可用/)
|
||||
assert.equal(env.calls.updated.length, before, '无效模型不应产生任何 updateBot')
|
||||
assert.equal(env.store.projectById(project.id).models.lead, undefined)
|
||||
} finally {
|
||||
await env.cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test('Q11b:中途 updateBot 失败时回滚已经修改的模型', async () => {
|
||||
const env = await setup()
|
||||
try {
|
||||
await env.tool('sansheng_provision').execute({ project: '项目A', workDir: 'C:/work/a' }, userExec)
|
||||
await env.reload()
|
||||
const project = Object.values(env.store.peek().projects)[0]
|
||||
const original = env.rt.updateBot
|
||||
env.rt.updateBot = async (id, patch) => {
|
||||
if (id === project.bots.shangshu && patch.model === 'provider/m2') throw new Error('模拟第二模型更新失败')
|
||||
return original.call(env.rt, id, patch)
|
||||
}
|
||||
const result = await env.tool('sansheng_config').execute({
|
||||
project: project.id,
|
||||
models: { lead: 'provider/m1', shangshu: 'provider/m2' },
|
||||
}, userExec)
|
||||
assert.match(result, /已回滚/)
|
||||
const updates = env.calls.updated.slice(-2)
|
||||
assert.equal(updates[0].id, project.bots.lead)
|
||||
assert.equal(updates[0].patch.model, 'provider/m1')
|
||||
assert.equal(updates[1].id, project.bots.lead)
|
||||
assert.equal(updates[1].patch.model, null, '回滚到原值')
|
||||
} finally {
|
||||
await env.cleanup()
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue