|
1 | 1 | // @vitest-environment node |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | +import { ConnectErrorDetailCodes } from "../../../packages/gateway-protocol/src/connect-error-details.js"; |
3 | 4 | import type { |
4 | 5 | GatewayBrowserClient, |
5 | 6 | GatewayBrowserClientOptions, |
@@ -154,6 +155,53 @@ describe("createApplicationGateway connection phase", () => { |
154 | 155 | expect(gateway.snapshot.phase).toBe("offline"); |
155 | 156 | }); |
156 | 157 |
|
| 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 | + |
157 | 205 | it("does not invent an assistant agent id before the gateway advertises one", () => { |
158 | 206 | const { gateway, current } = createStore(); |
159 | 207 |
|
|
0 commit comments