fix
This commit is contained in:
@@ -4,6 +4,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestScoreV1ProcessCompletedItem_processedStructure(t *testing.T) {
|
||||
@@ -149,11 +152,25 @@ func TestEnforceV1ProcessCompletedItem_fillsDescriptionMetaSanitizes(t *testing.
|
||||
|
||||
func TestEnforceV1ProcessCompletedItem_skipsTerminalStatuses(t *testing.T) {
|
||||
t.Parallel()
|
||||
item := V1ProcessJobItem{"ean": "1", "status": "not_found", "error": "missing"}
|
||||
item := V1ProcessJobItem{
|
||||
"ean": "1",
|
||||
"status": "not_found",
|
||||
"error": "missing",
|
||||
"ai_enhance": true,
|
||||
"finish_reason": "stop",
|
||||
"field_sources": map[string]any{"enhance_input_hash": "abc"},
|
||||
"prompt_tokens": 12,
|
||||
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
||||
}
|
||||
out := EnforceV1ProcessCompletedItem(item, "", nil)
|
||||
if _, ok := out["title"]; ok {
|
||||
t.Fatalf("should not invent fields for not_found: %v", out)
|
||||
}
|
||||
for _, junk := range []string{"id", "ai_enhance", "finish_reason", "field_sources", "prompt_tokens"} {
|
||||
if _, ok := out[junk]; ok {
|
||||
t.Fatalf("%s must be stripped from public items: %v", junk, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceV1ProcessCompletedItem_categoryFromCallerPreserved(t *testing.T) {
|
||||
@@ -328,6 +345,119 @@ func TestEnforceV1ProcessCompletedItem_refreshesPromptLeakageMeta(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompanyOmitsSEOMetaID(t *testing.T) {
|
||||
t.Parallel()
|
||||
a1 := uuid.MustParse("604f23a8-b66e-4b21-8b45-0d72b68f4790")
|
||||
demo := uuid.MustParse("2b3159b0-fc08-415b-b248-35ed02a6baab")
|
||||
legacy := uuid.MustParse(billing.A1LegacyCompanyID)
|
||||
other := uuid.MustParse("11111111-1111-1111-1111-111111111111")
|
||||
if !CompanyOmitsSEOMetaID(a1) || !CompanyOmitsSEOMetaID(demo) || !CompanyOmitsSEOMetaID(legacy) {
|
||||
t.Fatal("A1, Demo, and legacy A1 ids must omit SEO meta")
|
||||
}
|
||||
if CompanyOmitsSEOMetaID(other) || CompanyOmitsSEOMetaID(uuid.Nil) {
|
||||
t.Fatal("unrelated company ids must keep SEO meta")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyV1SEOMetaPolicy_omitsOnlyA1(t *testing.T) {
|
||||
t.Parallel()
|
||||
item := V1ProcessJobItem{
|
||||
"ean": "1",
|
||||
"status": "processed",
|
||||
"meta_title": "T",
|
||||
"meta_description": "D",
|
||||
}
|
||||
a1 := uuid.MustParse("604f23a8-b66e-4b21-8b45-0d72b68f4790")
|
||||
out := ApplyV1SEOMetaPolicy(a1, []V1ProcessJobItem{item})
|
||||
if _, ok := out[0]["meta_title"]; ok {
|
||||
t.Fatal("A1 must omit meta_title")
|
||||
}
|
||||
if _, ok := out[0]["meta_description"]; ok {
|
||||
t.Fatal("A1 must omit meta_description")
|
||||
}
|
||||
keep := V1ProcessJobItem{
|
||||
"ean": "1",
|
||||
"status": "processed",
|
||||
"meta_title": "T",
|
||||
"meta_description": "D",
|
||||
}
|
||||
other := uuid.MustParse("11111111-1111-1111-1111-111111111111")
|
||||
kept := ApplyV1SEOMetaPolicy(other, []V1ProcessJobItem{keep})
|
||||
if kept[0]["meta_title"] != "T" || kept[0]["meta_description"] != "D" {
|
||||
t.Fatalf("non-A1 must keep SEO meta: %v", kept[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceV1ProcessCompletedItemOpts_omitSEOMeta(t *testing.T) {
|
||||
t.Parallel()
|
||||
item := V1ProcessJobItem{
|
||||
"ean": "1",
|
||||
"status": "processed",
|
||||
"title": "Sony Headphones",
|
||||
"description": "Sony Headphones deliver clear audio with noise cancelling for daily commuting.",
|
||||
"meta_title": "Sony | Headphones",
|
||||
"meta_description": "Sony Headphones deliver clear audio.",
|
||||
"category": "48",
|
||||
"category_name": "Slušalke",
|
||||
"attributes": map[string]any{"brand": "Sony"},
|
||||
"eprel": nil,
|
||||
}
|
||||
out := EnforceV1ProcessCompletedItemOpts(item, EnforceV1Opts{Language: "sl", OmitSEOMeta: true})
|
||||
if _, ok := out["meta_title"]; ok {
|
||||
t.Fatalf("meta_title should be omitted: %v", out["meta_title"])
|
||||
}
|
||||
if _, ok := out["meta_description"]; ok {
|
||||
t.Fatalf("meta_description should be omitted: %v", out["meta_description"])
|
||||
}
|
||||
sc := ScoreV1ProcessCompletedItem(out, ScoreV1ProcessItemOptions{MappedCategory: "48", OmitSEOMeta: true})
|
||||
if !sc.OK {
|
||||
t.Fatalf("omit meta should still score OK, flags=%v", sc.FailFlags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceV1ProcessCompletedItemOpts_A1PollScrubsPromptDump(t *testing.T) {
|
||||
t.Parallel()
|
||||
item := V1ProcessJobItem{
|
||||
"ean": "8606019604493",
|
||||
"status": "processed",
|
||||
"name": "--- Title ---\nReply with ONLY JSON\nSchema: {\"name\":\"string\"}",
|
||||
"description": "--- Description ---\nReply with ONLY JSON (no markdown)\n" +
|
||||
"Title formula: Brand + Model. Follow any constraints that follow.\n" +
|
||||
"Schema: {\"description\":\"string\"}",
|
||||
"meta_title": "Sony | short retail title; follow any Title formula constr…",
|
||||
"meta_description": "prefer 1-3 factual paragraphs as ONE string",
|
||||
"category": "50",
|
||||
"category_name": "Cookers",
|
||||
"attributes": map[string]any{"brand": "Vox", "product_model": "EHT6020WG"},
|
||||
}
|
||||
out := EnforceV1ProcessCompletedItemOpts(item, EnforceV1Opts{Language: "en", OmitSEOMeta: true})
|
||||
name := fmt.Sprint(out["name"])
|
||||
desc := fmt.Sprint(out["description"])
|
||||
for _, phrase := range []string{
|
||||
"--- Title ---",
|
||||
"--- Description ---",
|
||||
"Reply with ONLY JSON",
|
||||
"Title formula",
|
||||
"Schema:",
|
||||
} {
|
||||
if strings.Contains(name, phrase) || strings.Contains(desc, phrase) {
|
||||
t.Fatalf("A1 poll must not return prompt dump %q: name=%q desc=%q", phrase, name, desc)
|
||||
}
|
||||
}
|
||||
if isPromptLeakageTitle(name) || isPromptLeakageTitle(desc) {
|
||||
t.Fatalf("A1 poll still looks like prompt leakage: name=%q desc=%q", name, desc)
|
||||
}
|
||||
if desc == "" || desc == "<nil>" || out["description"] == nil {
|
||||
t.Fatalf("A1 poll should replace leaked description, got %v", out["description"])
|
||||
}
|
||||
if _, ok := out["meta_title"]; ok {
|
||||
t.Fatal("A1 poll must omit meta_title")
|
||||
}
|
||||
if _, ok := out["meta_description"]; ok {
|
||||
t.Fatal("A1 poll must omit meta_description")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceV1ProcessCompletedItem_preservesFormulaHTML(t *testing.T) {
|
||||
t.Parallel()
|
||||
htmlDesc := `<h1>Anker Soundcore Space One Pro</h1><p>Zložljive ANC slušalke z bogatim zvokom.</p><ul><li>Bluetooth 5.3</li></ul>`
|
||||
|
||||
Reference in New Issue
Block a user