surfaces/tests/core/test_voice_slot.py
Mikhail Putilovskij 36730ae716 feat: implement core/ and platform/ with full test coverage
- platform/interface.py: PlatformClient Protocol + Pydantic models (User,
  MessageResponse, UserSettings) — no explicit session management, Master
  handles container lifecycle
- platform/mock.py: MockPlatformClient with simulated latency, [MOCK]
  responses, is_new correctly True only on first creation
- core/protocol.py: unified dataclasses for all events and responses
  (IncomingMessage/Command/Callback, OutgoingMessage/UI/Notification,
  AuthFlow, ChatContext, SettingsAction, etc.)
- core/store.py: StateStore Protocol + InMemoryStore (tests) + SQLiteStore
  (prod) with JSON serialization
- core/chat.py: ChatManager — chat metadata (C1/C2/C3), not container
  lifecycle (that's the platform's job)
- core/auth.py: AuthManager — start_flow / confirm / is_authenticated
- core/settings.py: SettingsManager — get/apply with store cache
- core/handler.py: EventDispatcher — registry-based routing with keys
  (command name, action name, attachment type, "*" catch-all)
- core/handlers/: register_all() + start/new/message/callback/settings
  handlers; voice slot falls back to stub text until voice_handler added
- conftest.py: sys.path fix so local platform/ shadows stdlib platform
- docs/api-contract.md: rewritten for Lambda Lab 3.0 container model

46 tests passing, 0 warnings.
2026-03-29 21:42:02 +03:00

49 lines
1.7 KiB
Python

# tests/core/test_voice_slot.py
import pytest
from core.protocol import IncomingMessage, Attachment, OutgoingMessage
from core.handlers.message import handle_message
from core.store import InMemoryStore
from core.auth import AuthManager
from core.chat import ChatManager
from core.settings import SettingsManager
from platform.mock import MockPlatformClient
@pytest.fixture
def deps():
platform = MockPlatformClient()
store = InMemoryStore()
auth_mgr = AuthManager(platform, store)
return dict(
platform=platform,
chat_mgr=ChatManager(platform, store),
auth_mgr=auth_mgr,
settings_mgr=SettingsManager(platform, store),
)
async def test_voice_message_returns_stub(deps):
await deps["auth_mgr"].confirm("u1")
msg = IncomingMessage(
user_id="u1", platform="telegram", chat_id="C1", text="",
attachments=[Attachment(type="audio", filename="voice.ogg")],
)
result = await handle_message(event=msg, **deps)
assert len(result) == 1
assert isinstance(result[0], OutgoingMessage)
assert "голосов" in result[0].text.lower()
async def test_text_message_calls_platform(deps):
await deps["auth_mgr"].confirm("u1")
msg = IncomingMessage(user_id="u1", platform="telegram", chat_id="C1", text="Привет!")
result = await handle_message(event=msg, **deps)
texts = [r.text for r in result if isinstance(r, OutgoingMessage)]
assert any("[MOCK]" in t for t in texts)
async def test_unauthenticated_user_gets_start_prompt(deps):
msg = IncomingMessage(user_id="new_user", platform="telegram", chat_id="C1", text="hello")
result = await handle_message(event=msg, **deps)
assert len(result) == 1
assert "/start" in result[0].text