feat(04-01): finalize AgentApi migration
This commit is contained in:
parent
cd59d89617
commit
430c82dba1
9 changed files with 225 additions and 350 deletions
|
|
@ -5,7 +5,6 @@ Smoke test: полный цикл через dispatcher + реальные manag
|
|||
"""
|
||||
import pytest
|
||||
from sdk.mock import MockPlatformClient
|
||||
from sdk.agent_session import build_thread_key
|
||||
from sdk.interface import MessageChunk, MessageResponse
|
||||
from sdk.prototype_state import PrototypeStateStore
|
||||
from sdk.real import RealPlatformClient
|
||||
|
|
@ -22,28 +21,15 @@ from core.protocol import (
|
|||
)
|
||||
|
||||
|
||||
class FakeAgentSessionClient:
|
||||
class FakeAgentApi:
|
||||
def __init__(self) -> None:
|
||||
self.send_calls: list[tuple[str, str]] = []
|
||||
self.calls: list[str] = []
|
||||
self.last_tokens_used = 0
|
||||
|
||||
async def send_message(self, *, thread_key: str, text: str) -> MessageResponse:
|
||||
self.send_calls.append((thread_key, text))
|
||||
return MessageResponse(
|
||||
message_id=thread_key,
|
||||
response=f"[REAL] {text}",
|
||||
tokens_used=5,
|
||||
finished=True,
|
||||
)
|
||||
|
||||
async def stream_message(self, *, thread_key: str, text: str):
|
||||
self.send_calls.append((thread_key, text))
|
||||
if False:
|
||||
yield MessageChunk(
|
||||
message_id=thread_key,
|
||||
delta=text,
|
||||
tokens_used=0,
|
||||
finished=True,
|
||||
)
|
||||
async def send_message(self, text: str):
|
||||
self.calls.append(text)
|
||||
yield type("Chunk", (), {"text": f"[REAL] {text}"})()
|
||||
self.last_tokens_used = 5
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -62,9 +48,9 @@ def dispatcher():
|
|||
|
||||
@pytest.fixture
|
||||
def real_dispatcher():
|
||||
agent_sessions = FakeAgentSessionClient()
|
||||
agent_api = FakeAgentApi()
|
||||
platform = RealPlatformClient(
|
||||
agent_sessions=agent_sessions,
|
||||
agent_api=agent_api,
|
||||
prototype_state=PrototypeStateStore(),
|
||||
platform="matrix",
|
||||
)
|
||||
|
|
@ -76,7 +62,7 @@ def real_dispatcher():
|
|||
settings_mgr=SettingsManager(platform, store),
|
||||
)
|
||||
register_all(d)
|
||||
return d, agent_sessions
|
||||
return d, agent_api
|
||||
|
||||
|
||||
async def test_full_flow_start_then_message(dispatcher):
|
||||
|
|
@ -132,8 +118,8 @@ async def test_toggle_skill_callback(dispatcher):
|
|||
assert any("browser" in r.text for r in result if isinstance(r, OutgoingMessage))
|
||||
|
||||
|
||||
async def test_full_flow_with_real_platform_uses_thread_key(real_dispatcher):
|
||||
dispatcher, agent_sessions = real_dispatcher
|
||||
async def test_full_flow_with_real_platform_uses_shared_agent_api(real_dispatcher):
|
||||
dispatcher, agent_api = real_dispatcher
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
result = await dispatcher.dispatch(start)
|
||||
|
|
@ -144,6 +130,4 @@ async def test_full_flow_with_real_platform_uses_thread_key(real_dispatcher):
|
|||
texts = [r.text for r in result if isinstance(r, OutgoingMessage)]
|
||||
|
||||
assert texts == ["[REAL] Привет!"]
|
||||
assert agent_sessions.send_calls == [
|
||||
(build_thread_key("matrix", "u1", "C1"), "Привет!")
|
||||
]
|
||||
assert agent_api.calls == ["Привет!"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue