This commit is contained in:
greeneclipse committed 2026-10-14 20:02:42 +02:00
1 parent 3b0d692839
commit 8b540d22bc
14 files changed
+526 -82

No files matched your search

@@ -9,47 +9,31 @@ import (
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
)
func TestSeedLanguagesAllSupported(t *testing.T) {
codes, err := langsToSeed("")
if err != nil || len(codes) != len(company.ContentLanguages) {
t.Fatalf("languages %v error %v", codes, err)
func TestDefaultMigrationRecognizesMixedLegacyEnglishWithoutTouchingCustom(t *testing.T) {
current := aiprompts.DefaultCategoryFormula("", "High chairs")
old := aiprompts.PriorDefaultCategoryFormula("", "High chairs")
seo := aiprompts.PreviousSEODefaultCategoryFormula("", "High chairs")
variants := []aiprompts.CategoryFormulaDefaults{current, seo, old, aiprompts.LegacyDefaultCategoryFormula("", "High chairs")}
mixed := strings.Replace(current.Overlay,
aiprompts.DescriptionSectionInstructions(current.Overlay),
aiprompts.DescriptionSectionInstructions(old.Overlay), 1)
if !isMixedBuiltInEnglishPrompt(mixed, variants) {
t.Fatal("old English five-section mixed default was not recognized")
}
if _, err := langsToSeed("invalid"); err == nil {
t.Fatal("invalid language accepted")
}
}
func TestOnlyPlatformDefaultsAreEligible(t *testing.T) {
source := aiprompts.GenericCategoryFormula().Overlay
translations := company.LangPromptMap{"de": "German default"}
eligible := categoryRow{Prompts: company.LangPromptMap{"*": source}}
if !catalog.IsUntouchedDefaultPrompt(eligible.Prompts, source, translations) {
t.Fatal("default should be eligible")
}
custom := categoryRow{Prompts: company.LangPromptMap{"*": source, "de": "tenant customized the prompt"}}
if catalog.IsUntouchedDefaultPrompt(custom.Prompts, source, translations) {
t.Fatal("custom prompt must be protected")
}
}
func TestOfflineDefaultCoverage(t *testing.T) {
for _, lang := range company.ContentLanguages {
if lang == "en" {
continue
} // English uses exact source text.
text, err := aiprompts.OfflineDefaultPrompt(lang)
if err != nil || strings.TrimSpace(text) == "" {
t.Fatalf("missing bundled language %s: %v", lang, err)
}
}
}
func TestStructuredCustomFormulasRemainProtected(t *testing.T) {
defaultTitle := `{"mode":"formula","productType":"lowercase"}`
if !matchesDefaultFormula(defaultTitle, defaultTitle) {
t.Fatal("matching default formula not recognized")
}
if matchesDefaultFormula(`{"mode":"formula","productType":"uppercase"}`, defaultTitle) {
t.Fatal("company-authored title formula must be protected")
cache := map[string]*defaultTranslation{
catalog.DefaultPromptHash(current.Overlay): {Source: current.Overlay, Values: company.LangPromptMap{"en": current.Overlay}},
catalog.DefaultPromptHash(old.Overlay): {Source: old.Overlay, Values: company.LangPromptMap{"en": old.Overlay}},
}
if !isKnownBuiltInVariantSet(company.LangPromptMap{"en": mixed}, variants, cache) {
t.Fatal("mixed, unedited platform default was flagged custom")
}
bad := strings.Replace(mixed, "--- Meta ---", "--- Meta ---\nUse my shop's custom brand voice", 1)
if isKnownBuiltInVariantSet(company.LangPromptMap{"en": bad}, variants, cache) {
t.Fatal("custom tenant meta text must remain protected")
}
a1 := company.LangPromptMap{"sl": "A1 custom Slovenian naming, meta, and description", "en": mixed}
changed := replaceKnownBuiltInLocales(a1, variants, cache)
if changed != 1 || a1["sl"] != "A1 custom Slovenian naming, meta, and description" || a1["en"] != current.Overlay {
t.Fatalf("A1 locale migration touched custom data: changed=%d, en=%q, sl=%q", changed, a1["en"], a1["sl"])
}
}