fixes
This commit is contained in:
1 parent
c92ee93482
commit
af670e79f0
9 files changed
+667
-104
No files matched your search
@@ -68,3 +68,122 @@ func TestV6SharedCacheMigrationUsesHistoricalExactStrings(t *testing.T) {
|
||||
t.Fatal("custom company locale overwritten")
|
||||
}
|
||||
}
|
||||
|
||||
// Reproduces the non-A1 records from the production report: the v3 seed
|
||||
// generated only a translated paragraph of five-H2 instructions in hr/bg,
|
||||
// while the English company variant still used five literal HTML H2 blocks.
|
||||
func TestV3NonA1DescriptionMigrationAcrossAll25Languages(t *testing.T) {
|
||||
canonical := aiprompts.DefaultCategoryFormula("", "Bathroom mixers")
|
||||
prior := aiprompts.PriorDefaultCategoryFormula("", "Bathroom mixers")
|
||||
versions := []aiprompts.CategoryFormulaDefaults{canonical, prior}
|
||||
oldPrompts := company.LangPromptMap{}
|
||||
for _, lang := range company.ContentLanguages {
|
||||
old, err := aiprompts.PreviousOfflineDefaultPromptV3(lang)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
oldPrompts[lang] = old
|
||||
}
|
||||
oldPrompts["*"] = prior.Overlay
|
||||
// A manually customized German description must remain untouched.
|
||||
oldPrompts["de"] = "--- Title ---\nMein Shop Titel\n--- End Title ---\n\n--- Description ---\nEigenes Unternehmen\n--- End Description ---\n\n--- Meta ---\nMeine Meta\n--- End Meta ---"
|
||||
got, count := repairOldLocaleDefaults(oldPrompts, versions, nil, nil, company.ContentLanguages)
|
||||
if count != len(company.ContentLanguages) { // 24 translated + wildcard; custom de untouched
|
||||
t.Fatalf("repaired %d entries; want %d", count, len(company.ContentLanguages))
|
||||
}
|
||||
if got["de"] != oldPrompts["de"] {
|
||||
t.Fatal("custom German company formula overwritten")
|
||||
}
|
||||
for _, lang := range company.ContentLanguages {
|
||||
if lang == "de" {
|
||||
continue
|
||||
}
|
||||
expected, err := aiprompts.OfflineDefaultPrompt(lang)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if lang == "en" {
|
||||
expected = canonical.Overlay
|
||||
}
|
||||
if got[lang] != expected {
|
||||
t.Fatalf("%s retained obsolete default", lang)
|
||||
}
|
||||
body := aiprompts.DescriptionSectionInstructions(got[lang])
|
||||
if strings.Count(body, "<h2>{") != 2 || strings.Count(body, "<p>{") != 2 || strings.Count(body, "<ul><li>{") != 1 {
|
||||
t.Fatalf("%s did not receive HTML scaffold: %s", lang, body)
|
||||
}
|
||||
if !strings.HasPrefix(body, "<p>{") {
|
||||
t.Fatalf("%s not starting with intro", lang)
|
||||
}
|
||||
}
|
||||
if got["*"] != canonical.Overlay {
|
||||
t.Fatal("shared English five-H2 default survived migration")
|
||||
}
|
||||
twice, further := repairOldLocaleDefaults(got, versions, nil, nil, company.ContentLanguages)
|
||||
if further != 0 {
|
||||
t.Fatalf("migration is not idempotent: %+v", twice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV3ExactReportedCroatianAndBulgarianMigration(t *testing.T) {
|
||||
snippets := map[string]string{
|
||||
"hr": "Napiši pet različitih naslova H2, a ispod svakog odlomak od približno 100 riječi.",
|
||||
"bg": "Напиши пет различни заглавия H2, всяко следвано от абзац с около 100 думи.",
|
||||
}
|
||||
current := aiprompts.DefaultCategoryFormula("", "Any")
|
||||
for lang, expected := range snippets {
|
||||
old, err := aiprompts.PreviousOfflineDefaultPromptV3(lang)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(old, expected) {
|
||||
t.Fatalf("lost exact %s regression fixture", lang)
|
||||
}
|
||||
if !isExactOldDefaultLanguage(old, lang, []aiprompts.CategoryFormulaDefaults{current}, nil, nil) {
|
||||
t.Fatalf("%s historical snapshot not recognized", lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestV3CustomRolePreservedWhileDefaultDescriptionRepaired(t *testing.T) {
|
||||
current := aiprompts.DefaultCategoryFormula("", "Other")
|
||||
old, err := aiprompts.PreviousOfflineDefaultPromptV3("hr")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
originalTitle := "Korisnički prilagođene upute za naslov"
|
||||
legacy := aiprompts.BuildCategoryEnhanceOverlay(aiprompts.LegacyEnhanceParts{
|
||||
TitleRules: originalTitle,
|
||||
DescriptionRules: aiprompts.ExtractEnhanceSectionBody(old, aiprompts.SectionDescriptionStart, aiprompts.SectionDescriptionEnd),
|
||||
MetaRules: "Korisnički SEO meta",
|
||||
})
|
||||
next, changed := repairOldLocaleDefaults(company.LangPromptMap{"hr": legacy}, []aiprompts.CategoryFormulaDefaults{current}, nil, nil, company.ContentLanguages)
|
||||
if changed != 1 {
|
||||
t.Fatalf("description partial migration changed=%d", changed)
|
||||
}
|
||||
updated := next["hr"]
|
||||
if aiprompts.ExtractEnhanceSectionBody(updated, aiprompts.SectionTitleStart, aiprompts.SectionTitleEnd) != originalTitle ||
|
||||
aiprompts.ExtractEnhanceSectionBody(updated, aiprompts.SectionMetaStart, aiprompts.SectionMetaEnd) != "Korisnički SEO meta" {
|
||||
t.Fatal("company-authored title/meta were overwritten")
|
||||
}
|
||||
if !strings.HasPrefix(aiprompts.DescriptionSectionInstructions(updated), "<p>{") {
|
||||
t.Fatal("old default Croatian description not repaired")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyDescriptionConstraintMustNotOverrideLocalizedPrompt(t *testing.T) {
|
||||
canonical := aiprompts.DefaultCategoryFormula("", "Bathroom mixers")
|
||||
previous := aiprompts.PriorDefaultCategoryFormula("", "Bathroom mixers")
|
||||
versions := []aiprompts.CategoryFormulaDefaults{canonical, previous}
|
||||
patched, ok := repairOldFormulaField(previous.DescriptionTemplateJSON, versions, false)
|
||||
if !ok || patched != canonical.DescriptionTemplateJSON {
|
||||
t.Fatal("old language-neutral five-H2 description formula was not upgraded")
|
||||
}
|
||||
own := `{"sections":[{"type":"p","instructions":"Custom layout"}]}`
|
||||
if updated, changed := repairOldFormulaField(own, versions, false); changed || updated != own {
|
||||
t.Fatal("custom formula was overwritten")
|
||||
}
|
||||
if updated, changed := repairOldFormulaField(canonical.DescriptionTemplateJSON, versions, false); changed || updated != canonical.DescriptionTemplateJSON {
|
||||
t.Fatal("canonical formula should be idempotent")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user