fix
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
|
||||
)
|
||||
|
||||
func TestBuildA1StyleEnhanceUserTemplate_mirrorsLegacyGenerator(t *testing.T) {
|
||||
t.Parallel()
|
||||
prompt := aiprompts.SectionTitleStart + "\n" +
|
||||
`Napiši novo ime izdelka po formuli: "tip izdelka sentence case", "znamka", "model". Ne uporabljaj vejic.` + "\n" +
|
||||
aiprompts.SectionTitleEnd + "\n\n" +
|
||||
aiprompts.SectionDescriptionStart + "\n" +
|
||||
`<H2>{Napiši Novo ime izdelka in izpostavi en benefit}</H2>` +
|
||||
`<p>{Napiši odstavek, ki je dolg 100 besed.}</p>` +
|
||||
`<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij}</li></ul>` + "\n" +
|
||||
aiprompts.SectionDescriptionEnd + "\n\n" +
|
||||
aiprompts.SectionMetaStart + "\n" +
|
||||
`Najprej napiši Novo ime in potem nadaljuj do 140 znakov.` + "\n" +
|
||||
aiprompts.SectionMetaEnd
|
||||
|
||||
descTpl := aiprompts.EffectiveDescriptionTemplateAny(nil, prompt)
|
||||
if !categoryUsesA1StyleFormula(prompt, nil, descTpl) {
|
||||
t.Fatal("expected A1-style formula detection")
|
||||
}
|
||||
user := buildA1StyleEnhanceUserTemplate(prompt, nil, descTpl, false)
|
||||
for _, want := range []string{
|
||||
"GPT predloga:",
|
||||
"Sledi tej GPT predlogi",
|
||||
"Staro_ime_izdelka: {{name}}",
|
||||
"Star_opis_izdelka: {{description}}",
|
||||
"<name>{",
|
||||
"<metaDescription>{",
|
||||
"<H2>{",
|
||||
`"name"`,
|
||||
`"description"`,
|
||||
} {
|
||||
if !strings.Contains(user, want) {
|
||||
t.Fatalf("missing %q in:\n%s", want, user)
|
||||
}
|
||||
}
|
||||
|
||||
sys, renderedUser := resolveProductPromptTemplates(ProductInput{
|
||||
CategoryEnhancePrompt: prompt,
|
||||
Language: "sl",
|
||||
})
|
||||
if !strings.Contains(sys, "Si tekstopisec") {
|
||||
t.Fatalf("system must be A1 copywriter, got:\n%s", sys)
|
||||
}
|
||||
if !strings.Contains(renderedUser, "GPT predloga:") {
|
||||
t.Fatalf("user must be A1 GPT predloga, got:\n%s", renderedUser)
|
||||
}
|
||||
// Soft overlay framing must not win over GPT predloga.
|
||||
if strings.Contains(renderedUser, "Category guidance (applies to name") {
|
||||
t.Fatal("A1 path must not use soft category guidance overlay")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLegacyEnhanceHTML(t *testing.T) {
|
||||
t.Parallel()
|
||||
raw := `<name>ovitek PanzerGlass Honor 200 Smart črna</name>` +
|
||||
`<metaDescription>Ovitek PanzerGlass za Honor 200 Smart z elegantnim videzom.</metaDescription>` +
|
||||
`<h2>Zaščita z elegantnim videzom</h2><p>Dolg odstavek o ovitku.</p>` +
|
||||
`<ul><li>Barva: črna</li></ul>`
|
||||
name, meta, body, ok := ParseLegacyEnhanceHTML(raw)
|
||||
if !ok {
|
||||
t.Fatal("expected parse ok")
|
||||
}
|
||||
if name != "ovitek PanzerGlass Honor 200 Smart črna" {
|
||||
t.Fatalf("name=%q", name)
|
||||
}
|
||||
if !strings.Contains(meta, "PanzerGlass") {
|
||||
t.Fatalf("meta=%q", meta)
|
||||
}
|
||||
if strings.Contains(body, "<name>") || strings.Contains(body, "metaDescription") {
|
||||
t.Fatalf("body still has tags: %q", body)
|
||||
}
|
||||
if !strings.Contains(body, "<h2>") || !strings.Contains(body, "<ul>") {
|
||||
t.Fatalf("body missing HTML: %q", body)
|
||||
}
|
||||
|
||||
obj := map[string]any{
|
||||
"name": "",
|
||||
"description": raw,
|
||||
}
|
||||
applyLegacyEnhanceTagFallback(obj, "")
|
||||
if obj["name"] != name {
|
||||
t.Fatalf("fallback name=%v", obj["name"])
|
||||
}
|
||||
if strings.Contains(fmt.Sprint(obj["description"]), "<name>") {
|
||||
t.Fatalf("fallback desc still has name tag: %v", obj["description"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user