@@ -710,6 +710,7 @@ describe("sendMessageSignal receipts", () => {
710710 it . each ( [
711711 "Signal RPC -32602: quote rejected" ,
712712 'Signal RPC -32602: Unrecognized field "quoteTimestamp"' ,
713+ "Signal REST 400: quote metadata invalid" ,
713714 ] ) ( "falls back to an ordinary send when native quote metadata fails: %s" , async ( message ) => {
714715 signalRpcRequestMock
715716 . mockRejectedValueOnce ( new Error ( message ) )
@@ -781,8 +782,12 @@ describe("sendMessageSignal receipts", () => {
781782 } ) ;
782783 } ) ;
783784
784- it ( "does not retry ordinary send failures as quote fallback" , async ( ) => {
785- signalRpcRequestMock . mockRejectedValueOnce ( new Error ( "Signal HTTP timed out after 10000ms" ) ) ;
785+ it . each ( [
786+ "Signal HTTP timed out after 10000ms" ,
787+ "quote metadata not found after an unknown transport failure" ,
788+ "Signal RPC -32000: quote metadata was rejected after an ambiguous send" ,
789+ ] ) ( "does not retry an unconfirmed quote rejection: %s" , async ( message ) => {
790+ signalRpcRequestMock . mockRejectedValueOnce ( new Error ( message ) ) ;
786791
787792 await expect (
788793 sendMessageSignal ( "+15551234567" , "hello" , {
@@ -791,12 +796,113 @@ describe("sendMessageSignal receipts", () => {
791796 replyToAuthor : "+15550002222" ,
792797 replyToBody : "original" ,
793798 } ) ,
794- ) . rejects . toThrow ( "Signal HTTP timed out" ) ;
799+ ) . rejects . toThrow ( message ) ;
795800
796801 expect ( signalRpcRequestMock ) . toHaveBeenCalledTimes ( 1 ) ;
797802 } ) ;
798803} ) ;
799804
805+ describe ( "Signal quoted-message provider replay safety" , ( ) => {
806+ it . each ( [
807+ { label : "HTTP 408" , transportKind : "container" , status : 408 , fallback : false } ,
808+ { label : "HTTP 429" , transportKind : "container" , status : 429 , fallback : false } ,
809+ { label : "HTTP 503" , transportKind : "container" , status : 503 , fallback : false } ,
810+ { label : "HTTP 400" , transportKind : "container" , status : 400 , fallback : true } ,
811+ { label : "RPC -32603" , transportKind : "external-native" , rpcCode : - 32603 , fallback : false } ,
812+ { label : "RPC -32602" , transportKind : "external-native" , rpcCode : - 32602 , fallback : true } ,
813+ ] as const ) ( "replays a real $label request only after definitive rejection" , async ( testCase ) => {
814+ const requests : Array < Record < string , unknown > > = [ ] ;
815+ const server = http . createServer ( ( request , response ) => {
816+ let body = "" ;
817+ request . on ( "data" , ( chunk : Buffer ) => {
818+ body += chunk . toString ( "utf8" ) ;
819+ } ) ;
820+ request . on ( "end" , ( ) => {
821+ const payload = JSON . parse ( body ) as Record < string , unknown > ;
822+ requests . push ( payload ) ;
823+ if ( requests . length === 1 ) {
824+ if ( testCase . transportKind === "container" ) {
825+ response . writeHead ( testCase . status , { "content-type" : "text/plain" } ) ;
826+ response . end ( "quote storage not found during upstream outage" ) ;
827+ } else {
828+ response . writeHead ( 200 , { "content-type" : "application/json" } ) ;
829+ response . end (
830+ JSON . stringify ( {
831+ jsonrpc : "2.0" ,
832+ id : payload . id ,
833+ error : {
834+ code : testCase . rpcCode ,
835+ message : "quote storage not found during upstream outage" ,
836+ } ,
837+ } ) ,
838+ ) ;
839+ }
840+ return ;
841+ }
842+ response . writeHead ( 200 , { "content-type" : "application/json" } ) ;
843+ response . end (
844+ JSON . stringify (
845+ testCase . transportKind === "container"
846+ ? { timestamp : 1700000000002 }
847+ : {
848+ jsonrpc : "2.0" ,
849+ id : payload . id ,
850+ result : { timestamp : 1700000000002 } ,
851+ } ,
852+ ) ,
853+ ) ;
854+ } ) ;
855+ } ) ;
856+ await new Promise < void > ( ( resolve ) => {
857+ server . listen ( 0 , "127.0.0.1" , resolve ) ;
858+ } ) ;
859+ const { port } = server . address ( ) as { port : number } ;
860+ const cfg = {
861+ channels : {
862+ signal : {
863+ accounts : {
864+ default : {
865+ account : "+15550001111" ,
866+ transport : { kind : testCase . transportKind , url : `http://127.0.0.1:${ port } ` } ,
867+ } ,
868+ } ,
869+ } ,
870+ } ,
871+ } satisfies OpenClawConfig ;
872+
873+ vi . doUnmock ( "./client-adapter.js" ) ;
874+ vi . resetModules ( ) ;
875+ const { sendMessageSignal : sendWithRealContainer } = await import ( "./send.js" ) ;
876+
877+ try {
878+ const delivery = sendWithRealContainer ( "+15551234567" , "deliver only once" , {
879+ cfg,
880+ textMode : "plain" ,
881+ replyToId : "1700000000001" ,
882+ replyToAuthor : "+15550002222" ,
883+ replyToBody : "original" ,
884+ } ) ;
885+ if ( testCase . fallback ) {
886+ await expect ( delivery ) . resolves . toMatchObject ( { messageId : "1700000000002" } ) ;
887+ } else {
888+ const expectedError =
889+ testCase . transportKind === "container"
890+ ? `Signal REST ${ testCase . status } `
891+ : `Signal RPC ${ testCase . rpcCode } ` ;
892+ await expect ( delivery ) . rejects . toThrow ( expectedError ) ;
893+ }
894+ expect ( requests ) . toHaveLength ( testCase . fallback ? 2 : 1 ) ;
895+ const quoteTimestampPath =
896+ testCase . transportKind === "container" ? "quote_timestamp" : "params.quoteTimestamp" ;
897+ expect ( requests [ 0 ] ) . toHaveProperty ( quoteTimestampPath , 1700000000001 ) ;
898+ } finally {
899+ await new Promise < void > ( ( resolve ) => {
900+ server . close ( ( ) => resolve ( ) ) ;
901+ } ) ;
902+ }
903+ } ) ;
904+ } ) ;
905+
800906describe ( "Signal native JSON-RPC recipient delivery" , ( ) => {
801907 it ( "rejects real per-recipient failures and preserves successful send receipts" , async ( ) => {
802908 const failureTypes = [
0 commit comments