|
1 | 1 | import { EventEmitter } from "node:events"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | +import { readGatewayNetworkClientConnectTimeoutMs } from "../../scripts/e2e/lib/gateway-network/limits.mjs"; |
3 | 4 | import { waitForWebSocketOpen } from "../../scripts/e2e/lib/gateway-network/open-websocket.mjs"; |
4 | 5 | |
5 | 6 | class FakeWebSocket extends EventEmitter { |
@@ -20,6 +21,38 @@ class FakeWebSocket extends EventEmitter {
|
20 | 21 | } |
21 | 22 | |
22 | 23 | describe("gateway network WebSocket open guard", () => { |
| 24 | +it("rejects loose client timeout env values instead of parsing prefixes", () => { |
| 25 | +expect(() => |
| 26 | +readGatewayNetworkClientConnectTimeoutMs({ |
| 27 | +OPENCLAW_GATEWAY_NETWORK_CLIENT_CONNECT_TIMEOUT_MS: "100ms", |
| 28 | +}), |
| 29 | +).toThrow("invalid OPENCLAW_GATEWAY_NETWORK_CLIENT_CONNECT_TIMEOUT_MS: 100ms"); |
| 30 | +expect(() => |
| 31 | +readGatewayNetworkClientConnectTimeoutMs({ |
| 32 | +OPENCLAW_GATEWAY_NETWORK_CONNECT_READY_TIMEOUT_MS: "1e3", |
| 33 | +}), |
| 34 | +).toThrow("invalid OPENCLAW_GATEWAY_NETWORK_CONNECT_READY_TIMEOUT_MS: 1e3"); |
| 35 | +expect(() => |
| 36 | +readGatewayNetworkClientConnectTimeoutMs({ |
| 37 | +OPENCLAW_GATEWAY_NETWORK_CLIENT_CONNECT_TIMEOUT_MS: "0", |
| 38 | +}), |
| 39 | +).toThrow("invalid OPENCLAW_GATEWAY_NETWORK_CLIENT_CONNECT_TIMEOUT_MS: 0"); |
| 40 | +}); |
| 41 | + |
| 42 | +it("prefers the explicit client timeout over the connect-ready fallback", () => { |
| 43 | +expect( |
| 44 | +readGatewayNetworkClientConnectTimeoutMs({ |
| 45 | +OPENCLAW_GATEWAY_NETWORK_CLIENT_CONNECT_TIMEOUT_MS: "5000", |
| 46 | +OPENCLAW_GATEWAY_NETWORK_CONNECT_READY_TIMEOUT_MS: "1000", |
| 47 | +}), |
| 48 | +).toBe(5000); |
| 49 | +expect( |
| 50 | +readGatewayNetworkClientConnectTimeoutMs({ |
| 51 | +OPENCLAW_GATEWAY_NETWORK_CONNECT_READY_TIMEOUT_MS: "3000", |
| 52 | +}), |
| 53 | +).toBe(3000); |
| 54 | +}); |
| 55 | + |
23 | 56 | it("consumes abort errors after open timeouts", async () => { |
24 | 57 | const ws = new FakeWebSocket(); |
25 | 58 | const keepAlive = setTimeout(() => {}, 100); |
|