fix(partners): avoid hang in split_message when max_len <= 0

When max_len is 0 or negative, the cut pointer never advances and split_message loops forever.
Return the content unsplit, matching the nanobot helpers pattern.
This commit is contained in:
santhreal
2026-07-18 17:13:19 -07:00
parent b030697df7
commit b10089741a
2 changed files with 20 additions and 0 deletions

View File

@@ -50,6 +50,9 @@ def split_message(content: str, max_len: int = 2000) -> list[str]:
"""
if not content:
return []
# Non-positive max_len cannot advance the cut pointer; return unsplit.
if max_len <= 0:
return [content]
if len(content) <= max_len:
return [content]
chunks: list[str] = []

View File

@@ -0,0 +1,17 @@
"""Regression tests for partners.helpers.split_message."""
from __future__ import annotations
from deeptutor.partners.helpers import split_message
def test_split_message_nonpositive_max_len_returns_unsplit() -> None:
content = "hello world"
assert split_message(content, max_len=0) == [content]
assert split_message(content, max_len=-1) == [content]
def test_split_message_normal_path() -> None:
chunks = split_message("aaa\nbbb\nccc", max_len=5)
assert chunks
assert all(len(c) <= 5 for c in chunks)