This commit is contained in:
Kaloyan Tenchov
2026-05-21 01:00:36 +08:00
committed by Xubin Ren
parent b300ea495f
commit 96767ca179
3 changed files with 55 additions and 67 deletions
+5 -15
View File
@@ -610,16 +610,12 @@ class TestCheckInboundPolicy:
def test_group_open_without_mention_blocks(self):
ch = _make_channel(group_enabled=True, group_policy="open", require_mention=True)
allowed, _ = self._call(
ch, is_group_message=True, group_id="g1", message_text="plain talk"
)
allowed, _ = self._call(ch, is_group_message=True, group_id="g1", message_text="plain talk")
assert allowed is False
def test_group_command_bypasses_mention_requirement(self):
ch = _make_channel(group_enabled=True, group_policy="open", require_mention=True)
allowed, _ = self._call(
ch, is_group_message=True, group_id="g1", message_text="/help"
)
allowed, _ = self._call(ch, is_group_message=True, group_id="g1", message_text="/help")
assert allowed is True
def test_allowed_group_appends_to_buffer(self):
@@ -703,9 +699,7 @@ class TestHandleDataMessageDM:
async def test_dm_allowlist_matches_uuid_case_insensitive(self):
"""UUID matching must be case-insensitive."""
uuid = "ABCDEF12-3456-7890-ABCD-EF1234567890"
ch, handled = self._make_dm_channel(
policy="allowlist", allow_from=[uuid.lower()]
)
ch, handled = self._make_dm_channel(policy="allowlist", allow_from=[uuid.lower()])
params = _dm_envelope(source_number="+19995550001", source_uuid=uuid)
await ch._handle_receive_notification(params)
assert len(handled) == 1
@@ -1076,9 +1070,7 @@ class TestCommandHandling:
ch, forwarded = _make_channel_with_capture(
group_enabled=True, group_policy="open", require_mention=True
)
params = _group_envelope(
source_number="+19995550001", group_id="grp==", message="/reset"
)
params = _group_envelope(source_number="+19995550001", group_id="grp==", message="/reset")
await ch._handle_receive_notification(params)
assert len(forwarded) == 1
assert "/reset" in forwarded[0]["content"]
@@ -1357,9 +1349,7 @@ def test_config_allow_from_aggregates_dm_and_group() -> None:
enabled=True,
phone_number="+10000000000",
dm=SignalDMConfig(enabled=True, policy="allowlist", allow_from=["+1111", "+2222"]),
group=SignalGroupConfig(
enabled=True, policy="allowlist", allow_from=["+3333", "+1111"]
),
group=SignalGroupConfig(enabled=True, policy="allowlist", allow_from=["+3333", "+1111"]),
)
combined = config.allow_from
assert "+1111" in combined
+10 -9
View File
@@ -1,7 +1,5 @@
"""Unit tests for the Signal markdown → plain text + textStyle converter."""
import pytest
from nanobot.channels.signal import _markdown_to_signal, _partition_styles
from nanobot.utils.helpers import split_message
@@ -94,8 +92,9 @@ def test_inline_code():
def test_code_block():
plain, styles = _markdown_to_signal("```\nprint('hi')\n```")
assert "print('hi')" in plain
assert styles_for(plain, styles).get("print('hi')\n") == ["MONOSPACE"] or \
"MONOSPACE" in str(styles_for(plain, styles))
assert styles_for(plain, styles).get("print('hi')\n") == ["MONOSPACE"] or "MONOSPACE" in str(
styles_for(plain, styles)
)
def test_code_block_with_lang():
@@ -278,9 +277,7 @@ def assert_within_utf16_bounds(plain: str, styles: list[str]) -> None:
start_s, length_s, _ = entry.split(":", 2)
start, length = int(start_s), int(length_s)
assert start >= 0
assert start + length <= limit, (
f"range {entry} exceeds utf-16 length {limit} of {plain!r}"
)
assert start + length <= limit, f"range {entry} exceeds utf-16 length {limit} of {plain!r}"
def test_bold_with_emoji_inside():
@@ -413,7 +410,9 @@ def test_partition_styles_long_message_preserves_chunk_one_styles():
for entry in final_styles:
s, ln, _ = entry.split(":", 2)
start, length = int(s), int(ln)
slice_ = final_chunk.encode("utf-16-le")[start * 2 : (start + length) * 2].decode("utf-16-le")
slice_ = final_chunk.encode("utf-16-le")[start * 2 : (start + length) * 2].decode(
"utf-16-le"
)
assert slice_ == "tail"
@@ -444,7 +443,9 @@ def test_partition_styles_with_non_bmp_chunk_offset():
for entry in final_styles:
s, ln, _ = entry.split(":", 2)
start, length = int(s), int(ln)
slice_ = final_chunk.encode("utf-16-le")[start * 2 : (start + length) * 2].decode("utf-16-le")
slice_ = final_chunk.encode("utf-16-le")[start * 2 : (start + length) * 2].decode(
"utf-16-le"
)
assert slice_ == "tail"