"""Message is the boundary every stored text passes through."""
from navi.llm.base import Message
class TestNulBytes:
"""PostgreSQL text cannot hold a NUL byte, and one arriving in a tool result
made the whole session_messages INSERT fail with CharacterNotInRepertoireError
— the turn died and the user lost it (three times on prod, 2026-10-07). The
strip lives on Message so it covers every writer downstream of it.
"""
def test_content_loses_nul_bytes(self):
assert Message(role="tool", content="bi\x00nary").content == "binary"
def test_thinking_loses_nul_bytes_too(self):
assert Message(role="assistant", thinking="th\x00ink").thinking == "think"
def test_clean_text_is_untouched(self):
text = "привет, мир — 100% ok"
assert Message(role="user", content=text).content == text
def test_absent_content_stays_none(self):
assert Message(role="assistant").content is None