2026-08-16 16:57:36 +02:00
|
|
|
package aiprompts
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCategoryEnhanceUserTemplateHasRequiredVars(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
vars := ExtractVariables(CategoryEnhanceUserTemplate)
|
|
|
|
|
want := []string{"language", "category", "name", "description", "attrs"}
|
|
|
|
|
got := map[string]struct{}{}
|
|
|
|
|
for _, v := range vars {
|
|
|
|
|
got[v] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
for _, w := range want {
|
|
|
|
|
if _, ok := got[w]; !ok {
|
|
|
|
|
t.Fatalf("CategoryEnhanceUserTemplate missing {{%s}}; vars=%v", w, vars)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lower := strings.ToLower(CategoryEnhanceUserTemplate)
|
|
|
|
|
if strings.Contains(lower, "100 besed") || strings.Contains(lower, "gpt predloga") {
|
|
|
|
|
t.Fatal("template must not demand legacy long HTML marketing docs")
|
|
|
|
|
}
|
2026-08-16 23:42:00 +02:00
|
|
|
if !strings.Contains(CategoryEnhanceUserTemplate, `{"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}`) {
|
|
|
|
|
t.Fatal("template should reference enhance JSON schema including meta_* and attrs")
|
|
|
|
|
}
|
2026-08-18 00:13:44 +02:00
|
|
|
// Attribute prompting is retired from category prompts — extraction guidance
|
|
|
|
|
// is pipeline-level (AppendAttributeConstraints), never prompt-authored.
|
|
|
|
|
if strings.Contains(strings.ToLower(CategoryEnhanceUserTemplate), `build json "attrs"`) {
|
|
|
|
|
t.Fatal("template must not carry an attributes role instruction")
|
2026-08-16 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) {
|
2026-08-18 00:13:44 +02:00
|
|
|
t.Fatal("canonical template must be role-sectioned for title/description/meta")
|
2026-08-16 16:57:36 +02:00
|
|
|
}
|
|
|
|
|
if !strings.Contains(lower, "{{language}}") {
|
|
|
|
|
t.Fatal("language must come from {{language}}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCategoryEnhancePromptNeedsRepair(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
if CategoryEnhancePromptNeedsRepair("") {
|
|
|
|
|
t.Fatal("empty should not need repair")
|
|
|
|
|
}
|
|
|
|
|
if CategoryEnhancePromptNeedsRepair(CategoryEnhanceUserTemplate) {
|
|
|
|
|
t.Fatal("canonical template should be idempotent")
|
|
|
|
|
}
|
|
|
|
|
if CategoryEnhancePromptNeedsRepair(" " + CategoryEnhanceUserTemplate + "\n") {
|
|
|
|
|
t.Fatal("whitespace-trimmed canonical should be idempotent")
|
|
|
|
|
}
|
|
|
|
|
legacy := `Ustvari nov opis\n<H2>foo</H2>\nAttrs missing`
|
|
|
|
|
if !CategoryEnhancePromptNeedsRepair(legacy) {
|
|
|
|
|
t.Fatal("legacy HTML prompt should need repair")
|
|
|
|
|
}
|
2026-08-17 00:39:25 +02:00
|
|
|
// Per-category sectioned overlay (Slovenian rules) must not force re-repair.
|
|
|
|
|
split := SplitLegacyCombinedEnhancePrompt(`GPT predloga:
|
|
|
|
|
<name>{Napiši tip izdelka}</name>
|
|
|
|
|
<metaDescription>{140 znakov}</metaDescription>
|
|
|
|
|
<H2>{benefit}</H2>`)
|
|
|
|
|
if CategoryEnhancePromptNeedsRepair(split) {
|
|
|
|
|
t.Fatal("sectioned split overlay should be idempotent")
|
|
|
|
|
}
|
2026-08-16 16:57:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuiltInProductEnhanceUsesSharedUserTemplate(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
def, ok := DefaultFor(KeyProductEnhance)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("missing product_enhance default")
|
|
|
|
|
}
|
|
|
|
|
if def.UserTemplate != CategoryEnhanceUserTemplate {
|
|
|
|
|
t.Fatalf("UserTemplate must be CategoryEnhanceUserTemplate")
|
|
|
|
|
}
|
2026-08-16 19:21:49 +02:00
|
|
|
if strings.Contains(def.SystemTemplate, "1-2 factual sentences") {
|
|
|
|
|
t.Fatal("system template must not force 1-2 sentences over category Description formulas")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(strings.ToLower(def.SystemTemplate), "description formula") {
|
|
|
|
|
t.Fatal("system template should defer to Description formula when present")
|
|
|
|
|
}
|
2026-08-16 16:57:36 +02:00
|
|
|
}
|