refactor: 下沉处理历史筛选到 audit 服务层

This commit is contained in:
2026-06-04 04:34:20 +08:00
parent 1b6c54fe78
commit a49524fd93
3 changed files with 120 additions and 43 deletions

View File

@@ -2,7 +2,7 @@ from django.urls import reverse
from agent_core.results import AgentResult
from apps.audit.models import AgentAuditLog, DemoBusinessRecord, NotificationRecord
from apps.audit.services import create_audit_log, create_notification_record
from apps.audit.services import build_history_list_context, create_audit_log, create_notification_record
from apps.chat.models import Conversation
from apps.documents.models import SubmissionBatch
from agent_core.tools.builtin_tools import query_demo_records
@@ -344,6 +344,71 @@ def test_audit_list_can_filter_by_risk_status(client, db):
assert "产品B" not in content
def test_build_history_list_context_filters_by_keyword_notify_and_risk(db):
create_audit_log(
"document_review",
"注册审核智能体",
"问题一",
AgentResult(
answer="回答一",
status="success",
structured_output={"highest_risk_level": "high"},
),
batch_id="SUB-20260604-011",
conversation_id="conv-011",
product_name="产品A",
)
create_audit_log(
"document_review",
"注册审核智能体",
"问题二",
AgentResult(
answer="回答二",
status="success",
structured_output={"highest_risk_level": "low"},
),
batch_id="SUB-20260604-012",
conversation_id="conv-012",
product_name="产品B",
)
create_notification_record(
batch_id="SUB-20260604-011",
conversation_id="conv-011",
product_name="产品A",
trigger_source="risk_report",
notify_reason="task_completed",
owner_role="注册资料负责人",
feishu_user_id="ou_demo_11",
message_status="sent",
web_detail_url="https://example.com/detail/11",
receipt={"message_id": "msg-11"},
)
create_notification_record(
batch_id="SUB-20260604-012",
conversation_id="conv-012",
product_name="产品B",
trigger_source="risk_report",
notify_reason="task_failed",
owner_role="注册资料负责人",
feishu_user_id="ou_demo_12",
message_status="failed",
web_detail_url="https://example.com/detail/12",
receipt={"message_id": "msg-12"},
)
context = build_history_list_context(
keyword="产品A",
notify_status="sent",
risk_status="high",
)
assert context["keyword"] == "产品A"
assert context["notify_status"] == "sent"
assert context["risk_status"] == "high"
assert len(context["history_rows"]) == 1
assert context["history_rows"][0]["log"].product_name == "产品A"
def test_audit_detail_page_shows_conversation_node_results(client, db):
Conversation.objects.create(
conversation_id="conv-001",