feat(regulatory): 输出法规核查过程日志
This commit is contained in:
31
tests/test_logging_filters.py
Normal file
31
tests/test_logging_filters.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import logging
|
||||
|
||||
from review_agent.logging_filters import SuppressWorkflowStatusPollFilter
|
||||
|
||||
|
||||
def test_suppress_workflow_status_poll_filter_hides_status_poll_requests():
|
||||
record = logging.LogRecord(
|
||||
name="django.server",
|
||||
level=logging.INFO,
|
||||
pathname="",
|
||||
lineno=1,
|
||||
msg='"GET /api/review-agent/regulatory-review/7/status/ HTTP/1.1" 200 1660',
|
||||
args=(),
|
||||
exc_info=None,
|
||||
)
|
||||
|
||||
assert SuppressWorkflowStatusPollFilter().filter(record) is False
|
||||
|
||||
|
||||
def test_suppress_workflow_status_poll_filter_keeps_other_requests():
|
||||
record = logging.LogRecord(
|
||||
name="django.server",
|
||||
level=logging.INFO,
|
||||
pathname="",
|
||||
lineno=1,
|
||||
msg='"POST /api/review-agent/regulatory-review/7/conditions/ HTTP/1.1" 200 256',
|
||||
args=(),
|
||||
exc_info=None,
|
||||
)
|
||||
|
||||
assert SuppressWorkflowStatusPollFilter().filter(record) is True
|
||||
@@ -91,3 +91,21 @@ def test_review_workflow_payload_retries_timeout_before_success(settings):
|
||||
assert attempts["count"] == 3
|
||||
assert result["status"] == "success"
|
||||
assert result["result"]["reviewed"] is True
|
||||
|
||||
|
||||
def test_review_workflow_payload_passes_configured_timeout(settings):
|
||||
settings.REGULATORY_LLM_REVIEW_RETRY_DELAY_SECONDS = 0
|
||||
settings.REGULATORY_LLM_REVIEW_TIMEOUT_SECONDS = 7
|
||||
observed = {}
|
||||
|
||||
def completion(messages, temperature=0.0, timeout=None):
|
||||
observed["timeout"] = timeout
|
||||
return json.dumps({"reviewed": True})
|
||||
|
||||
review_workflow_payload(
|
||||
stage="completeness_check",
|
||||
payload={"findings": []},
|
||||
completion_func=completion,
|
||||
)
|
||||
|
||||
assert observed["timeout"] == 7
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from review_agent.models import (
|
||||
@@ -147,6 +149,33 @@ def test_workflow_continues_when_llm_review_times_out(monkeypatch, settings, dja
|
||||
assert batch.error_message == ""
|
||||
|
||||
|
||||
def test_regulatory_workflow_logs_node_and_method_details(caplog, django_user_model):
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation = Conversation.objects.create(user=user, title="会话")
|
||||
summary = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-OK",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
batch = create_regulatory_review_batch(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
source_summary_batch=summary,
|
||||
)
|
||||
batch.condition_json = {"confirmed": True, "confirmed_conditions": {"product_category": "体外诊断试剂"}}
|
||||
batch.save(update_fields=["condition_json"])
|
||||
|
||||
with caplog.at_level(logging.INFO, logger="review_agent.regulatory_review.workflow"):
|
||||
start_regulatory_review_workflow(batch, async_run=False)
|
||||
|
||||
messages = [record.getMessage() for record in caplog.records]
|
||||
assert any("法规核查工作流开始" in message and batch.batch_no in message for message in messages)
|
||||
assert any("节点开始" in message and "完整性核查" in message for message in messages)
|
||||
assert any("方法执行" in message and "run_completeness_check" in message for message in messages)
|
||||
assert any("节点完成" in message and "完整性核查" in message for message in messages)
|
||||
|
||||
|
||||
def test_stream_message_prompts_for_summary_when_missing(monkeypatch, django_user_model):
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation = Conversation.objects.create(user=user, title="会话")
|
||||
|
||||
Reference in New Issue
Block a user