74 lines
3.8 KiB
Go
74 lines
3.8 KiB
Go
package ai
|
|
|
|
import (
|
|
"git.ipao.vip/rogee/go-sip/internal/configread"
|
|
"testing"
|
|
)
|
|
|
|
func TestProtocolCapabilitiesRejectUnexpressibleSettingsWithoutFallback(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, protocol string
|
|
change func(map[string]any)
|
|
connection func(map[string]configread.Provider)
|
|
}{
|
|
{name: "HTTP-speed", protocol: TTSProtocolDashScopeHTTP, change: func(a map[string]any) { a["tts"].(map[string]any)["speed"] = 1.5 }},
|
|
{name: "HTTP-missing-endpoint", protocol: TTSProtocolDashScopeHTTP, connection: func(p map[string]configread.Provider) { x := p["tts-example"]; x.Endpoint = ""; p[x.ProviderRef] = x }},
|
|
{name: "WS-missing-endpoint", protocol: TTSProtocolDashScopeTask, connection: func(p map[string]configread.Provider) { x := p["tts-example"]; x.WSEndpoint = ""; p[x.ProviderRef] = x }},
|
|
{name: "WS-speed", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["tts"].(map[string]any)["speed"] = 2.5 }},
|
|
{name: "WS-language", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["tts"].(map[string]any)["language_type"] = "not a language" }},
|
|
{name: "WS-unspecified-language", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["tts"].(map[string]any)["language_type"] = "und-US" }},
|
|
{name: "ASR-interim", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["asr"].(map[string]any)["interim"] = false }},
|
|
{name: "missing-ASR-model", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { delete(a["asr"].(map[string]any), "model") }},
|
|
{name: "ASR-rate", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["asr"].(map[string]any)["input"].(map[string]any)["sample_rate_hz"] = 48000 }},
|
|
{name: "ASR-language", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["asr"].(map[string]any)["language"] = "bad language" }},
|
|
{name: "unknown-parameter", protocol: TTSProtocolDashScopeTask, change: func(a map[string]any) { a["tts"].(map[string]any)["extra_parameter"] = true }},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
task, providers := protocolTask(t, tc.protocol)
|
|
if tc.change != nil {
|
|
task = changeCurrentAgent(t, task, tc.change)
|
|
}
|
|
if tc.connection != nil {
|
|
tc.connection(providers)
|
|
}
|
|
if _, err := Bind(task, providers); err == nil {
|
|
t.Fatal("unsupported request silently altered or accepted")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestKnownModelNamesDoNotSelectTheProtocol(t *testing.T) {
|
|
for _, tc := range []struct{ protocol, model string }{{TTSProtocolDashScopeHTTP, "cosyvoice-v3-flash"}, {TTSProtocolDashScopeTask, "qwen3-tts-flash"}} {
|
|
t.Run(tc.protocol, func(t *testing.T) {
|
|
task, providers := protocolTask(t, tc.protocol)
|
|
task = changeCurrentAgent(t, task, func(a map[string]any) { a["tts"].(map[string]any)["model"] = tc.model })
|
|
bound, err := Bind(task, providers)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if bound.TTS.Protocol != tc.protocol || bound.TTS.Model != tc.model {
|
|
t.Fatal("explicit selection replaced by a model-name mapping")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLanguageHintsKeepExplicitLanguageAndNeverGuessFromRegion(t *testing.T) {
|
|
for _, tc := range []struct{ value, want string }{{"Chinese", "zh"}, {"English", "en"}, {"Japanese", "ja"}, {"Korean", "ko"}, {"German", "de"}, {"French", "fr"}, {"Russian", "ru"}, {"Italian", "it"}, {"Spanish", "es"}, {"Portuguese", "pt"}, {"en-US", "en"}, {"zh-CN", "zh"}, {"fr-FR", "fr"}} {
|
|
got, err := bailianLanguageHint(tc.value)
|
|
if err != nil || got != tc.want {
|
|
t.Fatalf("hint %s = %s %v", tc.value, got, err)
|
|
}
|
|
}
|
|
for _, value := range []string{"", "und", "und-US", "not a language"} {
|
|
if _, err := bailianLanguageHint(value); err == nil {
|
|
t.Fatalf("language inferred from %q", value)
|
|
}
|
|
}
|
|
hints, err := bailianTTSLanguageHints("Auto")
|
|
if err != nil || hints != nil {
|
|
t.Fatal("explicit Auto must omit the hint")
|
|
}
|
|
}
|