refactor(models): unify preset names

This commit is contained in:
Xubin Ren
2026-08-16 11:50:56 +08:00
parent 8dc08853e4
commit 3dc38f6396
37 changed files with 239 additions and 209 deletions
+2 -4
View File
@@ -439,7 +439,7 @@ describe("webui API helpers", () => {
it("serializes model configuration creation", async () => {
await createModelConfiguration(mutationTransport, {
label: "Fast writing",
name: "Fast writing",
provider: "openai",
model: "openai/gpt-4.1-mini",
maxTokens: 4096,
@@ -451,7 +451,7 @@ describe("webui API helpers", () => {
expect(requestMutation).toHaveBeenCalledWith(
"settings.model_configuration.create",
{
label: "Fast writing",
name: "Fast writing",
provider: "openai",
model: "openai/gpt-4.1-mini",
max_tokens: 4096,
@@ -466,7 +466,6 @@ describe("webui API helpers", () => {
it("serializes model configuration updates", async () => {
await updateModelConfiguration(mutationTransport, {
name: "codex",
label: "Codex",
provider: "openai_codex",
model: "openai-codex/gpt-5.5",
maxTokens: 8192,
@@ -479,7 +478,6 @@ describe("webui API helpers", () => {
"settings.model_configuration.update",
{
name: "codex",
label: "Codex",
provider: "openai_codex",
model: "openai-codex/gpt-5.5",
max_tokens: 8192,
+17 -16
View File
@@ -89,7 +89,7 @@ async function togglePresetEditor(name = "primary") {
describe("Settings models", () => {
installSettingsViewTestHooks();
it("distinguishes the editable display name from the stable command name", async () => {
it("uses the preset name as the canonical identity", async () => {
const payload = settingsPayload();
payload.model_presets[0] = {
...payload.model_presets[0],
@@ -104,11 +104,10 @@ describe("Settings models", () => {
await togglePresetEditor("openai");
expect(screen.getByText("Display name")).toBeInTheDocument();
expect(
screen.getByText("Shown in the interface. The command name stays /model openai."),
).toBeInTheDocument();
expect(screen.getByDisplayValue("minimax")).toBeInTheDocument();
const editor = screen.getByTestId("model-preset-editor");
expect(within(editor).getByText("Preset name")).toBeInTheDocument();
expect(within(editor).getByText("openai")).toBeInTheDocument();
expect(within(editor).queryByText("minimax")).not.toBeInTheDocument();
});
it("keeps generation parameters collapsed until advanced options are opened", async () => {
@@ -188,7 +187,7 @@ describe("Settings models", () => {
"lg:max-w-6xl",
"rounded-floating",
);
expect(within(editor).getByDisplayValue("Primary")).toBeInTheDocument();
expect(within(editor).getByText("primary")).toBeInTheDocument();
const deleteButton = within(editor).getByRole("button", { name: "Delete" });
expect(deleteButton).toBeDisabled();
expect(deleteButton).toHaveAttribute("aria-describedby", "model-preset-delete-hint");
@@ -244,8 +243,9 @@ describe("Settings models", () => {
),
);
await togglePresetEditor();
fireEvent.change(screen.getByDisplayValue("Primary"), {
target: { value: "Primary draft" },
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
fireEvent.change(screen.getByLabelText("Temperature"), {
target: { value: "0.4" },
});
const primaryRow = screen.getByTestId("model-call-order-row-primary");
const backupRow = screen.getByTestId("model-call-order-row-backup");
@@ -270,7 +270,7 @@ describe("Settings models", () => {
});
expect(screen.queryByRole("button", { name: "Save order" })).not.toBeInTheDocument();
expect(screen.getByDisplayValue("Primary draft")).toBeInTheDocument();
expect(screen.getByLabelText("Temperature")).toHaveValue(0.4);
expect(screen.getByRole("button", { name: "Save preset" })).toBeEnabled();
});
@@ -430,7 +430,8 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models", initialSettings: payloadWithCodex });
const codexRow = await screen.findByTestId("model-call-order-row-codex");
expect(codexRow).toHaveTextContent("Codex");
expect(codexRow).toHaveTextContent("codex");
expect(codexRow).not.toHaveTextContent("Codex");
expect(codexRow).toHaveTextContent("openai-codex/gpt-5.5");
expect(codexRow).toHaveTextContent("Disabled");
expect(codexRow).toHaveAttribute("draggable", "false");
@@ -461,7 +462,7 @@ describe("Settings models", () => {
const { payload } = settingsPayloadWithBackup();
const writerPreset = {
...payload.model_presets[0],
name: "writer",
name: "Writer",
label: "Writer",
active: false,
model: "openai/gpt-4o-mini",
@@ -475,7 +476,7 @@ describe("Settings models", () => {
};
const orderedPayload: SettingsPayload = {
...createdPayload,
model_call_order: ["primary", "backup", "writer"],
model_call_order: ["primary", "backup", "Writer"],
created_model_preset: undefined,
};
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
@@ -528,15 +529,15 @@ describe("Settings models", () => {
await waitFor(() => {
expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_call_order.update",
{ order: ["primary", "backup", "writer"] },
{ order: ["primary", "backup", "Writer"] },
20_000,
);
});
const writerRow = await screen.findByTestId("model-call-order-row-writer");
const writerRow = await screen.findByTestId("model-call-order-row-Writer");
expect(writerRow).not.toHaveTextContent("Disabled");
expect(writerRow).not.toHaveTextContent(/Fallback/);
expect(within(writerRow).getByRole("switch", { name: "Disable preset" })).toBeChecked();
expect(screen.getByDisplayValue("Writer")).toBeInTheDocument();
expect(screen.getAllByText("Writer").length).toBeGreaterThan(0);
expect(screen.queryByRole("button", { name: "Save order" })).not.toBeInTheDocument();
});
+8 -8
View File
@@ -307,9 +307,9 @@ function ascii(bytes: Uint8Array, offset: number, length: number): string {
}
const MODEL_PRESETS = [
{ name: "kimi", label: "Kimi", provider: "moonshot" },
{ name: "dflash", label: "DFlash", provider: "deepseek" },
{ name: "dspro", label: "DS Pro", provider: "deepseek" },
{ name: "kimi", provider: "moonshot" },
{ name: "dflash", provider: "deepseek" },
{ name: "dspro", provider: "deepseek" },
];
function renderPresetComposer(variant: "thread" | "hero" = "thread") {
@@ -317,7 +317,7 @@ function renderPresetComposer(variant: "thread" | "hero" = "thread") {
render(
<ThreadComposer
onSend={vi.fn()}
modelLabel="Kimi"
modelLabel="kimi"
modelPreset="kimi"
modelProvider="moonshot"
modelPresets={MODEL_PRESETS}
@@ -327,7 +327,7 @@ function renderPresetComposer(variant: "thread" | "hero" = "thread") {
/>,
);
return {
badge: screen.getByRole("spinbutton", { name: "Kimi" }),
badge: screen.getByRole("spinbutton", { name: "kimi" }),
onPresetChange,
};
}
@@ -604,7 +604,7 @@ describe("ThreadComposer", () => {
expect(Array.from(pills).every((pill) => pill.querySelector("img"))).toBe(true);
expect(Array.from(badge.querySelectorAll("img")).every((image) => !image.draggable)).toBe(true);
const centeredPill = track.querySelector<HTMLElement>("[data-preset-offset='0']");
expect(centeredPill).toHaveTextContent("Kimi");
expect(centeredPill).toHaveTextContent("kimi");
expect(centeredPill).toHaveStyle({ transform: "scale(1.0800)" });
expect(
track.querySelector<HTMLElement>("[data-preset-offset='1']"),
@@ -615,13 +615,13 @@ describe("ThreadComposer", () => {
pointerId: 7,
pointerType: "mouse",
});
expect(track.querySelector("[data-preset-offset='0']")).toHaveTextContent("Kimi");
expect(track.querySelector("[data-preset-offset='0']")).toHaveTextContent("kimi");
fireEvent.pointerMove(badge, {
clientY: 123,
pointerId: 7,
pointerType: "mouse",
});
expect(track.querySelector("[data-preset-offset='0']")).toHaveTextContent("DS Pro");
expect(track.querySelector("[data-preset-offset='0']")).toHaveTextContent("dspro");
fireEvent.pointerUp(badge, {
clientY: 123,
pointerId: 7,
+7 -7
View File
@@ -609,7 +609,7 @@ describe("ThreadShell", () => {
),
);
expect(await screen.findByTitle("Fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
expect(await screen.findByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
expect(screen.queryByTitle("Default · deepseek-v4-pro · DeepSeek")).not.toBeInTheDocument();
});
@@ -645,19 +645,19 @@ describe("ThreadShell", () => {
"preset-order",
"/model fast",
);
expect(await screen.findByText("Fast")).toBeInTheDocument();
expect(await screen.findByText("fast")).toBeInTheDocument();
fireEvent.keyDown(
screen.getByRole("spinbutton", { name: "Fast" }),
screen.getByRole("spinbutton", { name: "fast" }),
{ key: "End" },
);
expect(client.sendSystemCommand).toHaveBeenLastCalledWith(
"preset-order",
"/model extra",
);
expect(await screen.findByText("Extra")).toBeInTheDocument();
expect(await screen.findByText("extra")).toBeInTheDocument();
rerender(view("fast"));
expect(await screen.findByText("Fast")).toBeInTheDocument();
expect(await screen.findByText("fast")).toBeInTheDocument();
});
it("uses the backend-resolved provider for an auto session preset", async () => {
@@ -692,7 +692,7 @@ describe("ThreadShell", () => {
),
);
expect(await screen.findByTitle("Fast · gpt-4 · Company Proxy")).toBeInTheDocument();
expect(await screen.findByTitle("fast · gpt-4 · Company Proxy")).toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Model not configured" })).not.toBeInTheDocument();
});
@@ -1070,7 +1070,7 @@ describe("ThreadShell", () => {
await screen.findByRole("spinbutton", { name: "Default" }),
{ key: "ArrowDown" },
);
expect(await screen.findByText("Fast")).toBeInTheDocument();
expect(await screen.findByText("fast")).toBeInTheDocument();
expect(client.sendSystemCommand).not.toHaveBeenCalled();
fireEvent.change(screen.getByLabelText("Message input"), {