refactor(sms): consolidate webhook test hooks (#106072)

This commit is contained in:
Vincent Koc
2026-07-13 14:02:10 +08:00
committed by GitHub
parent bebcf52d23
commit 2454511480
3 changed files with 12 additions and 9 deletions
+3 -5
View File
@@ -5,11 +5,9 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { SmsChannelRuntime } from "./inbound.js";
import { computeTwilioSignature, parseTwilioFormBody } from "./twilio.js";
import type { ResolvedSmsAccount } from "./types.js";
import {
createSmsWebhookHandler,
createSmsWebhookReplayGuard,
resetSmsWebhookReplayGuardsForTest,
} from "./webhook.js";
import { createSmsWebhookHandler, testing } from "./webhook.js";
const { createSmsWebhookReplayGuard, resetSmsWebhookReplayGuardsForTest } = testing;
const dispatchSmsInboundEvent = vi.hoisted(() => vi.fn(async () => undefined));
+8 -2
View File
@@ -46,7 +46,7 @@ type SmsWebhookReplayGuard = {
const replayGuardsByAccount = new Map<string, SmsWebhookReplayGuard>();
export function createSmsWebhookReplayGuard(
function createSmsWebhookReplayGuard(
options: {
ttlMs?: number;
maxKeys?: number;
@@ -102,7 +102,7 @@ function resolveSmsWebhookReplayGuard(account: ResolvedSmsAccount): SmsWebhookRe
return created;
}
export function resetSmsWebhookReplayGuardsForTest(): void {
function resetSmsWebhookReplayGuardsForTest(): void {
replayGuardsByAccount.clear();
invalidRequestRateLimiter.clear();
callbackDispatchRateLimiter.clear();
@@ -154,6 +154,12 @@ function rejectInvalidRequestRateLimit(params: {
return true;
}
/** Test-only hooks for webhook state that is otherwise private. */
export const testing = {
createSmsWebhookReplayGuard,
resetSmsWebhookReplayGuardsForTest,
};
// Each account route owns its guard so one saturated account cannot block sibling accounts.
export function createSmsWebhookHandler(
params: SmsWebhookHandlerParams,
+1 -2
View File
@@ -914,8 +914,7 @@ export const KNIP_UNUSED_EXPORT_BASELINE = [
"extensions/sms/src/twilio.ts: computeTwilioSignature",
"extensions/sms/src/twilio.ts: parseTwilioFormBody",
"extensions/sms/src/twilio.ts: TwilioSmsApiError",
"extensions/sms/src/webhook.ts: createSmsWebhookReplayGuard",
"extensions/sms/src/webhook.ts: resetSmsWebhookReplayGuardsForTest",
"extensions/sms/src/webhook.ts: testing",
"extensions/synology-chat/src/channel.ts: createSynologyChatPlugin",
"extensions/synology-chat/src/channel.ts: synologyChatMessageAdapter",
"extensions/synology-chat/src/client.ts: fetchChatUsers (synologyClient)",