fix(matrix): class-level split-threshold defaults for partially-constructed adapters

Text-batching tests (and any tooling) build MatrixAdapter via
object.__new__ without running __init__; moving _split_threshold from a
class constant to an instance attribute made _flush_text_batch die with
AttributeError, silently dropping the flush. Restore class-level
defaults (max_message_length, _split_threshold) that __init__ overrides,
and derive the near-limit test payload from adapter._split_threshold
instead of the old hardcoded 3950.
This commit is contained in:
Teknium 2026-07-20 10:58:17 -07:00
parent 086a56a028
commit 0e281b58e6
2 changed files with 8 additions and 2 deletions

View file

@ -837,6 +837,12 @@ class MatrixAdapter(BasePlatformAdapter):
# (see _normalize_matrix_bang_command), so instruction text shows "!".
typed_command_prefix = "!"
# Class-level defaults so partially-constructed instances (tests build
# adapters via object.__new__ without __init__) keep working; __init__
# overrides both from _resolve_max_message_length().
max_message_length = DEFAULT_MAX_MESSAGE_LENGTH
_split_threshold = DEFAULT_MAX_MESSAGE_LENGTH - 100
def __init__(self, config: PlatformConfig):
super().__init__(config, Platform.MATRIX)

View file

@ -278,9 +278,9 @@ class TestMatrixTextBatching:
@pytest.mark.asyncio
async def test_adaptive_delay_for_near_limit_chunk(self):
"""Chunks near the 4000-char limit should trigger longer delay."""
"""Chunks near the outbound limit should trigger longer delay."""
adapter = _make_matrix_adapter()
long_text = "x" * 3950
long_text = "x" * (adapter._split_threshold + 50)
adapter._enqueue_text_event(_make_event(long_text, Platform.MATRIX))
await asyncio.sleep(0.15)