refactor: 下沉 Word 导出执行链到 chat 服务层

This commit is contained in:
2026-06-04 04:44:47 +08:00
parent 47f887647b
commit e701b4502e
3 changed files with 87 additions and 45 deletions

View File

@@ -8,7 +8,11 @@ from agent_core.results import AgentResult
from apps.audit.models import AgentAuditLog
from apps.audit.models import NotificationRecord
from apps.chat.models import Conversation
from apps.chat.services import create_conversation_for_batch, execute_conversation_agent
from apps.chat.services import (
create_conversation_for_batch,
execute_conversation_agent,
execute_conversation_export,
)
from apps.documents.models import ExportedDocument, SubmissionBatch, UploadedDocument
@@ -412,6 +416,41 @@ def test_execute_conversation_agent_runs_in_service_layer_and_persists_audit_and
assert record.web_detail_url == f"/audit/{audit_log.id}/"
def test_execute_conversation_export_runs_in_service_layer_and_persists_audit(db, monkeypatch):
batch, conversation = _create_conversation_with_batch()
captured = {}
def fake_generate_registration_export(*, batch, conversation, upstream_summary=None):
captured["batch_id"] = batch.batch_id
captured["conversation_id"] = conversation.conversation_id
captured["upstream_summary"] = upstream_summary or {}
return {
"output_type": "registration_word_export_report",
"summary": "已生成草稿导出文件。",
"template_name": "注册证导出模板",
"template_version": "V1.0",
"export_status": "draft_only",
"download_url": "/media/exports/demo.docx",
"output_file": {
"file_name": "demo.docx",
"relative_path": "exports/demo.docx",
"export_mode": "draft",
},
}
monkeypatch.setattr("apps.chat.export_service.generate_registration_export", fake_generate_registration_export)
result = execute_conversation_export(batch=batch, conversation=conversation)
conversation.refresh_from_db()
assert captured["batch_id"] == batch.batch_id
assert captured["conversation_id"] == conversation.conversation_id
assert result["export_report"]["output_type"] == "registration_word_export_report"
assert result["audit_log"].scenario_name == "Word 回填导出"
assert conversation.latest_summary["structured_output"]["download_url"] == "/media/exports/demo.docx"
assert AgentAuditLog.objects.filter(conversation_id=conversation.conversation_id).count() == 1
def test_chat_page_shows_upload_entry_and_dynamic_context_cards(client, db):
batch, conversation = _create_conversation_with_batch()
conversation.node_results = [