Files

130 lines
3.1 KiB
Go

package ctxmgr
import (
"testing"
)
func TestDeriveMessageCategory(t *testing.T) {
tests := []struct {
name string
role string
intentStr string
branch string
meta map[string]any
wantCat string
}{
{
name: "Milestone in metadata has highest priority",
role: "assistant",
meta: map[string]any{"milestone": true},
wantCat: CategoryMilestone,
},
{
name: "File upload in metadata",
role: "user",
meta: map[string]any{"file_op": "upload"},
wantCat: CategoryFile,
},
{
name: "Interactive card in metadata",
role: "assistant",
meta: map[string]any{"interactive_card": map[string]any{"type": "confirm"}},
wantCat: CategoryReview,
},
{
name: "Task request in metadata",
role: "user",
meta: map[string]any{"task_request": true},
wantCat: CategoryTask,
},
{
name: "Assistant message inherits turn_intent from metadata",
role: "assistant",
intentStr: "",
meta: map[string]any{"turn_intent": "CASUAL_CHAT"},
wantCat: CategoryCasual,
},
{
name: "Assistant message inherits uncategorized turn_intent fallback",
role: "assistant",
intentStr: "uncategorized",
meta: map[string]any{"turn_intent": "DOCGOV_SUBMIT_REVIEW"},
wantCat: CategoryReview,
},
{
name: "Direct intent mapping casual",
role: "user",
intentStr: "CASUAL_CHAT",
wantCat: CategoryCasual,
},
{
name: "Direct intent mapping task",
role: "user",
intentStr: "TRIGGER_TASK",
wantCat: CategoryTask,
},
{
name: "Direct intent mapping review",
role: "user",
intentStr: "DOCGOV_SUBMIT_REVIEW",
wantCat: CategoryReview,
},
{
name: "Direct intent mapping consult",
role: "user",
intentStr: "QUERY_PROGRESS",
wantCat: CategoryConsult,
},
{
name: "Direct intent mapping security system",
role: "user",
intentStr: "SECURITY_FORBIDDEN",
wantCat: CategorySystem,
},
{
name: "System role fallback",
role: "system",
wantCat: CategorySystem,
},
{
name: "Ambiguous fallback branch",
role: "assistant",
branch: "AMBIGUOUS_FALLBACK",
wantCat: CategoryConsult,
},
{
name: "Uncategorized fallback",
role: "user",
wantCat: CategoryUncategorized,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := DeriveMessageCategory(tt.role, tt.intentStr, tt.branch, tt.meta)
if got != tt.wantCat {
t.Errorf("DeriveMessageCategory() = %v, want %v", got, tt.wantCat)
}
})
}
}
func TestGetCategoryLabelFinalized(t *testing.T) {
expected := map[string]string{
CategoryMilestone: "关键节点",
CategoryReview: "审批流转",
CategoryTask: "任务执行",
CategoryFile: "文件收发",
CategoryConsult: "业务咨询",
CategoryCasual: "日常闲聊",
CategorySystem: "系统通知",
CategoryUncategorized: "其他",
}
for cat, wantLabel := range expected {
if got := GetCategoryLabel(cat); got != wantLabel {
t.Errorf("GetCategoryLabel(%q) = %q, want %q", cat, got, wantLabel)
}
}
}