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

48 lines
1.6 KiB
Go

package ai
import (
"context"
"crypto/sha256"
"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")
}
maxTokens := int64(16)
temperature := 0.0
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", Temperature: &temperature, MaxTokens: &maxTokens, Timeout: 30 * time.Second,
},
}
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)))
}