import pytest from review_agent.file_summary.workflow_trigger import evaluate_file_summary_trigger from review_agent.models import Conversation, FileAttachment pytestmark = pytest.mark.django_db def test_trigger_matches_keywords_only_when_active_attachment_exists(django_user_model): user = django_user_model.objects.create_user(username="owner", password="pass") conversation = Conversation.objects.create(user=user, title="会话") no_file = evaluate_file_summary_trigger(conversation, "请自动汇总文件目录与页数") assert no_file.should_start is False assert no_file.reason == "missing_attachment" FileAttachment.objects.create( conversation=conversation, user=user, original_name="a.docx", storage_path="x/a.docx", file_size=1, ) matched = evaluate_file_summary_trigger(conversation, "请自动汇总文件目录与页数") assert matched.should_start is True assert matched.workflow_type == "file_summary" normal = evaluate_file_summary_trigger(conversation, "你好,帮我解释法规") assert normal.should_start is False assert normal.reason == "not_matched"