fixes
This commit is contained in:
1 parent
3b0d692839
commit
8b540d22bc
14 files changed
+526
-82
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package aiprompts
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCanonicalDefaultsSameForEveryCategory(t *testing.T) {
|
||||
canonical, err := OfflineDefaultPrompt("en")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
names := []string{"", "High chairs", "Televisions", "Cables", "Mixers", "Unlisted category", "Stolčki"}
|
||||
for _, name := range names {
|
||||
got := DefaultCategoryFormula("", name)
|
||||
if got.Overlay != canonical {
|
||||
t.Fatalf("%s differs from canonical English\n%s", name, got.Overlay)
|
||||
}
|
||||
if !strings.Contains(got.Overlay, "<p>{") || strings.Contains(got.Overlay, "first verified benefit") {
|
||||
t.Fatalf("legacy HTML slipped through for %s", name)
|
||||
}
|
||||
if got.DescriptionTemplateJSON != DefaultCategoryFormula("", "unknown").DescriptionTemplateJSON {
|
||||
t.Fatalf("%s has category-specific HTML validation shape", name)
|
||||
}
|
||||
if got.TitleTemplateJSON != DefaultCategoryFormula("", "unknown").TitleTemplateJSON {
|
||||
t.Fatalf("%s has category-specific structured title", name)
|
||||
}
|
||||
old := PriorDefaultCategoryFormula("", name)
|
||||
if old.Overlay == got.Overlay {
|
||||
t.Fatalf("%s lost old default for migration", name)
|
||||
}
|
||||
previous := PreviousSEODefaultCategoryFormula("", name)
|
||||
if previous.Overlay == got.Overlay {
|
||||
t.Fatalf("%s lost SEO-v4 default for migration", name)
|
||||
}
|
||||
}
|
||||
if sources := AllDefaultCategoryPrompts(); len(sources) != 1 || sources[0] != canonical {
|
||||
t.Fatalf("expected one shared template, got %d", len(sources))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizedMetaOverridesGlobalEnglishTemplate(t *testing.T) {
|
||||
en := DefaultCategoryFormula("", "Any")
|
||||
hr, err := OfflineDefaultPrompt("hr")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resolved := EffectiveDescriptionFormula(en.DescriptionTemplateJSON, hr)
|
||||
if !strings.Contains(resolved.MetaDescription, "sažmi") {
|
||||
t.Fatalf("Croatian meta instructions not honored: %s", resolved.MetaDescription)
|
||||
}
|
||||
if strings.Contains(resolved.MetaDescription, "Summarize what") {
|
||||
t.Fatalf("English leaked into Croatian meta")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalLocalesHaveExactlySameHTMLStructure(t *testing.T) {
|
||||
want := []string{"p", "h2", "p", "h2", "ul"}
|
||||
for _, lang := range OfflinePromptLanguages() {
|
||||
source, err := OfflineDefaultPrompt(lang)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
section := DescriptionSectionInstructions(source)
|
||||
f := DeriveDescriptionFormulaFromLegacyParts(LegacyEnhanceParts{DescriptionRules: section, WasLegacy: true})
|
||||
if len(f.Sections) != len(want) {
|
||||
t.Fatalf("%s has %d sections", lang, len(f.Sections))
|
||||
}
|
||||
for i, typ := range want {
|
||||
if f.Sections[i].Type != typ {
|
||||
t.Fatalf("%s section %d is %s not %s", lang, i, f.Sections[i].Type, typ)
|
||||
}
|
||||
}
|
||||
if !f.Sections[1].Optional || !f.Sections[2].Optional || !f.Sections[3].Optional || !f.Sections[4].Optional {
|
||||
t.Fatalf("%s optional feature/spec sections missing flags", lang)
|
||||
}
|
||||
if strings.Contains(section, "<h1>") || strings.Contains(section, "100 words") {
|
||||
t.Fatalf("%s obsolete structure", lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user