From 3b4638688763f2761580d18fb7c2edcb05ad9540 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Wed, 3 Jun 2026 10:56:44 +0800 Subject: [PATCH] test(email): cover progress message suppression Maintainer edit: add a regression test for the email channel fix so progress/tool-event messages return before SMTP is opened instead of sending empty emails. --- tests/channels/test_email_channel.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/channels/test_email_channel.py b/tests/channels/test_email_channel.py index 2ee915d9e..f6af636ed 100644 --- a/tests/channels/test_email_channel.py +++ b/tests/channels/test_email_channel.py @@ -395,6 +395,33 @@ async def test_send_uses_smtp_and_reply_subject(monkeypatch) -> None: assert sent["In-Reply-To"] == "" +@pytest.mark.asyncio +async def test_send_skips_progress_messages_before_smtp(monkeypatch) -> None: + called = {"smtp": False} + + def _smtp_factory(*_args, **_kwargs): + called["smtp"] = True + raise AssertionError("progress messages must not open an SMTP connection") + + monkeypatch.setattr("nanobot.channels.email.smtplib.SMTP", _smtp_factory) + + channel = EmailChannel(_make_config(), MessageBus()) + + await channel.send( + OutboundMessage( + channel="email", + chat_id="alice@example.com", + content="", + metadata={ + "_progress": True, + "_tool_events": [{"phase": "end", "name": "exec"}], + }, + ) + ) + + assert called["smtp"] is False + + @pytest.mark.asyncio async def test_send_skips_reply_when_auto_reply_disabled(monkeypatch) -> None: """When auto_reply_enabled=False, replies should be skipped but proactive sends allowed."""