Files
ai-agent/internal/services/customer_quick_action_intent_test.go
T

42 lines
1.3 KiB
Go
Raw Normal View History

package services
import (
"strings"
"testing"
"code.tczkiot.com/wlw/ai-agent/contract"
)
func TestMatchingDeterministicActionsOnlyShortCircuitsSingleSimpleIntent(t *testing.T) {
contains := func(marker string) func(string) bool {
return func(message string) bool { return strings.Contains(message, marker) }
}
service := &customerQuickActionService{actions: map[string]contract.CustomerQuickAction{
"card/traffic": {
Code: "card/traffic", CustomerTypes: []string{"card"}, Sort: 10, MatchIntent: contains("流量"),
},
"card/balance": {
Code: "card/balance", CustomerTypes: []string{"card"}, Sort: 20, MatchIntent: contains("余额"),
},
}}
for _, message := range []string{"查流量", "我的流量还剩多少"} {
matched := service.matchingDeterministicActions(message, "card")
if len(matched) != 1 || matched[0].Code != "card/traffic" {
t.Fatalf("simple lookup %q should short-circuit: %#v", message, matched)
}
}
for _, message := range []string{
"我不是查余额,我要查流量",
"我的流量为什么这么快用完",
"怎么查流量",
"流量套餐如何选择",
"查流量;另外查余额",
"顺便查下流量和余额",
} {
if matched := service.matchingDeterministicActions(message, "card"); len(matched) != 0 {
t.Fatalf("ambiguous free text %q must enter the Agent: %#v", message, matched)
}
}
}