package processing import ( "strings" "testing" ) func TestTruncateLogEnds(t *testing.T) { t.Parallel() short := truncateLogEnds("hello", 500, 500) if !strings.Contains(short, `body="hello"`) || !strings.Contains(short, "len=5") { t.Fatalf("short: %s", short) } long := strings.Repeat("a", 600) + "MID" + strings.Repeat("b", 600) got := truncateLogEnds(long, 10, 10) if !strings.Contains(got, "len=1203") || !strings.Contains(got, "head=") || !strings.Contains(got, "tail=") { t.Fatalf("long: %s", got) } if strings.Contains(got, "MID") { t.Fatalf("middle should be omitted: %s", got) } } func TestFormulaTemplateSummary(t *testing.T) { t.Parallel() if formulaTemplateSummary(nil, "description") != "none" { t.Fatal("nil → none") } desc := map[string]any{ "sections": []any{ map[string]any{"type": "h1", "instructions": "Heading"}, map[string]any{"type": "p", "instructions": "Body"}, map[string]any{"type": "ul", "instructions": "Specs"}, }, } sum := formulaTemplateSummary(desc, "description") if !strings.Contains(sum, "sections=h1+p+ul") || !strings.Contains(sum, "len=") || !strings.Contains(sum, "hash=") { t.Fatalf("desc summary: %s", sum) } title := map[string]any{ "separator": " ", "elements": []any{ map[string]any{"type": "variable", "value": "brand"}, map[string]any{"type": "text", "value": "TV"}, }, } ts := formulaTemplateSummary(title, "title") if !strings.Contains(ts, "elements=variable+text") || !strings.Contains(ts, `sep=" "`) { t.Fatalf("title summary: %s", ts) } } // TestA1StyleDescriptionFormulaInResolvedPrompts asserts a realistic multi-section // category description_template (A1-style) is injected into both system and user // enhance prompts via resolveProductPromptTemplates / RenderProductEnhancePrompts. func TestA1StyleDescriptionFormulaInResolvedPrompts(t *testing.T) { t.Parallel() // Representative A1 cooker/monitor style: h1 + p + ul sections. descFormula := map[string]any{ "sections": []any{ map[string]any{"type": "h1", "instructions": "Naziv izdelka"}, map[string]any{"type": "h2", "instructions": "Podnaslov prednosti"}, map[string]any{"type": "p", "instructions": "Kratek opis v slovenščini"}, map[string]any{"type": "ul", "instructions": "Ključne specifikacije"}, }, } titleFormula := map[string]any{ "separator": " ", "elements": []any{ map[string]any{"type": "variable", "value": "brand"}, map[string]any{"type": "variable", "value": "product_model"}, }, } sysTpl, userTpl := resolveProductPromptTemplates(ProductInput{ EnhanceSystemTemplate: "You write retail copy. description: 1-2 factual sentences.", EnhanceUserTemplate: "Category: {{category}}\nName: {{name}}\nAttrs: {{attrs}}", TitleTemplate: titleFormula, DescriptionTemplate: descFormula, }) if !strings.Contains(sysTpl, "Si tekstopisec") { t.Fatalf("system missing A1 copywriter: %s", sysTpl) } if !strings.Contains(userTpl, "GPT predloga:") || !strings.Contains(userTpl, "