






















@@ -3,7 +3,12 @@ import { describe, expect, it, vi } from "vitest";
33import type { WebSocketServer } from "ws";
44import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../protocol/client-info.js";
55import { PROTOCOL_VERSION } from "../protocol/index.js";
6-import { GATEWAY_STARTUP_UNAVAILABLE_REASON } from "../protocol/startup-unavailable.js";
6+import {
7+GATEWAY_STARTUP_CLOSE_CODE,
8+GATEWAY_STARTUP_CLOSE_REASON,
9+GATEWAY_STARTUP_PENDING_CLOSE_CAUSE,
10+GATEWAY_STARTUP_UNAVAILABLE_REASON,
11+} from "../protocol/startup-unavailable.js";
712import { attachGatewayWsConnectionHandler } from "./ws-connection.js";
813914function createLogger() {
@@ -51,6 +56,7 @@ describe("attachGatewayWsConnectionHandler startup readiness", () => {
5156headers: { host: "127.0.0.1:19001" },
5257socket: { localAddress: "127.0.0.1" },
5358};
59+const logWsControl = createLogger();
54605561attachGatewayWsConnectionHandler({
5662 wss,
@@ -64,7 +70,7 @@ describe("attachGatewayWsConnectionHandler startup readiness", () => {
6470refreshHealthSnapshot: vi.fn(async () => ({}) as never),
6571logGateway: createLogger() as never,
6672logHealth: createLogger() as never,
67-logWsControl: createLogger() as never,
73+logWsControl: logWsControl as never,
6874extraHandlers: {},
6975broadcast: vi.fn(),
7076buildRequestContext: () => createRequestContext() as never,
@@ -134,7 +140,25 @@ describe("attachGatewayWsConnectionHandler startup readiness", () => {
134140expect(response?.error?.retryAfterMs).toBe(500);
135141expect(response?.error?.details).toEqual({ reason: GATEWAY_STARTUP_UNAVAILABLE_REASON });
136142await vi.waitFor(() => {
137-expect(socket.close).toHaveBeenCalledWith(1013, "gateway starting");
143+expect(socket.close).toHaveBeenCalledWith(
144+GATEWAY_STARTUP_CLOSE_CODE,
145+GATEWAY_STARTUP_CLOSE_REASON,
146+);
138147});
148+expect(logWsControl.debug).toHaveBeenCalledWith(
149+expect.stringContaining("closed before connect"),
150+expect.objectContaining({
151+cause: GATEWAY_STARTUP_PENDING_CLOSE_CAUSE,
152+handshake: "failed",
153+}),
154+);
155+expect(logWsControl.debug).toHaveBeenCalledWith(
156+expect.stringContaining(`code=${GATEWAY_STARTUP_CLOSE_CODE}`),
157+expect.anything(),
158+);
159+expect(logWsControl.warn).not.toHaveBeenCalledWith(
160+expect.stringContaining("closed before connect"),
161+expect.anything(),
162+);
139163});
140164});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。