feat: 打通通知回执与消息状态留痕

This commit is contained in:
2026-06-04 02:00:41 +08:00
parent a663543b37
commit 3280186625
4 changed files with 109 additions and 3 deletions

View File

@@ -174,6 +174,51 @@ def test_chat_execution_creates_notification_record_from_agent_result(client, db
assert record.web_detail_url.endswith(f"/audit/{AgentAuditLog.objects.get().id}/")
def test_chat_execution_uses_notification_payload_message_status_and_receipt(client, db, monkeypatch):
batch, conversation = _create_conversation_with_batch()
UploadedDocument.objects.create(
batch=batch,
scenario_id="document_review",
original_name="说明书.md",
file_type="md",
size=1,
status=UploadedDocument.STATUS_INDEXED,
)
monkeypatch.setattr(
"apps.chat.views.run_agent",
lambda *args, **kwargs: AgentResult(
answer="通知已发送",
status="success",
notification_payload={
"batch_id": batch.batch_id,
"conversation_id": conversation.conversation_id,
"product_name": batch.product_name,
"notify_reason": "task_completed",
"message_status": "sent",
"web_detail_url": "https://example.com/audit/custom",
"receipt": {"message_id": "msg-custom", "status": "sent"},
"owners": [
{
"owner_role": "注册资料负责人",
"feishu_user_id": "ou_demo_1",
}
],
},
),
)
response = client.post(
reverse("chat:detail", args=[conversation.conversation_id]),
{"message": "执行通知任务"},
)
assert response.status_code == 200
record = NotificationRecord.objects.get()
assert record.message_status == "sent"
assert record.receipt["message_id"] == "msg-custom"
def test_chat_execution_creates_failed_notification_record_and_updates_conversation(client, db, monkeypatch):
batch, conversation = _create_conversation_with_batch()
UploadedDocument.objects.create(