|
| 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 | +}); |
0 commit comments