This commit is contained in:
2026-08-16 21:35:48 +02:00
parent 106f602232
commit 389608ea56
28 changed files with 2491 additions and 115 deletions
+119 -2
View File
@@ -223,8 +223,12 @@ func TestIsPromptLeakageTitle(t *testing.T) {
"write name in {{language}}": true,
"Schema: {\"name\":\"string\",\"description\":\"string\"}": true,
"Reply with ONLY JSON (no markdown)": true,
"Vox SWA-8000W dishwasher": false,
"Acme Widget Pro": false,
"Emit description as ONE HTML string covering each section in order": true,
"Description formula (REQUIRED — overrides any shorter \"1-2 sentences\" rule)": true,
"when a Description formula follows, emit ONE HTML string": true,
"never copy name as description": true,
"Vox SWA-8000W dishwasher": false,
"Acme Widget Pro": false,
"": false,
}
for in, want := range cases {
@@ -242,6 +246,119 @@ func TestIsPromptLeakageTitle(t *testing.T) {
}
}
func TestIsUnusableCategoryValue_rejectsNameAndFormula(t *testing.T) {
t.Parallel()
title := "NOSILEC W53070 81-140CM 180ST VOGELS"
if !isUnusableCategoryValue(title, title) {
t.Fatal("product title must not be usable as category")
}
if !isUnusableCategoryValue("Title formula (order matters; join with \" \")", title) {
t.Fatal("title formula must not be usable as category")
}
if !isUnusableCategoryValue("Emit description as ONE HTML string covering each section", title) {
t.Fatal("description formula must not be usable as category")
}
if !isUnusableCategoryValue("Category:", title) {
t.Fatal("prompt label must not be usable as category")
}
if isUnusableCategoryValue("28", title) {
t.Fatal("taxonomy unique_id must remain usable")
}
if isUnusableCategoryValue("TV mounts", title) {
t.Fatal("real category display name must remain usable")
}
}
func TestScrubCategoryPollution_clearsNameAsCategory(t *testing.T) {
t.Parallel()
title := "Vogel's WALL 3245 TV Wall Mount"
out := StepResult{
Name: title,
ProcessedName: title,
Category: title,
CategoryName: title,
FieldSources: map[string]any{"category": "vector"},
}
scrubCategoryPollution(&out, nil, nil)
if out.Category != "" || out.CategoryName != "" {
t.Fatalf("expected category cleared, got Category=%q CategoryName=%q", out.Category, out.CategoryName)
}
if src, _ := out.FieldSources["category"].(string); src != "cleared_invalid" {
t.Fatalf("field_sources.category=%v want cleared_invalid", out.FieldSources["category"])
}
}
func TestEnhance_rejectsDescriptionFormulaLeakageTitle(t *testing.T) {
leak := "Emit description as ONE HTML string covering each section in order in Slovenian"
e := &Engine{
Completer: stubCompleter{fn: func(system, user string) (Completion, error) {
return Completion{Text: `{"name":"` + leak + `","description":"A solid washer."}`, TotalTokens: 2}, nil
}},
Vector: NoopVectorCategorizer{},
}
out, err := e.RunSteps(context.Background(), "co", ProductInput{
GTIN: "8712285326882",
Name: "Vox SWA-8000W",
Mapped: map[string]any{"name": "Vox SWA-8000W", "description": "Washer", "category": "demo-electronics"},
}, "enhance_only", nil, StepPolicy{AllowAI: true})
if err != nil {
t.Fatal(err)
}
if out.ProcessedName != "Vox SWA-8000W" {
t.Fatalf("ProcessedName=%q want Vox SWA-8000W (reject description formula leakage)", out.ProcessedName)
}
}
func TestRunSteps_rejectsProductNameAsCategory(t *testing.T) {
title := "NOSILEC W53070 81-140CM 180ST VOGELS"
e := &Engine{
Completer: stubCompleter{fn: func(system, user string) (Completion, error) {
return Completion{Text: `{"name":"` + title + `","description":"TV wall mount for large screens."}`, TotalTokens: 2}, nil
}},
Vector: NoopVectorCategorizer{},
}
out, err := e.RunSteps(context.Background(), "co", ProductInput{
GTIN: "8712285326882",
Name: title,
PriorCategory: title,
Mapped: map[string]any{"name": title, "description": title, "category": title},
}, "enhance_only", nil, StepPolicy{AllowAI: true})
if err != nil {
t.Fatal(err)
}
if out.Category == title || strings.EqualFold(out.Category, out.ProcessedName) {
t.Fatalf("Category=%q must not equal product title", out.Category)
}
if categoryDisplayLabel(out) == title {
t.Fatalf("display category leaked product title: %q", categoryDisplayLabel(out))
}
}
func TestRunSteps_rejectsFormulaAsCategory(t *testing.T) {
leak := "Title formula (order matters; join with \" \"). Build name from Attrs"
e := &Engine{
Completer: stubCompleter{fn: func(system, user string) (Completion, error) {
return Completion{Text: `{"name":"Vox SWA-8000W","description":"Washer."}`, TotalTokens: 2}, nil
}},
Vector: NoopVectorCategorizer{},
}
out, err := e.RunSteps(context.Background(), "co", ProductInput{
GTIN: "8712285326882",
Name: "Vox SWA-8000W",
PriorCategory: leak,
Mapped: map[string]any{"name": "Vox SWA-8000W", "description": "Washer", "category": leak},
}, "enhance_only", nil, StepPolicy{AllowAI: true})
if err != nil {
t.Fatal(err)
}
if out.Category != "" {
t.Fatalf("Category=%q want empty (formula rejected)", out.Category)
}
if categoryDisplayLabel(out) != "" {
t.Fatalf("display=%q want empty", categoryDisplayLabel(out))
}
}
func TestEnhance_rejectsFormulaLeakageTitle(t *testing.T) {
leak := "short retail title; follow any Title formula constraints that follow; use Attrs"
e := &Engine{