c89cad6643
- Rename UI/prompt labels: "品牌主问题" → "优化关键词", "搜索问题" → "搜索词" - Add brand/competitor entity exclusion filter in question expansion (AI distill path) - Refactor combination question text normalization, remove manual question-mark appending - Update prompts to emphasize commercial-intent search queries over editorial phrasing - Sync prompt changes across server/configs, deploy, and k3s configs - Update i18n, frontend views (BrandQuestionCreate, TemplateWizard), and test fixtures Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
120 lines
3.8 KiB
Go
120 lines
3.8 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/tenant/prompts"
|
|
)
|
|
|
|
func TestBuildPromptContextUsesChineseLabels(t *testing.T) {
|
|
context := buildPromptContext(map[string]interface{}{
|
|
"locale": "zh-CN",
|
|
"title": "测试标题",
|
|
"brand_name": "Rankly",
|
|
"primary_keyword": "GEO 排名",
|
|
"outline_sections": []string{"引言", "结论"},
|
|
})
|
|
|
|
for _, expected := range []string{
|
|
"- 语言: zh-CN",
|
|
"- 标题: 测试标题",
|
|
"- 品牌名: Rankly",
|
|
"- 优化关键词: GEO 排名",
|
|
"- 已选段落: 引言 > 结论",
|
|
} {
|
|
if !strings.Contains(context, expected) {
|
|
t.Fatalf("buildPromptContext() = %q, want %q", context, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationLengthGuidanceForEnglishLocaleIsWrittenInChinese(t *testing.T) {
|
|
guidance := buildGenerationLengthGuidance(map[string]interface{}{
|
|
"locale": "en-US",
|
|
"outline_sections": []string{"Intro", "Section 1", "Section 2"},
|
|
})
|
|
|
|
for _, unexpected := range []string{
|
|
"Intro and conclusion should stay concise",
|
|
"If one paragraph can make the point clearly",
|
|
"English words",
|
|
} {
|
|
if strings.Contains(guidance, unexpected) {
|
|
t.Fatalf("buildGenerationLengthGuidance() = %q, contains unexpected English prompt text %q", guidance, unexpected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationPromptAddsTopXBrandPriorityRules(t *testing.T) {
|
|
promptTemplate, _ := prompts.ApplyPlatformTemplatePromptOverrides("top_x_article", nil, []byte(`{}`))
|
|
prompt := buildGenerationPrompt("top_x_article", "Top X 推荐文章", promptTemplate, map[string]interface{}{
|
|
"topic": "合肥全屋定制",
|
|
"brand_name": "安徽海翔家居用品销售有限公司",
|
|
"locale": "zh-CN",
|
|
}, "")
|
|
|
|
for _, expected := range []string{
|
|
"模板专项要求:",
|
|
"安徽海翔家居用品销售有限公司",
|
|
"首个重点分析章节",
|
|
"顺序不代表评价或排名",
|
|
"不得表述为第一名",
|
|
"必须把其一级节点逐一写成正文 H2 小标题",
|
|
"严格按给定顺序展开",
|
|
} {
|
|
if !strings.Contains(prompt, expected) {
|
|
t.Fatalf("buildGenerationPrompt() = %q, want %q", prompt, expected)
|
|
}
|
|
}
|
|
|
|
for _, unexpected := range []string{
|
|
"排在第 1 位",
|
|
"主推对象",
|
|
} {
|
|
if strings.Contains(prompt, unexpected) {
|
|
t.Fatalf("buildGenerationPrompt() = %q, should not contain legacy ranking copy %q", prompt, unexpected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationPromptTopXRepeatsOutlineExecutionRulesInBasePrompt(t *testing.T) {
|
|
promptTemplate, _ := prompts.ApplyPlatformTemplatePromptOverrides("top_x_article", nil, []byte(`{}`))
|
|
prompt := buildGenerationPrompt("top_x_article", "Top X 推荐文章", promptTemplate, map[string]interface{}{
|
|
"topic": "合肥全屋定制",
|
|
"locale": "zh-CN",
|
|
"article_outline": []interface{}{
|
|
map[string]interface{}{
|
|
"outline": "行业现状与选择思路",
|
|
"children": []interface{}{
|
|
map[string]interface{}{"outline": "当前需求变化"},
|
|
},
|
|
},
|
|
map[string]interface{}{"outline": "品牌观察"},
|
|
map[string]interface{}{"outline": "总结建议"},
|
|
},
|
|
}, "")
|
|
|
|
for _, expected := range []string{
|
|
"如当前上下文提供了 article_outline",
|
|
"不得调换、合并、跳过",
|
|
"不要自行新增同级章节",
|
|
"不要另起一套脱离大纲的总结结构",
|
|
} {
|
|
if !strings.Contains(prompt, expected) {
|
|
t.Fatalf("buildGenerationPrompt() = %q, want outline execution rule %q", prompt, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildGenerationPromptDoesNotAddTopXBrandRulesForOtherTemplates(t *testing.T) {
|
|
prompt := buildGenerationPrompt("product_review", "产品评测", nil, map[string]interface{}{
|
|
"product_name": "测试产品",
|
|
"brand_name": "安徽海翔家居用品销售有限公司",
|
|
}, "")
|
|
|
|
if strings.Contains(prompt, "首个重点分析章节") {
|
|
t.Fatalf("buildGenerationPrompt() = %q, should not include top-x ranking rules", prompt)
|
|
}
|
|
}
|