fix: prevent empty Matrix messages when progress callback sends empty content

Agent-Logs-Url: https://github.com/halldorjanetzko/nanobot/sessions/df528c59-8214-41a0-9b79-9d1d41857107

Co-authored-by: halldorjanetzko <158819146+halldorjanetzko@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-01 19:31:04 +08:00
committed by Xubin Ren
co-authored by halldorjanetzko
parent 15007afd4a
commit 0284174df9
2 changed files with 39 additions and 1 deletions
+38
View File
@@ -1246,6 +1246,44 @@ async def test_send_progress_keeps_typing_keepalive_running() -> None:
await channel.stop()
@pytest.mark.asyncio
async def test_send_empty_content_does_not_call_room_send() -> None:
"""Progress messages with empty content must not produce an empty body: '' event."""
channel = MatrixChannel(_make_config(), MessageBus())
client = _FakeAsyncClient("", "", "", None)
channel.client = client
await channel.send(
OutboundMessage(
channel="matrix",
chat_id="!room:matrix.org",
content="",
metadata={"_progress": True},
)
)
assert client.room_send_calls == []
@pytest.mark.asyncio
async def test_send_whitespace_only_content_does_not_call_room_send() -> None:
"""Progress messages with whitespace-only content must not produce an empty message."""
channel = MatrixChannel(_make_config(), MessageBus())
client = _FakeAsyncClient("", "", "", None)
channel.client = client
await channel.send(
OutboundMessage(
channel="matrix",
chat_id="!room:matrix.org",
content=" \n\n ",
metadata={"_progress": True},
)
)
assert client.room_send_calls == []
@pytest.mark.asyncio
async def test_send_clears_typing_when_send_fails() -> None:
channel = MatrixChannel(_make_config(), MessageBus())