@@ -791,31 +791,78 @@ describe("TTS runtime provider fallback and delivery behavior", () => {
791791} ) ;
792792
793793describe ( "cold speech runtime visible fallback" , ( ) => {
794- it ( "materializes voice-only structured speech as visible text when the runtime is unavailable" , async ( ) => {
795- const { setSpeechRuntimeAvailabilityGuard } = await import ( "./runtime-availability.js" ) ;
796- setSpeechRuntimeAvailabilityGuard ( ( ) => {
797- throw new Error ( "speech runtime configured cold" ) ;
798- } ) ;
799- try {
800- const payload : ReplyPayload = { text : "" } ;
801- setReplyPayloadMetadata ( payload , {
802- ttsExplicit : true ,
803- tts : { tagged : true , text : "Spoken greeting" } ,
794+ it . each ( [
795+ { loaded : true , structured : false } ,
796+ { loaded : true , structured : true } ,
797+ { loaded : false , structured : false } ,
798+ { loaded : false , structured : true } ,
799+ ] ) (
800+ "delivers voice-only speech when its runtime is unavailable (loaded: $loaded, structured: $structured)" ,
801+ async ( { loaded, structured } ) => {
802+ const { setSpeechRuntimeAvailabilityGuard } = await import ( "./runtime-availability.js" ) ;
803+ const restoreRegistry = installStructuredReplyTestChannel ( loaded ) ;
804+ setSpeechRuntimeAvailabilityGuard ( ( ) => {
805+ throw new Error ( "speech runtime configured cold" ) ;
804806 } ) ;
805- const result = await maybeApplyTtsToPayloadCore (
806- {
807- payload,
808- cfg : createTtsConfig ( "openclaw-speech-cold-runtime-fallback-test" ) ,
809- channel : "slack" ,
810- kind : "final" ,
811- } ,
812- async ( ) => "unused" ,
813- ) ;
814- expect ( result . text ) . toBe ( "Spoken greeting" ) ;
815- } finally {
816- setSpeechRuntimeAvailabilityGuard ( undefined ) ;
817- }
818- } ) ;
807+ routedPayloads . length = 0 ;
808+ synthesizeMock . mockClear ( ) ;
809+ try {
810+ const answer = "Spoken greeting" ;
811+ const channelData = structured
812+ ? {
813+ slack : {
814+ blocks : [
815+ { type : "section" , text : { type : "mrkdwn" , text : "Visible channel card" } } ,
816+ ] ,
817+ } ,
818+ }
819+ : { slack : { unfurl : false } } ;
820+ const cfg = createTtsConfig ( `openclaw-speech-cold-runtime-${ loaded } -${ structured } ` ) ;
821+ const routingResults : Array < Awaited < ReturnType < typeof routeReply > > > = [ ] ;
822+ const dispatcher = createReplyDispatcher ( {
823+ beforeDeliver : ( payload , info ) =>
824+ maybeApplyTtsToPayloadCore (
825+ { payload, cfg, channel : "slack" , kind : info . kind } ,
826+ async ( ) => "unused" ,
827+ ) ,
828+ deliver : async ( payload , info ) => {
829+ routingResults . push (
830+ await routeReply ( {
831+ payload,
832+ channel : "slack" ,
833+ to : "channel:C123" ,
834+ cfg,
835+ replyKind : info . kind ,
836+ } ) ,
837+ ) ;
838+ } ,
839+ } ) ;
840+
841+ expect (
842+ dispatcher . sendFinalReply (
843+ setReplyPayloadMetadata (
844+ { text : "" , channelData } ,
845+ { ttsExplicit : true , tts : { tagged : true , text : answer } } ,
846+ ) ,
847+ ) ,
848+ ) . toBe ( true ) ;
849+ dispatcher . markComplete ( ) ;
850+ await dispatcher . waitForIdle ( ) ;
851+
852+ expect ( routingResults ) . toEqual ( [ { ok : true , delivered : true , messageId : "tts-route-1" } ] ) ;
853+ expect ( routedPayloads ) . toHaveLength ( 1 ) ;
854+ expect ( routedPayloads [ 0 ] ) . toMatchObject ( {
855+ text : structured ? "" : answer ,
856+ channelData,
857+ } ) ;
858+ expect ( synthesizeMock ) . not . toHaveBeenCalled ( ) ;
859+ } finally {
860+ setSpeechRuntimeAvailabilityGuard ( undefined ) ;
861+ restoreRegistry ( ) ;
862+ routedPayloads . length = 0 ;
863+ }
864+ } ,
865+ ) ;
819866
820867 it ( "keeps payloads with visible text unchanged when the runtime is unavailable" , async ( ) => {
821868 const { setSpeechRuntimeAvailabilityGuard } = await import ( "./runtime-availability.js" ) ;
0 commit comments