thread-master/internal/library/placement/context_prompt_test.go

59 lines
2.0 KiB
Go
Raw Permalink Normal View History

2026-06-26 08:37:04 +00:00
package placement
import (
"strings"
"testing"
branddomain "haixun-backend/internal/model/brand/domain/usecase"
)
func TestPlacementTopicContextWritePromptBlock(t *testing.T) {
ctx := PlacementTopicContextFromBrand(&branddomain.BrandSummary{
DisplayName: "ecostore",
TopicName: "癌症病友沐浴敏感",
SeedQuery: "化療 無香 沐浴乳",
Brief: "找近期求助換沐浴乳的貼文",
ProductID: "p1",
Products: []branddomain.ProductSummary{
{ID: "p1", Label: "抗敏無香沐浴露", ProductContext: `{"brand":"ecostore","product":"抗敏無香沐浴露","features":"完全無香、抗敏、第三方認證"}`},
},
ProductContext: `{"brand":"ecostore","product":"抗敏無香沐浴露","features":"完全無香、抗敏、第三方認證"}`,
}, "")
var b strings.Builder
ctx.WritePromptBlock(&b)
out := b.String()
for _, want := range []string{
"【品牌】ecostore",
"【置入產品】抗敏無香沐浴露",
"【主題名稱】癌症病友沐浴敏感",
"【種子關鍵字】化療 無香 沐浴乳",
"【主題目標】找近期求助換沐浴乳的貼文",
"【產品詳情】",
"完全無香、抗敏、第三方認證",
} {
if !strings.Contains(out, want) {
t.Fatalf("prompt block missing %q:\n%s", want, out)
}
}
}
func TestBuildResearchMapAnalysisPrompts(t *testing.T) {
in := PlacementTopicContext{
BrandDisplayName: "ecostore",
TopicName: "癌症病友沐浴敏感",
}.ToResearchMapInput()
sys := BuildResearchMapAnalysisSystemPrompt()
if !strings.Contains(sys, "不要輸出 JSON") {
t.Fatal("analysis system prompt should forbid JSON")
}
user := BuildResearchMapAnalysisUserPrompt(in)
if !strings.Contains(user, "【品牌】ecostore") {
t.Fatalf("analysis user prompt missing brand: %s", user)
}
final := BuildResearchMapFinalizeUserPrompt(in, "分析段落")
if !strings.Contains(final, "【前置分析】") || !strings.Contains(final, "分析段落") {
t.Fatalf("finalize prompt missing analysis: %s", final)
}
}