147 lines
5.3 KiB
Go
147 lines
5.3 KiB
Go
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 TestSynthesizeProductDescription_formulaHTML(t *testing.T) {
|
|
t.Parallel()
|
|
title := "GIGABYTE GS27QC"
|
|
attrs := map[string]any{"brand": "GIGABYTE", "width": "61 cm"}
|
|
tpl := map[string]any{
|
|
"sections": []any{
|
|
map[string]any{"type": "h1", "instructions": "Main heading"},
|
|
map[string]any{"type": "p", "instructions": "Intro"},
|
|
map[string]any{"type": "ul", "instructions": "Specs"},
|
|
},
|
|
}
|
|
got := synthesizeProductDescription(title, "Gaming monitorji", "sl", attrs, tpl)
|
|
if !strings.Contains(got, "<h1>") || !strings.Contains(got, "<p>") || !strings.Contains(got, "<ul>") {
|
|
t.Fatalf("expected HTML skeleton from formula, got %q", got)
|
|
}
|
|
if !strings.Contains(got, title) {
|
|
t.Fatalf("expected title in formula synth: %q", got)
|
|
}
|
|
plain := synthesizeProductDescription(title, "Gaming monitorji", "sl", attrs, nil)
|
|
if strings.Contains(plain, "<h1>") {
|
|
t.Fatalf("nil formula should stay plain: %q", plain)
|
|
}
|
|
}
|
|
|
|
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 factual fallback")
|
|
}
|
|
if strings.Contains(strings.ToLower(en), "ready for retail listing") {
|
|
t.Fatalf("must not emit retail filler: %q", en)
|
|
}
|
|
if strings.Contains(strings.ToLower(en), "is a ") && strings.Contains(strings.ToLower(en), " product from ") {
|
|
t.Fatalf("must not emit invent boilerplate: %q", en)
|
|
}
|
|
for _, need := range []string{"Vogel", "TV Mounts", "45 cm", "40 kg"} {
|
|
if !strings.Contains(en, need) {
|
|
t.Fatalf("English fallback missing %q: %q", need, en)
|
|
}
|
|
}
|
|
if isWeakPriorEnhanceDescription(en, title) {
|
|
t.Fatalf("factual fallback must not be weak: %q", en)
|
|
}
|
|
|
|
sl := synthesizeDescriptionFromTitle(title, "TV Mounts", "sl", attrs)
|
|
if sl == "" || !strings.Contains(sl, "znamka") {
|
|
t.Fatalf("expected Slovenian factual fallback, got %q", sl)
|
|
}
|
|
if strings.Contains(strings.ToLower(sl), "je izdelek v kategoriji") {
|
|
t.Fatalf("must not emit invent boilerplate: %q", sl)
|
|
}
|
|
if strings.Contains(strings.ToLower(sl), "ready for retail listing") {
|
|
t.Fatalf("SL fallback must not emit EN filler: %q", sl)
|
|
}
|
|
if isWeakPriorEnhanceDescription(sl, title) {
|
|
t.Fatalf("SL factual fallback 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, "znamka") {
|
|
t.Fatalf("expected SL factual invent from system language, got %q", sl)
|
|
}
|
|
}
|