From df35829810e5e97bc7a2042c536c71a6a315f9de Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 22:23:02 +0000 Subject: [PATCH] test(inbound): share dispatch capture mock across channels --- .../monitor/message-handler.inbound-contract.test.ts | 12 ++---------- .../monitor/event-handler.inbound-contract.test.ts | 12 ++---------- test/helpers/inbound-contract-dispatch-mock.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 20 deletions(-) create mode 100644 test/helpers/inbound-contract-dispatch-mock.ts diff --git a/src/discord/monitor/message-handler.inbound-contract.test.ts b/src/discord/monitor/message-handler.inbound-contract.test.ts index f91e82eff76..378f99c5210 100644 --- a/src/discord/monitor/message-handler.inbound-contract.test.ts +++ b/src/discord/monitor/message-handler.inbound-contract.test.ts @@ -1,14 +1,6 @@ -import { describe, expect, it, vi } from "vitest"; -import { buildDispatchInboundContextCapture } from "../../../test/helpers/inbound-contract-capture.js"; +import { describe, expect, it } from "vitest"; +import { inboundCtxCapture as capture } from "../../../test/helpers/inbound-contract-dispatch-mock.js"; import { expectInboundContextContract } from "../../../test/helpers/inbound-contract.js"; -import type { MsgContext } from "../../auto-reply/templating.js"; - -const capture = vi.hoisted(() => ({ ctx: undefined as MsgContext | undefined })); - -vi.mock("../../auto-reply/dispatch.js", async (importOriginal) => { - return await buildDispatchInboundContextCapture(importOriginal, capture); -}); - import type { DiscordMessagePreflightContext } from "./message-handler.preflight.js"; import { processDiscordMessage } from "./message-handler.process.js"; import { createBaseDiscordMessageContext } from "./message-handler.test-harness.js"; diff --git a/src/signal/monitor/event-handler.inbound-contract.test.ts b/src/signal/monitor/event-handler.inbound-contract.test.ts index 8e73c463301..910e177a5c0 100644 --- a/src/signal/monitor/event-handler.inbound-contract.test.ts +++ b/src/signal/monitor/event-handler.inbound-contract.test.ts @@ -1,14 +1,6 @@ -import { describe, expect, it, vi } from "vitest"; -import { buildDispatchInboundContextCapture } from "../../../test/helpers/inbound-contract-capture.js"; +import { describe, expect, it } from "vitest"; +import { inboundCtxCapture as capture } from "../../../test/helpers/inbound-contract-dispatch-mock.js"; import { expectInboundContextContract } from "../../../test/helpers/inbound-contract.js"; -import type { MsgContext } from "../../auto-reply/templating.js"; - -const capture = vi.hoisted(() => ({ ctx: undefined as MsgContext | undefined })); - -vi.mock("../../auto-reply/dispatch.js", async (importOriginal) => { - return await buildDispatchInboundContextCapture(importOriginal, capture); -}); - import { createSignalEventHandler } from "./event-handler.js"; import { createBaseSignalEventHandlerDeps, diff --git a/test/helpers/inbound-contract-dispatch-mock.ts b/test/helpers/inbound-contract-dispatch-mock.ts new file mode 100644 index 00000000000..6193ae245c1 --- /dev/null +++ b/test/helpers/inbound-contract-dispatch-mock.ts @@ -0,0 +1,9 @@ +import { vi } from "vitest"; +import { createInboundContextCapture } from "./inbound-contract-capture.js"; +import { buildDispatchInboundContextCapture } from "./inbound-contract-capture.js"; + +export const inboundCtxCapture = createInboundContextCapture(); + +vi.mock("../../src/auto-reply/dispatch.js", async (importOriginal) => { + return await buildDispatchInboundContextCapture(importOriginal, inboundCtxCapture); +});