@@ -31,6 +31,8 @@ vi.mock("../../tts/provider-registry.js", () => ({
3131vi . mock ( "../../tts/tts.js" , ( ) => ttsMocks ) ;
3232
3333const { handleTtsCommands } = await import ( "./commands-tts.js" ) ;
34+ const PRIMARY_TTS_PROVIDER = "acme-speech" ;
35+ const FALLBACK_TTS_PROVIDER = "backup-speech" ;
3436
3537function buildTtsParams ( commandBodyNormalized : string ) : Parameters < typeof handleTtsCommands > [ 0 ] {
3638 return {
@@ -49,7 +51,7 @@ describe("handleTtsCommands status fallback reporting", () => {
4951 ttsMocks . resolveTtsConfig . mockReturnValue ( { } ) ;
5052 ttsMocks . resolveTtsPrefsPath . mockReturnValue ( "/tmp/tts-prefs.json" ) ;
5153 ttsMocks . isTtsEnabled . mockReturnValue ( true ) ;
52- ttsMocks . getTtsProvider . mockReturnValue ( "elevenlabs" ) ;
54+ ttsMocks . getTtsProvider . mockReturnValue ( PRIMARY_TTS_PROVIDER ) ;
5355 ttsMocks . isTtsProviderConfigured . mockReturnValue ( true ) ;
5456 ttsMocks . getTtsMaxLength . mockReturnValue ( 1500 ) ;
5557 ttsMocks . isSummarizationEnabled . mockReturnValue ( true ) ;
@@ -62,18 +64,18 @@ describe("handleTtsCommands status fallback reporting", () => {
6264 success : true ,
6365 textLength : 128 ,
6466 summarized : false ,
65- provider : "microsoft" ,
66- fallbackFrom : "elevenlabs" ,
67- attemptedProviders : [ "elevenlabs" , "microsoft" ] ,
67+ provider : FALLBACK_TTS_PROVIDER ,
68+ fallbackFrom : PRIMARY_TTS_PROVIDER ,
69+ attemptedProviders : [ PRIMARY_TTS_PROVIDER , FALLBACK_TTS_PROVIDER ] ,
6870 attempts : [
6971 {
70- provider : "elevenlabs" ,
72+ provider : PRIMARY_TTS_PROVIDER ,
7173 outcome : "failed" ,
7274 reasonCode : "provider_error" ,
7375 latencyMs : 73 ,
7476 } ,
7577 {
76- provider : "microsoft" ,
78+ provider : FALLBACK_TTS_PROVIDER ,
7779 outcome : "success" ,
7880 reasonCode : "success" ,
7981 latencyMs : 420 ,
@@ -84,10 +86,14 @@ describe("handleTtsCommands status fallback reporting", () => {
8486
8587 const result = await handleTtsCommands ( buildTtsParams ( "/tts status" ) , true ) ;
8688 expect ( result ?. shouldContinue ) . toBe ( false ) ;
87- expect ( result ?. reply ?. text ) . toContain ( "Fallback: elevenlabs -> microsoft" ) ;
88- expect ( result ?. reply ?. text ) . toContain ( "Attempts: elevenlabs -> microsoft" ) ;
8989 expect ( result ?. reply ?. text ) . toContain (
90- "Attempt details: elevenlabs:failed(provider_error) 73ms, microsoft:success(ok) 420ms" ,
90+ `Fallback: ${ PRIMARY_TTS_PROVIDER } -> ${ FALLBACK_TTS_PROVIDER } ` ,
91+ ) ;
92+ expect ( result ?. reply ?. text ) . toContain (
93+ `Attempts: ${ PRIMARY_TTS_PROVIDER } -> ${ FALLBACK_TTS_PROVIDER } ` ,
94+ ) ;
95+ expect ( result ?. reply ?. text ) . toContain (
96+ `Attempt details: ${ PRIMARY_TTS_PROVIDER } :failed(provider_error) 73ms, ${ FALLBACK_TTS_PROVIDER } :success(ok) 420ms` ,
9197 ) ;
9298 } ) ;
9399
@@ -98,10 +104,10 @@ describe("handleTtsCommands status fallback reporting", () => {
98104 textLength : 128 ,
99105 summarized : false ,
100106 error : "TTS conversion failed" ,
101- attemptedProviders : [ "elevenlabs" , "microsoft" ] ,
107+ attemptedProviders : [ PRIMARY_TTS_PROVIDER , FALLBACK_TTS_PROVIDER ] ,
102108 attempts : [
103109 {
104- provider : "elevenlabs" ,
110+ provider : PRIMARY_TTS_PROVIDER ,
105111 outcome : "failed" ,
106112 reasonCode : "timeout" ,
107113 latencyMs : 999 ,
@@ -113,8 +119,12 @@ describe("handleTtsCommands status fallback reporting", () => {
113119 const result = await handleTtsCommands ( buildTtsParams ( "/tts status" ) , true ) ;
114120 expect ( result ?. shouldContinue ) . toBe ( false ) ;
115121 expect ( result ?. reply ?. text ) . toContain ( "Error: TTS conversion failed" ) ;
116- expect ( result ?. reply ?. text ) . toContain ( "Attempts: elevenlabs -> microsoft" ) ;
117- expect ( result ?. reply ?. text ) . toContain ( "Attempt details: elevenlabs:failed(timeout) 999ms" ) ;
122+ expect ( result ?. reply ?. text ) . toContain (
123+ `Attempts: ${ PRIMARY_TTS_PROVIDER } -> ${ FALLBACK_TTS_PROVIDER } ` ,
124+ ) ;
125+ expect ( result ?. reply ?. text ) . toContain (
126+ `Attempt details: ${ PRIMARY_TTS_PROVIDER } :failed(timeout) 999ms` ,
127+ ) ;
118128 } ) ;
119129
120130 it ( "persists fallback metadata from /tts audio and renders it in /tts status" , async ( ) => {
@@ -126,18 +136,18 @@ describe("handleTtsCommands status fallback reporting", () => {
126136 ttsMocks . textToSpeech . mockResolvedValue ( {
127137 success : true ,
128138 audioPath : "/tmp/fallback.ogg" ,
129- provider : "microsoft" ,
130- fallbackFrom : "elevenlabs" ,
131- attemptedProviders : [ "elevenlabs" , "microsoft" ] ,
139+ provider : FALLBACK_TTS_PROVIDER ,
140+ fallbackFrom : PRIMARY_TTS_PROVIDER ,
141+ attemptedProviders : [ PRIMARY_TTS_PROVIDER , FALLBACK_TTS_PROVIDER ] ,
132142 attempts : [
133143 {
134- provider : "elevenlabs" ,
144+ provider : PRIMARY_TTS_PROVIDER ,
135145 outcome : "failed" ,
136146 reasonCode : "provider_error" ,
137147 latencyMs : 65 ,
138148 } ,
139149 {
140- provider : "microsoft" ,
150+ provider : FALLBACK_TTS_PROVIDER ,
141151 outcome : "success" ,
142152 reasonCode : "success" ,
143153 latencyMs : 175 ,
@@ -153,11 +163,15 @@ describe("handleTtsCommands status fallback reporting", () => {
153163
154164 const statusResult = await handleTtsCommands ( buildTtsParams ( "/tts status" ) , true ) ;
155165 expect ( statusResult ?. shouldContinue ) . toBe ( false ) ;
156- expect ( statusResult ?. reply ?. text ) . toContain ( "Provider: microsoft" ) ;
157- expect ( statusResult ?. reply ?. text ) . toContain ( "Fallback: elevenlabs -> microsoft" ) ;
158- expect ( statusResult ?. reply ?. text ) . toContain ( "Attempts: elevenlabs -> microsoft" ) ;
166+ expect ( statusResult ?. reply ?. text ) . toContain ( `Provider: ${ FALLBACK_TTS_PROVIDER } ` ) ;
167+ expect ( statusResult ?. reply ?. text ) . toContain (
168+ `Fallback: ${ PRIMARY_TTS_PROVIDER } -> ${ FALLBACK_TTS_PROVIDER } ` ,
169+ ) ;
170+ expect ( statusResult ?. reply ?. text ) . toContain (
171+ `Attempts: ${ PRIMARY_TTS_PROVIDER } -> ${ FALLBACK_TTS_PROVIDER } ` ,
172+ ) ;
159173 expect ( statusResult ?. reply ?. text ) . toContain (
160- " Attempt details: elevenlabs :failed(provider_error) 65ms, microsoft :success(ok) 175ms" ,
174+ ` Attempt details: ${ PRIMARY_TTS_PROVIDER } :failed(provider_error) 65ms, ${ FALLBACK_TTS_PROVIDER } :success(ok) 175ms` ,
161175 ) ;
162176 } ) ;
163177} ) ;
0 commit comments