test(ios): cover voice trigger + camera clamps
This commit is contained in:
@@ -187,12 +187,12 @@ actor CameraController {
|
||||
return AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: position)
|
||||
}
|
||||
|
||||
private nonisolated static func clampQuality(_ quality: Double?) -> Double {
|
||||
nonisolated static func clampQuality(_ quality: Double?) -> Double {
|
||||
let q = quality ?? 0.9
|
||||
return min(1.0, max(0.05, q))
|
||||
}
|
||||
|
||||
private nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
||||
nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
||||
let v = ms ?? 3000
|
||||
// Keep clips short by default; avoid huge base64 payloads on the bridge.
|
||||
return min(15000, max(250, v))
|
||||
|
||||
@@ -334,7 +334,7 @@ final class VoiceWakeManager: NSObject, ObservableObject {
|
||||
Self.extractCommand(from: transcript, triggers: self.activeTriggerWords)
|
||||
}
|
||||
|
||||
private static func extractCommand(from transcript: String, triggers: [String]) -> String? {
|
||||
nonisolated static func extractCommand(from transcript: String, triggers: [String]) -> String? {
|
||||
var bestRange: Range<String.Index>?
|
||||
for trigger in triggers {
|
||||
let token = trigger.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
24
apps/ios/Tests/CameraControllerClampTests.swift
Normal file
24
apps/ios/Tests/CameraControllerClampTests.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import Testing
|
||||
@testable import Clawdis
|
||||
|
||||
@Suite struct CameraControllerClampTests {
|
||||
@Test func clampQualityDefaultsAndBounds() {
|
||||
#expect(CameraController.clampQuality(nil) == 0.9)
|
||||
#expect(CameraController.clampQuality(0.0) == 0.05)
|
||||
#expect(CameraController.clampQuality(0.049) == 0.05)
|
||||
#expect(CameraController.clampQuality(0.05) == 0.05)
|
||||
#expect(CameraController.clampQuality(0.5) == 0.5)
|
||||
#expect(CameraController.clampQuality(1.0) == 1.0)
|
||||
#expect(CameraController.clampQuality(1.1) == 1.0)
|
||||
}
|
||||
|
||||
@Test func clampDurationDefaultsAndBounds() {
|
||||
#expect(CameraController.clampDurationMs(nil) == 3000)
|
||||
#expect(CameraController.clampDurationMs(0) == 250)
|
||||
#expect(CameraController.clampDurationMs(249) == 250)
|
||||
#expect(CameraController.clampDurationMs(250) == 250)
|
||||
#expect(CameraController.clampDurationMs(1000) == 1000)
|
||||
#expect(CameraController.clampDurationMs(15000) == 15000)
|
||||
#expect(CameraController.clampDurationMs(15001) == 15000)
|
||||
}
|
||||
}
|
||||
33
apps/ios/Tests/VoiceWakeManagerExtractCommandTests.swift
Normal file
33
apps/ios/Tests/VoiceWakeManagerExtractCommandTests.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import Testing
|
||||
@testable import Clawdis
|
||||
|
||||
@Suite struct VoiceWakeManagerExtractCommandTests {
|
||||
@Test func extractCommandReturnsNilWhenNoTriggerFound() {
|
||||
#expect(VoiceWakeManager.extractCommand(from: "hello world", triggers: ["clawd"]) == nil)
|
||||
}
|
||||
|
||||
@Test func extractCommandTrimsTokensAndResult() {
|
||||
let cmd = VoiceWakeManager.extractCommand(from: "hey clawd do thing ", triggers: [" clawd "])
|
||||
#expect(cmd == "do thing")
|
||||
}
|
||||
|
||||
@Test func extractCommandPicksLatestTriggerOccurrence() {
|
||||
let transcript = "clawd first\nthen something\nclaude second"
|
||||
let cmd = VoiceWakeManager.extractCommand(from: transcript, triggers: ["clawd", "claude"])
|
||||
#expect(cmd == "second")
|
||||
}
|
||||
|
||||
@Test func extractCommandIsCaseInsensitive() {
|
||||
let cmd = VoiceWakeManager.extractCommand(from: "HELLO CLAWD run it", triggers: ["clawd"])
|
||||
#expect(cmd == "run it")
|
||||
}
|
||||
|
||||
@Test func extractCommandReturnsNilWhenNothingAfterTrigger() {
|
||||
#expect(VoiceWakeManager.extractCommand(from: "hey clawd \n", triggers: ["clawd"]) == nil)
|
||||
}
|
||||
|
||||
@Test func extractCommandIgnoresEmptyTriggers() {
|
||||
let cmd = VoiceWakeManager.extractCommand(from: "hey clawd do thing", triggers: ["", " ", "clawd"])
|
||||
#expect(cmd == "do thing")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user