2026-08-17 00:39:25 +02:00
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" )
}
2026-08-18 00:53:26 +02:00
// 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.
2026-08-17 00:39:25 +02:00
split := SplitLegacyCombinedEnhancePrompt ( `GPT predloga:
<name>{Napiši tip izdelka, znamka, poln model}</name>
<metaDescription>{140 znakov}</metaDescription>
<H2>{benefit}</H2>` )
2026-08-18 00:53:26 +02:00
if strings . Contains ( split , "never brand-only" ) {
t . Fatalf ( "split overlay must not embed role boilerplate: %s" , split )
}
if ! strings . Contains ( split , "Napiši tip izdelka, znamka, poln model" ) {
t . Fatalf ( "split Title section must keep the legacy naming text: %s" , split )
2026-08-17 00:39:25 +02:00
}
}
func TestDeriveTitleTemplateJSON_roundTrip ( t * testing . T ) {
t . Parallel ()
raw := DeriveTitleTemplateJSON ( `formuli: "tip izdelka sentence case", "znamka s pravilno kapitalizacijo", "poln model izdelka"` )
if TitleTemplateNeedsRepair ( raw ) {
t . Fatalf ( "derived JSON should be OK: %s" , raw )
}
if ! strings . Contains ( raw , `"product_type"` ) || ! strings . Contains ( raw , `"brand"` ) || ! strings . Contains ( raw , `"product_model"` ) {
t . Fatalf ( "missing core vars: %s" , raw )
}
}