"""Unit tests for Telegram formatting and message splitting.""" from homeagent.bot.utils import split_message def test_split_short_message(): text = "Short message" assert split_message(text, max_length=100) == ["Short message"] def test_split_long_message_preserves_code_blocks(): code = "```python\n" + "\n".join([f"x_{i} = {i}" for i in range(50)]) + "\n```" chunks = split_message(code, max_length=150) assert len(chunks) > 1 # First chunk should have closed code block assert chunks[0].strip().endswith("```") # Second chunk should have reopened code block assert chunks[1].strip().startswith("```python")