@@ -1209,6 +1209,57 @@ describe("createCodexDynamicToolBridge", () => {
12091209 expect ( Object . keys ( result ) ) . not . toContain ( "terminate" ) ;
12101210 } ) ;
12111211
1212+ it ( "keeps normalized explicit source routes terminal" , async ( ) => {
1213+ setActivePluginRegistry (
1214+ createTestRegistry ( [
1215+ {
1216+ pluginId : "sms" ,
1217+ plugin : {
1218+ id : "sms" ,
1219+ messaging : {
1220+ normalizeTarget : ( raw : string ) => {
1221+ const digits = raw . replace ( / \D / gu, "" ) ;
1222+ return digits . length === 11 && digits . startsWith ( "1" ) ? `+${ digits } ` : raw . trim ( ) ;
1223+ } ,
1224+ } ,
1225+ } ,
1226+ source : "test" ,
1227+ } ,
1228+ ] ) ,
1229+ ) ;
1230+ const bridge = createBridgeWithToolResult (
1231+ "message" ,
1232+ textToolResult ( "Sent." , { ok : true , messageId : "sms-853" } ) ,
1233+ {
1234+ sourceReplyDeliveryMode : "message_tool_only" ,
1235+ currentChannelProvider : "sms" ,
1236+ currentChannelId : "sms:+12069106512" ,
1237+ currentMessagingTarget : "+12069106512" ,
1238+ } ,
1239+ ) ;
1240+
1241+ const result = await handleMessageToolCall ( bridge , {
1242+ action : "reply" ,
1243+ channel : "sms" ,
1244+ target : "+1 (206) 910-6512" ,
1245+ messageId : "853" ,
1246+ message : "visible reply" ,
1247+ } ) ;
1248+
1249+ expect ( result ) . toEqual ( expectInputText ( "Sent." ) ) ;
1250+ expect ( bridge . telemetry . messagingToolSentTargets ) . toEqual ( [
1251+ expect . objectContaining ( {
1252+ tool : "message" ,
1253+ provider : "sms" ,
1254+ to : "+12069106512" ,
1255+ text : "visible reply" ,
1256+ } ) ,
1257+ ] ) ;
1258+ expect ( result . terminate ) . toBe ( true ) ;
1259+ expect ( bridge . telemetry . didDeliverSourceReplyViaMessageTool ) . toBe ( true ) ;
1260+ expect ( Object . keys ( result ) ) . not . toContain ( "terminate" ) ;
1261+ } ) ;
1262+
12121263 it ( "keeps message-tool-only source replies terminal when the reply receipt matches the current message id" , async ( ) => {
12131264 const bridge = createBridgeWithToolResult (
12141265 "message" ,
0 commit comments