thread-master/internal/library/knowledge/queries_test.go

49 lines
1.3 KiB
Go
Raw Permalink Normal View History

2026-06-26 08:37:04 +00:00
package knowledge
import (
"testing"
"unicode/utf8"
)
func TestPlanQueriesCapsAtConfigLimit(t *testing.T) {
queries := PlanQueries(PlanInput{
Seed: "敏感肌",
TargetAudience: "孕婦",
L1Labels: []string{"a", "b", "c", "d", "e", "f", "g", "h"},
})
max := MaxPlanQueriesPerRound()
if len(queries) > max {
t.Fatalf("expected <= %d queries, got %d", max, len(queries))
}
if len(queries) < 4 {
t.Fatalf("expected at least 4 queries, got %d", len(queries))
}
}
func TestDeriveSearchTagsFromGraph(t *testing.T) {
graph := Graph{
Nodes: []Node{
{ID: "n1", Label: "敏感肌", NodeKind: "pain", Layer: 0},
{ID: "n2", Label: "屏障受損", NodeKind: "symptom", Layer: 1},
},
}
DeriveSearchTagsFromGraph(&graph, PatrolTagInput{
Questions: []string{"敏感肌沐浴乳有推薦嗎"},
Pillars: []string{"敏感肌沐浴用品挑選"},
})
if graph.PainTagCount != 2 {
t.Fatalf("expected pain tag count 2, got %d", graph.PainTagCount)
}
for _, tag := range graph.Nodes[0].DerivedTags.Relevance {
if utf8.RuneCountInString(tag) < 6 {
t.Fatalf("expected human-length tag, got %q", tag)
}
}
if len(graph.Nodes[0].DerivedTags.Relevance) == 0 {
t.Fatal("expected relevance tags on core node")
}
if len(graph.Nodes[0].DerivedTags.Recency) == 0 {
t.Fatal("expected recency tags on pain node")
}
}