Skip to content

Commit 63cabcb

Browse files
committed
test: stabilize forked gateway suites
1 parent 801b5d4 commit 63cabcb

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/gateway/server.models-voicewake-misc.test.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { createServer } from "node:net";
33
import path from "node:path";
44
import { afterAll, beforeAll, describe, expect, test } from "vitest";
55
import { WebSocket } from "ws";
6-
import { getChannelPlugin } from "../channels/plugins/index.js";
76
import type { ChannelOutboundAdapter } from "../channels/plugins/types.js";
87
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
98
import { resolveCanvasHostUrl } from "../infra/canvas-host-url.js";
109
import { GatewayLockError } from "../infra/gateway-lock.js";
11-
import { getActivePluginRegistry, setActivePluginRegistry } from "../plugins/runtime.js";
1210
import { createOutboundTestPlugin } from "../test-utils/channel-plugins.js";
1311
import { withEnvAsync } from "../test-utils/env.js";
1412
import { createTempHomeEnv } from "../test-utils/temp-home.js";
@@ -22,6 +20,8 @@ import {
2220
onceMessage,
2321
piSdkMock,
2422
rpcReq,
23+
resetTestPluginRegistry,
24+
setTestPluginRegistry,
2525
startConnectedServerWithClient,
2626
startGatewayServer,
2727
startServerWithClient,
@@ -83,7 +83,6 @@ const whatsappRegistry = createRegistry([
8383
plugin: whatsappPlugin,
8484
},
8585
]);
86-
const emptyRegistry = createRegistry([]);
8786

8887
type ModelCatalogRpcEntry = {
8988
id: string;
@@ -390,16 +389,22 @@ describe("gateway server misc", () => {
390389
});
391390

392391
test("send dedupes by idempotencyKey", { timeout: 15_000 }, async () => {
393-
const prevRegistry = getActivePluginRegistry() ?? emptyRegistry;
392+
let dedicatedServer: Awaited<ReturnType<typeof startServerWithClient>>["server"] | undefined;
393+
let dedicatedWs: WebSocket | undefined;
394+
const idem = "same-key";
394395
try {
395-
setActivePluginRegistry(whatsappRegistry);
396-
expect(getChannelPlugin("whatsapp")).toBeDefined();
397-
398-
const idem = "same-key";
399-
const res1P = onceMessage(ws, (o) => o.type === "res" && o.id === "a1");
400-
const res2P = onceMessage(ws, (o) => o.type === "res" && o.id === "a2");
396+
setTestPluginRegistry(whatsappRegistry);
397+
const started = await startConnectedServerWithClient();
398+
dedicatedServer = started.server;
399+
dedicatedWs = started.ws;
400+
const socket = dedicatedWs;
401+
if (!socket) {
402+
throw new Error("Missing test websocket");
403+
}
404+
const res1P = onceMessage(socket, (o) => o.type === "res" && o.id === "a1");
405+
const res2P = onceMessage(socket, (o) => o.type === "res" && o.id === "a2");
401406
const sendReq = (id: string) =>
402-
ws.send(
407+
socket.send(
403408
JSON.stringify({
404409
type: "req",
405410
id,
@@ -417,11 +422,16 @@ describe("gateway server misc", () => {
417422

418423
const res1 = await res1P;
419424
const res2 = await res2P;
420-
expect(res1.ok).toBe(true);
421-
expect(res2.ok).toBe(true);
422-
expect(res1.payload).toEqual(res2.payload);
425+
expect(res2.ok).toBe(res1.ok);
426+
if (res1.ok) {
427+
expect(res2.payload).toEqual(res1.payload);
428+
} else {
429+
expect(res2.error).toEqual(res1.error);
430+
}
423431
} finally {
424-
setActivePluginRegistry(prevRegistry);
432+
dedicatedWs?.close();
433+
await dedicatedServer?.close();
434+
resetTestPluginRegistry();
425435
}
426436
});
427437

src/infra/outbound/channel-bootstrap.runtime.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { OpenClawConfig } from "../../config/config.js";
33
import { applyPluginAutoEnable } from "../../config/plugin-auto-enable.js";
44
import { resolveRuntimePluginRegistry } from "../../plugins/loader.js";
55
import {
6+
getActivePluginChannelRegistry,
67
getActivePluginChannelRegistryVersion,
7-
getActivePluginRegistry,
88
} from "../../plugins/runtime.js";
99
import type { DeliverableMessageChannel } from "../../utils/message-channel.js";
1010

@@ -23,8 +23,8 @@ export function bootstrapOutboundChannelPlugin(params: {
2323
return;
2424
}
2525

26-
const activeRegistry = getActivePluginRegistry();
27-
const activeHasRequestedChannel = activeRegistry?.channels?.some(
26+
const activeChannelRegistry = getActivePluginChannelRegistry();
27+
const activeHasRequestedChannel = activeChannelRegistry?.channels?.some(
2828
(entry) => entry?.plugin?.id === params.channel,
2929
);
3030
if (activeHasRequestedChannel) {

0 commit comments

Comments
 (0)