Преглед на файлове

fix(settings): 修复自定义模型名称无法清空

保留编辑过程中的空字符串,避免默认名称在删除后立即回填。
补充名称清空与配置持久化回归测试。
darknessomi преди 1 седмица
родител
ревизия
4ffbfc89ea

+ 38 - 0
src/components/settings/sections/custom-provider-cards.persist.spec.tsx

@@ -56,6 +56,12 @@ describe("listCustomProviderCards restart mapping", () => {
       custom: { label: "自定义模型", model: "legacy" },
     })).toEqual([])
   })
+
+  it("preserves an empty label while the user is editing it", () => {
+    expect(listCustomProviderCards({
+      "custom-1710000000000": { label: "" },
+    })[0]?.label).toBe("")
+  })
 })
 
 describe("CustomProviderCards persistence UI", () => {
@@ -113,6 +119,38 @@ describe("CustomProviderCards persistence UI", () => {
     expect(host.textContent).not.toContain("暂未添加任何模型配置")
     vi.restoreAllMocks()
   })
+
+  it("allows deleting the entire default model name", async () => {
+    useWikiStore.setState({
+      providerConfigs: {
+        "custom-1710000000000": { label: "自定义模型", enabled: true },
+      },
+    })
+    await act(async () => root.render(<CustomProviderCards />))
+
+    const labelButton = [...host.querySelectorAll("button")].find(
+      (button) => button.textContent?.trim() === "自定义模型",
+    )
+    expect(labelButton).toBeTruthy()
+    await act(async () => labelButton!.click())
+
+    const input = host.querySelector<HTMLInputElement>('input[placeholder="配置名称"]')
+    expect(input).toBeTruthy()
+    await act(async () => {
+      const valueSetter = Object.getOwnPropertyDescriptor(
+        HTMLInputElement.prototype,
+        "value",
+      )?.set
+      valueSetter?.call(input, "")
+      input!.dispatchEvent(new Event("input", { bubbles: true }))
+    })
+
+    expect(input!.value).toBe("")
+    expect(useWikiStore.getState().providerConfigs["custom-1710000000000"]?.label).toBe("")
+    expect(persistMocks.saveProviderConfigs.mock.calls.at(-1)?.[0]).toMatchObject({
+      "custom-1710000000000": { label: "" },
+    })
+  })
 })
 
 describe("close-path wiring", () => {

+ 1 - 1
src/components/settings/sections/custom-provider-cards.tsx

@@ -43,7 +43,7 @@ export function listCustomProviderCards(providerConfigs: ProviderConfigs): Custo
       const config = providerConfigs[key] ?? {}
       return {
         id: key,
-        label: config.label || "自定义模型",
+        label: config.label ?? "自定义模型",
         apiMode: config.apiMode || "chat_completions",
         baseUrl: config.baseUrl || "",
         apiKey: config.apiKey || "",