test(perf): speed up slow gateway specs

This commit is contained in:
Vincent Koc
2026-04-15 12:30:16 +01:00
parent 1bca9ba479
commit 3830e687dd
2 changed files with 24 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
import type { IncomingMessage } from "node:http";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { createIMessageTestPlugin } from "../../test/helpers/channels/imessage-test-plugin.js";
import type { OpenClawConfig } from "../config/config.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
@@ -31,6 +30,14 @@ const createDemoAliasPlugin = () => ({
},
});
const createIMessageAliasPlugin = () => ({
...createChannelTestPluginBase({
id: "imessage",
label: "iMessage",
docsPath: "/channels/imessage",
}),
});
describe("gateway hooks helpers", () => {
const resolveHooksConfigOrThrow = (cfg: OpenClawConfig) => {
const resolved = resolveHooksConfig(cfg);
@@ -131,7 +138,7 @@ describe("gateway hooks helpers", () => {
{
pluginId: "imessage",
source: "test",
plugin: createIMessageTestPlugin(),
plugin: createIMessageAliasPlugin(),
},
]),
);

View File

@@ -20,15 +20,22 @@ installGatewayTestHooks({ scope: "suite" });
const cleanupDirs: string[] = [];
let harness: Awaited<ReturnType<typeof createGatewaySuiteHarness>>;
let subscribedOperatorWs:
| Awaited<ReturnType<Awaited<ReturnType<typeof createGatewaySuiteHarness>>["openWs"]>>
| undefined;
let previousMinimalGateway: string | undefined;
beforeAll(async () => {
previousMinimalGateway = process.env.OPENCLAW_TEST_MINIMAL_GATEWAY;
delete process.env.OPENCLAW_TEST_MINIMAL_GATEWAY;
harness = await createGatewaySuiteHarness();
subscribedOperatorWs = await harness.openWs();
await connectOk(subscribedOperatorWs, { scopes: ["operator.read"] });
await rpcReq(subscribedOperatorWs, "sessions.subscribe");
});
afterAll(async () => {
subscribedOperatorWs?.close();
await harness.close();
if (previousMinimalGateway === undefined) {
delete process.env.OPENCLAW_TEST_MINIMAL_GATEWAY;
@@ -52,17 +59,12 @@ async function createSessionStoreFile(): Promise<string> {
}
async function withOperatorSessionSubscriber<T>(
harness: Awaited<ReturnType<typeof createGatewaySuiteHarness>>,
run: (ws: Awaited<ReturnType<typeof harness.openWs>>) => Promise<T>,
run: (ws: NonNullable<typeof subscribedOperatorWs>) => Promise<T>,
) {
const ws = await harness.openWs();
try {
await connectOk(ws, { scopes: ["operator.read"] });
await rpcReq(ws, "sessions.subscribe");
return await run(ws);
} finally {
ws.close();
if (!subscribedOperatorWs) {
throw new Error("subscribed operator websocket is not ready");
}
return await run(subscribedOperatorWs);
}
function waitForSessionMessageEvent(
@@ -157,7 +159,7 @@ describe("session.message websocket events", () => {
storePath,
});
await withOperatorSessionSubscriber(harness, async (ws) => {
await withOperatorSessionSubscriber(async (ws) => {
const changedEvent = onceMessage(
ws,
(message) =>
@@ -327,7 +329,7 @@ describe("session.message websocket events", () => {
"utf-8",
);
await withOperatorSessionSubscriber(harness, async (ws) => {
await withOperatorSessionSubscriber(async (ws) => {
const { messageEvent, changedEvent } = await emitTranscriptUpdateAndCollectEvents({
ws,
sessionKey: "agent:main:main",
@@ -487,7 +489,7 @@ describe("session.message websocket events", () => {
"utf-8",
);
await withOperatorSessionSubscriber(harness, async (ws) => {
await withOperatorSessionSubscriber(async (ws) => {
const { messageEvent, changedEvent } = await emitTranscriptUpdateAndCollectEvents({
ws,
sessionKey: "agent:main:main",
@@ -636,7 +638,7 @@ describe("session.message websocket events", () => {
"utf-8",
);
await withOperatorSessionSubscriber(harness, async (ws) => {
await withOperatorSessionSubscriber(async (ws) => {
const messageEventPromise = waitForSessionMessageEvent(ws, "agent:main:newer");
emitSessionTranscriptUpdate({