refactor(test): share gateway server plugin mocks

This commit is contained in:
Peter Steinberger
2026-02-14 23:11:16 +00:00
parent 5f4dda6c7c
commit e0d7f97c55
3 changed files with 42 additions and 71 deletions

View File

@@ -7,8 +7,8 @@ import type { ChannelPlugin } from "../channels/plugins/types.js";
import type { PluginRegistry } from "../plugins/registry.js";
import { whatsappPlugin } from "../../extensions/whatsapp/src/channel.js";
import { emitAgentEvent, registerAgentRunContext } from "../infra/agent-events.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";
import { setRegistry } from "./server.agent.gateway-server-agent.mocks.js";
import {
agentCommand,
connectOk,
@@ -41,34 +41,6 @@ afterAll(async () => {
await server.close();
});
const registryState = vi.hoisted(() => ({
registry: {
plugins: [],
tools: [],
channels: [],
providers: [],
gatewayHandlers: {},
httpHandlers: [],
httpRoutes: [],
cliRegistrars: [],
services: [],
diagnostics: [],
} as PluginRegistry,
}));
vi.mock("./server-plugins.js", async () => {
const { setActivePluginRegistry } = await import("../plugins/runtime.js");
return {
loadGatewayPlugins: (params: { baseMethods: string[] }) => {
setActivePluginRegistry(registryState.registry);
return {
pluginRegistry: registryState.registry,
gatewayMethods: params.baseMethods ?? [],
};
},
};
});
const _BASE_IMAGE_PNG =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X3mIAAAAASUVORK5CYII=";
@@ -123,13 +95,11 @@ async function useTempSessionStorePath() {
describe("gateway server agent", () => {
beforeEach(() => {
registryState.registry = defaultRegistry;
setActivePluginRegistry(defaultRegistry);
setRegistry(defaultRegistry);
});
afterEach(() => {
registryState.registry = emptyRegistry;
setActivePluginRegistry(emptyRegistry);
setRegistry(emptyRegistry);
});
test("agent falls back when last-channel plugin is unavailable", async () => {
@@ -140,8 +110,7 @@ describe("gateway server agent", () => {
plugin: createMSTeamsPlugin(),
},
]);
registryState.registry = registry;
setActivePluginRegistry(registry);
setRegistry(registry);
await useTempSessionStorePath();
await writeSessionStore({
entries: {
@@ -179,8 +148,7 @@ describe("gateway server agent", () => {
plugin: createMSTeamsPlugin({ aliases: ["teams"] }),
},
]);
registryState.registry = registry;
setActivePluginRegistry(registry);
setRegistry(registry);
await useTempSessionStorePath();
await writeSessionStore({
entries: {