package aiprompts import ( "strings" "testing" ) func TestCategoryEnhanceHasRoleSections(t *testing.T) { t.Parallel() if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) { t.Fatal("canonical CategoryEnhanceUserTemplate must have title/description/meta/attributes sections") } if CategoryEnhanceHasRoleSections("legacy HTML prompt") { t.Fatal("unstructured prompt must not report role sections") } if CategoryEnhanceHasRoleSections("--- Title ---\nonly title") { t.Fatal("partial sections must not pass") } } func TestCategoryPromptRolesOrder(t *testing.T) { t.Parallel() want := []string{RoleCategorize, RoleTitle, RoleDescription, RoleMeta, RoleAttributes} if len(CategoryPromptRoles) != len(want) { t.Fatalf("roles len=%d want %d", len(CategoryPromptRoles), len(want)) } for i, w := range want { if CategoryPromptRoles[i] != w { t.Fatalf("roles[%d]=%q want %q", i, CategoryPromptRoles[i], w) } } } func TestCategoryEnhanceUserTemplateRoleMarkers(t *testing.T) { t.Parallel() tpl := CategoryEnhanceUserTemplate for _, marker := range []string{ SectionTitleStart, SectionTitleEnd, SectionDescriptionStart, SectionDescriptionEnd, SectionMetaStart, SectionMetaEnd, SectionAttributesStart, SectionAttributesEnd, } { if !strings.Contains(tpl, marker) { t.Fatalf("template missing %q", marker) } } lower := strings.ToLower(tpl) for _, role := range []string{"role: title", "role: description", "role: meta", "role: attributes"} { if !strings.Contains(lower, role) { t.Fatalf("template missing %q", role) } } // HeuristicCompleter / labeledPromptValue depend on these product context labels. for _, label := range []string{"Name: {{name}}", "Description: {{description}}", "Category: {{category}}", "Attrs: {{attrs}}"} { if !strings.Contains(tpl, label) { t.Fatalf("template missing product label %q", label) } } if !strings.Contains(tpl, "meta_title") || !strings.Contains(tpl, "meta_description") { t.Fatal("template must keep enhance meta_* schema (parallel title/meta work)") } if !strings.Contains(tpl, `"attrs":{}`) { t.Fatal("template must keep enhance attrs schema (parallel attributes work)") } } func TestSEOMetaUserTemplateHasMetaSection(t *testing.T) { t.Parallel() def, ok := DefaultFor(KeySEOMeta) if !ok { t.Fatal("missing seo_meta default") } if !strings.Contains(def.UserTemplate, SectionMetaStart) { t.Fatal("seo_meta user template should use --- Meta --- section") } if !strings.Contains(strings.ToLower(def.UserTemplate), "role: meta") { t.Fatal("seo_meta user template should declare Role: meta") } }