mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
refactor(sms): consolidate webhook test hooks (#106072)
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)",
|
||||
|
||||
Reference in New Issue
Block a user