package processing import ( "strings" "testing" ) func TestIsWeakPriorEnhanceDescription_fillerPhrases(t *testing.T) { title := "Vogel's WALL 3245 TV Wall Mount" cases := []struct { desc string want bool }{ {"Ready for retail listing with extra padding text here.", true}, {title + " in the Mounts category. Ready for retail listing.", true}, {"Product description placeholder text that is long enough to pass length.", true}, {"A product in the Mounts category based on available specifications.", true}, {"Product with available specifications ready for retail listing.", true}, {"Generic one-liner without product tokens and enough length!!!!!", true}, { "Vogel's WALL 3245 is a TV Mounts product from Vogel's. Key specs: width 45 cm, max_load 40 kg.", false, }, { "This durable retail mount includes mounting hardware, load ratings, and install guidance for wall displays.", false, }, } for _, tc := range cases { got := isWeakPriorEnhanceDescription(tc.desc, title) if got != tc.want { t.Fatalf("desc=%q got weak=%v want %v", tc.desc, got, tc.want) } } // Long non-filler copy that does not share tokens with this title is still usable // once past the short-boilerplate window (hash-skip quality floor). longUnrelated := strings.Repeat("Detailed retail copy covering materials finishes warranty and care. ", 3) if isWeakPriorEnhanceDescription(longUnrelated, title) { t.Fatalf("long non-filler unrelated copy should not be weak solely for token miss: %q", longUnrelated) } if !isWeakPriorEnhanceDescription("ok", title) { t.Fatal("too-short must be weak") } if !isWeakPriorEnhanceDescription(title, title) { t.Fatal("title-echo must be weak") } } func TestSynthesizeDescriptionFromTitle_brandModelCategory(t *testing.T) { title := "Vogel's WALL 3245 TV Wall Mount" attrs := map[string]any{ "brand": "Vogel's", "product_model": "WALL 3245", "width": "45 cm", "max_load": "40 kg", } en := synthesizeDescriptionFromTitle(title, "TV Mounts", "en", attrs) if en == "" { t.Fatal("expected nonempty English invent") } if strings.Contains(strings.ToLower(en), "ready for retail listing") { t.Fatalf("must not emit retail filler: %q", en) } for _, need := range []string{"Vogel", "TV Mounts", "45 cm", "40 kg"} { if !strings.Contains(en, need) { t.Fatalf("English invent missing %q: %q", need, en) } } if isWeakPriorEnhanceDescription(en, title) { t.Fatalf("factual invent must not be weak: %q", en) } sl := synthesizeDescriptionFromTitle(title, "TV Mounts", "sl", attrs) if sl == "" || !strings.Contains(sl, "kategoriji") { t.Fatalf("expected Slovenian invent, got %q", sl) } if strings.Contains(strings.ToLower(sl), "ready for retail listing") { t.Fatalf("SL invent must not emit EN filler: %q", sl) } if isWeakPriorEnhanceDescription(sl, title) { t.Fatalf("SL factual invent must not be weak: %q", sl) } } func TestInventHeuristicDescription_fromBrandModelCategory(t *testing.T) { title := "Vogel's WALL 3245 TV Wall Mount" user := ProductEnhanceUser("TV Mounts", title, "", map[string]any{ "brand": "Vogel's", "product_model": "WALL 3245", "width": "45 cm", "max_load": "40 kg", }) system := "Write name and description in English. Return JSON with \"name\" and \"description\"." got := inventHeuristicDescription(system, user, title) if got == "" { t.Fatal("expected invent output") } t.Logf("TV mount invent sample: %s", got) if strings.Contains(strings.ToLower(got), "ready for retail listing") { t.Fatalf("invent must not return retail filler: %q", got) } for _, need := range []string{"Vogel", "TV Mounts", "45 cm"} { if !strings.Contains(got, need) { t.Fatalf("invent missing %q: %q", need, got) } } if isWeakPriorEnhanceDescription(got, title) { t.Fatalf("invent output must not be classified weak: %q", got) } slSystem := "Write name and description in Slovenian. Return JSON with \"name\"." sl := inventHeuristicDescription(slSystem, user, title) if !strings.Contains(sl, "kategoriji") { t.Fatalf("expected SL invent from system language, got %q", sl) } }