An edit carries m.mentions twice: once inside m.new_content and once at the top level. When a budget-sized edit names many distinct Matrix IDs, that fixed part alone could pass the content budget. Shortening the fallback body then had no room to work with, and the edit still went out at about 54 KB, which an encrypted room would reject with M_TOO_LARGE. When the edit is still over budget with an empty fallback, it now drops the top-level mentions copy. That copy only drives the edit's own notifications, and m.new_content keeps the full list. The event-size tests move to tests/plugins/platforms/matrix/test_event_size.py, mirroring the plugin source tree, and gain a mention-heavy text. The tests/gateway/test_matrix_message_length.py file is back to main apart from the env-override value that the new ceiling requires. (cherry picked from commit 4b06bcb7dbffb732bef6e877cb66dea2fbff8c73)
35 lines
905 B
Python
35 lines
905 B
Python
"""Tests for Matrix outbound message length configuration (#53026)."""
|
|
|
|
|
|
from gateway.config import PlatformConfig
|
|
|
|
|
|
def _make_adapter(**extra):
|
|
from plugins.platforms.matrix.adapter import MatrixAdapter
|
|
|
|
config = PlatformConfig(
|
|
enabled=True,
|
|
token="syt_test_token",
|
|
extra={
|
|
"homeserver": "https://matrix.example.org",
|
|
"user_id": "@bot:example.org",
|
|
**extra,
|
|
},
|
|
)
|
|
return MatrixAdapter(config)
|
|
|
|
|
|
class TestMatrixMaxMessageLength:
|
|
|
|
def test_extra_override(self):
|
|
adapter = _make_adapter(max_message_length=12000)
|
|
assert adapter.max_message_length == 12000
|
|
assert adapter._SPLIT_THRESHOLD == 11900
|
|
|
|
def test_env_override(self, monkeypatch):
|
|
monkeypatch.setenv("MATRIX_MAX_MESSAGE_LENGTH", "9000")
|
|
adapter = _make_adapter()
|
|
assert adapter.max_message_length == 9000
|
|
|
|
|