DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix: prompt for a matching profile before core downgrade (#847)
Matt Van Horndd825a6409e8
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex a8b9d462..55593f50 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -399,7 +399,7 @@"core.local_unsupported_toast": "Local core is too old","core.local_unsupported_hint": "Built-in plugins need dsh {{version}} or newer, so the bundled core is used instead. Update the local core before switching back to it.","core.breaking_title": "Breaking changes",- "core.breaking_desc": "{{from}} → {{to}} has breaking changes that may break this profile's plugins and settings. Switch to a matching profile; keeping the old profile leaves stale core packages behind, which breaks saving settings and needs manual repair.",+ "core.breaking_desc": "{{from}} → {{to}} switches core versions (upgrade or downgrade). Mixing them is incompatible: a newer profile on an older core can fail startup when core bundles are unavailable, and an older profile on a newer core leaves packages that break plugins and settings. Switch to a matching profile.","core.breaking_profile_label": "Profile name","core.breaking_ignore": "Keep old profile","core.breaking_profile_failed": "Failed to switch profile — the core was not switched",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 34236056..3613742a 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -399,7 +399,7 @@"core.local_unsupported_toast": "本地核心版本过低","core.local_unsupported_hint": "内置插件需要 dsh {{version}} 及以上,已自动改用预打包核心。请先更新本地核心,再切换回它。","core.breaking_title": "破坏性更改",- "core.breaking_desc": "{{from}} → {{to}} 含破坏性更改,可能破坏当前档案的插件与设置。请切换到配套档案;继续沿用旧档案会残留旧版核心包,导致设置无法保存,需手动修复该档案。",+ "core.breaking_desc": "{{from}} → {{to}} 会切换核心版本(升级或降级),两者档案不兼容:较新档案配较旧核心时,核心包不可用会导致启动失败;较旧档案配较新核心会留下不配套的包,破坏插件与设置。请切换到配套档案。","core.breaking_profile_label": "档案名称","core.breaking_ignore": "仍沿用旧档案","core.breaking_profile_failed": "切换档案失败,核心未切换",diff --git a/src/ui/config/hooks/use-core-profile-switch.tsx b/src/ui/config/hooks/use-core-profile-switch.tsxindex 49b45616..2bc269a0 100644--- a/src/ui/config/hooks/use-core-profile-switch.tsx+++ b/src/ui/config/hooks/use-core-profile-switch.tsx@@ -10,7 +10,7 @@ import { coreProfileName, isCoreUpgrade } from '@/utils/core-version'import { normalizeProfileId } from '@/utils/profile-id'import { toast } from '@/utils/toast'-/** 核心升级前的档案确认结果 */+/** 核心换版前的档案确认结果 */export interface CoreUpgradeGuard {/** 警告弹窗是否已处理切换确认(true 时调用方不必再弹普通切换确认) */handled: boolean@@ -19,11 +19,12 @@ export interface CoreUpgradeGuard {}/**- * 切换/更新核心前的「破坏性更改 → 请切换档案」守卫,三个入口共用:+ * 切换/更新核心前的「版本不配套 → 请切换档案」守卫,三个入口共用:* 核心面板切换、更新提示 toast(桌面外壳)、调试页「存在新版本」。*- * 核心与档案配套:换到更新的 dsh 版本前,先让用户把当前档案换成与目标版本同名的- * 版本档案(缺失则新建),新版本的插件与设置才不会破坏原档案。+ * 核心与档案配套:主/次/修订号变化(升级或降级,issue #748)前,先让用户换成与目标版本同名的+ * 版本档案(缺失则新建)。降级沿用较新档案时,旧核心找不到档案里的包,Harness 无法启动;+ * 升级沿用旧档案则会把不配套的包留在原档案里。同一 x.y.z 的预发布互换不弹窗。** 版本比对必须走本地数据:核心面板直接把列表里已加载的「在用核心」版本传进来;* 未传时退回只用本地信息的 `get_runtime_info`——绝不能为比对去拉 `get_cores`@@ -51,7 +52,7 @@ export function useCoreProfileSwitch() {}/**- * 目标版本是在用核心的升级时弹警告并按用户选择处理档案。+ * 目标版本与在用核心的主/次/修订号不同(升级或降级)时弹警告并按用户选择处理档案。** `fromVersion` 由调用方从本地已有数据传入(核心面板传列表里的在用核心版本);* 省略时退回本地读取。@@ -60,7 +61,8 @@ export function useCoreProfileSwitch() {*/async function guardCoreUpgrade(toVersion: string, fromVersion?: string): Promise<CoreUpgradeGuard | null> {const from = fromVersion ?? await localActiveVersion()- if (!isCoreUpgrade(from, toVersion))+ // isCoreUpgrade 仍只表示「目标更高」。两个方向一起看,降级才会同样隔离档案。+ if (!isCoreUpgrade(from, toVersion) && !isCoreUpgrade(toVersion, from))return { handled: false }let choice: CoreUpgradeChoice@@ -74,6 +76,7 @@ export function useCoreProfileSwitch() {catch {return null}+ // 明确无视风险时不改档案。沿用当前档案仍可能与目标核心不兼容(issue #748)。if (choice.mode === 'ignore')return { handled: true }diff --git a/test/core-upgrade-profile.test.ts b/test/core-upgrade-profile.test.tsindex 282b970f..f6876bcb 100644--- a/test/core-upgrade-profile.test.ts+++ b/test/core-upgrade-profile.test.ts@@ -2,10 +2,10 @@ import { describe, expect, it } from 'vitest'import { readLocale, readSource } from './setup/read-source'/**- * 「升级到更新的核心 → 请切换档案」链路的结构契约。+ * 「版本号变化(升级或降级)→ 请切换档案」链路的结构契约。** 前端不在单测里挂载组件(与 clone-profile.test.ts 同款跨层守卫),因此读源码断言结构:- * 期望值一律取自需求本身(顺序、命令名、i18n key、本地比对),不与被测实现同源。+ * 期望值一律取自需求本身(顺序、命令名、i18n key、双向本地比对),不与被测实现同源。** 三个入口共用同一个守卫 hook:核心面板切换、更新提示 toast(桌面外壳)、调试页更新按钮。*/@@ -51,10 +51,14 @@ describe('版本比对一律走本地数据', () => {expect(body).not.toContain('\'get_cores\'')})- it('任何更新的版本都判定为升级,默认档案名取目标版本号(含 patch,Core-x.y.z)', () => {+ it('核心号任一方向变化都要换档案,默认档案名取目标版本号(含 patch,Core-x.y.z)', () => {const body = bodyOf(guardSource, 'async function guardCoreUpgrade')+ const bypass = body.indexOf('return { handled: false }')expect(body).toContain('isCoreUpgrade(from, toVersion)')+ expect(body).toContain('isCoreUpgrade(toVersion, from)')+ expect(body.indexOf('isCoreUpgrade(from, toVersion)')).toBeLessThan(bypass)+ expect(body.indexOf('isCoreUpgrade(toVersion, from)')).toBeLessThan(bypass)expect(body).toContain('coreProfileName(toVersion)')expect(body).toMatch(/defaultName:/)})