From 7d74b8a90df93fcfcb18af23902c1fa4f5184d9e Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Thu, 14 May 2026 17:15:54 +0100 Subject: [PATCH] refactor(mollifier): move DI seam types to the modules that define them MollifierEvaluateGate and MollifierGetBuffer were defined in the consumer (triggerTask.server.ts) but described the surface of the gate and the buffer accessor respectively. Move each to the module that owns the underlying implementation so the type lives with the producer, not the caller. No behavioural change. --- .../runEngine/services/triggerTask.server.ts | 20 ++++++------------- .../v3/mollifier/mollifierBuffer.server.ts | 4 ++++ .../app/v3/mollifier/mollifierGate.server.ts | 6 ++++++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/webapp/app/runEngine/services/triggerTask.server.ts b/apps/webapp/app/runEngine/services/triggerTask.server.ts index 802f820af..f6456a357 100644 --- a/apps/webapp/app/runEngine/services/triggerTask.server.ts +++ b/apps/webapp/app/runEngine/services/triggerTask.server.ts @@ -42,24 +42,16 @@ import type { } from "../types"; import { evaluateGate as defaultEvaluateGate, - type GateOutcome, + type MollifierEvaluateGate, } from "~/v3/mollifier/mollifierGate.server"; -import { getMollifierBuffer as defaultGetMollifierBuffer } from "~/v3/mollifier/mollifierBuffer.server"; +import { + getMollifierBuffer as defaultGetMollifierBuffer, + type MollifierGetBuffer, +} from "~/v3/mollifier/mollifierBuffer.server"; import { buildBufferedTriggerPayload } from "~/v3/mollifier/bufferedTriggerPayload.server"; -import { serialiseSnapshot, type MollifierBuffer } from "@trigger.dev/redis-worker"; +import { serialiseSnapshot } from "@trigger.dev/redis-worker"; import { QueueSizeLimitExceededError, ServiceValidationError } from "~/v3/services/common.server"; -export type MollifierEvaluateGate = ( - inputs: { - envId: string; - orgId: string; - taskId: string; - orgFeatureFlags: Record | null; - }, -) => Promise; - -export type MollifierGetBuffer = () => MollifierBuffer | null; - class NoopTriggerRacepointSystem implements TriggerRacepointSystem { async waitForRacepoint(options: { racepoint: TriggerRacepoints; id: string }): Promise { return; diff --git a/apps/webapp/app/v3/mollifier/mollifierBuffer.server.ts b/apps/webapp/app/v3/mollifier/mollifierBuffer.server.ts index 426458f77..682b9a870 100644 --- a/apps/webapp/app/v3/mollifier/mollifierBuffer.server.ts +++ b/apps/webapp/app/v3/mollifier/mollifierBuffer.server.ts @@ -3,6 +3,10 @@ import { env } from "~/env.server"; import { logger } from "~/services/logger.server"; import { singleton } from "~/utils/singleton"; +// DI seam type for consumers (e.g. triggerTask.server.ts) that need a +// nullable buffer accessor at construction time. +export type MollifierGetBuffer = () => MollifierBuffer | null; + function initializeMollifierBuffer(): MollifierBuffer { logger.debug("Initializing mollifier buffer", { host: env.MOLLIFIER_REDIS_HOST, diff --git a/apps/webapp/app/v3/mollifier/mollifierGate.server.ts b/apps/webapp/app/v3/mollifier/mollifierGate.server.ts index dead22190..4fbab0154 100644 --- a/apps/webapp/app/v3/mollifier/mollifierGate.server.ts +++ b/apps/webapp/app/v3/mollifier/mollifierGate.server.ts @@ -51,6 +51,12 @@ export type GateInputs = { export type TripEvaluator = (inputs: GateInputs) => Promise; +// DI seam type for consumers (e.g. triggerTask.server.ts) that inject the +// gate at construction time. Deliberately narrower than `evaluateGate`'s +// real signature — no `deps` param — because consumers only call it with +// inputs and rely on the module-level defaults. +export type MollifierEvaluateGate = (inputs: GateInputs) => Promise; + export type GateDependencies = { isMollifierEnabled: () => boolean; isShadowModeOn: () => boolean;