Skip to content

Commit 9998423

Browse files
committed
fix(ui): resolve provider usage build
1 parent fcd93db commit 9998423

4 files changed

Lines changed: 130 additions & 97 deletions

File tree

‎ui/src/app/vite-config.node.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ describe("Control UI Vite config", () => {
373373
find: "@openclaw/normalization-core/phone-presentation",
374374
replacement: path.join(repoRoot, "packages/normalization-core/src/phone-presentation.ts"),
375375
});
376+
const resultAliasIndex = aliases.findIndex(
377+
(alias) => alias.find === "@openclaw/normalization-core/result",
378+
);
379+
const rootAliasIndex = aliases.findIndex(
380+
(alias) => alias.find === "@openclaw/normalization-core",
381+
);
382+
expect(aliases[resultAliasIndex]).toEqual({
383+
find: "@openclaw/normalization-core/result",
384+
replacement: path.join(repoRoot, "packages/normalization-core/src/result.ts"),
385+
});
386+
expect(resultAliasIndex).toBeGreaterThanOrEqual(0);
387+
expect(rootAliasIndex).toBeGreaterThan(resultAliasIndex);
376388
});
377389

378390
it("uses Node package resolution for external packages inherited by worktrees", () => {
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Control UI E2E proves provider-usage request failures remain distinct from provider data.
2+
import { mkdir } from "node:fs/promises";
3+
import path from "node:path";
4+
import { expect, it } from "vitest";
5+
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
6+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
7+
8+
const suite = createControlUiE2eSuite({
9+
name: "Control UI Model Provider usage outcomes mocked Gateway E2E",
10+
startServerBeforeBrowser: true,
11+
unavailableMessage: (executablePath) =>
12+
`Playwright Chromium is not available at ${executablePath}`,
13+
});
14+
const now = Date.now();
15+
const recordVisuals = process.env.OPENCLAW_UI_E2E_RECORD === "1";
16+
const artifactDir = path.resolve(".artifacts/control-ui-e2e/model-providers");
17+
const unavailableMessage =
18+
"Provider usage is unavailable; the last request failed. Refresh to retry.";
19+
20+
function providerUsageResponses(usageStatus: unknown) {
21+
return {
22+
"config.get": { config: {}, hash: "provider-usage-outcome" },
23+
"models.list": { models: [] },
24+
"models.authStatus": {
25+
ts: now,
26+
providers: [
27+
{
28+
provider: "openai",
29+
displayName: "OpenAI",
30+
status: "ok",
31+
profiles: [],
32+
},
33+
],
34+
},
35+
"sessions.usage": { aggregates: { byProvider: [] } },
36+
"usage.status": usageStatus,
37+
};
38+
}
39+
40+
suite.define(() => {
41+
it("shows a visible warning when the provider usage request fails", async () => {
42+
await suite.withPage(
43+
{
44+
locale: "en-US",
45+
serviceWorkers: "block",
46+
viewport: { height: 1_000, width: 1_440 },
47+
},
48+
async ({ page }) => {
49+
const gateway = await installMockGateway(page, {
50+
methodResponses: providerUsageResponses({
51+
__mockError: { code: "INTERNAL_ERROR", message: "gateway transport unavailable" },
52+
}),
53+
});
54+
55+
await page.goto(`${suite.server.baseUrl}settings/model-providers`);
56+
await page.locator('[data-provider-id="openai"]').waitFor();
57+
await expect
58+
.poll(async () => (await gateway.getRequests("usage.status")).length)
59+
.toBeGreaterThan(0);
60+
await expect
61+
.poll(() => page.locator(".settings-page").textContent())
62+
.toContain(unavailableMessage);
63+
if (recordVisuals) {
64+
await mkdir(artifactDir, { recursive: true });
65+
await page.screenshot({
66+
animations: "disabled",
67+
fullPage: true,
68+
path: path.join(artifactDir, "provider-usage-request-failed.png"),
69+
});
70+
}
71+
},
72+
);
73+
});
74+
75+
it("keeps provider-scoped usage errors as data without the global warning", async () => {
76+
await suite.withPage(
77+
{
78+
locale: "en-US",
79+
serviceWorkers: "block",
80+
viewport: { height: 1_000, width: 1_440 },
81+
},
82+
async ({ page }) => {
83+
const gateway = await installMockGateway(page, {
84+
methodResponses: providerUsageResponses({
85+
updatedAt: now,
86+
providers: [
87+
{
88+
provider: "openai",
89+
displayName: "OpenAI",
90+
windows: [],
91+
error: "provider API unavailable",
92+
},
93+
],
94+
}),
95+
});
96+
97+
await page.goto(`${suite.server.baseUrl}settings/model-providers`);
98+
const card = page.locator('[data-provider-id="openai"]');
99+
await card.waitFor();
100+
await expect
101+
.poll(async () => (await gateway.getRequests("usage.status")).length)
102+
.toBeGreaterThan(0);
103+
await expect.poll(() => card.textContent()).toContain("provider API unavailable");
104+
await expect
105+
.poll(() => page.locator(".settings-page").textContent())
106+
.not.toContain(unavailableMessage);
107+
if (recordVisuals) {
108+
await mkdir(artifactDir, { recursive: true });
109+
await card.screenshot({
110+
animations: "disabled",
111+
path: path.join(artifactDir, "provider-usage-provider-error.png"),
112+
});
113+
}
114+
},
115+
);
116+
});
117+
});

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

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,6 @@ function providerConfig(value: string): { apiKey: string } {
4141
return Object.fromEntries([["apiKey", value]]) as { apiKey: string };
4242
}
4343

44-
function providerUsageResponses(usageStatus: unknown) {
45-
return {
46-
"config.get": { config: {}, hash: "provider-usage-outcome" },
47-
"models.list": { models: [] },
48-
"models.authStatus": {
49-
ts: NOW,
50-
providers: [
51-
{
52-
provider: "openai",
53-
displayName: "OpenAI",
54-
status: "ok",
55-
profiles: [],
56-
},
57-
],
58-
},
59-
"sessions.usage": { aggregates: { byProvider: [] } },
60-
"usage.status": usageStatus,
61-
};
62-
}
63-
6444
function modelPickerValue(locator: Locator) {
6545
return locator.evaluate((element) => String((element as HTMLElement & { value?: string }).value));
6646
}
@@ -93,83 +73,6 @@ describeControlUiE2e("Control UI Models mocked Gateway E2E", () => {
9373
await server?.close();
9474
});
9575

96-
it("shows a visible warning when the provider usage request fails", async () => {
97-
const context = await browser.newContext({
98-
locale: "en-US",
99-
serviceWorkers: "block",
100-
viewport: { height: 1000, width: 1440 },
101-
});
102-
const page = await context.newPage();
103-
const gateway = await installMockGateway(page, {
104-
methodResponses: providerUsageResponses({
105-
__mockError: { code: "INTERNAL_ERROR", message: "gateway transport unavailable" },
106-
}),
107-
});
108-
109-
try {
110-
await page.goto(`${server.baseUrl}settings/model-providers`);
111-
await page.locator('[data-provider-id="openai"]').waitFor();
112-
await expect
113-
.poll(async () => (await gateway.getRequests("usage.status")).length)
114-
.toBeGreaterThan(0);
115-
await expect
116-
.poll(() => page.locator(".settings-page").textContent())
117-
.toContain("Provider usage is unavailable; the last request failed. Refresh to retry.");
118-
if (recordVisuals) {
119-
await page.screenshot({
120-
animations: "disabled",
121-
fullPage: true,
122-
path: path.join(artifactDir, "provider-usage-request-failed.png"),
123-
});
124-
}
125-
} finally {
126-
await context.close();
127-
}
128-
});
129-
130-
it("keeps provider-scoped usage errors as data without the global warning", async () => {
131-
const context = await browser.newContext({
132-
locale: "en-US",
133-
serviceWorkers: "block",
134-
viewport: { height: 1000, width: 1440 },
135-
});
136-
const page = await context.newPage();
137-
const gateway = await installMockGateway(page, {
138-
methodResponses: providerUsageResponses({
139-
updatedAt: NOW,
140-
providers: [
141-
{
142-
provider: "openai",
143-
displayName: "OpenAI",
144-
windows: [],
145-
error: "provider API unavailable",
146-
},
147-
],
148-
}),
149-
});
150-
151-
try {
152-
await page.goto(`${server.baseUrl}settings/model-providers`);
153-
const card = page.locator('[data-provider-id="openai"]');
154-
await card.waitFor();
155-
await expect
156-
.poll(async () => (await gateway.getRequests("usage.status")).length)
157-
.toBeGreaterThan(0);
158-
await expect.poll(() => card.textContent()).toContain("provider API unavailable");
159-
await expect
160-
.poll(() => page.locator(".settings-page").textContent())
161-
.not.toContain("Provider usage is unavailable; the last request failed. Refresh to retry.");
162-
if (recordVisuals) {
163-
await card.screenshot({
164-
animations: "disabled",
165-
path: path.join(artifactDir, "provider-usage-provider-error.png"),
166-
});
167-
}
168-
} finally {
169-
await context.close();
170-
}
171-
});
172-
17376
it("defers live provider discovery until refresh while preserving model setup", async () => {
17477
const context = await browser.newContext({
17578
colorScheme: "dark",

‎ui/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export function resolveSourcePackageAliasesForVite(): ControlUiViteAlias[] {
310310
sourcePackageAlias("normalization-core", "number-coercion"),
311311
sourcePackageAlias("normalization-core", "phone-presentation"),
312312
sourcePackageAlias("normalization-core", "record-coerce"),
313+
sourcePackageAlias("normalization-core", "result"),
313314
sourcePackageAlias("normalization-core", "string-coerce"),
314315
sourcePackageAlias("normalization-core", "string-normalization"),
315316
sourcePackageAlias("normalization-core", "utf16-slice"),

0 commit comments

Comments
 (0)