- MemoryService 异步路径委托 MemoryIngestService / MemoryRetrievalService;富化派发经 MemoryEnrichmentScheduler - WebSocket pipeline 经 ChatTurnService 与显式 DTO 编排单轮对话;回忆录片段入队由 MemoirIngestScheduler 封装 - 新增 LlmGateway(LlmUseCase),各 agent、任务与适配器对齐 ports - 补充 memory 提示适配、runtime 类型、memory-retrieval 文档、ai-touchpoints 说明与扫描脚本及配套测试 Made-with: Cursor
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
import pytest
|
|
|
|
from app.agents.chat.agent_turn import AgentChatTurn
|
|
from app.features.conversation.chat_turn import (
|
|
ChatTurnContext,
|
|
ChatTurnInput,
|
|
ChatTurnService,
|
|
)
|
|
|
|
|
|
class _FakeOrchestrator:
|
|
def __init__(self) -> None:
|
|
self.calls: list[dict] = []
|
|
|
|
async def process_user_message(self, **kwargs):
|
|
self.calls.append(kwargs)
|
|
return AgentChatTurn(
|
|
messages=["第一泡", "第二泡"],
|
|
skip_tts=False,
|
|
memory_retrieval_trace={"chunks": 1},
|
|
interview_state_meta={"recent_questions": ["你当时在哪里?"]},
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_chat_turn_service_exposes_one_turn_contract() -> None:
|
|
orchestrator = _FakeOrchestrator()
|
|
service = ChatTurnService(orchestrator=orchestrator)
|
|
ts = datetime(2026, 4, 29, tzinfo=timezone.utc)
|
|
|
|
result = await service.process_turn(
|
|
ChatTurnInput(
|
|
conversation_id="conv-1",
|
|
user_message="我小时候住在河边。",
|
|
is_from_voice=True,
|
|
voice_session_id="voice-1",
|
|
user_message_timestamp=ts,
|
|
audio_duration_seconds=12,
|
|
force_skip_tts=True,
|
|
),
|
|
ChatTurnContext(
|
|
db=object(),
|
|
user=object(),
|
|
conversation=object(),
|
|
apply_extracted_profile_fn=lambda *args, **kwargs: None,
|
|
get_missing_profile_fields_fn=lambda user: [],
|
|
get_filled_profile_fields_fn=lambda user: {},
|
|
),
|
|
)
|
|
|
|
assert result.messages == ["第一泡", "第二泡"]
|
|
assert result.skip_tts is True
|
|
assert result.memory_retrieval_trace == {"chunks": 1}
|
|
assert result.interview_state_meta == {
|
|
"recent_questions": ["你当时在哪里?"]
|
|
}
|
|
assert result.decision.force_skip_tts is True
|
|
|
|
assert len(orchestrator.calls) == 1
|
|
call = orchestrator.calls[0]
|
|
assert call["conversation_id"] == "conv-1"
|
|
assert call["user_message"] == "我小时候住在河边。"
|
|
assert call["is_from_voice"] is True
|
|
assert call["voice_session_id"] == "voice-1"
|
|
assert call["user_message_timestamp"] is ts
|
|
assert call["audio_duration_seconds"] == 12
|