fix: use direct agent api per request
This commit is contained in:
parent
7d270d3d31
commit
7d58dd1caf
14 changed files with 285 additions and 400 deletions
|
|
@ -4,7 +4,6 @@ Smoke test: полный цикл через dispatcher + реальные manag
|
|||
Имитирует что делает адаптер (Telegram или Matrix) при получении события.
|
||||
"""
|
||||
import pytest
|
||||
from lambda_agent_api.server import MsgEventTextChunk
|
||||
|
||||
from core.auth import AuthManager
|
||||
from core.chat import ChatManager
|
||||
|
|
@ -23,10 +22,13 @@ from core.store import InMemoryStore
|
|||
from sdk.mock import MockPlatformClient
|
||||
from sdk.prototype_state import PrototypeStateStore
|
||||
from sdk.real import RealPlatformClient
|
||||
from sdk.upstream_agent_api import MsgEventTextChunk
|
||||
|
||||
|
||||
class FakeAgentApi:
|
||||
def __init__(self, chat_id: str) -> None:
|
||||
def __init__(self, agent_id: str, base_url: str, chat_id: str) -> None:
|
||||
self.agent_id = agent_id
|
||||
self.base_url = base_url
|
||||
self.chat_id = chat_id
|
||||
self.calls: list[tuple[str, list[str]]] = []
|
||||
self.connect_calls = 0
|
||||
|
|
@ -46,12 +48,12 @@ class FakeAgentApi:
|
|||
class FakeAgentApiFactory:
|
||||
def __init__(self) -> None:
|
||||
self.created_chat_ids: list[str] = []
|
||||
self.instances: dict[str, FakeAgentApi] = {}
|
||||
self.instances: dict[str, list[FakeAgentApi]] = {}
|
||||
|
||||
def for_chat(self, chat_id: str) -> FakeAgentApi:
|
||||
chat_api = FakeAgentApi(chat_id)
|
||||
def __call__(self, agent_id: str, base_url: str, chat_id: str) -> FakeAgentApi:
|
||||
chat_api = FakeAgentApi(agent_id, base_url, chat_id)
|
||||
self.created_chat_ids.append(chat_id)
|
||||
self.instances[chat_id] = chat_api
|
||||
self.instances.setdefault(chat_id, []).append(chat_api)
|
||||
return chat_api
|
||||
|
||||
|
||||
|
|
@ -73,7 +75,9 @@ def dispatcher():
|
|||
def real_dispatcher():
|
||||
agent_api = FakeAgentApiFactory()
|
||||
platform = RealPlatformClient(
|
||||
agent_api=agent_api,
|
||||
agent_id="matrix-bot",
|
||||
agent_base_url="http://platform-agent:8000",
|
||||
agent_api_cls=agent_api,
|
||||
prototype_state=PrototypeStateStore(),
|
||||
platform="matrix",
|
||||
)
|
||||
|
|
@ -147,7 +151,7 @@ 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_shared_agent_api(real_dispatcher):
|
||||
async def test_full_flow_with_real_platform_uses_direct_agent_api(real_dispatcher):
|
||||
dispatcher, agent_api = real_dispatcher
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
|
|
@ -160,7 +164,7 @@ async def test_full_flow_with_real_platform_uses_shared_agent_api(real_dispatche
|
|||
|
||||
assert texts == ["[REAL] Привет!"]
|
||||
assert agent_api.created_chat_ids == ["C1"]
|
||||
assert agent_api.instances["C1"].calls == [("Привет!", [])]
|
||||
assert [instance.calls for instance in agent_api.instances["C1"]] == [[("Привет!", [])]]
|
||||
|
||||
|
||||
async def test_full_flow_with_real_platform_forwards_workspace_attachment(real_dispatcher):
|
||||
|
|
@ -185,6 +189,6 @@ async def test_full_flow_with_real_platform_forwards_workspace_attachment(real_d
|
|||
)
|
||||
await dispatcher.dispatch(msg)
|
||||
|
||||
assert agent_api.instances["C1"].calls == [
|
||||
("Посмотри файл", ["surfaces/matrix/u1/room/inbox/report.pdf"])
|
||||
assert [instance.calls for instance in agent_api.instances["C1"]] == [
|
||||
[("Посмотри файл", ["surfaces/matrix/u1/room/inbox/report.pdf"])]
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue