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_DocumentSummaryIsReadonly(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.IntentQueryDocStatus { t.Fatalf("expected QUERY_DOC_STATUS, got %s", res.TopIntent.Intent) } if got := res.TopIntent.FilledSlots[intent.SlotQueryTopic]; got != "doc_summary" { t.Fatalf("query_topic=%q want doc_summary", got) } if got := res.TopIntent.FilledSlots[intent.SlotTargetDoc]; got != "用户初始需求表" { t.Fatalf("target_doc=%q", got) } } func TestWorkflowMatcher_LatestUploadSummarySentinel(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.IntentQueryDocStatus { t.Fatalf("expected QUERY_DOC_STATUS, got %s", res.TopIntent.Intent) } if got := res.TopIntent.FilledSlots[intent.SlotQueryTopic]; got != "doc_summary" { t.Fatalf("query_topic=%q want doc_summary", got) } if got := res.TopIntent.FilledSlots[intent.SlotTargetDoc]; got != intent.TargetDocLatestUpload { t.Fatalf("target_doc=%q want %q", got, intent.TargetDocLatestUpload) } } func TestWorkflowMatcher_LatestUploadWithWriteVerbNotSummary(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.IntentQueryDocStatus && res.TopIntent.FilledSlots[intent.SlotQueryTopic] == "doc_summary" { t.Fatalf("write+upload must not be classified as doc_summary, got %+v", res.TopIntent) } } 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) } }