Skip to content

Commit ab4761f

Browse files
fix(ui): preserve structured login error codes (#120069)
1 parent dcb125d commit ab4761f

3 files changed

Lines changed: 100 additions & 1 deletion

File tree

‎ui/src/app/gateway-store.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @vitest-environment node
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { ConnectErrorDetailCodes } from "../../../packages/gateway-protocol/src/connect-error-details.js";
34
import type {
45
GatewayBrowserClient,
56
GatewayBrowserClientOptions,
@@ -154,6 +155,53 @@ describe("createApplicationGateway connection phase", () => {
154155
expect(gateway.snapshot.phase).toBe("offline");
155156
});
156157

158+
it.each([
159+
{
160+
name: "missing-token auth detail",
161+
outerCode: "INVALID_REQUEST",
162+
detailCode: ConnectErrorDetailCodes.AUTH_TOKEN_MISSING,
163+
message: "token missing",
164+
},
165+
{
166+
name: "pairing-required detail",
167+
outerCode: "NOT_PAIRED",
168+
detailCode: ConnectErrorDetailCodes.PAIRING_REQUIRED,
169+
message: "device is not approved",
170+
},
171+
])("preserves the structured $name in the login snapshot", (fixture) => {
172+
const { gateway, current } = createStore();
173+
gateway.start();
174+
175+
current().opts.onClose?.({
176+
code: 4008,
177+
reason: "connect failed",
178+
error: {
179+
code: fixture.outerCode,
180+
message: fixture.message,
181+
details: { code: fixture.detailCode },
182+
},
183+
willRetry: false,
184+
});
185+
186+
expect(gateway.snapshot.lastError).toBe(fixture.message);
187+
expect(gateway.snapshot.lastErrorCode).toBe(fixture.detailCode);
188+
});
189+
190+
it("preserves an outer code when a transport failure has no structured detail", () => {
191+
const { gateway, current } = createStore();
192+
gateway.start();
193+
194+
current().opts.onClose?.({
195+
code: 1006,
196+
reason: "websocket error",
197+
error: { code: "UNAVAILABLE", message: "WebSocket connection failed" },
198+
willRetry: false,
199+
});
200+
201+
expect(gateway.snapshot.lastError).toBe("WebSocket connection failed");
202+
expect(gateway.snapshot.lastErrorCode).toBe("UNAVAILABLE");
203+
});
204+
157205
it("does not invent an assistant agent id before the gateway advertises one", () => {
158206
const { gateway, current } = createStore();
159207

‎ui/src/app/gateway-store.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ControlUiBootstrapProfileHint } from "../../../src/gateway/control
44
import type { EventLogEntry } from "../api/event-log.ts";
55
import {
66
GatewayBrowserClient,
7+
resolveGatewayErrorDetailCode,
78
type GatewayBrowserClientOptions,
89
type GatewayEventListener,
910
type GatewayHelloOk,
@@ -412,7 +413,7 @@ export function createApplicationGateway(
412413
canvasPluginSurfaceUrl: null,
413414
selfUser: null,
414415
lastError: error?.message ?? `disconnected (${code}): ${reason || "no reason"}`,
415-
lastErrorCode: error?.code ?? null,
416+
lastErrorCode: resolveGatewayErrorDetailCode(error) ?? error?.code ?? null,
416417
});
417418
},
418419
onGap: ({ expected, received }) => {

‎ui/src/e2e/login-gate.e2e.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,56 @@ suite.define(() => {
8686
}
8787
});
8888

89+
it.each([
90+
{
91+
name: "missing token",
92+
error: {
93+
code: "INVALID_REQUEST",
94+
message: "token missing",
95+
details: { code: ConnectErrorDetailCodes.AUTH_TOKEN_MISSING },
96+
},
97+
expectedKind: "auth-required",
98+
expectedTitle: "Auth required",
99+
},
100+
{
101+
name: "pairing approval",
102+
error: {
103+
code: "NOT_PAIRED",
104+
message: "device is not approved",
105+
details: { code: ConnectErrorDetailCodes.PAIRING_REQUIRED },
106+
},
107+
expectedKind: "pairing-required",
108+
expectedTitle: "Device pairing required",
109+
},
110+
{
111+
name: "generic transport",
112+
error: {
113+
code: "UNAVAILABLE",
114+
message: "WebSocket connection failed",
115+
},
116+
expectedKind: "network",
117+
expectedTitle: "Could not connect",
118+
},
119+
])("renders $name guidance from the application gateway snapshot", async (fixture) => {
120+
const context = await suite.browser.newContext({ viewport: { height: 900, width: 1280 } });
121+
const page = await context.newPage();
122+
const gateway = await installMockGateway(page, { deferredMethods: ["connect"] });
123+
124+
try {
125+
await page.goto(suite.server.baseUrl);
126+
await gateway.waitForRequest("connect");
127+
await gateway.rejectDeferred("connect", fixture.error);
128+
129+
const failure = page.locator(`.login-gate__failure[data-kind="${fixture.expectedKind}"]`);
130+
await failure.waitFor({ timeout: 10_000 });
131+
expect(await failure.locator(".login-gate__failure-title").textContent()).toBe(
132+
fixture.expectedTitle,
133+
);
134+
} finally {
135+
await closeContext(context);
136+
}
137+
});
138+
89139
it("keeps mobile controls compact, touchable, and keyboard-friendly", async () => {
90140
const context = await suite.browser.newContext({
91141
hasTouch: true,

0 commit comments

Comments
 (0)