feat(webui): improve model and provider settings UX (#6145)

* feat(webui): improve model and provider settings UX

* refactor(webui): organize provider forms and model picker interactions

* fix(webui): separate OAuth credentials from provider configuration

* fix(webui): stabilize shared combobox navigation

* refactor(config): store provider connections as sparse entries

* fix(webui): preserve provider validation and isolate catalog tests

* refactor(config): manage explicit provider connections

* refactor(webui): decouple settings UX from provider removal

* fix(webui): select current combobox options during rapid input

* feat(webui): refine model preset and provider management

* style(webui): refine preset footer actions

* fix(webui): align model settings with responsive layout rules

* refactor(webui): finalize preset dialogs and simplify provider state

* fix(webui): keep fallback heading stable while sorting presets

Animate card dimensions without changing layout height and keep the section heading outside sortable cards. Remove proxy normalization from this PR.

* docs: update WebUI model and provider setup instructions

* docs: start model setup from new preset

* docs: remove duplicate WebUI model setup instructions
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-11 04:30:43 +08:00
1 parent 8080ea843a
commit 9261e731ce
88 files changed
+2854 -1734

No files matched your search

+327 -82
View File
@@ -86,6 +86,31 @@ async function togglePresetEditor(name = "primary") {
fireEvent.click(within(row).getAllByRole("button")[0]);
}
function mockPresetRowLayout() {
let top = 100;
return screen.getAllByTestId(/^model-call-order-row-/).map((row, index) => {
const rect = DOMRect.fromRect({ x: 0, y: top, width: 800, height: index === 0 ? 240 : 80 });
vi.spyOn(row.closest('[role="listitem"]')!, "getBoundingClientRect").mockReturnValue(rect);
top += rect.height + (index === 0 ? 72 : 8);
return rect.top + rect.height / 2;
});
}
async function openModelPicker() {
const input = await screen.findByRole("combobox", { name: "Select model" });
await openPopover(input);
return input;
}
function returnToPresetEditor() {
const advanced = screen.queryByRole("dialog", { name: "Advanced options", exact: true });
if (advanced) fireEvent.click(within(advanced).getByRole("button", { name: "Close", exact: true }));
}
function presetSaveButton() {
return within(screen.getByTestId("model-preset-editor")).getByRole("button", { name: "Save", hidden: true });
}
async function openPresetAdvancedOptions() {
await togglePresetEditor();
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
@@ -120,35 +145,38 @@ describe("Settings models", () => {
expect(screen.getAllByRole("option")).toHaveLength(3);
fireEvent.click(screen.getByRole("option", { name: "Responses" }));
expect(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).not.toBeChecked();
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update",
{ name: "primary", api: { supported_apis: ["responses"], preferred_api: "responses" } },
20_000,
));
await waitFor(() => expect(screen.getByRole("button", { name: "Save" })).toBeDisabled());
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
await openPresetAdvancedOptions();
expect(screen.getByLabelText("API connection")).toHaveTextContent("Responses");
fireEvent.click(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" }));
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update",
{ name: "primary", api: { supported_apis: ["responses", "chat_completions"], preferred_api: "responses" } },
20_000,
));
await waitFor(() => expect(screen.getByRole("button", { name: "Save" })).toBeDisabled());
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
await openPresetAdvancedOptions();
expect(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).toBeChecked();
await openPopover(screen.getByLabelText("API connection"));
fireEvent.click(screen.getByRole("option", { name: "Responses" }));
expect(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).toBeChecked();
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
await openPopover(screen.getByLabelText("API connection"));
fireEvent.click(screen.getByRole("option", { name: "Auto" }));
expect(screen.queryByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update", { name: "primary", api: null }, 20_000,
));
@@ -178,17 +206,18 @@ describe("Settings models", () => {
expect(screen.getAllByRole("option")).toHaveLength(4);
fireEvent.click(screen.getByRole("option", { name: "Anthropic Messages" }));
expect(screen.queryByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update",
{ name: "primary", api: { supported_apis: ["anthropic_messages"], preferred_api: "anthropic_messages" } },
20_000,
));
await waitFor(() => expect(screen.getByRole("button", { name: "Save" })).toBeDisabled());
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
await openPresetAdvancedOptions();
expect(screen.getByLabelText("API connection")).toHaveTextContent("Anthropic Messages");
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
await openPopover(screen.getByLabelText("API connection"));
fireEvent.click(screen.getByRole("option", { name: "Responses" }));
expect(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).not.toBeChecked();
@@ -215,14 +244,16 @@ describe("Settings models", () => {
requestMutationMock.mockResolvedValue(payload);
renderSettingsView({ initialSection: "models", initialSettings: payload });
await openPresetAdvancedOptions();
await openPopover(screen.getByRole("button", { name: "anthropic/claude-sonnet-4", exact: true }));
const search = screen.getByRole("combobox", { name: "Choose model" });
returnToPresetEditor();
const search = await openModelPicker();
fireEvent.change(search, { target: { value: "gpt-4o" } });
fireEvent.keyDown(search, { key: "Enter" });
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
await waitFor(() => expect(screen.getByLabelText("API connection")).toHaveTextContent("Auto (Chat Completions)"));
await openPopover(screen.getByLabelText("API connection"));
fireEvent.click(screen.getByRole("option", { name: "Responses" }));
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.update", {
name: "primary", model: "gpt-4o",
@@ -251,13 +282,17 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await openPresetAdvancedOptions();
await waitFor(() => expect(screen.getByLabelText("API connection")).toHaveTextContent("Auto (Chat Completions)"));
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
await openPopover(screen.getByLabelText("API connection"));
expect(screen.getByRole("option", { name: "Auto (Chat Completions)" })).toHaveAttribute("aria-selected", "true");
fireEvent.click(screen.getByRole("option", { name: "Auto (Chat Completions)" }));
returnToPresetEditor();
fireEvent.change(screen.getByLabelText("Reasoning effort"), { target: { value: "high" } });
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
await waitFor(() => expect(fetchMock.mock.calls.some(([url]) => String(url).includes("reasoning_effort=high"))).toBe(true));
returnToPresetEditor();
fireEvent.change(screen.getByLabelText("Reasoning effort"), { target: { value: "none" } });
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
await waitFor(() => expect(fetchMock.mock.calls.some(([url]) => String(url).includes("reasoning_effort=none"))).toBe(true));
await waitFor(() => expect(screen.getByLabelText("API connection")).toHaveTextContent("Auto (Chat Completions)"));
await act(async () => { finishHigh(jsonResponse({ provider: "openai", api: "responses" })); });
@@ -283,9 +318,12 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await openPresetAdvancedOptions();
await waitFor(() => expect(screen.getByLabelText("API connection")).toHaveTextContent("Auto (Chat Completions)"));
returnToPresetEditor();
fireEvent.change(screen.getByLabelText("Reasoning effort"), { target: { value: "high" } });
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
await waitFor(() => expect(screen.getByLabelText("API connection")).toHaveTextContent("Auto (Responses)"));
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.update", { name: "primary", reasoning_effort: "high" }, 20_000,
));
@@ -306,7 +344,7 @@ describe("Settings models", () => {
await waitFor(() => expect(fetchMock.mock.calls.some(([url]) => String(url).includes("/model-api?"))).toBe(true));
await act(async () => { await Promise.resolve(); });
expect(screen.getByLabelText("API connection")).toHaveTextContent(/^Auto$/);
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
});
it.each([undefined, ["future_api"], ["future_api", "future_api_v2"], "responses"])("hides API controls when host support is unconfirmed (%s)", async (requestAPIs) => {
@@ -335,9 +373,10 @@ describe("Settings models", () => {
await togglePresetEditor();
expect(screen.queryByRole("combobox", { name: "API connection" })).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: /Advanced options/ })).toHaveAttribute("aria-expanded", "false");
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
fireEvent.change(screen.getByLabelText("Preset name"), { target: { value: "Renamed" } });
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.update", { name: "primary", new_name: "Renamed" }, 20_000,
));
@@ -358,7 +397,7 @@ describe("Settings models", () => {
expect(screen.getByText(apiLabel, { exact: true })).toBeVisible();
expect(screen.queryByRole("combobox", { name: "API connection" })).not.toBeInTheDocument();
expect(screen.queryByRole("switch")).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
});
it.each(["manual", "poll", "direct"])("reauthenticates from the catalog and preserves the preset draft (%s)", async (mode) => {
@@ -400,7 +439,7 @@ describe("Settings models", () => {
fireEvent.change(screen.getByRole("textbox", { name: "Preset name" }), {
target: { value: "My unsaved preset" },
});
await openPopover(screen.getByRole("button", { name: "Select model" }));
await openModelPicker();
fireEvent.click(await screen.findByRole("button", { name: "Sign in again" }));
if (mode === "manual") {
fireEvent.change(await screen.findByRole("textbox", { name: "Callback URL" }), {
@@ -410,7 +449,7 @@ describe("Settings models", () => {
}
await waitFor(() => expect(recovered).toBe(true), { timeout: 3000 });
expect(screen.getByRole("textbox", { name: "Preset name" })).toHaveValue("My unsaved preset");
await openPopover(screen.getByRole("button", { name: "Select model" }));
await openModelPicker();
expect(await screen.findByRole("option", { name: /openai-codex\/new-model/ })).toBeVisible();
expect(screen.queryByText("Authorization expired. Please sign in again.")).not.toBeInTheDocument();
expect(requestMutationMock.mock.calls.every(([action]) => action.startsWith("settings.provider.oauth_"))).toBe(true);
@@ -467,7 +506,8 @@ describe("Settings models", () => {
fireEvent.change(screen.getByLabelText("Temperature"), {
target: { value: "0.4" },
});
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => {
expect(requestMutationMock).toHaveBeenCalledWith(
@@ -498,7 +538,8 @@ describe("Settings models", () => {
const nameInput = screen.getByRole("textbox", { name: "Preset name" });
fireEvent.change(nameInput, { target: { value: "Codex" } });
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => {
expect(requestMutationMock).toHaveBeenCalledWith(
@@ -521,7 +562,8 @@ describe("Settings models", () => {
const nameInput = screen.getByRole("textbox", { name: "Preset name" });
fireEvent.change(nameInput, { target: { value: "Codex" } });
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
expect(await screen.findByRole("alert")).toHaveTextContent(
"A preset with this name already exists.",
@@ -530,7 +572,7 @@ describe("Settings models", () => {
expect(nameInput).toHaveFocus();
});
it("keeps generation parameters collapsed until advanced options are opened", async () => {
it("opens generation parameters in the advanced options dialog", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async (input: RequestInfo | URL) => {
@@ -553,16 +595,17 @@ describe("Settings models", () => {
fireEvent.click(advanced);
expect(await screen.findByText("Context window")).toBeInTheDocument();
expect(within(screen.getByRole("dialog", { name: "Advanced options", exact: true })).getByText("Context window")).toBeInTheDocument();
expect(screen.getByText("Temperature")).toBeInTheDocument();
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue("200k");
returnToPresetEditor();
const reasoningEffort = screen.getByLabelText("Reasoning effort");
expect(reasoningEffort).toHaveProperty("type", "text");
fireEvent.change(reasoningEffort, { target: { value: "provider-native-mode" } });
expect(reasoningEffort).toHaveValue("provider-native-mode");
});
it.each([["128000", 128000], ["131072", 131072], ["272k", 272000], ["256K", 256000], ["1.5m", 1500000], ["1.001k", 1001]] as const)("saves a custom context budget (%s)", async (input, tokens) => {
it.each([["128000", 128000, "128k"], ["131072", 131072, "131072"], ["272k", 272000, "272k"], ["256K", 256000, "256k"], ["1.5m", 1500000, "1500k"], ["1.001k", 1001, "1001"]] as const)("saves a custom context budget (%s)", async (input, tokens, restored) => {
const payload = settingsPayload();
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
requestMutationMock.mockResolvedValue({
@@ -575,11 +618,13 @@ describe("Settings models", () => {
fireEvent.change(screen.getByRole("textbox", { name: "Context window" }), {
target: { value: input },
});
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.update", expect.objectContaining({ context_window_tokens: tokens }), expect.any(Number),
));
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue(input);
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue(restored);
});
it.each(["", "0", "-1", "1.5", "abc", "2ki", "0.0001k", "9007199254740992"])("keeps invalid context input unsaved (%s)", async (value) => {
@@ -589,12 +634,50 @@ describe("Settings models", () => {
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
const input = screen.getByRole("textbox", { name: "Context window" });
fireEvent.change(input, { target: { value } });
fireEvent.click(screen.getByRole("button", { name: "Save" }));
expect(input).toHaveAttribute("aria-invalid", "true");
expect(input).toHaveAccessibleDescription("Enter a positive token count, such as 200k, 1m, or 131072.");
await new Promise((resolve) => setTimeout(resolve, 750));
expect(requestMutationMock).not.toHaveBeenCalled();
expect(input).toHaveValue(value);
returnToPresetEditor();
expect(presetSaveButton()).toBeDisabled();
});
it("saves abbreviated output budgets as integers and keeps an incomplete input unsaved", async () => {
let payload = settingsPayload();
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
requestMutationMock.mockImplementation(async (_action, args) => {
payload = {
...payload,
model_presets: payload.model_presets.map((preset) => ({ ...preset, max_tokens: args.max_tokens })),
};
return payload;
});
renderSettingsView({ initialSection: "models", initialSettings: payload });
await openPresetAdvancedOptions();
let input = screen.getByRole("textbox", { name: "Max output tokens" });
fireEvent.change(input, { target: { value: "32K" } });
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update", expect.objectContaining({ max_tokens: 32000 }), expect.any(Number),
));
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
input = screen.getByRole("textbox", { name: "Max output tokens" });
expect(input).toHaveValue("32k");
requestMutationMock.mockClear();
fireEvent.change(input, { target: { value: "" } });
expect(input).toHaveAttribute("aria-invalid", "true");
expect(presetSaveButton()).toBeDisabled();
await new Promise((resolve) => setTimeout(resolve, 750));
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.change(input, { target: { value: "8.192k" } });
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_configuration.update", expect.objectContaining({ max_tokens: 8192 }), expect.any(Number),
));
});
it("opens the preset editor in a dialog and protects the primary preset", async () => {
@@ -633,13 +716,75 @@ describe("Settings models", () => {
expect(deleteButton).toBeDisabled();
expect(deleteButton).toHaveAttribute("aria-describedby", "model-preset-delete-hint");
expect(
within(editor).getByText("Choose another primary preset before deleting this one."),
within(editor).getByText("Cannot delete the primary model"),
).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
});
it("drags model presets to reorder and saves the model call order immediately", async () => {
it("opens advanced options in a separate dialog and preserves the preset draft", async () => {
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
await togglePresetEditor();
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
const advanced = screen.getByRole("dialog", { name: "Advanced options", exact: true });
fireEvent.change(within(advanced).getByLabelText("Context window"), { target: { value: "128k" } });
fireEvent.click(within(advanced).getByRole("button", { name: "Close", exact: true }));
expect(screen.queryByRole("dialog", { name: "Advanced options", exact: true })).not.toBeInTheDocument();
expect(screen.getByTestId("model-preset-editor")).toBeVisible();
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
expect(within(screen.getByRole("dialog", { name: "Advanced options", exact: true })).getByLabelText("Context window")).toHaveValue("128k");
});
it.each([true, false])("closes the preset editor only after deletion succeeds (success: %s)", async (success) => {
const { payload } = settingsPayloadWithBackup();
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
if (success) requestMutationMock.mockResolvedValueOnce({
...payload,
model_presets: payload.model_presets.filter((preset) => preset.name !== "backup"),
model_call_order: ["primary"],
});
else requestMutationMock.mockRejectedValueOnce(new Error("Delete failed"));
renderSettingsView({ initialSection: "models", initialSettings: payload });
fireEvent.click(within(screen.getByTestId("model-call-order-row-backup")).getByRole("button", { name: "Configure", exact: true }));
fireEvent.click(within(screen.getByTestId("model-preset-editor")).getByRole("button", { name: "Delete", exact: true }));
const confirmation = screen.getByRole("dialog", { name: "Delete model preset?" });
fireEvent.click(within(confirmation).getByRole("button", { name: "Delete", exact: true }));
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.delete", { name: "backup" }, 20_000,
));
if (success) {
await waitFor(() => expect(screen.queryByTestId("model-preset-editor")).not.toBeInTheDocument());
expect(screen.queryByTestId("model-call-order-row-backup")).not.toBeInTheDocument();
} else {
await waitFor(() => expect(within(confirmation).getByRole("button", { name: "Delete", exact: true })).toBeEnabled());
expect(screen.getByTestId("model-preset-editor")).toBeInTheDocument();
}
});
it.each([true, false])("shows a saved primary summary inside the shared settings layout (sidebar: %s)", async (showSidebar) => {
const payload = settingsPayload();
payload.model_presets[0].context_window_tokens = 262_144;
payload.model_presets[0].max_tokens = 32_768;
renderSettingsView({ initialSection: "models", initialSettings: payload, showSidebar });
expect(screen.queryAllByRole("heading", { name: "Models", exact: true })).toHaveLength(showSidebar ? 0 : 1);
expect(screen.getByRole("heading", { name: "Model presets", exact: true })).toHaveClass("settings-section-title");
expect(screen.queryByRole("heading", { name: "Fallback presets" })).not.toBeInTheDocument();
const summary = within(screen.getByTestId("model-call-order-row-primary"));
expect(summary.getByText(`${payload.model_presets[0].model} 256K Default`)).toBeInTheDocument();
await togglePresetEditor();
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
fireEvent.change(screen.getByLabelText("Context window"), { target: { value: "128k" } });
expect(summary.getByText(`${payload.model_presets[0].model} 256K Default`)).toBeInTheDocument();
});
it.each([
["backup", 1, 0],
["primary", 0, 1],
] as const)("drags %s across different row heights and saves the model call order immediately", async (name, from, to) => {
const { payload, backupPreset } = settingsPayloadWithBackup();
const updatedPayload: SettingsPayload = {
...payload,
@@ -686,11 +831,15 @@ describe("Settings models", () => {
target: { value: "0.4" },
});
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
const backupRow = screen.getByTestId("model-call-order-row-backup");
fireEvent.pointerDown(backupRow, { button: 0, clientY: 100, pointerId: 1 });
fireEvent.pointerMove(backupRow, { clientY: 40, pointerId: 1, buttons: 1 });
fireEvent.pointerUp(backupRow, { pointerId: 1 });
fireEvent.click(backupRow);
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
const centers = mockPresetRowLayout();
const draggedRow = screen.getByTestId(`model-call-order-row-${name}`);
fireEvent.pointerDown(draggedRow, { button: 0, clientY: centers[from], pointerId: 1 });
fireEvent.pointerMove(draggedRow, { clientY: centers[to] + (to > from ? 1 : -1), pointerId: 1, buttons: 1 });
expect(within(screen.getByTestId("model-call-order-row-backup")).getByText("Primary")).toBeInTheDocument();
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.pointerUp(draggedRow, { pointerId: 1 });
fireEvent.click(draggedRow);
await waitFor(() => {
expect(requestMutationMock).toHaveBeenCalledWith(
@@ -700,10 +849,49 @@ describe("Settings models", () => {
);
});
fireEvent.click(within(screen.getByTestId("model-call-order-row-primary")).getByRole("button"));
const newPrimary = screen.getByTestId("model-call-order-row-backup");
expect(within(newPrimary).getByText("Primary")).toBeInTheDocument();
expect(within(newPrimary).getByText(`${backupPreset.model} 200K Default`)).toBeInTheDocument();
fireEvent.click(within(screen.getByTestId("model-call-order-row-primary")).getByRole("button", { name: "Configure", exact: true }));
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
expect(screen.getByLabelText("Temperature")).toHaveValue(0.4);
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
expect(presetSaveButton()).toBeEnabled();
});
it("allows the next switch click when a drag ends without a click event", async () => {
const { payload } = settingsPayloadWithBackup();
requestMutationMock
.mockResolvedValueOnce({ ...payload, model_call_order: ["backup", "primary"] })
.mockResolvedValueOnce({ ...payload, model_call_order: ["backup"] });
renderSettingsView({ initialSection: "models", initialSettings: payload });
const centers = mockPresetRowLayout();
const backupRow = screen.getByTestId("model-call-order-row-backup");
fireEvent.pointerDown(backupRow, { button: 0, clientY: centers[1], pointerId: 1 });
fireEvent.pointerMove(backupRow, { clientY: centers[0], pointerId: 1, buttons: 1 });
fireEvent.pointerUp(backupRow, { pointerId: 1 });
await waitFor(() => expect(within(backupRow).getByText("Primary")).toBeInTheDocument());
const toggle = within(screen.getByTestId("model-call-order-row-primary")).getByRole("switch");
await waitFor(() => expect(toggle).toBeEnabled());
fireEvent.pointerDown(toggle, { button: 0, pointerId: 1 });
fireEvent.pointerUp(toggle, { pointerId: 1 });
fireEvent.click(toggle);
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
"settings.model_call_order.update", { order: ["backup"] }, 20_000,
));
});
it("restores the primary preview without saving when a pointer drag is cancelled", async () => {
const { payload } = settingsPayloadWithBackup();
renderSettingsView({ initialSection: "models", initialSettings: payload });
const centers = mockPresetRowLayout();
const backupRow = screen.getByTestId("model-call-order-row-backup");
fireEvent.pointerDown(backupRow, { button: 0, clientY: centers[1], pointerId: 1 });
fireEvent.pointerMove(backupRow, { clientY: centers[0] - 1, pointerId: 1, buttons: 1 });
expect(within(backupRow).getByText("Primary")).toBeInTheDocument();
fireEvent.pointerCancel(backupRow, { pointerId: 1 });
expect(within(screen.getByTestId("model-call-order-row-primary")).getByText("Primary")).toBeInTheDocument();
expect(requestMutationMock).not.toHaveBeenCalled();
});
it("keeps repeated fallback preset rows stable when changing the primary preset", async () => {
@@ -761,8 +949,9 @@ describe("Settings models", () => {
expect(screen.getByRole("button", { name: "Delete", exact: true })).toBeDisabled();
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
fireEvent.pointerDown(primaryRow, { button: 0, clientY: 100, pointerId: 1 });
fireEvent.pointerMove(primaryRow, { clientY: 40, pointerId: 1, buttons: 1 });
const centers = mockPresetRowLayout();
fireEvent.pointerDown(primaryRow, { button: 0, clientY: centers[1], pointerId: 1 });
fireEvent.pointerMove(primaryRow, { clientY: centers[0], pointerId: 1, buttons: 1 });
fireEvent.pointerUp(primaryRow, { pointerId: 1 });
await waitFor(() =>
@@ -936,19 +1125,16 @@ describe("Settings models", () => {
);
fireEvent.click(screen.getByRole("button", { name: "New preset" }));
expect(screen.getByRole("dialog", { name: "New preset" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
expect(presetSaveButton()).toBeDisabled();
fireEvent.change(screen.getByRole("textbox", { name: "Preset name" }), {
target: { value: "Writer" },
});
await openPopover(screen.getByRole("button", { name: "Select model" }));
const modelSearch = await screen.findByRole("combobox", {
name: "Choose model",
});
const modelSearch = await openModelPicker();
fireEvent.change(modelSearch, {
target: { value: "openai/gpt-4o-mini" },
});
fireEvent.keyDown(modelSearch, { key: "Enter" });
const saveButton = screen.getByRole("button", { name: "Save" });
const saveButton = presetSaveButton();
expect(saveButton).toBeEnabled();
fireEvent.click(saveButton);
@@ -977,13 +1163,11 @@ describe("Settings models", () => {
fireEvent.click(screen.getByRole("button", { name: "New preset" }));
const nameInput = screen.getByRole("textbox", { name: "Preset name" });
fireEvent.change(nameInput, { target: { value: "PRIMARY" } });
await openPopover(screen.getByRole("button", { name: "Select model" }));
const modelSearch = await screen.findByRole("combobox", {
name: "Choose model",
});
const modelSearch = await openModelPicker();
fireEvent.change(modelSearch, { target: { value: "openai/gpt-4o-mini" } });
fireEvent.keyDown(modelSearch, { key: "Enter" });
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
expect(requestMutationMock).not.toHaveBeenCalled();
expect(nameInput).toHaveAttribute("aria-invalid", "true");
@@ -1170,6 +1354,10 @@ describe("Settings models", () => {
],
model_call_order: [],
model_call_order_editable: false,
providers: [{
name: "openai", label: "openai", configured: true,
api_key_required: true, api_key_hint: "sk-...",
}],
};
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
@@ -1192,7 +1380,9 @@ describe("Settings models", () => {
}),
});
expect(screen.getAllByText("Company Proxy").length).toBeGreaterThan(0);
expect(screen.queryByText("Provider setup required")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Manage providers" }));
expect(screen.getByRole("button", { name: "Company Proxy" })).toBeInTheDocument();
});
it("does not treat auto dynamic provider api keys as configured without apiBase", async () => {
@@ -1344,7 +1534,9 @@ describe("Settings models", () => {
const providerPicker = await screen.findByRole("combobox", { name: /DeepSeek/ });
fireEvent.keyDown(providerPicker, { key: "ArrowDown" });
expect(await screen.findByRole("option", { name: /DeepSeek/ })).toBeInTheDocument();
expect(await screen.findByRole("option", { name: "DeepSeek", exact: true })).toBeInTheDocument();
expect(screen.queryByRole("option", { name: "OpenAI Codex", exact: true })).not.toBeInTheDocument();
expect(screen.queryByRole("option", { name: "GitHub Copilot", exact: true })).not.toBeInTheDocument();
});
it("does not fetch model lists for unsigned OAuth providers", async () => {
@@ -1408,7 +1600,7 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await togglePresetEditor();
await openPopover(await screen.findByRole("button", { name: /Select model/i }));
await openModelPicker();
expect(
await screen.findByText("Configure this provider before loading models."),
).toBeInTheDocument();
@@ -1467,10 +1659,8 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await togglePresetEditor();
const modelButtons = await screen.findAllByRole("button", { name: /open-codex\/gpt-5\.5/i });
await openPopover(modelButtons[modelButtons.length - 1]);
const input = (await screen.findByPlaceholderText("Choose model")) as HTMLInputElement;
expect(input.value).toBe("open-codex/gpt-5.5");
const input = await openModelPicker();
expect(input).toHaveValue("open-codex/gpt-5.5");
fireEvent.change(input, { target: { value: "openai-codex/gpt-5.5" } });
expect(await screen.findByText("“openai-codex/gpt-5.5”")).toBeInTheDocument();
@@ -1543,8 +1733,7 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await togglePresetEditor();
const modelButtons = await screen.findAllByRole("button", { name: /orcarouter\/auto/i });
await openPopover(modelButtons[modelButtons.length - 1]);
await openModelPicker();
expect(await screen.findByText("Search this provider’s model catalog.")).toBeInTheDocument();
expect(
fetchMock.mock.calls.some(([input]) =>
@@ -1627,10 +1816,7 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models", initialSettings: payload });
await togglePresetEditor();
const modelButtons = await screen.findAllByRole("button", {
name: /openai-codex\/gpt-5\.5/i,
});
await openPopover(modelButtons[modelButtons.length - 1]);
await openModelPicker();
expect(await screen.findByText("GPT-5.6-Sol")).toBeInTheDocument();
expect(screen.getByText(/Latest frontier agentic coding model\./)).toBeInTheDocument();
@@ -1709,10 +1895,7 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models", initialSettings: payload });
await togglePresetEditor();
const modelButtons = await screen.findAllByRole("button", {
name: /xai-grok\/grok-4\.5/i,
});
await openPopover(modelButtons[modelButtons.length - 1]);
const modelInput = await openModelPicker();
expect(await screen.findByText("Grok 4.6")).toBeInTheDocument();
expect(screen.getByText(/Latest frontier model/)).toBeInTheDocument();
@@ -1721,7 +1904,7 @@ describe("Settings models", () => {
expect.objectContaining({ headers: { Authorization: "Bearer tok" } }),
);
fireEvent.keyDown(document.activeElement!, { key: "Escape" });
await waitFor(() => expect(modelButtons[modelButtons.length - 1]).toHaveFocus());
await waitFor(() => expect(modelInput).toHaveFocus());
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
await waitFor(() => expect(within(screen.getByTestId("model-call-order-row-primary")).getAllByRole("button")[0]).toBeVisible());
});
@@ -1748,7 +1931,6 @@ describe("Settings models", () => {
const createButton = await screen.findByRole("button", { name: "New preset" });
const previousPointerEvents = document.body.style.pointerEvents;
expect(createButton).toHaveClass("w-full");
fireEvent.click(createButton);
expect(screen.getByRole("dialog", { name: "New preset" })).toBeInTheDocument();
@@ -1756,35 +1938,97 @@ describe("Settings models", () => {
expect(screen.getByRole("textbox", { name: "Preset name" })).toHaveValue("");
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
expect(screen.getByText("Temperature")).toBeInTheDocument();
returnToPresetEditor();
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
await waitFor(() => expect(document.body.style.pointerEvents).toBe(previousPointerEvents));
await waitFor(() => expect(createButton).toHaveFocus());
fireEvent.click(screen.getByRole("button", { name: "New preset" }));
const nameInput = await screen.findByRole("textbox", { name: "Preset name" });
expect(nameInput).toHaveValue("");
expect(nameInput).toHaveAttribute("placeholder", "e.g. Fast writing");
await openPopover(screen.getByRole("button", { name: "Select model" }));
const modelSearch = await screen.findByRole("combobox", {
name: "Choose model",
});
const modelSearch = await openModelPicker();
fireEvent.change(modelSearch, { target: { value: "openai/gpt-4o-mini" } });
fireEvent.keyDown(modelSearch, { key: "Enter" });
expect(nameInput).toHaveValue("gpt-4o-mini");
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
expect(presetSaveButton()).toBeEnabled();
fireEvent.change(nameInput, { target: { value: "Writer" } });
await openPopover(screen.getByRole("button", { name: /openai\/gpt-4o-mini/ }));
const nextModelSearch = await screen.findByRole("combobox", {
name: "Choose model",
});
const nextModelSearch = await openModelPicker();
fireEvent.change(nextModelSearch, { target: { value: "openai/gpt-4.1-mini" } });
fireEvent.keyDown(nextModelSearch, { key: "Enter" });
expect(nameInput).toHaveValue("Writer");
});
it.each([
{ context: 1_000_000, manual: undefined, expected: "1m" },
{ context: 1_000_000, manual: "256k", expected: "256k" },
{ context: null, manual: undefined, expected: "200k" },
])("initializes new preset context from the selected model while preserving overrides ($expected)", async ({ context, manual, expected }) => {
const payload = settingsPayload();
payload.model_presets[0].provider = "openai";
payload.model_presets[0].context_window_tokens = 200_000;
payload.providers = [{ name: "openai", label: "OpenAI", configured: true }];
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings") return new Promise<Response>(() => {});
if (url.includes("/provider-models?")) return jsonResponse({
provider: "openai", status: "available", catalog_kind: "official",
models: [{ id: "catalog-model", context_window: context, reasoning_efforts: ["low", "high"] }], model_count: 1,
});
return jsonResponse(payload);
}));
requestMutationMock.mockResolvedValue(payload);
renderSettingsView({ initialSection: "models", initialSettings: payload });
fireEvent.click(screen.getByRole("button", { name: "New preset" }));
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
if (manual) fireEvent.change(screen.getByRole("textbox", { name: "Context window" }), { target: { value: manual } });
returnToPresetEditor();
await openModelPicker();
fireEvent.click(await screen.findByRole("option", { name: /catalog-model/ }));
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
await waitFor(() => expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue(expected));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.create", expect.objectContaining({ context_window_tokens: manual ? 256000 : context ?? 200000 }), expect.any(Number),
));
});
it("offers model-specific reasoning levels and retains manual values", async () => {
const payload = settingsPayload();
payload.model_presets[0].provider = "openai";
payload.model_presets[0].reasoning_effort = "high";
payload.providers = [{ name: "openai", label: "OpenAI", configured: true }];
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => String(input).includes("/provider-models?")
? jsonResponse({ provider: "openai", status: "available", catalog_kind: "official", models: [
{ id: payload.model_presets[0].model, reasoning_efforts: ["low", "high"] },
{ id: "another-model", reasoning_efforts: ["ultra"] },
], model_count: 2 }) : jsonResponse(payload)));
requestMutationMock.mockResolvedValue(payload);
renderSettingsView({ initialSection: "models", initialSettings: payload });
await togglePresetEditor();
const input = screen.getByRole("combobox", { name: "Reasoning effort" });
fireEvent.click(input);
fireEvent.click(await screen.findByRole("option", { name: "low", exact: true }));
await waitFor(() => expect(input).toHaveValue("low"));
fireEvent.click(input);
expect(screen.queryByRole("option", { name: "ultra", exact: true })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("option", { name: "Default", exact: true }));
await waitFor(() => expect(input).toHaveValue(""));
fireEvent.click(input);
fireEvent.change(input, { target: { value: "provider-native-mode" } });
fireEvent.keyDown(input, { key: "Enter" });
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.model_configuration.update", expect.objectContaining({ reasoning_effort: "provider-native-mode" }), expect.any(Number),
));
});
it("loads provider models and lets users choose one without typing the id manually", async () => {
const payload: SettingsPayload = {
...settingsPayload(),
@@ -1861,18 +2105,19 @@ describe("Settings models", () => {
renderSettingsView({ initialSection: "models" });
await togglePresetEditor();
const modelButtons = await screen.findAllByRole("button", { name: /deepseek-chat/i });
await openPopover(modelButtons[modelButtons.length - 1]);
await openModelPicker();
await screen.findByText("deepseek-reasoner");
fireEvent.click(screen.getAllByText("deepseek-reasoner")[0]);
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
fireEvent.change(screen.getByLabelText("Temperature"), {
target: { value: "0.4" },
});
returnToPresetEditor();
fireEvent.change(screen.getByLabelText("Reasoning effort"), {
target: { value: "provider-native-mode" },
});
fireEvent.click(screen.getByRole("button", { name: "Save" }));
returnToPresetEditor();
fireEvent.click(presetSaveButton());
await waitFor(() =>
expect(fetchMock).toHaveBeenCalledWith(