74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
import pytest
|
|
|
|
from review_agent.file_summary.workflow_trigger import (
|
|
evaluate_attachment_reader_trigger,
|
|
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"
|
|
|
|
|
|
def test_attachment_reader_trigger_matches_file_content_phrases(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
|
|
missing = evaluate_attachment_reader_trigger(conversation, "根据提供的简历文件内容,简要介绍")
|
|
assert missing.should_start is False
|
|
assert missing.reason == "missing_attachment"
|
|
|
|
FileAttachment.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
original_name="resume.docx",
|
|
storage_path="x/resume.docx",
|
|
file_size=1,
|
|
)
|
|
|
|
matched = evaluate_attachment_reader_trigger(conversation, "根据提供的简历文件内容,简要介绍")
|
|
assert matched.should_start is True
|
|
assert matched.workflow_type == "attachment_reader"
|
|
|
|
|
|
def test_attachment_reader_trigger_matches_resume_project_experience_request(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
FileAttachment.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
original_name="resume.docx",
|
|
storage_path="x/resume.docx",
|
|
file_size=1,
|
|
)
|
|
|
|
matched = evaluate_attachment_reader_trigger(conversation, "阅读下附件简历中的项目经历")
|
|
|
|
assert matched.should_start is True
|
|
assert matched.workflow_type == "attachment_reader"
|