package ai import ( "context" "crypto/sha256" "encoding/json" "net/url" "os" "strings" "testing" "time" "git.ipao.vip/rogee/go-sip/internal/configread" ) // This opt-in diagnostic checks one real provider SDK request. It is not a // business call, an approved SaaS task, or evidence of ASR/TTS availability. func TestRealBailianDiagnosticOnce(t *testing.T) { if os.Getenv("AGENT_CALL_REAL_AI_INTEGRATION") != "1" { t.Skip("real AI diagnostic requires explicit opt-in") } endpoint := os.Getenv("BAILIAN_BASE_URL") credential := os.Getenv("BAILIAN_API_KEY") parsed, err := url.Parse(endpoint) if err != nil || parsed.Scheme != "https" || parsed.Host == "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" || credential == "" { t.Fatal("real AI diagnostic requires a private API key and plain HTTPS endpoint") } bound := Binding{ Mode: "full_ai", Prompt: "This is a harmless connectivity test. Respond briefly.", LLM: &LLMConfig{ Provider: configread.Provider{Endpoint: endpoint, Credential: credential}, Model: "qwen-plus", Params: map[string]json.RawMessage{"temperature": json.RawMessage("0"), "max_tokens": json.RawMessage("16")}, }, } ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second) defer cancel() reply, err := bound.Complete(ctx, "Respond with OK.") if err != nil { t.Fatalf("real AI diagnostic failed: type=%T error_sha256=%x", err, sha256.Sum256([]byte(err.Error()))) } if strings.TrimSpace(reply) == "" { t.Fatal("real AI diagnostic returned no text") } t.Logf("real LLM response: bytes=%d sha256=%x", len(reply), sha256.Sum256([]byte(reply))) }