@@ -14,6 +14,7 @@ import {
1414} from "@t3tools/contracts" ;
1515
1616import { act , render } from "../../test/render" ;
17+ import type { createBrowserVoiceInputPlatform } from "./browserVoiceInput" ;
1718import { useEnvironmentSpeechInput } from "./useEnvironmentSpeechInput" ;
1819import {
1920 chooseAudioDestination ,
@@ -133,12 +134,10 @@ vi.mock("@t3tools/client-runtime/voice-input", async (importOriginal) => ({
133134 return { text : `Cleaned ${ transcript } ` } ;
134135 } ) ,
135136} ) ) ;
136- // Capture and the wire live behind the platform; its `prepared` is where audio would go.
137137vi . mock ( "./browserVoiceInput" , ( ) => ( {
138- createBrowserVoiceInputPlatform : ( input : {
139- prepared : PreparedConnection ;
140- getTranscriptionOptions ?: ( ) => SpeechTranscriptionOptions ;
141- } ) => {
138+ createBrowserVoiceInputPlatform : (
139+ input : Parameters < typeof createBrowserVoiceInputPlatform > [ 0 ] ,
140+ ) => {
142141 const environmentId = input . prepared . environmentId ;
143142 mocks . platforms . push ( environmentId ) ;
144143 return {
@@ -152,12 +151,13 @@ vi.mock("./browserVoiceInput", () => ({
152151 } ,
153152 transcriber : {
154153 prepare : async ( ) => {
155- const options = input . getTranscriptionOptions ?.( ) ;
156- if ( options ) mocks . recordingOptions . push ( options ) ;
154+ mocks . recordingOptions . push ( input . getTranscriptionOptions ( ) ) ;
157155 return {
158156 locale : "en" ,
159157 transcribe : async ( ) => {
160- mocks . transcribeCalls . push ( environmentId ) ;
158+ mocks . transcribeCalls . push (
159+ input . cloudProvider ? `${ input . cloudProvider } via ${ environmentId } ` : environmentId ,
160+ ) ;
161161 const next = mocks . transcripts . shift ( ) ?? "dictated" ;
162162 if ( next instanceof Error ) throw next ;
163163 return next ;
@@ -401,16 +401,23 @@ it("revokes across windows even before the storage event and survives stale pref
401401
402402it ( "recovers from a corrupt choice without enabling cloud dictation before the save completes" , async ( ) => {
403403 setup ( ) ;
404+ mocks . cloudVoiceCapable . add ( "env-b" ) ;
405+ mocks . modelState = "missing-model" ;
404406 window . localStorage . setItem ( "t3code:voice-audio-grant:v1" , "not-json" ) ;
405407 const save = pendingCloudAudioChoice ( {
406408 kind : "cloud" ,
407409 environmentId : EnvironmentId . make ( "env-b" ) ,
408- provider : "openai " ,
410+ provider : "xai " ,
409411 } ) ;
410412 await using _screen = await render ( < Probe /> ) ;
411413 expect ( mocks . voice . transcriptionEnvironmentId ) . toBeNull ( ) ;
414+ await act ( ( ) => mocks . voice . start ( ) ) ;
415+ expectNoAudioSent ( ) ;
412416 await act ( save ) ;
413- expect ( mocks . voice . transcriptionEnvironmentId ) . toBe ( "env-b" ) ;
417+ await act ( ( ) => mocks . voice . start ( ) ) ;
418+ await act ( ( ) => mocks . voice . stop ( ) ) ;
419+ expect ( mocks . transcribeCalls ) . toEqual ( [ "xai via env-b" ] ) ;
420+ expect ( mocks . statusRequests ) . toEqual ( [ ] ) ;
414421} ) ;
415422
416423it ( "uses neither destination when the cloud save marker cannot be read" , async ( ) => {
0 commit comments