2026-03-03 16:33:55 +00:00
|
|
|
import Foundation
|
2026-02-21 21:47:39 +02:00
|
|
|
import Testing
|
|
|
|
|
@testable import OpenClaw
|
|
|
|
|
|
2026-02-24 22:38:47 +00:00
|
|
|
@MainActor
|
2026-02-21 21:47:39 +02:00
|
|
|
@Suite struct TalkModeConfigParsingTests {
|
2026-02-24 22:38:47 +00:00
|
|
|
@Test func prefersNormalizedTalkProviderPayload() {
|
2026-02-21 21:47:39 +02:00
|
|
|
let talk: [String: Any] = [
|
|
|
|
|
"provider": "elevenlabs",
|
|
|
|
|
"providers": [
|
|
|
|
|
"elevenlabs": [
|
|
|
|
|
"voiceId": "voice-normalized",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
"voiceId": "voice-legacy",
|
|
|
|
|
]
|
|
|
|
|
|
2026-02-24 22:38:47 +00:00
|
|
|
let selection = TalkModeManager.selectTalkProviderConfig(talk)
|
2026-02-21 21:47:39 +02:00
|
|
|
#expect(selection?.provider == "elevenlabs")
|
|
|
|
|
#expect(selection?.config["voiceId"] as? String == "voice-normalized")
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 22:38:47 +00:00
|
|
|
@Test func ignoresLegacyTalkFieldsWhenNormalizedPayloadMissing() {
|
2026-02-21 21:47:39 +02:00
|
|
|
let talk: [String: Any] = [
|
|
|
|
|
"voiceId": "voice-legacy",
|
2026-03-06 19:35:26 -05:00
|
|
|
"apiKey": "legacy-key", // pragma: allowlist secret
|
2026-02-21 21:47:39 +02:00
|
|
|
]
|
|
|
|
|
|
2026-02-24 22:38:47 +00:00
|
|
|
let selection = TalkModeManager.selectTalkProviderConfig(talk)
|
|
|
|
|
#expect(selection == nil)
|
2026-02-21 21:47:39 +02:00
|
|
|
}
|
2026-03-03 16:33:55 +00:00
|
|
|
|
|
|
|
|
@Test func detectsPCMFormatRejectionFromElevenLabsError() {
|
|
|
|
|
let error = NSError(
|
|
|
|
|
domain: "ElevenLabsTTS",
|
|
|
|
|
code: 403,
|
|
|
|
|
userInfo: [
|
|
|
|
|
NSLocalizedDescriptionKey: "ElevenLabs failed: 403 subscription_required output_format=pcm_44100",
|
|
|
|
|
])
|
|
|
|
|
#expect(TalkModeManager._test_isPCMFormatRejectedByAPI(error))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test func ignoresGenericPlaybackFailuresForPCMFormatRejection() {
|
|
|
|
|
let error = NSError(
|
|
|
|
|
domain: "StreamingAudio",
|
|
|
|
|
code: -1,
|
|
|
|
|
userInfo: [NSLocalizedDescriptionKey: "queue enqueue failed"])
|
|
|
|
|
#expect(TalkModeManager._test_isPCMFormatRejectedByAPI(error) == false)
|
|
|
|
|
}
|
2026-02-21 21:47:39 +02:00
|
|
|
}
|