PMFlow/backend/tests/test_ai_orchestration_run_s...

57 lines
1.5 KiB
Python

from __future__ import annotations
from types import SimpleNamespace
import pytest
from app.services.ai_orchestration_run.service import AIOrchestrationRunService
class _FakeDB:
def __init__(self) -> None:
self.added = None
def add(self, row) -> None: # noqa: ANN001
self.added = row
async def flush(self) -> None:
return None
@pytest.mark.asyncio
async def test_enqueue_ingress_run_persists_thread_context_in_task_payload(monkeypatch) -> None:
db = _FakeDB()
service = AIOrchestrationRunService(db)
async def _fake_get_run(*, tenant_id, trace_id): # noqa: ARG001
return None
monkeypatch.setattr(service, "get_run", _fake_get_run)
row, created = await service.enqueue_ingress_run(
tenant_id=1,
source_system="feishu",
source_message_id="msg-1",
sender="林宇航",
message_text="它是什么时候创建的?",
channel_ref="chat-1",
source_sender_open_id="ou-1",
chat_type="group",
captured_at=None,
project_hint_id=None,
thread_context={
"thread_id": "th-1",
"root_message_id": "root-1",
"reply_to_message_id": "reply-1",
},
)
assert created is True
assert db.added is row
assert isinstance(row.result_payload, dict)
assert row.result_payload["task_payload"]["thread_context"] == {
"thread_id": "th-1",
"root_message_id": "root-1",
"reply_to_message_id": "reply-1",
}