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

@@ -4,7 +4,7 @@ import path from "node:path";
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
import type { ChannelPlugin } from "../channels/plugins/types.js";
import type { PluginRegistry } from "../plugins/registry.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { setRegistry } from "./server.agent.gateway-server-agent.mocks.js";
import {
agentCommand,
connectOk,
@@ -32,39 +32,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 setRegistry = (registry: PluginRegistry) => {
registryState.registry = registry;
setActivePluginRegistry(registry);
};
const BASE_IMAGE_PNG =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X3mIAAAAASUVORK5CYII=";