103 lines
3.2 KiB
Go
103 lines
3.2 KiB
Go
package intent_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/bizdev"
|
|
"chat-agent-system/internal/intent"
|
|
)
|
|
|
|
func TestIntentRecognition_QueryProgress(t *testing.T) {
|
|
rec := intent.NewRecognizer()
|
|
ctx := &intent.ContextSnapshot{
|
|
SnapshotID: "ctx_test_1",
|
|
CurrentStage: string(bizdev.StageV01_Triage),
|
|
}
|
|
|
|
res, err := rec.Recognize(context.Background(), "现在这个便携超声立项评估到哪一步了?有啥风险没?", ctx)
|
|
if err != nil {
|
|
t.Fatalf("recognize failed: %v", err)
|
|
}
|
|
|
|
if res.TopIntent.Intent != intent.IntentQueryProgress {
|
|
t.Errorf("expected intent QUERY_PROGRESS, got %s", res.TopIntent.Intent)
|
|
}
|
|
if res.TopIntent.Confidence < 0.8 {
|
|
t.Errorf("expected confidence >= 0.8, got %v", res.TopIntent.Confidence)
|
|
}
|
|
if len(res.Candidates) == 0 {
|
|
t.Errorf("expected candidate intents list")
|
|
}
|
|
}
|
|
|
|
func TestIntentRecognition_SupplementInfo(t *testing.T) {
|
|
rec := intent.NewRecognizer()
|
|
ctx := &intent.ContextSnapshot{
|
|
SnapshotID: "ctx_test_2",
|
|
}
|
|
|
|
res, err := rec.Recognize(context.Background(), "客户刚才补充说,目标市场除了国内还想考虑欧洲 CE 认证", ctx)
|
|
if err != nil {
|
|
t.Fatalf("recognize failed: %v", err)
|
|
}
|
|
|
|
if res.TopIntent.Intent != intent.IntentSupplementInfo {
|
|
t.Errorf("expected intent SUPPLEMENT_INFO, got %s", res.TopIntent.Intent)
|
|
}
|
|
if res.TopIntent.FilledSlots[intent.SlotFactKey] != "target_market" {
|
|
t.Errorf("expected slot target_market, got %s", res.TopIntent.FilledSlots[intent.SlotFactKey])
|
|
}
|
|
}
|
|
|
|
func TestIntentRecognition_AdvanceStage(t *testing.T) {
|
|
rec := intent.NewRecognizer()
|
|
ctx := &intent.ContextSnapshot{
|
|
SnapshotID: "ctx_test_3",
|
|
CurrentStage: string(bizdev.StageV01_Triage),
|
|
}
|
|
|
|
res, err := rec.Recognize(context.Background(), "摸底表我看过了,没问题,可以进入方案论证阶段了", ctx)
|
|
if err != nil {
|
|
t.Fatalf("recognize failed: %v", err)
|
|
}
|
|
|
|
if res.TopIntent.Intent != intent.IntentAdvanceStage {
|
|
t.Errorf("expected intent ADVANCE_STAGE, got %s", res.TopIntent.Intent)
|
|
}
|
|
if res.TopIntent.FilledSlots[intent.SlotTargetStage] != string(bizdev.StageV05_Feasibility) {
|
|
t.Errorf("expected target stage V0.5_feasibility, got %s", res.TopIntent.FilledSlots[intent.SlotTargetStage])
|
|
}
|
|
}
|
|
|
|
func TestIntentRecognition_TriggerTask(t *testing.T) {
|
|
rec := intent.NewRecognizer()
|
|
ctx := &intent.ContextSnapshot{
|
|
SnapshotID: "ctx_test_4",
|
|
}
|
|
|
|
res, err := rec.Recognize(context.Background(), "先帮我出一版初步报价单看看", ctx)
|
|
if err != nil {
|
|
t.Fatalf("recognize failed: %v", err)
|
|
}
|
|
|
|
if res.TopIntent.Intent != intent.IntentTriggerTask {
|
|
t.Errorf("expected intent TRIGGER_TASK, got %s", res.TopIntent.Intent)
|
|
}
|
|
if res.TopIntent.FilledSlots[intent.SlotTargetTask] != "cdo_quote" {
|
|
t.Errorf("expected target task cdo_quote, got %s", res.TopIntent.FilledSlots[intent.SlotTargetTask])
|
|
}
|
|
}
|
|
|
|
func TestIntentRecognition_CasualChat(t *testing.T) {
|
|
rec := intent.NewRecognizer()
|
|
res, err := rec.Recognize(context.Background(), "你好,请问你是谁?", nil)
|
|
if err != nil {
|
|
t.Fatalf("recognize failed: %v", err)
|
|
}
|
|
|
|
if res.TopIntent.Intent != intent.IntentCasualChat {
|
|
t.Errorf("expected intent CASUAL_CHAT, got %s", res.TopIntent.Intent)
|
|
}
|
|
}
|