Skip to content
Python

Settings error line: i18n, fetch timeout, tests

Rohit C Prasadd6178ab27089
diff --git a/surfaces/gui/e2e/settings.spec.ts b/surfaces/gui/e2e/settings.spec.ts
index 7451fcb4..008c38c4 100644
--- a/surfaces/gui/e2e/settings.spec.ts
+++ b/surfaces/gui/e2e/settings.spec.ts
@@ -26,17 +26,30 @@ test("Settings opens as a full page and navigates sections", async ({ page }) =>
await expect(page.getByTestId("set-provider-openai")).toBeVisible();
});
-test("Models explains when the agent server cannot be reached", async ({ page }) => {
+// #43: when /v1/settings fails (server down, or hung past the 10 s timeout) Models says so
+// and offers Retry instead of "Loading…" forever; Retry reloads once the server answers.
+test("Models explains when the server cannot be reached, and Retry recovers", async ({ page }) => {
await page.goto("/");
await page.getByTestId("account-row").click();
await page.getByRole("button", { name: "Settings", exact: true }).click();
- await page.route("**/v1/settings", (route) => route.abort("failed"));
+ // Later routes win over the fixture's catch-all: fail GET /v1/settings until "the server
+ // comes back"; every other call keeps its fixture answer.
+ let serverDown = true;
+ await page.route("**/v1/settings", async (route) => {
+ if (route.request().method() === "GET" && serverDown) return route.abort("connectionrefused");
+ await route.fallback();
+ });
await page.getByRole("button", { name: "Models & Keys", exact: true }).click();
- await expect(page.getByText("Couldn't reach the agent server")).toBeVisible();
- await expect(page.getByText("Make sure OpenWorker is running, then try again.")).toBeVisible();
- await expect(page.getByTestId("settings-retry")).toBeVisible();
+ await expect(page.getByTestId("settings-error")).toContainText("Couldn't reach the server to load settings");
+ await expect(page.getByText("Loading…", { exact: true })).toHaveCount(0);
+ await expect(page.getByTestId("set-provider-openai")).toHaveCount(0);
+
+ serverDown = false;
+ await page.getByTestId("settings-retry").click();
+ await expect(page.getByTestId("set-provider-openai")).toBeVisible();
+ await expect(page.getByTestId("settings-error")).toHaveCount(0);
});
// The flag's "0" escape hatch hides the tab again (the default is on — UX-029).
diff --git a/surfaces/gui/src/api.ts b/surfaces/gui/src/api.ts
index 730d1ca5..d360c083 100644
--- a/surfaces/gui/src/api.ts
+++ b/surfaces/gui/src/api.ts
@@ -2271,9 +2271,16 @@ export async function runSandboxRemove(machineId?: string | null): Promise<{ ok:
return res.json();
}
-export async function getSettings(machineId?: string | null): Promise<ModelSettings> {
- const res = await fetch(`${engineBase(machineId)}/v1/settings`);
- return res.json();
+export async function getSettings(machineId?: string | null, timeoutMs = 10_000): Promise<ModelSettings> {
+ // A hung server must end in an error the page can show (#43), never an endless "Loading…".
+ const ctrl = new AbortController();
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
+ try {
+ const res = await fetch(`${engineBase(machineId)}/v1/settings`, { signal: ctrl.signal });
+ return await res.json();
+ } finally {
+ clearTimeout(timer);
+ }
}
export async function setModelKey(
diff --git a/surfaces/gui/src/components/ManageTabs.models-error.test.tsx b/surfaces/gui/src/components/ManageTabs.models-error.test.tsx
new file mode 100644
index 00000000..ac50cff5
--- /dev/null
+++ b/surfaces/gui/src/components/ManageTabs.models-error.test.tsx
@@ -0,0 +1,91 @@
+// #43: Settings ▸ Models must not sit on "Loading…" forever. A settings fetch that fails
+// (or is aborted by the 10 s timeout) shows one error line with Retry; Retry fetches again.
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+import type { ModelSettings } from "../api";
+
+vi.mock("../tauri", () => ({ openExternal: vi.fn() }));
+vi.mock("../api", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../api")>()),
+ getSettings: vi.fn(),
+}));
+// The provider gallery has its own tests; here it only needs to render empty.
+vi.mock("../providers/ProviderSetup", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../providers/ProviderSetup")>()),
+ useProviderSetup: () => ({
+ providers: [],
+ ordered: [],
+ refreshProviders: async () => {},
+ sel: null,
+ info: undefined,
+ fields: {},
+ setFieldValue: () => {},
+ dirty: false,
+ verify: { state: "idle" },
+ showEndpoint: false,
+ setShowEndpoint: () => {},
+ keylessOk: new Set(),
+ credentialed: false,
+ savedState: false,
+ secretFilled: false,
+ openProvider: () => {},
+ backToGallery: () => {},
+ runTestAndSave: async () => true,
+ removeKey: async () => {},
+ cancelBackTimer: () => {},
+ statusFor: () => null,
+ saveField: async () => {},
+ fieldSaved: null,
+ }),
+}));
+
+import { getSettings } from "../api";
+import { ModelsTab } from "./ManageTabs";
+
+const SETTINGS = {
+ provider: "openai",
+ model: "gpt-4o",
+ models: ["gpt-4o"],
+ has_key: true,
+ model_ready: true,
+ source: "store",
+ onboarded: true,
+ surfaces: { cowork: true, chat: false, code: true },
+ scratch_base: "~/OpenWorker",
+ secrets_path: "/tmp/secrets.json",
+} as unknown as ModelSettings;
+
+const flush = () => act(async () => { await Promise.resolve(); await Promise.resolve(); });
+
+afterEach(cleanup);
+
+describe("ModelsTab when settings cannot load", () => {
+ it("shows the error line with Retry instead of Loading…", async () => {
+ vi.mocked(getSettings).mockRejectedValue(new TypeError("Failed to fetch"));
+ render(<ModelsTab />);
+ await flush();
+ expect(screen.getByTestId("settings-error").textContent).toContain("Couldn't reach the server to load settings");
+ expect(screen.getByTestId("settings-retry")).toBeTruthy();
+ expect(screen.queryByText("Loading…")).toBeNull();
+ });
+
+ it("treats a timed-out (aborted) fetch the same way", async () => {
+ vi.mocked(getSettings).mockRejectedValue(new DOMException("aborted", "AbortError"));
+ render(<ModelsTab />);
+ await flush();
+ expect(screen.getByTestId("settings-error")).toBeTruthy();
+ });
+
+ it("Retry fetches again and clears the error once the server answers", async () => {
+ vi.mocked(getSettings).mockRejectedValueOnce(new TypeError("Failed to fetch")).mockResolvedValue(SETTINGS);
+ render(<ModelsTab />);
+ await flush();
+ expect(screen.getByTestId("settings-error")).toBeTruthy();
+
+ const before = vi.mocked(getSettings).mock.calls.length;
+ fireEvent.click(screen.getByTestId("settings-retry"));
+ await flush();
+ expect(vi.mocked(getSettings).mock.calls.length).toBe(before + 1);
+ expect(screen.queryByTestId("settings-error")).toBeNull();
+ });
+});
diff --git a/surfaces/gui/src/components/ManageTabs.tsx b/surfaces/gui/src/components/ManageTabs.tsx
index ab309fb4..920b7f68 100644
--- a/surfaces/gui/src/components/ManageTabs.tsx
+++ b/surfaces/gui/src/components/ManageTabs.tsx
@@ -118,15 +118,14 @@ export function ModelsTab() {
} catch { /* private window */ }
}, []);
+ // #43: a failed or hung settings fetch says so and offers Retry (same shape as the
+ // local-models status line below) instead of sitting on "Loading…" forever.
if (settingsError) {
return (
- <div className="text-ui text-muted space-y-3">
- <div>
- <p className="text-ink font-medium">Couldn&apos;t reach the agent server</p>
- <p className="mt-1">Make sure OpenWorker is running, then try again.</p>
- </div>
- <button className={BTN_BORDERED} onClick={refreshSettings} data-testid="settings-retry">
- Retry
+ <div className="text-ui text-warnInk" data-testid="settings-error">
+ {t("manage.settings_failed")}{" "}
+ <button className="text-muted underline underline-offset-2 hover:text-ink" onClick={refreshSettings} data-testid="settings-retry">
+ {t("manage.retry")}
</button>
</div>
);
diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.json
index 56a2caa4..743e1f45 100644
--- a/surfaces/gui/src/locales/en.json
+++ b/surfaces/gui/src/locales/en.json
@@ -1389,6 +1389,7 @@
"local_models_loading": "Asking the server which models it has…",
"local_models_failed": "Couldn't reach the server to list its models.",
"local_models_failed_ollama": "Couldn't reach Ollama to list its models.",
+ "settings_failed": "Couldn't reach the server to load settings — make sure OpenWorker is running.",
"retry": "Retry"
},
"models": {
diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.json
index 4c932360..b3ccec33 100644
--- a/surfaces/gui/src/locales/zh.json
+++ b/surfaces/gui/src/locales/zh.json
@@ -1372,6 +1372,7 @@
"local_models_loading": "正在向服务器查询可用模型…",
"local_models_failed": "无法连接服务器以列出模型。",
"local_models_failed_ollama": "无法连接 Ollama 以列出模型。",
+ "settings_failed": "无法连接服务器以加载设置,请确认 OpenWorker 正在运行。",
"retry": "重试"
},
"models": {