fix: deliver validated AI insight responses
This commit is contained in:
68
internal/coach/generator_test.go
Normal file
68
internal/coach/generator_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package coach
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestProfileNormalizationAndChangedFields(t *testing.T) {
|
||||
previous := ProfileInput{BusinessDescription: " فروشگاه آنلاین محصولات آموزشی ", Niches: []string{"آموزش", "فروش"}, SalesChannels: []string{"وبسایت"}, PrimaryGoal: "رشد فروش", Constraints: "تیم کوچک"}
|
||||
next := ProfileInput{BusinessDescription: "فروشگاه آنلاین محصولات آموزشی", Niches: []string{"فروش", "آموزش"}, SalesChannels: []string{"وبسایت", "اینستاگرام"}, PrimaryGoal: "رشد فروش", Constraints: "تیم کوچک"}
|
||||
if fields := ChangedProfileFields(previous, next); len(fields) != 1 || fields[0] != "salesChannels" {
|
||||
t.Fatalf("changed fields = %#v", fields)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateGenerationRequiresActionableSubtasks(t *testing.T) {
|
||||
metricID, direction, level := "success_rate", "INCREASE", "SMALL"
|
||||
generation := Generation{DailyBrief: "جمعبندی معتبر", Suggestions: []GenerationSuggestion{
|
||||
{ActionType: "METRIC", Title: "بهبود تجربه پرداخت", Rationale: "بر پایه شواهد", ExpectedImpact: "اثر قابل سنجش", Effort: "MEDIUM", EvidenceIDs: []string{"payment-health"}, MetricID: &metricID, MetricDirection: &direction, ActionLevel: &level, Subtasks: []GenerationSubtask{{Title: "خطاهای پرتکرار پرداخت را مرور کنید"}, {Title: "متن راهنمای پرداخت را بازنویسی کنید"}, {Title: "نسخه تازه مسیر پرداخت را آزمایش کنید"}}},
|
||||
{ActionType: "METRIC", Title: "بهبود پرداخت موفق", Rationale: "بر پایه شواهد", ExpectedImpact: "اثر قابل سنجش", Effort: "LOW", EvidenceIDs: []string{"payment-health"}, MetricID: &metricID, MetricDirection: &direction, ActionLevel: &level, Subtasks: []GenerationSubtask{{Title: "یک گزارش خطا آماده کنید"}, {Title: "یک اصلاح مشخص انتخاب کنید"}, {Title: "نتیجه اصلاح را بررسی کنید"}}},
|
||||
{ActionType: "METRIC", Title: "کاهش ریزش پرداخت", Rationale: "بر پایه شواهد", ExpectedImpact: "اثر قابل سنجش", Effort: "HIGH", EvidenceIDs: []string{"payment-health"}, MetricID: &metricID, MetricDirection: &direction, ActionLevel: &level, Subtasks: []GenerationSubtask{{Title: "نقطه ریزش را شناسایی کنید"}, {Title: "یک اقدام اصلاحی اجرا کنید"}, {Title: "بازخورد کاربران را ثبت کنید"}}},
|
||||
}}
|
||||
evidence := MetricEvidence{Sessions: 120, Values: map[string]float64{"success_rate": 80}, EvidenceIDs: []string{"payment-health"}}
|
||||
if err := validateGeneration(generation, evidence); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
generation.Suggestions[0].Subtasks = generation.Suggestions[0].Subtasks[:2]
|
||||
if err := validateGeneration(generation, evidence); err == nil {
|
||||
t.Fatal("generation with fewer than three subtasks must be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeGenerationClearsMetricFieldsFromManualSuggestions(t *testing.T) {
|
||||
metricID := "paid_count"
|
||||
direction := "INCREASE"
|
||||
level := "SMALL"
|
||||
generation := Generation{Suggestions: []GenerationSuggestion{{
|
||||
ActionType: "MANUAL",
|
||||
MetricID: &metricID,
|
||||
MetricDirection: &direction,
|
||||
ActionLevel: &level,
|
||||
}}}
|
||||
|
||||
normalizeGeneration(&generation)
|
||||
|
||||
suggestion := generation.Suggestions[0]
|
||||
if suggestion.MetricID != nil || suggestion.MetricDirection != nil || suggestion.ActionLevel != nil {
|
||||
t.Fatalf("manual suggestion retained metric fields: %+v", suggestion)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeGenerationReplacesInternalTermsInUserFacingProse(t *testing.T) {
|
||||
generation := Generation{
|
||||
DailyBrief: "شواهد payment-health و operational-efficiency بررسی شدند.",
|
||||
Suggestions: []GenerationSuggestion{{
|
||||
Title: "بهبود success_rate",
|
||||
Rationale: "payment-volume افت کرده است.",
|
||||
ExpectedImpact: "کاهش fee_amount",
|
||||
}},
|
||||
}
|
||||
|
||||
normalizeGeneration(&generation)
|
||||
|
||||
if generation.DailyBrief != "شواهد نرخ موفقیت پرداخت و سرعت تأیید پرداخت بررسی شدند." {
|
||||
t.Fatalf("DailyBrief = %q", generation.DailyBrief)
|
||||
}
|
||||
suggestion := generation.Suggestions[0]
|
||||
if suggestion.Title != "بهبود نرخ موفقیت پرداخت" || suggestion.Rationale != "تعداد و مبلغ پرداخت موفق افت کرده است." || suggestion.ExpectedImpact != "کاهش کارمزد پرداختشده" {
|
||||
t.Fatalf("suggestion prose = %+v", suggestion)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user