test: share gateway dispatch mock exports

This commit is contained in:
Peter Steinberger
2026-04-20 19:02:35 +01:00
parent 34f60de970
commit ed1716cd9d

View File

@@ -82,6 +82,22 @@ async function importEmbeddedRunMockModule<TModule extends object>(
};
}
function createDispatchInboundMessageMockExports(
actual: typeof import("../auto-reply/dispatch.js"),
): typeof import("../auto-reply/dispatch.js") {
return {
...actual,
dispatchInboundMessage: (...args: Parameters<typeof actual.dispatchInboundMessage>) => {
const impl = gatewayTestHoisted.dispatchInboundMessage.getMockImplementation();
return impl
? (gatewayTestHoisted.dispatchInboundMessage(...args) as ReturnType<
typeof actual.dispatchInboundMessage
>)
: actual.dispatchInboundMessage(...args);
},
};
}
vi.mock("../agents/pi-model-discovery.js", async () => {
const actual = await vi.importActual<typeof import("../agents/pi-model-discovery.js")>(
"../agents/pi-model-discovery.js",
@@ -279,29 +295,13 @@ vi.mock("../auto-reply/dispatch.js", async () => {
const actual = await vi.importActual<typeof import("../auto-reply/dispatch.js")>(
"../auto-reply/dispatch.js",
);
return {
...actual,
dispatchInboundMessage: (...args: Parameters<typeof actual.dispatchInboundMessage>) => {
const impl = gatewayTestHoisted.dispatchInboundMessage.getMockImplementation();
return impl
? gatewayTestHoisted.dispatchInboundMessage(...args)
: actual.dispatchInboundMessage(...args);
},
};
return createDispatchInboundMessageMockExports(actual);
});
vi.mock("/src/auto-reply/dispatch.js", async () => {
const actual = await vi.importActual<typeof import("../auto-reply/dispatch.js")>(
"../auto-reply/dispatch.js",
);
return {
...actual,
dispatchInboundMessage: (...args: Parameters<typeof actual.dispatchInboundMessage>) => {
const impl = gatewayTestHoisted.dispatchInboundMessage.getMockImplementation();
return impl
? gatewayTestHoisted.dispatchInboundMessage(...args)
: actual.dispatchInboundMessage(...args);
},
};
return createDispatchInboundMessageMockExports(actual);
});
vi.mock("../auto-reply/reply.js", () => ({
getReplyFromConfig: (...args: Parameters<GetReplyFromConfigFn>) =>