138 lines
4.8 KiB
Python
138 lines
4.8 KiB
Python
import pytest
|
|
|
|
from review_agent.models import (
|
|
Conversation,
|
|
ExportedSummaryFile,
|
|
FileSummaryBatch,
|
|
Message,
|
|
RegulatoryArtifact,
|
|
RegulatoryIssue,
|
|
RegulatoryNotificationRecord,
|
|
RegulatoryReviewBatch,
|
|
RegulatoryRuleVersion,
|
|
WorkflowEvent,
|
|
WorkflowNodeRun,
|
|
)
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_regulatory_models_store_batch_issue_artifact_and_notification(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="法规核查")
|
|
trigger = Message.objects.create(
|
|
conversation=conversation,
|
|
role=Message.Role.USER,
|
|
content="请做NMPA法规核查",
|
|
)
|
|
summary_batch = FileSummaryBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="FS-READY",
|
|
status=FileSummaryBatch.Status.SUCCESS,
|
|
)
|
|
rule_version = RegulatoryRuleVersion.objects.create(
|
|
code="nmpa_ivd_registration_v1",
|
|
name="NMPA IVD 注册资料 Demo 规则",
|
|
yaml_path="review_agent/regulatory_review/rules/nmpa_ivd_registration_v1.yaml",
|
|
yaml_hash="abc123",
|
|
rag_collection="nmpa_ivd_registration_v1",
|
|
rag_index_version="idx-1",
|
|
rag_index_hash="hash-1",
|
|
status=RegulatoryRuleVersion.Status.ACTIVE,
|
|
)
|
|
|
|
batch = RegulatoryReviewBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
trigger_message=trigger,
|
|
source_summary_batch=summary_batch,
|
|
rule_version=rule_version,
|
|
batch_no="RR-202606070001-abcdef",
|
|
)
|
|
issue = RegulatoryIssue.objects.create(
|
|
batch=batch,
|
|
rule_code="registration_test_report",
|
|
category=RegulatoryIssue.Category.COMPLETENESS,
|
|
severity=RegulatoryIssue.Severity.BLOCKING,
|
|
title="缺少注册检验报告",
|
|
suggestion="请补充注册检验报告并复核。",
|
|
evidence={"matched_files": []},
|
|
citations=[{"source": "法规.doc", "text": "注册检验报告"}],
|
|
)
|
|
artifact = RegulatoryArtifact.objects.create(
|
|
batch=batch,
|
|
artifact_type=RegulatoryArtifact.ArtifactType.JSON,
|
|
name="结果包",
|
|
storage_path="media/regulatory_review/result.json",
|
|
content_hash="hash",
|
|
)
|
|
notification = RegulatoryNotificationRecord.objects.create(
|
|
batch=batch,
|
|
channel=RegulatoryNotificationRecord.Channel.MOCK,
|
|
target="todo-plan",
|
|
payload={"issue_id": issue.pk},
|
|
)
|
|
|
|
assert batch.status == RegulatoryReviewBatch.Status.PENDING
|
|
assert batch.source_summary_batch == summary_batch
|
|
assert issue.status == RegulatoryIssue.Status.OPEN
|
|
assert artifact.artifact_type == RegulatoryArtifact.ArtifactType.JSON
|
|
assert notification.status == RegulatoryNotificationRecord.Status.PENDING
|
|
|
|
|
|
def test_generic_workflow_fields_support_file_summary_and_regulatory_batches(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
summary_batch = FileSummaryBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="FS-GENERIC",
|
|
)
|
|
regulatory_batch = RegulatoryReviewBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_summary_batch=summary_batch,
|
|
batch_no="RR-GENERIC",
|
|
)
|
|
|
|
file_node = WorkflowNodeRun.objects.create(
|
|
batch=summary_batch,
|
|
workflow_type="file_summary",
|
|
workflow_batch_id=summary_batch.pk,
|
|
node_group="file_summary",
|
|
node_code="inventory",
|
|
node_name="文件扫描",
|
|
)
|
|
regulatory_node = WorkflowNodeRun.objects.create(
|
|
workflow_type="regulatory_review",
|
|
workflow_batch_id=regulatory_batch.pk,
|
|
node_group="regulatory_review",
|
|
node_code="prepare",
|
|
node_name="准备",
|
|
)
|
|
event = WorkflowEvent.objects.create(
|
|
batch=summary_batch,
|
|
workflow_type="regulatory_review",
|
|
workflow_batch_id=regulatory_batch.pk,
|
|
conversation=conversation,
|
|
event_type="workflow_created",
|
|
payload={"batch_no": regulatory_batch.batch_no},
|
|
)
|
|
exported = ExportedSummaryFile.objects.create(
|
|
batch=summary_batch,
|
|
workflow_type="regulatory_review",
|
|
workflow_batch_id=regulatory_batch.pk,
|
|
export_category="result_package",
|
|
export_type=ExportedSummaryFile.ExportType.JSON,
|
|
file_name="result.json",
|
|
storage_path="media/regulatory_review/result.json",
|
|
)
|
|
|
|
assert file_node.batch == summary_batch
|
|
assert regulatory_node.batch is None
|
|
assert regulatory_node.workflow_batch_id == regulatory_batch.pk
|
|
assert event.conversation == conversation
|
|
assert exported.export_type == ExportedSummaryFile.ExportType.JSON
|