@@ -20,7 +20,6 @@ defineDiscordVoiceTests(
2020 resolveRealtimeBootstrapContextInstructionsMock,
2121 createRealtimeVoiceBridgeSessionMock,
2222 realtimeSessionMock,
23- decodeOpusStreamChunksMock,
2423 managerModule,
2524 createClient,
2625 createManager,
@@ -29,9 +28,6 @@ defineDiscordVoiceTests(
2928 getSessionEntry,
3029 getVoiceReceive,
3130 getLastAudioPlayer,
32- loggerErrorMock,
33- lastRealtimeBridgeParams,
34- beginSpeakerTurn,
3531 expectOffEventWithFunction,
3632 createJoinedAgentProxyFixture,
3733 createJoinedBidiFixture,
@@ -134,133 +130,6 @@ defineDiscordVoiceTests(
134130 expect ( newStopped ) . toHaveBeenCalledOnce ( ) ;
135131 } ) ;
136132
137- it . each ( [
138- [ "agent-proxy" , "completed" ] ,
139- [ "agent-proxy" , "error" ] ,
140- [ "bidi" , "completed" ] ,
141- [ "bidi" , "error" ] ,
142- ] as const ) (
143- "retires %s voice on provider %s without affecting its replacement" ,
144- async ( mode , reason ) => {
145- const oldConnection = createConnectionMock ( ) ;
146- const newConnection = createConnectionMock ( ) ;
147- joinVoiceChannelMock . mockReturnValueOnce ( oldConnection ) . mockReturnValueOnce ( newConnection ) ;
148- const manager = createAgentProxyManager ( undefined , {
149- allowFrom : [ "discord:u-owner" ] ,
150- voice : { mode } ,
151- } ) ;
152- let finishDecoding ! : ( ) => void ;
153- const decoding = new Promise < void > ( ( resolve ) => {
154- finishDecoding = resolve ;
155- } ) ;
156- let receive : Promise < void > | undefined ;
157- try {
158- await manager . join ( { guildId : "g1" , channelId : "1001" } ) ;
159- const entry = getSessionEntry ( manager ) ;
160- const onStop = vi . fn ( ) ;
161- const transcripts = {
162- sessionId : "notes-1" ,
163- onUtterance : vi . fn ( ) ,
164- onStop : ( ) => {
165- onStop ( entry . transcripts ) ;
166- entry . stop ( ) ;
167- } ,
168- } ;
169- await manager . join ( { guildId : "g1" , channelId : "1001" } , { transcripts } ) ;
170- decodeOpusStreamChunksMock . mockReturnValueOnce ( decoding ) ;
171- receive = handleSpeakingStart ( manager , entry , "u-owner" ) ;
172- await vi . waitFor ( ( ) => expect ( decodeOpusStreamChunksMock ) . toHaveBeenCalledOnce ( ) ) ;
173- const captureStream = expectDefined (
174- oldConnection . receiver . subscribe . mock . results [ 0 ] ?. value ,
175- "voice capture stream" ,
176- ) ;
177- getVoiceReceive ( manager ) . scheduleCaptureFinalize ( entry , "u-owner" , "speaker end" ) ;
178- expect ( entry . capture . captureFinalizeTimers . size ) . toBe ( 1 ) ;
179- const turn = beginSpeakerTurn ( entry ) ;
180- const provider = lastRealtimeBridgeParams ( ) ;
181- const player = getLastAudioPlayer ( ) ;
182- provider . audioSink . sendAudio ( Buffer . alloc ( 24_000 ) ) ;
183- expect ( player . play ) . toHaveBeenCalledOnce ( ) ;
184-
185- provider . onClose ?.( reason ) ;
186-
187- expect ( manager . status ( ) ) . toEqual ( [ ] ) ;
188- expect ( entry . realtime ) . toBeUndefined ( ) ;
189- expect ( entry . transcripts ) . toBeUndefined ( ) ;
190- expect ( onStop ) . toHaveBeenCalledExactlyOnceWith ( undefined ) ;
191- expect ( captureStream . destroy ) . toHaveBeenCalledOnce ( ) ;
192- expect ( entry . capture . activeCaptureStreams . size ) . toBe ( 0 ) ;
193- expect ( entry . capture . captureFinalizeTimers . size ) . toBe ( 0 ) ;
194- expect ( oldConnection . destroy ) . toHaveBeenCalledOnce ( ) ;
195- expect ( realtimeSessionMock . close ) . toHaveBeenCalledOnce ( ) ;
196- expect ( loggerErrorMock ) . toHaveBeenCalledExactlyOnceWith (
197- expect . stringContaining ( `Realtime provider closed unexpectedly: ${ reason } ` ) ,
198- ) ;
199- expect ( player . stop ) . toHaveBeenCalledWith ( true ) ;
200- expectOffEventWithFunction ( oldConnection . receiver . speaking . off , "start" ) ;
201- expectOffEventWithFunction ( oldConnection . receiver . speaking . off , "end" ) ;
202- const audioPlayer = expectDefined (
203- createAudioPlayerMock . mock . results [ 0 ] ?. value ,
204- "audio player" ,
205- ) ;
206- expectOffEventWithFunction ( audioPlayer . off , "idle" ) ;
207-
208- await manager . join ( { guildId : "g1" , channelId : "1001" } ) ;
209- const replacement = getSessionEntry ( manager ) ;
210- const replacementTranscripts = {
211- sessionId : "notes-2" ,
212- onUtterance : vi . fn ( ) ,
213- onStop : vi . fn ( ) ,
214- } ;
215- await manager . join (
216- { guildId : "g1" , channelId : "1001" } ,
217- { transcripts : replacementTranscripts } ,
218- ) ;
219- const inputCalls = realtimeSessionMock . sendAudio . mock . calls . length ;
220- turn ?. sendInputAudio ( Buffer . alloc ( 3840 ) ) ;
221- turn ?. close ( ) ;
222- provider . onClose ?.( reason ) ;
223- provider . onReady ?.( ) ;
224- provider . onEvent ?.( { direction : "client" , type : "session.reconnect.ready" } ) ;
225- provider . audioSink . sendAudio ( Buffer . alloc ( 24_000 ) ) ;
226- provider . onTranscript ?.( "user" , "stale transcript" , true ) ;
227- provider . onEvent ?.( { direction : "server" , type : "response.done" } ) ;
228- await Promise . resolve ( ) ;
229-
230- expectConnectedStatus ( manager , "1001" ) ;
231- expect ( getSessionEntry ( manager ) ) . toBe ( replacement ) ;
232- expect ( newConnection . destroy ) . not . toHaveBeenCalled ( ) ;
233- expect ( realtimeSessionMock . close ) . toHaveBeenCalledOnce ( ) ;
234- expect ( loggerErrorMock ) . toHaveBeenCalledOnce ( ) ;
235- expect ( realtimeSessionMock . sendAudio ) . toHaveBeenCalledTimes ( inputCalls ) ;
236- expect ( player . play ) . toHaveBeenCalledOnce ( ) ;
237- expect ( onStop ) . toHaveBeenCalledOnce ( ) ;
238- expect ( replacementTranscripts . onStop ) . not . toHaveBeenCalled ( ) ;
239- expect ( transcripts . onUtterance ) . not . toHaveBeenCalled ( ) ;
240- expect ( replacementTranscripts . onUtterance ) . not . toHaveBeenCalled ( ) ;
241- beginSpeakerTurn ( replacement ) ;
242- expect ( realtimeSessionMock . sendAudio ) . toHaveBeenCalledTimes ( inputCalls + 1 ) ;
243- } finally {
244- finishDecoding ( ) ;
245- await receive ;
246- await manager . destroy ( ) ;
247- }
248- } ,
249- ) ;
250-
251- it ( "does not report a terminal error when local close synchronously closes the provider" , async ( ) => {
252- const { bridgeParams, manager } = await createJoinedAgentProxyFixture ( ) ;
253- realtimeSessionMock . close . mockImplementationOnce ( ( ) => bridgeParams . onClose ?.( "completed" ) ) ;
254- try {
255- await manager . leave ( { guildId : "g1" } ) ;
256- expect ( manager . status ( ) ) . toEqual ( [ ] ) ;
257- expect ( realtimeSessionMock . close ) . toHaveBeenCalledOnce ( ) ;
258- expect ( loggerErrorMock ) . not . toHaveBeenCalled ( ) ;
259- } finally {
260- await manager . destroy ( ) ;
261- }
262- } ) ;
263-
264133 it ( "attaches transcripts capture to an existing voice session" , async ( ) => {
265134 const manager = createManager ( ) ;
266135
0 commit comments