Skip to content

Commit ea3b5df

Browse files
committed
improve(ui): simplify local provider recovery (#117165)
Preserve the signed PR commit series. PR-specific UI checks passed; the remaining compact tooling failure matches current main.
2 parents e1101d1 + 53d5cf3 commit ea3b5df

12 files changed

Lines changed: 509 additions & 115 deletions

‎ui/src/e2e/model-setup-llamacpp.e2e.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ describeControlUiE2e("Control UI llama.cpp setup mocked Gateway E2E", () => {
226226
await page.setViewportSize({ height: 900, width: 1280 });
227227
await page.getByRole("button", { name: "Stay in settings" }).click();
228228
const currentConnection = page.locator(".model-setup__current");
229-
await currentConnection.getByText(modelRef, { exact: true }).waitFor();
229+
await currentConnection.getByText("llama.cpp", { exact: true }).waitFor();
230+
await currentConnection.getByText("gemma-4-e4b-it-q4_k_m", { exact: true }).waitFor();
230231
await expect
231232
.poll(() => currentConnection.locator('[data-provider-icon="llamacpp"]').count())
232233
.toBe(1);

‎ui/src/e2e/model-setup-lmstudio.e2e.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ describeControlUiE2e("Control UI LM Studio setup mocked Gateway E2E", () => {
229229
await page.setViewportSize({ height: 900, width: 1280 });
230230
await page.getByRole("button", { name: "Stay in settings" }).click();
231231
const currentConnection = page.locator(".model-setup__current");
232-
await currentConnection.getByText(modelRef, { exact: true }).waitFor();
232+
await currentConnection.getByText("LM Studio", { exact: true }).waitFor();
233+
await currentConnection.getByText("qwen3-8b-instruct", { exact: true }).waitFor();
233234
await expect
234235
.poll(() => currentConnection.locator('[data-provider-icon="lmstudio"]').count())
235236
.toBe(1);

‎ui/src/e2e/model-setup-reconnect.e2e.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describeControlUiE2e("Control UI model setup same-client reconnect", () => {
6767
try {
6868
const response = await page.goto(`${server.baseUrl}settings/model-setup`);
6969
expect(response?.status()).toBe(200);
70-
await page.getByText("provider/original-model").waitFor();
70+
await page.getByText("original-model", { exact: true }).waitFor();
7171
const initialDetections = (await gateway.getRequests("openclaw.setup.detect")).length;
7272
const initialConnections = (await gateway.getRequests("connect")).length;
7373
await gateway.setMethodResponse(
@@ -76,15 +76,17 @@ describeControlUiE2e("Control UI model setup same-client reconnect", () => {
7676
);
7777
await gateway.deferNext("connect");
7878
await gateway.closeLatest(1012, "model setup reconnect proof");
79-
await expect.poll(async () => page.getByText("provider/original-model").count()).toBe(0);
79+
await expect
80+
.poll(async () => page.getByText("original-model", { exact: true }).count())
81+
.toBe(0);
8082
await expect
8183
.poll(async () => (await gateway.getRequests("connect")).length)
8284
.toBeGreaterThan(initialConnections);
8385
await gateway.resolveDeferred("connect");
8486
await expect
8587
.poll(async () => (await gateway.getRequests("openclaw.setup.detect")).length)
8688
.toBe(initialDetections + 1);
87-
await page.getByText("provider/reconnected-model").waitFor();
89+
await page.getByText("reconnected-model", { exact: true }).waitFor();
8890
expect(pageErrors).toEqual([]);
8991

9092
if (captureUiProofEnabled) {
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Control UI tests cover local-provider recovery against a mocked Gateway.
2+
import { mkdir } from "node:fs/promises";
3+
import path from "node:path";
4+
import { chromium, type Browser } from "playwright";
5+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
6+
import {
7+
canRunPlaywrightChromium,
8+
installMockGateway,
9+
resolvePlaywrightChromiumExecutablePath,
10+
startControlUiE2eServer,
11+
type ControlUiE2eServer,
12+
} from "../test-helpers/control-ui-e2e.ts";
13+
14+
const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath());
15+
const chromiumAvailable = canRunPlaywrightChromium(chromiumExecutablePath);
16+
const allowMissingChromium = process.env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1";
17+
const describeControlUiE2e = chromiumAvailable || !allowMissingChromium ? describe : describe.skip;
18+
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
19+
20+
let browser: Browser;
21+
let server: ControlUiE2eServer;
22+
23+
describeControlUiE2e("Control UI local-provider recovery mocked Gateway E2E", () => {
24+
beforeAll(async () => {
25+
if (!chromiumAvailable) {
26+
throw new Error(`Playwright Chromium is unavailable at ${chromiumExecutablePath}`);
27+
}
28+
server = await startControlUiE2eServer();
29+
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
30+
});
31+
32+
afterAll(async () => {
33+
await browser?.close();
34+
await server?.close();
35+
});
36+
37+
it("shows a failed LM Studio connection with its detected endpoint", async () => {
38+
const context = await browser.newContext({
39+
colorScheme: "dark",
40+
locale: "en-US",
41+
serviceWorkers: "block",
42+
viewport: { height: 900, width: 1280 },
43+
});
44+
const page = await context.newPage();
45+
const modelRef = "lmstudio/qwen3-8b-instruct";
46+
const gateway = await installMockGateway(page, {
47+
featureMethods: [
48+
"chat.metadata",
49+
"chat.startup",
50+
"openclaw.setup.detect",
51+
"openclaw.setup.verify",
52+
"openclaw.setup.prepare.start",
53+
"wizard.next",
54+
],
55+
methodResponses: {
56+
"openclaw.setup.detect": {
57+
candidates: [
58+
{
59+
kind: "provider-auto:lmstudio",
60+
brandId: "lmstudio",
61+
label: "LM Studio",
62+
detail: "qwen3-8b-instruct at http://localhost:1234/v1",
63+
modelRef,
64+
recommended: false,
65+
credentials: true,
66+
},
67+
],
68+
manualProviders: [],
69+
prepareOptions: [
70+
{
71+
id: "lmstudio",
72+
brandId: "lmstudio",
73+
label: "LM Studio",
74+
hint: "Connect to a running LM Studio server and use an already loaded model",
75+
actionLabel: "Connect server",
76+
},
77+
],
78+
workspace: "/tmp/openclaw-e2e",
79+
configuredModel: modelRef,
80+
setupComplete: true,
81+
},
82+
"openclaw.setup.verify": {
83+
ok: false,
84+
status: "unavailable",
85+
error: "connect ECONNREFUSED 127.0.0.1:1234",
86+
},
87+
"openclaw.setup.prepare.start": {
88+
sessionId: "lmstudio-recovery-session",
89+
done: false,
90+
status: "running",
91+
},
92+
"wizard.next": {
93+
done: false,
94+
status: "running",
95+
step: {
96+
id: "lmstudio-base-url",
97+
type: "text",
98+
message: "LM Studio base URL",
99+
initialValue: "http://localhost:1234/v1",
100+
},
101+
},
102+
},
103+
});
104+
105+
try {
106+
const response = await page.goto(`${server.baseUrl}settings/model-setup`);
107+
expect(response?.status()).toBe(200);
108+
const selectedModel = page.locator(".model-setup__current");
109+
await selectedModel.getByText("LM Studio", { exact: true }).waitFor();
110+
await selectedModel.getByRole("button", { name: "Check model" }).click();
111+
await selectedModel.getByText("qwen3-8b-instruct at http://localhost:1234/v1").waitFor();
112+
await selectedModel.getByText("LM Studio isn’t responding.").waitFor();
113+
await selectedModel.getByRole("button", { name: "Try again" }).waitFor();
114+
await expect.poll(() => selectedModel.getByText("Change connection").count()).toBe(0);
115+
await expect
116+
.poll(() => page.locator('[data-candidate-kind="provider-auto:lmstudio"]').count())
117+
.toBe(0);
118+
119+
if (artifactDir) {
120+
await mkdir(artifactDir, { recursive: true });
121+
await page.screenshot({
122+
animations: "disabled",
123+
fullPage: true,
124+
path: path.join(artifactDir, "local-provider-failure-desktop.png"),
125+
});
126+
await page.setViewportSize({ height: 844, width: 390 });
127+
await page.screenshot({
128+
animations: "disabled",
129+
fullPage: true,
130+
path: path.join(artifactDir, "local-provider-failure-mobile.png"),
131+
});
132+
}
133+
134+
const verify = await gateway.waitForRequest("openclaw.setup.verify");
135+
expect(verify.params).toEqual({});
136+
} finally {
137+
await context.close();
138+
}
139+
});
140+
});

‎ui/src/e2e/model-setup.e2e.test.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ describeControlUiE2e("Control UI Model Setup mocked Gateway E2E", () => {
482482
});
483483
await page.getByRole("button", { name: "Stay in settings" }).click();
484484
const currentConnection = page.locator(".model-setup__current");
485-
await currentConnection.getByText("ollama/qwen3:0.6b", { exact: true }).waitFor();
485+
await currentConnection.getByText("Ollama", { exact: true }).waitFor();
486+
await currentConnection.getByText("qwen3:0.6b", { exact: true }).waitFor();
486487
await expect
487488
.poll(() => currentConnection.locator('[data-provider-icon="ollama"]').count())
488489
.toBe(1);
@@ -871,17 +872,21 @@ describeControlUiE2e("Control UI Model Setup mocked Gateway E2E", () => {
871872
});
872873
await page.setViewportSize({ height: 900, width: 1280 });
873874
}
874-
await page.getByRole("button", { name: "Verify connection" }).click();
875+
await page.getByRole("button", { name: "Check model" }).click();
875876
const verify = await gateway.waitForRequest("openclaw.setup.verify");
876877
expect(verify.params).toEqual({});
877-
await page.getByText("Answered in 1234 ms").waitFor();
878+
await page.getByText("Ready · 1234 ms").waitFor();
878879
const detectCountBeforeRefresh = (await gateway.getRequests("openclaw.setup.detect")).length;
880+
const verifyCountBeforeRefresh = (await gateway.getRequests("openclaw.setup.verify")).length;
879881
await page.getByRole("button", { name: "Check again" }).click();
880882
await expect
881-
.poll(async () => (await gateway.getRequests("openclaw.setup.detect")).length)
882-
.toBe(detectCountBeforeRefresh + 1);
883-
await page.getByRole("button", { name: "Verify connection" }).waitFor();
884-
expect(await page.getByText("Answered in 1234 ms").count()).toBe(0);
883+
.poll(async () => (await gateway.getRequests("openclaw.setup.verify")).length)
884+
.toBe(verifyCountBeforeRefresh + 1);
885+
expect((await gateway.getRequests("openclaw.setup.detect")).length).toBe(
886+
detectCountBeforeRefresh,
887+
);
888+
await page.getByRole("button", { name: "Check again" }).waitFor();
889+
await page.getByText("Ready · 1234 ms").waitFor();
885890
} finally {
886891
await context.close();
887892
}

‎ui/src/i18n/locales/en.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,11 +1989,15 @@ export const en: TranslationMap = {
19891989
retry: "Retry",
19901990
checkAgain: "Check again",
19911991
verify: {
1992-
title: "Current connection",
1993-
button: "Verify connection",
1992+
title: "Selected model",
1993+
button: "Check model",
1994+
retry: "Try again",
1995+
checkAgain: "Check again",
1996+
checkingButton: "Checking…",
19941997
checking: "Checking — asking {modelRef} for a quick reply…",
1995-
answered: "Answered",
1996-
answeredIn: "Answered in {latencyMs} ms",
1998+
ready: "Ready",
1999+
readyIn: "Ready · {latencyMs} ms",
2000+
providerUnavailable: "{provider} isn’t responding.",
19972001
},
19982002
access: {
19992003
adminRequired: "Model setup requires operator.admin access.",
@@ -2006,6 +2010,7 @@ export const en: TranslationMap = {
20062010
signInNeeded: "Sign-in needed",
20072011
detected: "Detected",
20082012
testAndUse: "Test & use",
2013+
retry: "Retry test",
20092014
testingButton: "Testing…",
20102015
testing: "Testing — asking {modelRef} for a quick reply…",
20112016
},
@@ -2067,6 +2072,14 @@ export const en: TranslationMap = {
20672072
unavailable: "Unavailable",
20682073
unknown: "Connection failed",
20692074
},
2075+
failureGuidance: {
2076+
auth: "Review the provider credential or sign-in, then retry.",
2077+
rateLimit: "Wait for the provider limit to reset, then retry.",
2078+
billing: "Restore provider billing or quota, then retry.",
2079+
unavailable: "Make sure the provider service is running and reachable, then retry.",
2080+
format: "Check that the endpoint exposes a compatible chat model, then retry.",
2081+
unknown: "Review the connection details, then retry.",
2082+
},
20702083
errors: {
20712084
requestFailed: "Model setup request failed.",
20722085
activationFailed: "The model could not be activated.",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { nothing, render } from "lit";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+
import type { SystemAgentSetupDetectResult } from "../../api/types.ts";
6+
import { i18n } from "../../i18n/index.ts";
7+
import { renderConfiguredModel } from "./configured-model.ts";
8+
9+
function mount(result: SystemAgentSetupDetectResult) {
10+
const container = document.createElement("div");
11+
document.body.append(container);
12+
const onVerify = vi.fn();
13+
render(
14+
renderConfiguredModel({
15+
result,
16+
verify: {
17+
phase: "failed",
18+
status: "unavailable",
19+
error: "connect ECONNREFUSED",
20+
},
21+
canVerify: true,
22+
actionsDisabled: false,
23+
onVerify,
24+
}),
25+
container,
26+
);
27+
return { container, onVerify };
28+
}
29+
30+
function text(container: Element): string {
31+
return container.textContent?.replace(/\s+/gu, " ").trim() ?? "";
32+
}
33+
34+
describe("renderConfiguredModel", () => {
35+
beforeEach(async () => {
36+
await i18n.setLocale("en");
37+
});
38+
39+
afterEach(() => {
40+
for (const container of document.body.querySelectorAll("div")) {
41+
render(nothing, container);
42+
}
43+
document.body.replaceChildren();
44+
});
45+
46+
it.each([
47+
{
48+
brandId: "ollama",
49+
detail: "qwen3:8b at http://127.0.0.1:11434",
50+
kind: "provider-auto:ollama",
51+
label: "Ollama",
52+
modelRef: "ollama/qwen3:8b",
53+
},
54+
{
55+
brandId: "llama-cpp",
56+
detail: "gemma-4-e4b-it-q4_k_m (downloaded)",
57+
kind: "provider-auto:llama-cpp",
58+
label: "llama.cpp",
59+
modelRef: "llama-cpp/gemma-4-e4b-it-q4_k_m",
60+
},
61+
{
62+
brandId: "lmstudio",
63+
detail: "qwen3-8b-instruct at http://localhost:1234/v1",
64+
kind: "provider-auto:lmstudio",
65+
label: "LM Studio",
66+
modelRef: "lmstudio/qwen3-8b-instruct",
67+
},
68+
] as const)("shows a quiet recovery state for $brandId", (fixture) => {
69+
const result: SystemAgentSetupDetectResult = {
70+
candidates: [
71+
{
72+
kind: fixture.kind,
73+
brandId: fixture.brandId,
74+
label: fixture.label,
75+
detail: fixture.detail,
76+
modelRef: fixture.modelRef,
77+
recommended: false,
78+
credentials: true,
79+
},
80+
],
81+
manualProviders: [],
82+
prepareOptions: [],
83+
workspace: "/tmp/workspace",
84+
configuredModel: fixture.modelRef,
85+
setupComplete: true,
86+
};
87+
const { container, onVerify } = mount(result);
88+
89+
expect(text(container)).toContain(`Selected model ${fixture.label} ${fixture.detail}`);
90+
expect(text(container)).toContain(`${fixture.label} isn’t responding.`);
91+
expect(text(container)).not.toContain("Change connection");
92+
const button = container.querySelector<HTMLButtonElement>("button");
93+
expect(button?.textContent?.trim()).toBe("Try again");
94+
95+
button?.click();
96+
expect(onVerify).toHaveBeenCalledOnce();
97+
});
98+
});

0 commit comments

Comments
 (0)