Files
Agent-System/internal/intent/workflow_matcher_test.go
T
WeiCHENandCursor dda6a06e4a feat(intent): Phase 3 workflow/help intents and coordinator handlers
Add SWITCH/TRIGGER/QUERY workflow, doc status, help and unsupported intents
with ActionSpec registry entries, NL matchers, L2 handlers with creator-only
switch gate, router routes, and capability-aware AvailableActions.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:21 +00:00

80 lines
2.6 KiB
Go

package intent_test
import (
"context"
"strings"
"testing"
"chat-agent-system/internal/intent"
)
func TestWorkflowMatcher_SwitchProductManager(t *testing.T) {
rec := intent.NewRecognizer()
ctx := &intent.ContextSnapshot{
AvailableActions: []string{"SWITCH_WORKFLOW", "QUERY_WORKFLOW"},
}
res, err := rec.Recognize(context.Background(), "切换到智能测试经理工作流", ctx)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentSwitchWorkflow {
t.Fatalf("expected SWITCH_WORKFLOW, got %s", res.TopIntent.Intent)
}
if res.TopIntent.FilledSlots[intent.SlotTargetWorkflow] != "test_manager" {
t.Errorf("expected test_manager, got %s", res.TopIntent.FilledSlots[intent.SlotTargetWorkflow])
}
if res.IntentFrameV2 == nil || res.IntentFrameV2.ActionKey != "workflow.switch" {
t.Errorf("expected v2 action workflow.switch, got %+v", res.IntentFrameV2)
}
}
func TestWorkflowMatcher_QueryStatus(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "当前激活的是哪个工作流?", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentQueryWorkflowStatus {
t.Fatalf("expected QUERY_WORKFLOW_STATUS, got %s", res.TopIntent.Intent)
}
}
func TestWorkflowMatcher_HelpNotCasualChat(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "这个系统能做什么?", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentHelpCapabilities {
t.Fatalf("expected HELP_CAPABILITIES, got %s", res.TopIntent.Intent)
}
}
func TestWorkflowMatcher_UnsupportedAction(t *testing.T) {
rec := intent.NewRecognizer()
res, err := rec.Recognize(context.Background(), "帮我把这条回复下载下来", nil)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentUnsupportedAction {
t.Fatalf("expected UNSUPPORTED_ACTION, got %s", res.TopIntent.Intent)
}
}
func TestWorkflowMatcher_NonCreatorCapabilityHint(t *testing.T) {
rec := intent.NewRecognizer()
ctx := &intent.ContextSnapshot{
AvailableActions: []string{"QUERY_PROGRESS"},
}
res, err := rec.Recognize(context.Background(), "切换到产品经理工作流", ctx)
if err != nil {
t.Fatalf("recognize: %v", err)
}
if res.TopIntent.Intent != intent.IntentSwitchWorkflow {
t.Fatalf("expected semantic SWITCH_WORKFLOW, got %s", res.TopIntent.Intent)
}
if res.TopIntent.Reasoning == "" || !strings.Contains(res.TopIntent.Reasoning, "AvailableActions") {
t.Errorf("expected capability hint in reasoning, got %q", res.TopIntent.Reasoning)
}
}