test(gateway): cover immediate websocket connect after startup

This commit is contained in:
George Pickett
2026-04-20 15:25:01 -07:00
parent 880f55b5ac
commit f68b06843a

View File

@@ -1,5 +1,6 @@
import http from "node:http";
import { afterEach, describe, expect, it, vi } from "vitest";
import { connectGatewayClient, disconnectGatewayClient } from "./test-helpers.e2e.js";
import { getFreePort, installGatewayTestHooks, startGatewayServer } from "./test-helpers.js";
const machineNameDelay = vi.hoisted(() => {
@@ -104,4 +105,39 @@ describe("gateway startup websocket readiness", () => {
}
}
});
it("accepts an immediate websocket connection once startup resolves", async () => {
machineNameDelay.reset();
const previousMinimal = process.env.OPENCLAW_TEST_MINIMAL_GATEWAY;
process.env.OPENCLAW_TEST_MINIMAL_GATEWAY = "0";
let server: Awaited<ReturnType<typeof startGatewayServer>> | undefined;
let client: Awaited<ReturnType<typeof connectGatewayClient>> | undefined;
try {
const port = await getFreePort();
machineNameDelay.release();
server = await startGatewayServer(port, {
auth: { mode: "none" },
});
client = await connectGatewayClient({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 5_000,
timeoutMessage: "expected websocket connect to succeed immediately after startup",
});
expect(client).toBeDefined();
} finally {
if (client) {
await disconnectGatewayClient(client);
}
if (server) {
await server.close();
}
if (previousMinimal === undefined) {
delete process.env.OPENCLAW_TEST_MINIMAL_GATEWAY;
} else {
process.env.OPENCLAW_TEST_MINIMAL_GATEWAY = previousMinimal;
}
}
});
});