Files
go-sip/internal/ai/provider_pipeline_test.go
T

55 lines
1.6 KiB
Go

package ai
import (
"context"
"strings"
"testing"
"git.ipao.vip/rogee/go-sip/contracts"
)
func TestLoadProviderPipelineConfigAllowsASROnlyCredentials(t *testing.T) {
t.Setenv("VOLC_ASR_APP_NAME", "asr-app")
t.Setenv("VOLC_ASR_APP_KEY", "asr-key")
t.Setenv("VOLC_ASR_WSS_URL", "")
t.Setenv("BAILIAN_API_KEY", "")
t.Setenv("BAILIAN_BASE_URL", "")
t.Setenv("BAILIAN_TTS_VOICE", "")
if _, err := LoadProviderPipelineConfigFromEnv(); err != nil {
t.Fatalf("ASR-only provider config should not require Bailian credentials: %v", err)
}
}
func TestProviderPipelineRunsASROnlyWithoutBailian(t *testing.T) {
raw, err := contracts.Read("examples/agent-version-asr-only.json")
if err != nil {
t.Fatal(err)
}
snapshot, err := ValidateForMode(raw, ModeASROnly)
if err != nil {
t.Fatal(err)
}
pipeline, err := NewProviderPipeline(ProviderPipelineConfig{VolcAppID: "asr-app", VolcAPIKey: "asr-key"})
if err != nil {
t.Fatal(err)
}
pipeline.recognizeFn = func(context.Context, string, string, []byte) (string, error) {
return "recognized without Bailian", nil
}
result, err := pipeline.RunTurn(context.Background(), snapshot, []byte{1, 2})
if err != nil {
t.Fatal(err)
}
if result.Transcript != "recognized without Bailian" || result.Reply != "" || len(result.AudioPCM16) != 0 {
t.Fatalf("unexpected ASR-only result: %+v", result)
}
}
func TestProviderPipelineASROnlyDoesNotUseTTS(t *testing.T) {
pipeline := &ProviderPipeline{}
_, err := pipeline.Synthesize(context.Background(), Snapshot{Mode: ModeASROnly}, "opening")
if err == nil || !strings.Contains(err.Error(), "does not use TTS") {
t.Fatalf("Synthesize(ASR-only) error=%v", err)
}
}