fix: deliver validated AI insight responses
This commit is contained in:
40
internal/coach/avalai_smoke_test.go
Normal file
40
internal/coach/avalai_smoke_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package coach_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/aiprovider"
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/coach"
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/insight"
|
||||
)
|
||||
|
||||
func TestAvalAISmokePageInsightAndCoach(t *testing.T) {
|
||||
if os.Getenv("AVALAI_SMOKE") != "1" {
|
||||
t.Skip("set AVALAI_SMOKE=1 to run the real provider contract")
|
||||
}
|
||||
client := aiprovider.New(aiprovider.Config{BaseURL: os.Getenv("AVALAI_BASE_URL"), APIKey: os.Getenv("AVALAI_API_KEY"), Model: os.Getenv("AVALAI_MODEL"), Timeout: 30 * time.Second}, &http.Client{})
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 90*time.Second)
|
||||
defer cancel()
|
||||
fallback := insight.Copy{Past: insight.Narrative{Headline: "گذشته", Body: "متن قطعی", EvidenceID: []string{"payment-health"}}, LatestObserved: insight.Narrative{Headline: "اکنون", Body: "متن قطعی", EvidenceID: []string{"payment-health"}}, Future7Days: insight.Narrative{Headline: "هفته", Body: "متن قطعی", EvidenceID: []string{"payment-health"}}, Future30Days: insight.Narrative{Headline: "ماه", Body: "متن قطعی", EvidenceID: []string{"payment-health"}}, Findings: []insight.Finding{{EvidenceID: "payment-health", Title: "سلامت", Summary: "متن قطعی", ScoreBPS: 5000, Confidence: insight.ConfidenceMedium}}, Options: []insight.Option{{Title: "بررسی", Description: "متن قطعی", EvidenceID: []string{"payment-health"}}}}
|
||||
_, pageUsage, err := insight.NewAvalAIGenerator(client).Generate(ctx, insight.ModulePayments, insight.SectionFull, json.RawMessage(`{"paymentHealth":"aggregate only"}`), fallback)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pageUsage.ProviderRequestID == "" {
|
||||
t.Fatal("page insight provider request id missing")
|
||||
}
|
||||
profile := coach.Profile{ProfileID: "smoke", TerminalID: "terminal", Version: 1, Difficulty: 2, ProfileInput: coach.ProfileInput{BusinessDescription: "فروشگاه اینترنتی کالاهای مصرفی برای مشتریان عمومی", Niches: []string{"خردهفروشی"}, SalesChannels: []string{"وبسایت"}, PrimaryGoal: "بهبود پرداخت موفق"}}
|
||||
evidence := coach.MetricEvidence{Sessions: 120, Values: map[string]float64{"success_rate": 80, "paid_count": 96, "paid_amount": 1000000, "avg_latency": 1200, "fee_amount": 10000}, EvidenceIDs: []string{"payment-health", "payment-volume", "operational-efficiency"}, DataThrough: "2026-08-20"}
|
||||
_, coachUsage, err := coach.NewAvalAIGenerator(client).Generate(ctx, "WEEKLY", profile, evidence)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if coachUsage.ProviderRequestID == "" {
|
||||
t.Fatal("coach provider request id missing")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user