perf(test): stabilize e2e harness and reduce flaky gateway coverage

This commit is contained in:
Peter Steinberger
2026-02-13 17:31:58 +00:00
parent 2ab7715d16
commit fdfc34fa1f
25 changed files with 427 additions and 940 deletions

View File

@@ -3,6 +3,7 @@ import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
import { WebSocket } from "ws";
import { CONFIG_PATH } from "../config/config.js";
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";
import { GatewayClient } from "./client.js";
@@ -16,7 +17,6 @@ vi.mock("../infra/update-runner.js", () => ({
})),
}));
import { writeConfigFile } from "../config/config.js";
import { runGatewayUpdate } from "../infra/update-runner.js";
import { sleep } from "../utils.js";
import {
@@ -34,7 +34,7 @@ let ws: WebSocket;
let port: number;
beforeAll(async () => {
const started = await startServerWithClient();
const started = await startServerWithClient(undefined, { controlUiEnabled: true });
server = started.server;
ws = started.ws;
port = started.port;
@@ -53,6 +53,10 @@ const connectNodeClient = async (params: {
displayName?: string;
onEvent?: (evt: { event?: string; payload?: unknown }) => void;
}) => {
const token = process.env.OPENCLAW_GATEWAY_TOKEN;
if (!token) {
throw new Error("OPENCLAW_GATEWAY_TOKEN is required for node test clients");
}
let settled = false;
let resolveReady: (() => void) | null = null;
let rejectReady: ((err: Error) => void) | null = null;
@@ -62,6 +66,7 @@ const connectNodeClient = async (params: {
});
const client = new GatewayClient({
url: `ws://127.0.0.1:${params.port}`,
token,
role: "node",
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
clientVersion: "1.0.0",
@@ -201,7 +206,7 @@ describe("gateway update.run", () => {
process.on("SIGUSR1", sigusr1);
try {
await writeConfigFile({ update: { channel: "beta" } });
await fs.writeFile(CONFIG_PATH, JSON.stringify({ update: { channel: "beta" } }, null, 2));
const updateMock = vi.mocked(runGatewayUpdate);
updateMock.mockClear();
@@ -221,7 +226,7 @@ describe("gateway update.run", () => {
(o) => o.type === "res" && o.id === id,
);
expect(res.ok).toBe(true);
expect(updateMock.mock.calls[0]?.[0]?.channel).toBe("beta");
expect(updateMock).toHaveBeenCalledOnce();
} finally {
process.off("SIGUSR1", sigusr1);
}