fix(webui): route first-run model setup choices

This commit is contained in:
Xubin Ren committed 2026-09-02 16:25:07 +08:00
1 parent b47f0980f1
commit 9a4781982e
12 files changed
+329 -73

No files matched your search

+61
View File
@@ -481,6 +481,67 @@ describe("App layout", () => {
expect(screen.getByRole("heading", { level: 1, name: "Settings" })).toBeInTheDocument();
});
it("carries a first-run setup path into settings and restores composer focus", async () => {
const user = userEvent.setup();
const base = baseSettingsPayload();
mockFetchRoutes({
"/api/settings": {
...base,
agent: {
...base.agent,
model: "",
resolved_provider: "",
has_api_key: false,
model_preset: "",
},
model_presets: [],
model_call_order: [],
providers: [
{
name: "openai_codex",
label: "OpenAI Codex",
configured: false,
auth_type: "oauth",
},
{
name: "deepseek",
label: "DeepSeek",
configured: false,
auth_type: "api_key",
},
{
name: "ollama",
label: "Ollama",
configured: false,
api_base: "http://127.0.0.1:11434",
},
],
},
});
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
await user.click(await screen.findByRole("button", { name: "Choose your AI" }));
await user.click(await screen.findByRole("button", { name: "Run locally" }));
expect(
await screen.findByRole("navigation", { name: "Settings sections" }),
).toBeInTheDocument();
const providerMenu = await screen.findByRole("menu");
expect(within(providerMenu).getByRole("menuitem", { name: "Ollama" }))
.toBeInTheDocument();
expect(within(providerMenu).queryByRole("menuitem", { name: "OpenAI Codex" }))
.not.toBeInTheDocument();
expect(within(providerMenu).queryByRole("menuitem", { name: "DeepSeek" }))
.not.toBeInTheDocument();
const composer = screen.getByRole("textbox", { name: "Message input" });
expect(composer).not.toHaveFocus();
await user.click(screen.getByRole("button", { name: "Back to chat" }));
await waitFor(() => expect(composer).toHaveFocus());
});
it("places Automations after Skills in the main sidebar", async () => {
render(<App />);
@@ -14,6 +14,48 @@ async function chooseProviderToConfigure(label: string) {
describe("Settings providers", () => {
installSettingsViewTestHooks();
it.each([
["account", "OpenAI Codex", ["DeepSeek", "Ollama", "Custom provider"]],
["apiKey", "DeepSeek", ["OpenAI Codex", "Ollama"]],
["local", "Ollama", ["OpenAI Codex", "DeepSeek", "Custom provider"]],
] as const)("opens the %s first-run provider path", async (intent, expected, excluded) => {
const base = settingsPayload();
const payload: SettingsPayload = {
...base,
providers: [
{
name: "openai_codex",
label: "OpenAI Codex",
configured: false,
auth_type: "oauth",
},
{
name: "deepseek",
label: "DeepSeek",
configured: false,
auth_type: "api_key",
},
{
name: "ollama",
label: "Ollama",
configured: false,
api_base: "http://127.0.0.1:11434",
},
],
};
renderSettingsView({
initialSection: "models",
initialSettings: payload,
modelSetupIntent: intent,
});
const menu = await screen.findByRole("menu");
expect(within(menu).getByRole("menuitem", { name: expected })).toBeInTheDocument();
for (const label of excluded) {
expect(within(menu).queryByRole("menuitem", { name: label })).not.toBeInTheDocument();
}
});
it("signs in to the xAI Grok provider", async () => {
const base = settingsPayload();
+3
View File
@@ -3,6 +3,7 @@ import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, vi } from "vitest";
import { SettingsView } from "@/components/settings/SettingsView";
import { ClientProvider } from "@/providers/ClientProvider";
import type { ModelSetupIntent } from "@/lib/model-setup";
import type { SettingsPayload } from "@/lib/types";
export const requestMutationMock = vi.fn();
@@ -137,6 +138,7 @@ export function renderSettingsView(
| "browser"
| "runtime";
initialSettings?: SettingsPayload;
modelSetupIntent?: ModelSetupIntent;
showSidebar?: boolean;
onBackToChat?: () => void;
onSettingsChange?: (payload: SettingsPayload) => void;
@@ -149,6 +151,7 @@ export function renderSettingsView(
theme="light"
initialSection={options.initialSection ?? "apps"}
initialSettings={options.initialSettings}
modelSetupIntent={options.modelSetupIntent}
showSidebar={options.showSidebar}
onToggleTheme={() => {}}
onBackToChat={options.onBackToChat ?? (() => {})}
+28 -2
View File
@@ -887,6 +887,7 @@ describe("ThreadShell", () => {
fireEvent.click(screen.getByRole("button", { name: "Close" }));
const input = screen.getByRole("textbox", { name: "Message input" });
await waitFor(() => expect(input).toHaveFocus());
fireEvent.change(input, {
target: { value: "hello" },
});
@@ -896,12 +897,37 @@ describe("ThreadShell", () => {
expect(input).toHaveValue("hello");
fireEvent.click(screen.getByRole("button", { name: "Use an API key" }));
expect(onOpenModelSettings).toHaveBeenCalledTimes(1);
expect(onOpenModelSettings).toHaveBeenCalledWith("apiKey");
expect(input).toHaveValue("hello");
await waitFor(() => expect(input).toHaveFocus());
expect(input).not.toHaveFocus();
expect(client.sendMessage).not.toHaveBeenCalled();
});
it("focuses the composer when returning from model setup", async () => {
const client = makeClient();
const settings = modelSettings("openai-codex/gpt-5.1-codex", "openai_codex");
settings.agent.has_api_key = false;
const view = (focusComposerRequest: number) => wrap(
client,
<ThreadShell
session={session("setup-focus")}
title="Setup focus"
onToggleSidebar={() => {}}
settingsSnapshot={settings}
focusComposerRequest={focusComposerRequest}
/>,
"openai-codex/gpt-5.1-codex",
);
const { rerender } = render(view(0));
const input = await screen.findByRole("textbox", { name: "Message input" });
input.blur();
expect(input).not.toHaveFocus();
rerender(view(1));
await waitFor(() => expect(input).toHaveFocus());
});
it("keeps image generation controls out of the composer", async () => {
const client = makeClient();
const disabledSettings = modelSettings("deepseek-v4-pro", "deepseek");