The per-category prompt editor showed English machine boilerplate
("Role: description. Build JSON …", schema intro, {{var}} context lines)
because seed/sync baked the render framing into categories.prompt. Now the
stored overlay is exactly the legacy wp_product_categories.sql content,
split into the three sections a user would type themselves:
--- Title --- Slovenian naming formula
--- Description --- legacy <H2>/<p>/<ul> body structure
--- Meta --- legacy metaDescription instruction
Schema, role framing, and Name/Description/Category/Attrs product context
stay render-time only (system template + ensureCategoryEnhanceUserContext),
where they already existed.
- SplitLegacyCombinedEnhancePrompt: non-legacy input now returns "" —
categories without seed/legacy content get their override CLEARED
(company default) instead of being stuffed with the canonical template
(e.g. parent categories like "Bela tehnika" absent from the SQL).
- CategoryEnhancePromptNeedsRepair flags stored boilerplate ("parsed as
JSON", "Build JSON", retired Attributes section) so Sync rewrites old
data to the clean shape; repair supports clearing (prompt = '{}').
- seed-a1 apply-category-prompts skips instead of writing template text.
- Web editor compose stores only the user's section text: empty sections
keep bare markers, default bodies and the default preamble are never
persisted (DEFAULT_SECTION_BODIES removed).
- Verified locally: apply rewrote 238 A1+Demo categories (216 exact
splits, 22 cleared), zero boilerplate matches in DB, idempotent re-run
(would_update=0).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
84 lines
3.2 KiB
Go
84 lines
3.2 KiB
Go
package aiprompts
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCategoryEnhanceUserTemplateHasRequiredVars(t *testing.T) {
|
|
t.Parallel()
|
|
vars := ExtractVariables(CategoryEnhanceUserTemplate)
|
|
want := []string{"language", "category", "name", "description", "attrs"}
|
|
got := map[string]struct{}{}
|
|
for _, v := range vars {
|
|
got[v] = struct{}{}
|
|
}
|
|
for _, w := range want {
|
|
if _, ok := got[w]; !ok {
|
|
t.Fatalf("CategoryEnhanceUserTemplate missing {{%s}}; vars=%v", w, vars)
|
|
}
|
|
}
|
|
lower := strings.ToLower(CategoryEnhanceUserTemplate)
|
|
if strings.Contains(lower, "100 besed") || strings.Contains(lower, "gpt predloga") {
|
|
t.Fatal("template must not demand legacy long HTML marketing docs")
|
|
}
|
|
if !strings.Contains(CategoryEnhanceUserTemplate, `{"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}`) {
|
|
t.Fatal("template should reference enhance JSON schema including meta_* and attrs")
|
|
}
|
|
// Attribute prompting is retired from category prompts — extraction guidance
|
|
// is pipeline-level (AppendAttributeConstraints), never prompt-authored.
|
|
if strings.Contains(strings.ToLower(CategoryEnhanceUserTemplate), `build json "attrs"`) {
|
|
t.Fatal("template must not carry an attributes role instruction")
|
|
}
|
|
if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) {
|
|
t.Fatal("canonical template must be role-sectioned for title/description/meta")
|
|
}
|
|
if !strings.Contains(lower, "{{language}}") {
|
|
t.Fatal("language must come from {{language}}")
|
|
}
|
|
}
|
|
|
|
func TestCategoryEnhancePromptNeedsRepair(t *testing.T) {
|
|
t.Parallel()
|
|
if CategoryEnhancePromptNeedsRepair("") {
|
|
t.Fatal("empty should not need repair")
|
|
}
|
|
// A STORED copy of the built-in template is boilerplate pollution — repair
|
|
// clears it so the category falls back to the company default.
|
|
if !CategoryEnhancePromptNeedsRepair(CategoryEnhanceUserTemplate) {
|
|
t.Fatal("stored canonical template text should need repair (cleared to default)")
|
|
}
|
|
legacy := `Ustvari nov opis\n<H2>foo</H2>\nAttrs missing`
|
|
if !CategoryEnhancePromptNeedsRepair(legacy) {
|
|
t.Fatal("legacy HTML prompt should need repair")
|
|
}
|
|
// Per-category sectioned overlay (pure Slovenian rules) must not force re-repair.
|
|
split := SplitLegacyCombinedEnhancePrompt(`GPT predloga:
|
|
<name>{Napiši tip izdelka}</name>
|
|
<metaDescription>{140 znakov}</metaDescription>
|
|
<H2>{benefit}</H2>`)
|
|
if CategoryEnhancePromptNeedsRepair(split) {
|
|
t.Fatal("sectioned split overlay should be idempotent")
|
|
}
|
|
if CategoryEnhancePromptNeedsRepair(" " + split + "\n") {
|
|
t.Fatal("whitespace-trimmed split overlay should be idempotent")
|
|
}
|
|
}
|
|
|
|
func TestBuiltInProductEnhanceUsesSharedUserTemplate(t *testing.T) {
|
|
t.Parallel()
|
|
def, ok := DefaultFor(KeyProductEnhance)
|
|
if !ok {
|
|
t.Fatal("missing product_enhance default")
|
|
}
|
|
if def.UserTemplate != CategoryEnhanceUserTemplate {
|
|
t.Fatalf("UserTemplate must be CategoryEnhanceUserTemplate")
|
|
}
|
|
if strings.Contains(def.SystemTemplate, "1-2 factual sentences") {
|
|
t.Fatal("system template must not force 1-2 sentences over category Description formulas")
|
|
}
|
|
if !strings.Contains(strings.ToLower(def.SystemTemplate), "description formula") {
|
|
t.Fatal("system template should defer to Description formula when present")
|
|
}
|
|
}
|