package aiprompts
import (
"strings"
"testing"
)
func TestDeriveTitleFormulaFromLegacyNameRules_Agregati(t *testing.T) {
t.Parallel()
rules := `Napiši novo ime izdelka po formuli: "tip izdelka sentence case", "znamka s pravilno kapitalizacijo", "poln model izdelka, če lahko z besedo in ID uppercase". Ne uporabljaj vejic.`
f := DeriveTitleFormulaFromLegacyNameRules(rules)
if len(f.Elements) < 3 {
t.Fatalf("want >=3 elements, got %#v", f.Elements)
}
vals := make([]string, 0, len(f.Elements))
for _, el := range f.Elements {
if el.Type == "variable" {
vals = append(vals, el.Value)
}
}
wantOrder := []string{"product_type", "brand", "product_model"}
for i, w := range wantOrder {
if i >= len(vals) || vals[i] != w {
t.Fatalf("vars=%v want prefix %v", vals, wantOrder)
}
}
if TitleTemplateIsBrandOnly(f) {
t.Fatal("derived formula must not be brand-only")
}
}
func TestDeriveTitleFormulaFromLegacyNameRules_CarSeatOrder(t *testing.T) {
t.Parallel()
rules := `Napiši novo ime izdelka po formuli: "znamka s pravilno kapitalizacijo", "tip izdelka lowercase", "poln model izdelka, če lahko z besedo in ID uppercase", "skupina po teži [kg]". Ne uporabljaj vejic.`
f := DeriveTitleFormulaFromLegacyNameRules(rules)
vars := []string{}
for _, el := range f.Elements {
if el.Type == "variable" {
vars = append(vars, el.Value)
}
}
if len(vars) < 3 || vars[0] != "brand" || vars[1] != "product_type" || vars[2] != "product_model" {
t.Fatalf("unexpected order: %v", vars)
}
foundWeight := false
for _, v := range vars {
if v == "weight_group" {
foundWeight = true
}
}
if !foundWeight {
t.Fatalf("missing weight_group in %v", vars)
}
}
func TestTitleTemplateIsBrandOnly(t *testing.T) {
t.Parallel()
brandOnly := map[string]any{
"separator": " ",
"elements": []any{
map[string]any{"type": "variable", "value": "brand", "label": "Znamka"},
},
}
if !TitleTemplateIsBrandOnly(brandOnly) {
t.Fatal("single brand variable should be brand-only")
}
if !TitleTemplateNeedsRepair(brandOnly) {
t.Fatal("brand-only needs repair")
}
if TitleTemplateIsBrandOnly(DefaultRetailTitleFormula()) {
t.Fatal("default retail must not be brand-only")
}
if TitleTemplateNeedsRepair(DefaultRetailTitleFormula()) {
t.Fatal("default retail must not need repair")
}
if !TitleTemplateNeedsRepair(nil) {
t.Fatal("nil needs repair")
}
}
func TestTitleRoleInstructionNeverBrandOnly(t *testing.T) {
t.Parallel()
if !strings.Contains(strings.ToLower(TitleRoleInstruction), "never brand-only") {
t.Fatal("TitleRoleInstruction must forbid brand-only names")
}
if !strings.Contains(CategoryEnhanceUserTemplate, TitleRoleInstruction) {
t.Fatal("CategoryEnhanceUserTemplate must embed TitleRoleInstruction")
}
// Split overlays carry ONLY the legacy per-category text; the never-brand-only
// rule lives in the render-time role framing, not the stored prompt.
split := SplitLegacyCombinedEnhancePrompt(`GPT predloga: