From ed1716cd9d44b30b942b181626e4795561bf8ab7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 19:02:35 +0100 Subject: [PATCH] test: share gateway dispatch mock exports --- src/gateway/test-helpers.mocks.ts | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/gateway/test-helpers.mocks.ts b/src/gateway/test-helpers.mocks.ts index ea2131d7340..3f16c03cf62 100644 --- a/src/gateway/test-helpers.mocks.ts +++ b/src/gateway/test-helpers.mocks.ts @@ -82,6 +82,22 @@ async function importEmbeddedRunMockModule( }; } +function createDispatchInboundMessageMockExports( + actual: typeof import("../auto-reply/dispatch.js"), +): typeof import("../auto-reply/dispatch.js") { + return { + ...actual, + dispatchInboundMessage: (...args: Parameters) => { + 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( "../agents/pi-model-discovery.js", @@ -279,29 +295,13 @@ vi.mock("../auto-reply/dispatch.js", async () => { const actual = await vi.importActual( "../auto-reply/dispatch.js", ); - return { - ...actual, - dispatchInboundMessage: (...args: Parameters) => { - 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( "../auto-reply/dispatch.js", ); - return { - ...actual, - dispatchInboundMessage: (...args: Parameters) => { - 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) =>