Phase 7: Directory restructuring (messaging/ and tests/)

- Create messaging/platforms/ (base, discord, telegram, factory)
- Create messaging/rendering/ (discord_markdown, telegram_markdown)
- Create messaging/trees/ (data, repository, processor, queue_manager)
- Organize tests/ into api/, providers/, messaging/, cli/, config/
- Add backward-compatible re-exports at old locations
- Update handler.py and test_messaging_factory.py imports
- Fix Telegram type hints for TELEGRAM_AVAILABLE=False case
- Fix Python 3 except syntax in discord_markdown

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
This commit is contained in:
Cursor Agent 2026-02-17 02:25:42 +00:00
parent 38a7980546
commit 4b4f87515d
76 changed files with 3294 additions and 3124 deletions

View file

@ -0,0 +1,73 @@
import pytest
from unittest.mock import patch
from api.models.anthropic import MessagesRequest, TokenCountRequest, Message
from config.settings import Settings
@pytest.fixture
def mock_settings():
settings = Settings()
settings.model = "target-model-from-settings"
return settings
def test_messages_request_map_model_claude_to_default(mock_settings):
with patch("api.models.anthropic.get_settings", return_value=mock_settings):
request = MessagesRequest(
model="claude-3-opus",
max_tokens=100,
messages=[Message(role="user", content="hello")],
)
assert request.model == "target-model-from-settings"
assert request.original_model == "claude-3-opus"
def test_messages_request_map_model_non_claude_unchanged(mock_settings):
with patch("api.models.anthropic.get_settings", return_value=mock_settings):
request = MessagesRequest(
model="gpt-4",
max_tokens=100,
messages=[Message(role="user", content="hello")],
)
# normalize_model_name returns original if not Claude
assert request.model == "gpt-4"
def test_messages_request_map_model_with_provider_prefix(mock_settings):
with patch("api.models.anthropic.get_settings", return_value=mock_settings):
request = MessagesRequest(
model="anthropic/claude-3-haiku",
max_tokens=100,
messages=[Message(role="user", content="hello")],
)
assert request.model == "target-model-from-settings"
def test_token_count_request_model_validation(mock_settings):
with patch("api.models.anthropic.get_settings", return_value=mock_settings):
request = TokenCountRequest(
model="claude-3-sonnet", messages=[Message(role="user", content="hello")]
)
assert request.model == "target-model-from-settings"
def test_messages_request_model_mapping_logs(mock_settings):
with (
patch("api.models.anthropic.get_settings", return_value=mock_settings),
patch("api.models.anthropic.logger.debug") as mock_log,
):
MessagesRequest(
model="claude-2.1",
max_tokens=100,
messages=[Message(role="user", content="hello")],
)
mock_log.assert_called()
args = mock_log.call_args[0][0]
assert "MODEL MAPPING" in args
assert "claude-2.1" in args
assert "target-model-from-settings" in args