fix(regulatory): 自动执行法规核查前置汇总

This commit is contained in:
2026-06-07 12:17:20 +08:00
parent 911e5378e8
commit 1b4a10b5ba
4 changed files with 110 additions and 14 deletions

View File

@@ -187,6 +187,16 @@ def test_frontend_refreshes_generated_workflow_messages():
assert "data-message-url-template" in script
def test_frontend_only_scrolls_after_appending_new_messages():
script = open("static/js/app.js", encoding="utf-8").read()
assert "return false;" in script
assert "return true;" in script
assert "var appendedCount = 0;" in script
assert "if (appendConversationMessage(message))" in script
assert "if (appendedCount > 0)" in script
def test_frontend_can_replace_partial_stream_content():
script = open("static/js/app.js", encoding="utf-8").read()

View File

@@ -3,6 +3,7 @@ import pytest
from review_agent.models import (
Conversation,
ExportedSummaryFile,
FileAttachment,
FileSummaryBatch,
FileSummaryItem,
Message,
@@ -132,10 +133,54 @@ def test_stream_message_prompts_for_summary_when_missing(monkeypatch, django_use
frames = list(stream_message(conversation, "请做法规核查"))
joined = "".join(frames)
assert "请先执行自动汇总" in joined
assert "请先在当前对话右侧上传需要核查的文件或压缩包" in joined
assert "我会先自动汇总再继续法规核查" in joined
assert not RegulatoryReviewBatch.objects.exists()
def test_stream_message_auto_runs_summary_before_regulatory_review(
monkeypatch, settings, tmp_path, django_user_model
):
settings.MEDIA_ROOT = tmp_path
settings.REGULATORY_REVIEW_ASYNC = False
user = django_user_model.objects.create_user(username="owner", password="pass")
conversation = Conversation.objects.create(user=user, title="会话")
attachment_path = tmp_path / "application.txt"
attachment_path.write_text("产品名称:甲胎蛋白检测试剂盒", encoding="utf-8")
FileAttachment.objects.create(
conversation=conversation,
user=user,
original_name="application.txt",
storage_path=str(attachment_path),
file_size=attachment_path.stat().st_size,
is_active=True,
)
monkeypatch.setattr(
"review_agent.services.route_message_intent",
lambda conversation, content: SkillRoute(
action="regulatory_review",
workflow_type="regulatory_review",
confidence=0.9,
),
)
def finish_summary(batch, async_run=True):
batch.status = FileSummaryBatch.Status.SUCCESS
batch.save(update_fields=["status"])
monkeypatch.setattr("review_agent.services.start_file_summary_workflow", finish_summary)
frames = list(stream_message(conversation, "进行第一章NMPA 法规核查"))
joined = "".join(frames)
assert "\"workflow_type\": \"file_summary\"" in joined
assert "\"workflow_type\": \"regulatory_review\"" in joined
assert "已先启动文件目录与页数自动汇总工作流" in joined
assert FileSummaryBatch.objects.filter(conversation=conversation, status=FileSummaryBatch.Status.SUCCESS).exists()
regulatory = RegulatoryReviewBatch.objects.get(conversation=conversation)
assert regulatory.condition_json["rule_scope"]["attachment4_chapter"] == "1"
def test_stream_message_starts_regulatory_workflow(monkeypatch, settings, django_user_model):
settings.REGULATORY_REVIEW_ASYNC = False
user = django_user_model.objects.create_user(username="owner", password="pass")