fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
@@ -82,6 +83,66 @@ func TestTruncateMetaDescription_collapsesSpace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetaFieldsFromEnhanceObj_snakeAndCamel(t *testing.T) {
|
||||
t.Parallel()
|
||||
mt, md := metaFieldsFromEnhanceObj(map[string]any{
|
||||
"meta_title": "Acme Widget Pro | Daily Use",
|
||||
"meta_description": "Shop Acme Widget Pro for reliable everyday performance.",
|
||||
})
|
||||
if mt != "Acme Widget Pro | Daily Use" {
|
||||
t.Fatalf("meta_title=%q", mt)
|
||||
}
|
||||
if !strings.Contains(md, "Acme Widget Pro") {
|
||||
t.Fatalf("meta_description=%q", md)
|
||||
}
|
||||
mt, md = metaFieldsFromEnhanceObj(map[string]any{
|
||||
"metaTitle": "<b>Camel Title</b>",
|
||||
"metaDescription": "<p>Camel desc with enough characters for a real SEO snippet about the product.</p>",
|
||||
})
|
||||
if strings.Contains(mt, "<") || mt == "" {
|
||||
t.Fatalf("camel meta_title should be plain: %q", mt)
|
||||
}
|
||||
if strings.Contains(md, "<") || md == "" {
|
||||
t.Fatalf("camel meta_description should be plain: %q", md)
|
||||
}
|
||||
mt, md = metaFieldsFromEnhanceObj(map[string]any{
|
||||
"meta_title": "short retail title; follow any Title formula",
|
||||
})
|
||||
if mt != "" || md != "" {
|
||||
t.Fatalf("leakage meta must be dropped: %q %q", mt, md)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSteps_enhancePersistsMetaFields(t *testing.T) {
|
||||
e := &Engine{Completer: stubCompleter{fn: func(system, user string) (Completion, error) {
|
||||
return Completion{Text: `{
|
||||
"name":"Acme Widget Pro",
|
||||
"description":"<h2>Acme Widget Pro</h2><p>Durable widget for everyday use.</p>",
|
||||
"meta_title":"Acme Widget Pro | Durable Daily Use",
|
||||
"meta_description":"Shop Acme Widget Pro for reliable everyday performance. Clear specs and fast delivery."
|
||||
}`, TotalTokens: 12}, nil
|
||||
}}}
|
||||
out, err := e.RunSteps(context.Background(), "c1", ProductInput{
|
||||
Mapped: map[string]any{"name": "Raw", "description": "old", "category": "tools"},
|
||||
Language: "en",
|
||||
}, "full", nil, StepPolicy{AllowAI: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.MetaTitle != "Acme Widget Pro | Durable Daily Use" {
|
||||
t.Fatalf("MetaTitle=%q", out.MetaTitle)
|
||||
}
|
||||
if !strings.Contains(out.MetaDescription, "Shop Acme Widget Pro") {
|
||||
t.Fatalf("MetaDescription=%q", out.MetaDescription)
|
||||
}
|
||||
if !strings.Contains(out.ProcessedDescription, "<h2>") {
|
||||
t.Fatalf("description should stay HTML: %q", out.ProcessedDescription)
|
||||
}
|
||||
if strings.Contains(out.MetaDescription, "<") {
|
||||
t.Fatalf("meta_description must be plain: %q", out.MetaDescription)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1PollMetaFallback_usesTemplateWhenEmpty(t *testing.T) {
|
||||
t.Parallel()
|
||||
title := "Cordless Drill"
|
||||
|
||||
Reference in New Issue
Block a user