fix: stabilize ci
This commit is contained in:
@@ -2,7 +2,14 @@ export const MAX_PAYLOAD_BYTES = 512 * 1024; // cap incoming frame size
|
||||
export const MAX_BUFFERED_BYTES = 1.5 * 1024 * 1024; // per-connection send buffer limit
|
||||
|
||||
export const MAX_CHAT_HISTORY_MESSAGES_BYTES = 6 * 1024 * 1024; // keep history responses comfortably under client WS limits
|
||||
export const HANDSHAKE_TIMEOUT_MS = 10_000;
|
||||
export const DEFAULT_HANDSHAKE_TIMEOUT_MS = 10_000;
|
||||
export const getHandshakeTimeoutMs = () => {
|
||||
if (process.env.VITEST && process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS) {
|
||||
const parsed = Number(process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS);
|
||||
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
||||
}
|
||||
return DEFAULT_HANDSHAKE_TIMEOUT_MS;
|
||||
};
|
||||
export const TICK_INTERVAL_MS = 30_000;
|
||||
export const HEALTH_REFRESH_INTERVAL_MS = 60_000;
|
||||
export const DEDUPE_TTL_MS = 5 * 60_000;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { WebSocket } from "ws";
|
||||
import { PROTOCOL_VERSION } from "./protocol/index.js";
|
||||
import { HANDSHAKE_TIMEOUT_MS } from "./server-constants.js";
|
||||
import { getHandshakeTimeoutMs } from "./server-constants.js";
|
||||
import {
|
||||
connectReq,
|
||||
getFreePort,
|
||||
@@ -28,10 +28,21 @@ async function waitForWsClose(ws: WebSocket, timeoutMs: number): Promise<boolean
|
||||
describe("gateway server auth/connect", () => {
|
||||
test("closes silent handshakes after timeout", { timeout: 60_000 }, async () => {
|
||||
vi.useRealTimers();
|
||||
const { server, ws } = await startServerWithClient();
|
||||
const closed = await waitForWsClose(ws, HANDSHAKE_TIMEOUT_MS + 2_000);
|
||||
expect(closed).toBe(true);
|
||||
await server.close();
|
||||
const prevHandshakeTimeout = process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS;
|
||||
process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS = "250";
|
||||
try {
|
||||
const { server, ws } = await startServerWithClient();
|
||||
const handshakeTimeoutMs = getHandshakeTimeoutMs();
|
||||
const closed = await waitForWsClose(ws, handshakeTimeoutMs + 2_000);
|
||||
expect(closed).toBe(true);
|
||||
await server.close();
|
||||
} finally {
|
||||
if (prevHandshakeTimeout === undefined) {
|
||||
delete process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS;
|
||||
} else {
|
||||
process.env.CLAWDBOT_TEST_HANDSHAKE_TIMEOUT_MS = prevHandshakeTimeout;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("connect (req) handshake returns hello-ok payload", async () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isWebchatClient } from "../../utils/message-channel.js";
|
||||
|
||||
import type { ResolvedGatewayAuth } from "../auth.js";
|
||||
import { isLoopbackAddress } from "../net.js";
|
||||
import { HANDSHAKE_TIMEOUT_MS } from "../server-constants.js";
|
||||
import { getHandshakeTimeoutMs } from "../server-constants.js";
|
||||
import type { GatewayRequestContext, GatewayRequestHandlers } from "../server-methods/types.js";
|
||||
import { formatError } from "../server-utils.js";
|
||||
import { logWs } from "../ws-log.js";
|
||||
@@ -210,6 +210,7 @@ export function attachGatewayWsConnectionHandler(params: {
|
||||
close();
|
||||
});
|
||||
|
||||
const handshakeTimeoutMs = getHandshakeTimeoutMs();
|
||||
const handshakeTimer = setTimeout(() => {
|
||||
if (!client) {
|
||||
handshakeState = "failed";
|
||||
@@ -219,7 +220,7 @@ export function attachGatewayWsConnectionHandler(params: {
|
||||
logWsControl.warn(`handshake timeout conn=${connId} remote=${remoteAddr ?? "?"}`);
|
||||
close();
|
||||
}
|
||||
}, HANDSHAKE_TIMEOUT_MS);
|
||||
}, handshakeTimeoutMs);
|
||||
|
||||
attachGatewayWsMessageHandler({
|
||||
socket,
|
||||
|
||||
Reference in New Issue
Block a user