mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-04-30 14:02:56 +08:00
test(perf): speed up slow gateway specs
This commit is contained in:
@@ -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(),
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user