- 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.
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
# tests/core/test_protocol.py
|
|
from datetime import datetime
|
|
from core.protocol import (
|
|
Attachment, IncomingMessage, IncomingCommand, IncomingCallback,
|
|
OutgoingMessage, OutgoingUI, OutgoingTyping, OutgoingNotification,
|
|
UIButton, ChatContext, AuthFlow, ConfirmationRequest, SettingsAction, PaymentRequired,
|
|
)
|
|
|
|
|
|
def test_incoming_message_defaults():
|
|
msg = IncomingMessage(user_id="u1", platform="telegram", chat_id="C1", text="hi")
|
|
assert msg.attachments == []
|
|
assert msg.reply_to is None
|
|
|
|
|
|
def test_attachment_audio():
|
|
a = Attachment(type="audio", filename="voice.ogg", mime_type="audio/ogg")
|
|
assert a.type == "audio"
|
|
assert a.url is None
|
|
|
|
|
|
def test_incoming_command_defaults():
|
|
cmd = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="new")
|
|
assert cmd.args == []
|
|
|
|
|
|
def test_outgoing_message_defaults():
|
|
msg = OutgoingMessage(chat_id="C1", text="hello")
|
|
assert msg.parse_mode == "plain"
|
|
assert msg.attachments == []
|
|
|
|
|
|
def test_ui_button_defaults():
|
|
btn = UIButton(label="OK", action="confirm")
|
|
assert btn.style == "secondary"
|
|
assert btn.payload == {}
|
|
|
|
|
|
def test_settings_action():
|
|
action = SettingsAction(action="toggle_skill", payload={"skill": "browser", "enabled": True})
|
|
assert action.action == "toggle_skill"
|
|
assert action.payload["skill"] == "browser"
|