11// Sms tests cover send plugin behavior.
22import { isChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound" ;
3+ import { PlatformMessageNotDispatchedError } from "openclaw/plugin-sdk/error-runtime" ;
34import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
5+ import { resolveSmsAccount } from "./accounts.js" ;
6+ import {
7+ prepareSmsMediaAttempt ,
8+ sendPreparedSmsMediaAttempt ,
9+ sendSmsTextChunks ,
10+ toSmsPlainText ,
11+ } from "./send.js" ;
412import type { sendSmsViaTwilio as sendSmsViaTwilioType } from "./twilio.js" ;
513import type { ResolvedSmsAccount } from "./types.js" ;
614
715type SendModule = typeof import ( "./send.js" ) ;
816type SendSmsMediaParams = Parameters < SendModule [ "prepareSmsMediaAttempt" ] > [ 0 ] &
917 Omit < Parameters < SendModule [ "sendPreparedSmsMediaAttempt" ] > [ 0 ] , "attempt" > ;
1018
11- let sendSmsTextChunks : SendModule [ "sendSmsTextChunks" ] ;
12- let prepareSmsMediaAttempt : SendModule [ "prepareSmsMediaAttempt" ] ;
13- let sendPreparedSmsMediaAttempt : SendModule [ "sendPreparedSmsMediaAttempt" ] ;
14- let toSmsPlainText : SendModule [ "toSmsPlainText" ] ;
15- let resolveSmsAccount : ( typeof import ( "./accounts.js" ) ) [ "resolveSmsAccount" ] ;
16-
1719const sendSmsViaTwilio = vi . hoisted ( ( ) =>
1820 vi . fn < typeof sendSmsViaTwilioType > ( async ( { to, onPlatformSendDispatch } ) => {
1921 await onPlatformSendDispatch ?.( ) ;
@@ -33,8 +35,28 @@ const hostedMediaMocks = vi.hoisted(() => {
3335const recordInitialSmsDeliveryResult = vi . hoisted ( ( ) => vi . fn ( async ( ) => null ) ) ;
3436const deliveryWarn = vi . hoisted ( ( ) => vi . fn ( ) ) ;
3537
36- beforeEach ( async ( ) => {
37- vi . resetModules ( ) ;
38+ vi . mock ( "./twilio.js" , async ( importOriginal ) => ( {
39+ ...( await importOriginal < typeof import ( "./twilio.js" ) > ( ) ) ,
40+ sendSmsViaTwilio,
41+ } ) ) ;
42+ vi . mock ( "./media.js" , async ( importOriginal ) => ( {
43+ ...( await importOriginal < typeof import ( "./media.js" ) > ( ) ) ,
44+ prepareHostedSmsMedia : hostedMediaMocks . prepare ,
45+ } ) ) ;
46+ vi . mock ( "./delivery-observations.js" , async ( importOriginal ) => ( {
47+ ...( await importOriginal < typeof import ( "./delivery-observations.js" ) > ( ) ) ,
48+ recordInitialSmsDeliveryResult,
49+ } ) ) ;
50+ vi . mock ( "./runtime.js" , async ( importOriginal ) => ( {
51+ ...( await importOriginal < typeof import ( "./runtime.js" ) > ( ) ) ,
52+ getSmsRuntime : ( ) => ( {
53+ logging : {
54+ getChildLogger : ( ) => ( { warn : deliveryWarn } ) ,
55+ } ,
56+ } ) ,
57+ } ) ) ;
58+
59+ beforeEach ( ( ) => {
3860 sendSmsViaTwilio . mockReset ( ) ;
3961 sendSmsViaTwilio . mockImplementation ( async ( { to, onPlatformSendDispatch } ) => {
4062 await onPlatformSendDispatch ?.( ) ;
@@ -50,33 +72,9 @@ beforeEach(async () => {
5072 recordInitialSmsDeliveryResult . mockReset ( ) ;
5173 recordInitialSmsDeliveryResult . mockResolvedValue ( null ) ;
5274 deliveryWarn . mockClear ( ) ;
53- vi . doMock ( "./twilio.js" , ( ) => ( {
54- sendSmsViaTwilio,
55- TWILIO_MESSAGE_BODY_MAX_LENGTH : 1600 ,
56- } ) ) ;
57- vi . doMock ( "./media.js" , ( ) => ( {
58- prepareHostedSmsMedia : hostedMediaMocks . prepare ,
59- } ) ) ;
60- vi . doMock ( "./delivery-observations.js" , ( ) => ( {
61- recordInitialSmsDeliveryResult,
62- } ) ) ;
63- vi . doMock ( "./runtime.js" , ( ) => ( {
64- getSmsRuntime : ( ) => ( {
65- logging : {
66- getChildLogger : ( ) => ( { warn : deliveryWarn } ) ,
67- } ,
68- } ) ,
69- } ) ) ;
70- ( { prepareSmsMediaAttempt, sendPreparedSmsMediaAttempt, sendSmsTextChunks, toSmsPlainText } =
71- await import ( "./send.js" ) ) ;
72- ( { resolveSmsAccount } = await import ( "./accounts.js" ) ) ;
7375} ) ;
7476
7577afterEach ( ( ) => {
76- vi . doUnmock ( "./twilio.js" ) ;
77- vi . doUnmock ( "./media.js" ) ;
78- vi . doUnmock ( "./delivery-observations.js" ) ;
79- vi . doUnmock ( "./runtime.js" ) ;
8078 delete process . env . TWILIO_ACCOUNT_SID ;
8179 delete process . env . TWILIO_AUTH_TOKEN ;
8280 delete process . env . TWILIO_PHONE_NUMBER ;
@@ -408,7 +406,6 @@ describe("sendSmsTextChunks", () => {
408406
409407describe ( "sendSmsMedia" , ( ) => {
410408 it ( "preserves existing pre-dispatch proof from hosted-media staging" , async ( ) => {
411- const { PlatformMessageNotDispatchedError } = await import ( "openclaw/plugin-sdk/error-runtime" ) ;
412409 const rejection = new PlatformMessageNotDispatchedError ( "unsupported hosted media" , {
413410 cause : new Error ( "unsupported content type" ) ,
414411 retryable : false ,
0 commit comments