mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-21 06:51:01 +00:00
test: stabilize gateway alias coverage
This commit is contained in:
@@ -3,9 +3,9 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { WebSocket } from "ws";
|
||||
import { whatsappPlugin } from "../../extensions/whatsapp/src/channel.js";
|
||||
import type { ChannelPlugin } from "../channels/plugins/types.js";
|
||||
import { emitAgentEvent, registerAgentRunContext } from "../infra/agent-events.js";
|
||||
import { createChannelTestPluginBase } from "../test-utils/channel-plugins.js";
|
||||
import { setRegistry } from "./server.agent.gateway-server-agent.mocks.js";
|
||||
import { createRegistry } from "./server.e2e-registry-helpers.js";
|
||||
import {
|
||||
@@ -58,12 +58,31 @@ const createMSTeamsPlugin = (params?: { aliases?: string[] }): ChannelPlugin =>
|
||||
},
|
||||
});
|
||||
|
||||
const createStubChannelPlugin = (params: {
|
||||
id: ChannelPlugin["id"];
|
||||
label: string;
|
||||
}): ChannelPlugin => ({
|
||||
...createChannelTestPluginBase({
|
||||
id: params.id,
|
||||
label: params.label,
|
||||
config: {
|
||||
listAccountIds: () => [],
|
||||
resolveAccount: () => ({}),
|
||||
},
|
||||
}),
|
||||
outbound: {
|
||||
deliveryMode: "direct",
|
||||
sendText: async () => ({ channel: params.id, messageId: "msg-test" }),
|
||||
sendMedia: async () => ({ channel: params.id, messageId: "msg-test" }),
|
||||
},
|
||||
});
|
||||
|
||||
const emptyRegistry = createRegistry([]);
|
||||
const defaultRegistry = createRegistry([
|
||||
{
|
||||
pluginId: "whatsapp",
|
||||
source: "test",
|
||||
plugin: whatsappPlugin,
|
||||
plugin: createStubChannelPlugin({ id: "whatsapp", label: "WhatsApp" }),
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -181,7 +200,7 @@ describe("gateway server agent", () => {
|
||||
expect(vi.mocked(agentCommand)).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("agent accepts channel aliases (imsg/teams)", async () => {
|
||||
test("agent accepts built-in channel alias (imsg)", async () => {
|
||||
const registry = createRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
@@ -204,6 +223,19 @@ describe("gateway server agent", () => {
|
||||
});
|
||||
expect(resIMessage.ok).toBe(true);
|
||||
|
||||
expectAgentRoutingCall({ channel: "imessage", deliver: true, fromEnd: 1 });
|
||||
});
|
||||
|
||||
test("agent accepts plugin channel alias (teams)", async () => {
|
||||
const registry = createRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
source: "test",
|
||||
plugin: createMSTeamsPlugin({ aliases: ["teams"] }),
|
||||
},
|
||||
]);
|
||||
setRegistry(registry);
|
||||
|
||||
const resTeams = await rpcReq(ws, "agent", {
|
||||
message: "hi",
|
||||
sessionKey: "main",
|
||||
@@ -213,8 +245,6 @@ describe("gateway server agent", () => {
|
||||
idempotencyKey: "idem-agent-teams",
|
||||
});
|
||||
expect(resTeams.ok).toBe(true);
|
||||
|
||||
expectAgentRoutingCall({ channel: "imessage", deliver: true, fromEnd: 2 });
|
||||
expectAgentRoutingCall({
|
||||
channel: "msteams",
|
||||
deliver: false,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { vi } from "vitest";
|
||||
import { createEmptyPluginRegistry, type PluginRegistry } from "../plugins/registry.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { setTestPluginRegistry } from "./test-helpers.mocks.js";
|
||||
|
||||
export const registryState: { registry: PluginRegistry } = {
|
||||
registry: createEmptyPluginRegistry(),
|
||||
@@ -8,6 +9,7 @@ export const registryState: { registry: PluginRegistry } = {
|
||||
|
||||
export function setRegistry(registry: PluginRegistry) {
|
||||
registryState.registry = registry;
|
||||
setTestPluginRegistry(registry);
|
||||
setActivePluginRegistry(registry);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user