[PATCH b4 v2 02/44] tests: cover the shared outgoing-seen helper

Christian Brauner <[email protected]> Fri, 31 Jul 2026 23:58:43 +0200
Newsgroups org.kernel.linux.tools
Message-ID <20260731-work-b4-editor-branch-guard-v2-2-243fd19d322d@kernel.org>
The helper records the message, writes nothing on a dry run, and does
not let a failure escape into the send path.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 src/tests/test_messages.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/tests/test_messages.py b/src/tests/test_messages.py
index 1dfcc82..904776d 100644
--- a/src/tests/test_messages.py
+++ b/src/tests/test_messages.py
@@ -1,6 +1,7 @@
 import datetime
 import email.message
 import os
+import sqlite3
 from typing import Dict, List, Optional
 
 import pytest
@@ -318,3 +319,45 @@ class TestMarkOutgoingSeen:
         count = conn.execute('SELECT COUNT(*) FROM messages').fetchone()[0]
         assert count == 0
         conn.close()
+
+
+class TestMarkOutgoingSeenHelper:
+    """The TUI wrapper every send path funnels through."""
+
+    @staticmethod
+    def _make_msg(msgid: str) -> 'email.message.EmailMessage':
+        msg = email.message.EmailMessage()
+        msg['Subject'] = 'Test'
+        msg['Message-Id'] = f'<{msgid}>'
+        return msg
+
+    def test_records_the_message(self, tmp_path: pytest.TempPathFactory) -> None:
+        from b4.review_tui._common import mark_outgoing_seen
+
+        mark_outgoing_seen([self._make_msg('[email protected]')])
+        conn = messages.get_db()
+        assert 'Seen' in messages.get_flags(conn, '[email protected]')
+        conn.close()
+
+    def test_dryrun_records_nothing(self, tmp_path: pytest.TempPathFactory) -> None:
+        """A dry run never puts the message on the list, so there is nothing
+        coming back that would need to be already read."""
+        from b4.review_tui._common import mark_outgoing_seen
+
+        mark_outgoing_seen([self._make_msg('[email protected]')], dryrun=True)
+        conn = messages.get_db()
+        assert messages.get_flags(conn, '[email protected]') == ''
+        conn.close()
+
+    def test_never_raises(
+        self, tmp_path: pytest.TempPathFactory, monkeypatch: pytest.MonkeyPatch
+    ) -> None:
+        """It runs after the message is already gone, so a bookkeeping
+        failure must not reach the caller as a failure to send."""
+        from b4.review_tui._common import mark_outgoing_seen
+
+        def boom(msgs: object) -> None:
+            raise sqlite3.OperationalError('database is locked')
+
+        monkeypatch.setattr(messages, 'mark_outgoing_seen', boom)
+        mark_outgoing_seen([self._make_msg('[email protected]')])

-- 
2.53.0