package com.cottondb.messages.chat import android.app.Application import android.os.ParcelFileDescriptor import android.speech.RecognizerIntent import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * The emulator (22 Nov 2026): the phone held no model for the language, and the app's ask for it went with the listening * intent, whose recording pipe was already closed: "Bad file descriptor", no model, no words on any voice message. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = Application::class) class VoiceModelAskTest { @Test fun the_ask_for_a_language_model_carries_no_recording() { val ask = VoiceTranscript.modelIntent("en-US") assertEquals(RecognizerIntent.ACTION_RECOGNIZE_SPEECH, ask.action) assertEquals("en-US", ask.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE)) assertTrue(ask.getBooleanExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, false)) assertFalse("no pipe to close under it", ask.hasExtra(RecognizerIntent.EXTRA_AUDIO_SOURCE)) // Each ask is its own: a listening intent built from it does not reach back into the next ask. val pipe = ParcelFileDescriptor.createPipe() VoiceTranscript.modelIntent("en-US").putExtra(RecognizerIntent.EXTRA_AUDIO_SOURCE, pipe[0]) assertFalse(VoiceTranscript.modelIntent("en-US").hasExtra(RecognizerIntent.EXTRA_AUDIO_SOURCE)) pipe.forEach { it.close() } } }