Files
geo/server/internal/tenant/app/template_prompt_test.go
T
root 1eae6fb6d4
Deployment Config CI / Deployment Config (push) Successful in 29s
Frontend CI / Frontend (push) Successful in 4m4s
Backend CI / Backend (push) Failing after 7m12s
feat(questions): make brand questions the primary monitoring & template axis
- add /questions/combination-fill endpoint with AI-driven, IP-region-aware matrix fill
- extract ip2region resolver from ops/app into shared/ipregion for cross-service use
- thread question_id filter through dashboard composite, citation summary, and collect-now
- switch template wizard from keyword inputs to brand-question selection (primary + supplemental)
- pass brand_question and supplemental_questions through assist/title/outline prompts
- add AiWaitingModal + 45s client timeout and request_timeout error mapping for long AI flows

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 15:59:39 +08:00

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)
}
}