Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

test(wake-word): cover matcher, settings, and wake-word call paths

Rishabh Bajpai6a240a2e657b
diff --git a/app/src/test/java/com/gotcha/data/SettingsTest.kt b/app/src/test/java/com/gotcha/data/SettingsTest.kt
index ff97127..4e0b311 100644
--- a/app/src/test/java/com/gotcha/data/SettingsTest.kt
+++ b/app/src/test/java/com/gotcha/data/SettingsTest.kt
@@ -305,4 +305,24 @@ class SettingsTest {
)
assertEquals(false, samosa.hasUsableModel)
}
+
+ @Test
+ fun `wake word defaults match the model card balanced recommendation`() {
+ val defaults = Settings()
+ assertEquals(false, defaults.wakeWordEnabled)
+ // 0.75 sensitivity maps to threshold 0.50; we keep the slider in the
+ // upper-mid range by default so a first-time user gets the balanced
+ // behaviour the model card recommends.
+ assertEquals(0.75f, defaults.wakeWordSensitivity, 0.001f)
+ }
+
+ @Test
+ fun `wake word settings are independent fields on copy`() {
+ val defaults = Settings()
+ val enabled = defaults.copy(wakeWordEnabled = true, wakeWordSensitivity = 0.35f)
+ assertEquals(true, enabled.wakeWordEnabled)
+ assertEquals(0.35f, enabled.wakeWordSensitivity, 0.001f)
+ // Untouched fields stay at their defaults.
+ assertEquals(false, enabled.assistiveBallEnabled)
+ }
}
diff --git a/app/src/test/java/com/gotcha/service/CallSessionControllerTest.kt b/app/src/test/java/com/gotcha/service/CallSessionControllerTest.kt
index 7f24d62..04a3b73 100644
--- a/app/src/test/java/com/gotcha/service/CallSessionControllerTest.kt
+++ b/app/src/test/java/com/gotcha/service/CallSessionControllerTest.kt
@@ -154,4 +154,40 @@ class CallSessionControllerTest {
assertTrue("a changed API key must force a client rebuild", first !== second)
}
+
+ @Test
+ fun `startWakeWordCall transitions out of idle when configuration is valid`() {
+ settingsRepository.save(
+ Settings(
+ provider = LlmProvider.SAMOSA_AI,
+ samosaSessionToken = "samosa-jwt-token",
+ sttProvider = AudioProvider.SAMOSA_AI,
+ sttApiModel = "whisper-1",
+ ttsProvider = AudioProvider.SAMOSA_AI,
+ ttsApiModel = "tts-1"
+ )
+ )
+
+ val started = controller.startWakeWordCall()
+
+ assertTrue("startWakeWordCall should reuse the valid startCall path", started)
+ assertTrue(
+ "A wake-word call must immediately leave the idle state",
+ controller.isActive()
+ )
+ }
+
+ @Test
+ fun `startWakeWordCall fails when configuration is invalid`() {
+ // No provider / API key configured — buildClient() returns null and
+ // the call reports an error, so startWakeWordCall must short-circuit.
+ var errorMessage: String? = null
+ controller.onError = { errorMessage = it }
+
+ val started = controller.startWakeWordCall()
+
+ assertFalse("startWakeWordCall must surface configuration errors", started)
+ assertTrue(errorMessage != null)
+ assertFalse("The call controller must stay idle on a failed wake-word start", controller.isActive())
+ }
}
diff --git a/app/src/test/java/com/gotcha/service/WakeWordMatcherTest.kt b/app/src/test/java/com/gotcha/service/WakeWordMatcherTest.kt
new file mode 100644
index 0000000..6778f77
--- /dev/null
+++ b/app/src/test/java/com/gotcha/service/WakeWordMatcherTest.kt
@@ -0,0 +1,81 @@
+package com.gotcha.service
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class WakeWordMatcherTest {
+
+ @Test
+ fun `default sensitivity maps to the model card balanced threshold`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ // 0.70 - 0.27 * 0.75 = 0.4975
+ assertEquals(0.4975f, matcher.threshold(), 0.001f)
+ }
+
+ @Test
+ fun `zero sensitivity gives the high-precision end of the model card range`() {
+ val matcher = WakeWordMatcher(0f)
+ assertEquals(0.70f, matcher.threshold(), 0.001f)
+ }
+
+ @Test
+ fun `full sensitivity gives the high-sensitivity end of the model card range`() {
+ val matcher = WakeWordMatcher(1f)
+ assertEquals(0.43f, matcher.threshold(), 0.001f)
+ }
+
+ @Test
+ fun `sensitivity is clamped before mapping to a threshold`() {
+ val negative = WakeWordMatcher(sensitivity = -5f)
+ assertEquals(0.70f, negative.threshold(), 0.001f)
+ val huge = WakeWordMatcher(sensitivity = 5f)
+ assertEquals(0.43f, huge.threshold(), 0.001f)
+ }
+
+ @Test
+ fun `single frame above threshold does not fire`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ assertFalse(matcher.onScore(matcher.threshold() + 0.1f))
+ }
+
+ @Test
+ fun `two consecutive frames above threshold fire the detection`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ matcher.onScore(matcher.threshold() + 0.1f)
+ assertTrue(matcher.onScore(matcher.threshold() + 0.1f))
+ }
+
+ @Test
+ fun `streak resets when a low score breaks the run`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ matcher.onScore(matcher.threshold() + 0.1f)
+ matcher.onScore(matcher.threshold() - 0.1f)
+ assertFalse(matcher.onScore(matcher.threshold() + 0.1f))
+ }
+
+ @Test
+ fun `streak resets after a successful detection so the next word requires two frames again`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ matcher.onScore(matcher.threshold() + 0.1f)
+ matcher.onScore(matcher.threshold() + 0.1f) // fires; streak reset to 0
+ assertFalse(matcher.onScore(matcher.threshold() + 0.1f)) // streak=1
+ assertTrue(matcher.onScore(matcher.threshold() + 0.1f)) // streak=2 fires
+ }
+
+ @Test
+ fun `reset clears the streak`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ matcher.onScore(matcher.threshold() + 0.1f)
+ matcher.reset()
+ assertFalse(matcher.onScore(matcher.threshold() + 0.1f))
+ }
+
+ @Test
+ fun `scores exactly at threshold still count`() {
+ val matcher = WakeWordMatcher(WakeWordMatcher.DEFAULT_SENSITIVITY)
+ matcher.onScore(matcher.threshold())
+ assertTrue(matcher.onScore(matcher.threshold()))
+ }
+}