The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(shared): type the handshake close as CloseEvent; drop the dead error-detail branch
kshitijk4poor6338e988bdb4
diff --git a/apps/shared/src/json-rpc-gateway-connect.test.ts b/apps/shared/src/json-rpc-gateway-connect.test.tsindex 25e10b719fd..bff00a18463 100644--- a/apps/shared/src/json-rpc-gateway-connect.test.ts+++ b/apps/shared/src/json-rpc-gateway-connect.test.ts@@ -4,16 +4,8 @@ import { JsonRpcGatewayClient } from './json-rpc-gateway'/** EventTarget-based WebSocket stand-in that never opens, so each failure leg can be driven by hand. */class StuckSocket extends EventTarget {- static OPEN = 1- static last: StuckSocket | null = null-readyState = 0- constructor() {- super()- StuckSocket.last = this- }-send(): void {}close(): void {@@ -30,8 +22,10 @@ const rejection = (pending: Promise<void>): Promise<Error> =>)const dial = (connectTimeoutMs = 1000) => {+ let socket!: StuckSocket+const client = new JsonRpcGatewayClient({- socketFactory: () => new StuckSocket() as unknown as WebSocket,+ socketFactory: () => (socket = new StuckSocket()) as unknown as WebSocket,heartbeatIntervalMs: 0,heartbeatDeadlineMs: 0,connectTimeoutMs,@@ -41,7 +35,7 @@ const dial = (connectTimeoutMs = 1000) => {const pending = client.connect('ws://gateway.test/api/ws')pending.catch(() => {})- return { client, pending, socket: StuckSocket.last as StuckSocket }+ return { client, pending, socket }}// Regression for #41566: the overlay showed the same sentence for an auth rejection, a TLS failure and a@@ -64,12 +58,12 @@ describe('JsonRpcGatewayClient.connect failure classes', () => {expect(timedOut.client.connectionState).toBe('error')})- it('an error before open still names the base message so existing "sidecar down" matchers keep working', async () => {+ it('every failure keeps the base message as its prefix — the overlay headline and includes() matchers bind to it', async () => {const { pending, socket } = dial()socket.dispatchEvent(new Event('error'))const error = await rejection(pending)expect(error.message.startsWith(connectErrorMessage)).toBe(true)- expect(error.message).toContain('error before open')+ expect(error.message).not.toBe(connectErrorMessage)})})diff --git a/apps/shared/src/json-rpc-gateway.ts b/apps/shared/src/json-rpc-gateway.tsindex 9637ea0b598..fe8f5759b1a 100644--- a/apps/shared/src/json-rpc-gateway.ts+++ b/apps/shared/src/json-rpc-gateway.ts@@ -255,7 +255,7 @@ export class JsonRpcGatewayClient {// Every rejection below names its failure class. The boot overlay renders this message verbatim, and// a bare connectErrorMessage collapses "server refused the token", "TLS/DNS/refused before open" and// "nothing answered" into one sentence nobody can act on (#41566).- const onError = (event: Event) => {+ const onError = () => {if (settled || this.socket !== socket) {return}@@ -263,10 +263,8 @@ export class JsonRpcGatewayClient {settled = truecleanup()this.setState('error')- const detail = (event as { message?: unknown }).message- reject(- this.connectFailure(`WebSocket error before open${typeof detail === 'string' && detail ? `: ${detail}` : ''}`)- )+ // A browser/renderer 'error' event carries no detail; the class is the message.+ reject(this.connectFailure('WebSocket error before open'))}// A server that closes during the handshake (auth gate, 4401/4403)@@ -276,7 +274,7 @@ export class JsonRpcGatewayClient {// and moved the generation to 'closed'; the branch below only runs// when `onSocketClose` intercepted that transition and left the// half-open socket bound.- const onClose = (event: Event) => {+ const onClose = (event: CloseEvent) => {if (settled) {return}@@ -289,10 +287,9 @@ export class JsonRpcGatewayClient {this.setState('error')}- const { code, reason } = event as { code?: unknown; reason?: unknown }reject(this.connectFailure(- `WebSocket closed during handshake: code ${typeof code === 'number' ? code : 'unknown'}${typeof reason === 'string' && reason ? ` ${reason}` : ''}`+ `WebSocket closed during handshake: code ${event.code}${event.reason ? ` ${event.reason}` : ''}`))}