Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(profile): 版本档案建议名带上 patch 与 Core- 前缀

hairyf9d07ac10f115
diff --git a/src/ui/config/hooks/use-core-profile-switch.tsx b/src/ui/config/hooks/use-core-profile-switch.tsx
index 6541c54d..49b45616 100644
--- a/src/ui/config/hooks/use-core-profile-switch.tsx
+++ b/src/ui/config/hooks/use-core-profile-switch.tsx
@@ -6,7 +6,7 @@ import { invoke } from '@tauri-apps/api/core'
import { useTranslation } from 'react-i18next'
import { queryKeys } from '@/config/query-keys'
import { CoreUpgradeProfileDialog } from '@/ui/dialog/core-upgrade-profile'
-import { coreMajorMinor, isCoreUpgrade } from '@/utils/core-version'
+import { coreProfileName, isCoreUpgrade } from '@/utils/core-version'
import { normalizeProfileId } from '@/utils/profile-id'
import { toast } from '@/utils/toast'
@@ -68,7 +68,7 @@ export function useCoreProfileSwitch() {
choice = await openDialog({
fromVersion: from,
toVersion,
- defaultName: coreMajorMinor(toVersion),
+ defaultName: coreProfileName(toVersion),
})
}
catch {
diff --git a/src/ui/dialog/core-upgrade-profile.tsx b/src/ui/dialog/core-upgrade-profile.tsx
index 80284258..3871a976 100644
--- a/src/ui/dialog/core-upgrade-profile.tsx
+++ b/src/ui/dialog/core-upgrade-profile.tsx
@@ -16,7 +16,7 @@ export interface CoreUpgradeProfileDialogProps extends PropsWithOverlays {
fromVersion: string
/** 目标核心版本(展示用) */
toVersion: string
- /** 档案名默认值:目标版本的主/次版本号(`x.x`) */
+ /** 档案名默认值:目标版本号(含 patch,如 `Core-0.1.7`;同一 patch 的 rc 共用档案) */
defaultName: string
}
@@ -47,7 +47,7 @@ export function CoreUpgradeProfileDialog(props: CoreUpgradeProfileDialogProps) {
<AlertDialog.Dialog className="sm:max-w-[420px]">
<AlertDialog.CloseTrigger />
<AlertDialog.Header>
- <AlertDialog.Icon status="warning" />
+ <AlertDialog.Icon status="danger" />
<AlertDialog.Heading>{t('core.breaking_title')}</AlertDialog.Heading>
</AlertDialog.Header>
<AlertDialog.Body className="space-y-3">
diff --git a/src/utils/core-version.ts b/src/utils/core-version.ts
index dae9e3e7..29fec09b 100644
--- a/src/utils/core-version.ts
+++ b/src/utils/core-version.ts
@@ -28,10 +28,22 @@ export function compareVersions(a: string, b: string): number {
return semver.compare(pa, pb)
}
-/** 主/次版本号(`x.x`,不含 patch 与预发布标识);缺失或不可解析时为空串 */
-export function coreMajorMinor(version: string): string {
+/**
+ * 版本档案的建议名(`Core-x.y.z`,含 patch、不含预发布标识);缺失或不可解析时为空串。
+ *
+ * 必须带上 patch:破坏性更改在 patch 之间同样发生(用户实测 0.1.5-rc.2 → 0.1.7-rc.2),
+ * 只取 `x.y` 会让两个核心共用一个档案——经 `normalizeProfileId` 归一化后 `0.1.5` 与
+ * `0.1.7` 都落成 `01`,用户在弹窗里照默认名确认,实际切回的就是同一个档案,等于没隔离。
+ * 预发布标识(`-rc.2`)不参与取名:同一 patch 的 rc 之间共用档案,避免每次 rc 都新建。
+ *
+ * 前缀 `Core-` 不是装饰:`create_profile` 只拿归一化后的 id 建目录,而档案在 UI 上的
+ * 展示名取自清单 `name` 去掉 `dsh-profile-` 前缀(首字母大写,见
+ * `service::profile::display_name`),所以没有前缀时列表里就是一个光秃秃的 `017`,
+ * 用户根本看不出它是核心版本档案;带上前缀即 `Core-017`。
+ */
+export function coreProfileName(version: string): string {
const parsed = semver.parse(stripVersionPrefix(version))
- return parsed ? `${parsed.major}.${parsed.minor}` : ''
+ return parsed ? `Core-${parsed.major}.${parsed.minor}.${parsed.patch}` : ''
}
/**
diff --git a/test/core-upgrade-profile.test.ts b/test/core-upgrade-profile.test.ts
index 31c9e5c1..3d9edc19 100644
--- a/test/core-upgrade-profile.test.ts
+++ b/test/core-upgrade-profile.test.ts
@@ -51,11 +51,11 @@ describe('版本比对一律走本地数据', () => {
expect(body).not.toContain('\'get_cores\'')
})
- it('任何更新的版本都判定为升级,默认档案名取目标版本的主/次版本号(x.x)', () => {
+ it('任何更新的版本都判定为升级,默认档案名取目标版本号(含 patch,Core-x.y.z)', () => {
const body = bodyOf(guardSource(), 'async function guardCoreUpgrade')
expect(body).toContain('isCoreUpgrade(from, toVersion)')
- expect(body).toContain('coreMajorMinor(toVersion)')
+ expect(body).toContain('coreProfileName(toVersion)')
expect(body).toMatch(/defaultName:/)
})
})
@@ -183,7 +183,7 @@ describe('更新提示入口(桌面外壳 / 调试页)走同一守卫', () =
})
describe('警告对话框控件', () => {
- it('档案名默认填 x.x、可编辑,并用 InputGroup 组合而非自绘 Label + Input', () => {
+ it('档案名默认填目标版本号(含 patch)、可编辑,并用 InputGroup 组合而非自绘 Label + Input', () => {
const source = dialogSource()
expect(source).toMatch(/useState\(props\.defaultName\)/)
diff --git a/test/core-version.test.ts b/test/core-version.test.ts
index c2e6c732..770613e4 100644
--- a/test/core-version.test.ts
+++ b/test/core-version.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
-import { coreMajorMinor, isCoreUnsupported, isCoreUpgrade, MIN_SUPPORTED_CORE_VERSION } from '@/utils/core-version'
+import { coreProfileName, isCoreUnsupported, isCoreUpgrade, MIN_SUPPORTED_CORE_VERSION } from '@/utils/core-version'
+import { normalizeProfileId } from '@/utils/profile-id'
/**
* issue #596:随包内置插件依赖的平台种子词自 dsh 0.1.5 起才存在,核心低于最低支持
@@ -37,22 +38,42 @@ describe('isCoreUnsupported', () => {
})
})
-describe('coreMajorMinor', () => {
- it('只取主/次版本号,丢掉 patch 与预发布标识', () => {
- expect(coreMajorMinor('0.17.1')).toBe('0.17')
- expect(coreMajorMinor('0.18.0-rc.1')).toBe('0.18')
- expect(coreMajorMinor('1.2.3')).toBe('1.2')
+/**
+ * 版本档案建议名必须带 patch、且带 `Core-` 前缀:
+ * - patch 升级同样可能带破坏性更改(用户实测 0.1.5-rc.2 → 0.1.7-rc.2)。只取 `x.y` 时
+ * 两个核心经 `normalizeProfileId` 归一化后都会落成 `01`,用户照默认名确认其实切回
+ * 同一个档案,隔离等于没做(见最后一条 id 断言);
+ * - 档案在 UI 上的展示名 = 清单名去 `dsh-profile-` 前缀后首字母大写,也就是 id 本身,
+ * 所以没有前缀时列表里只有 `017` 这种看不懂的名字(见 `Core-` 断言);
+ * - 同一 patch 的 rc 不参与取名,避免每次 rc 都新建档案。
+ */
+describe('coreProfileName', () => {
+ it('取主/次/补丁版本号并加 Core- 前缀,丢掉预发布标识', () => {
+ expect(coreProfileName('0.1.7-rc.2')).toBe('Core-0.1.7')
+ expect(coreProfileName('0.17.1')).toBe('Core-0.17.1')
+ expect(coreProfileName('0.18.0-rc.1')).toBe('Core-0.18.0')
+ expect(coreProfileName('1.2.3')).toBe('Core-1.2.3')
+ })
+
+ it('同一个 patch 的 rc 共用档案名', () => {
+ expect(coreProfileName('0.1.7-rc.1')).toBe(coreProfileName('0.1.7-rc.2'))
+ expect(coreProfileName('0.1.7-rc.2')).toBe('Core-0.1.7')
})
- it('剥掉 dsh-/src- 前缀后再取主/次版本号', () => {
- expect(coreMajorMinor('dsh-0.1.0-rc.8-32331963388')).toBe('0.1')
- expect(coreMajorMinor('src-2.0.0')).toBe('2.0')
+ it('剥掉 dsh-/src- 前缀后再取名', () => {
+ expect(coreProfileName('dsh-0.1.0-rc.8-32331963388')).toBe('Core-0.1.0')
+ expect(coreProfileName('src-2.0.0')).toBe('Core-2.0.0')
})
it('版本缺失或不可解析时为空串', () => {
- expect(coreMajorMinor('')).toBe('')
- expect(coreMajorMinor('local')).toBe('')
- expect(coreMajorMinor('app-0.1.0-rc.8')).toBe('')
+ expect(coreProfileName('')).toBe('')
+ expect(coreProfileName('local')).toBe('')
+ expect(coreProfileName('app-0.1.0-rc.8')).toBe('')
+ })
+
+ it('patch 不同的两个核心归一化后仍是两个不同档案 id,且名字可读', () => {
+ expect(normalizeProfileId(coreProfileName('0.1.5-rc.2'))).toBe('core-015')
+ expect(normalizeProfileId(coreProfileName('0.1.7-rc.2'))).toBe('core-017')
})
})