feat: 打通通知回执与消息状态留痕
This commit is contained in:
@@ -460,3 +460,54 @@ owner_mappings:
|
||||
assert result.notification_payload["notify_reason"] == "task_failed"
|
||||
assert owner["owner_name"] == "孙七"
|
||||
assert owner["feishu_open_id"] == "on_failed_1"
|
||||
|
||||
|
||||
def test_feishu_notification_report_builds_notification_payload_with_receipt_and_node_status():
|
||||
scenario = {
|
||||
"id": "document_review",
|
||||
"name": "注册审核智能体",
|
||||
"agent": {
|
||||
"role": "注册审核助手",
|
||||
"goal": "输出通知结果",
|
||||
"instructions": ["输出结构化通知结果"],
|
||||
},
|
||||
"rag": {"enabled": False},
|
||||
"tools": [],
|
||||
"output": {"type": "feishu_notification_report"},
|
||||
}
|
||||
provider_response = """
|
||||
{
|
||||
"batch_id": "SUB-20260604-003",
|
||||
"conversation_id": "conv-003",
|
||||
"notify_reason": "task_completed",
|
||||
"mentioned_users": ["ou_demo_1"],
|
||||
"message_status": "sent",
|
||||
"web_detail_url": "https://example.com/audit/3",
|
||||
"receipt": {
|
||||
"message_id": "msg-3",
|
||||
"status": "sent"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
class FakeProvider:
|
||||
def generate(self, messages, response_format=None):
|
||||
from agent_core.llm_provider import LLMResponse
|
||||
|
||||
return LLMResponse(content=provider_response, model_name="demo-model", success=True)
|
||||
|
||||
result = run_agent(
|
||||
scenario,
|
||||
"请生成通知结果",
|
||||
options={
|
||||
"llm_provider": FakeProvider(),
|
||||
"batch_id": "SUB-20260604-003",
|
||||
"conversation_id": "conv-003",
|
||||
"product_name": "产品C",
|
||||
},
|
||||
)
|
||||
|
||||
assert result.node_results[7]["status"] == "已完成"
|
||||
assert result.notification_payload["message_status"] == "sent"
|
||||
assert result.notification_payload["web_detail_url"] == "https://example.com/audit/3"
|
||||
assert result.notification_payload["receipt"]["message_id"] == "msg-3"
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user