mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-21 05:11:26 +00:00
fix: follow-up for salvaged PR #22263
- Restore allowed_chats gate before thread_id check so ignored_threads applies universally (even to guest mentions). - Compute _message_mentions_bot once in _should_process_message to eliminate redundant second entity scan when guest_mode=true and the message does not mention the bot. - Remove redundant _is_group_chat from _is_guest_mention (caller already verified the message is a group chat). - Update _telegram_allowed_chats docstring to note guest_mode exception. - Add test coverage: bot_command entity, text_mention entity, caption_entities, and ignored_threads + guest_mode interaction. - Add nik1t7n to AUTHOR_MAP.
This commit is contained in:
parent
55f518e521
commit
dae94fa652
4 changed files with 71 additions and 9 deletions
|
|
@ -827,3 +827,40 @@ class TestTelegramGuestMentionGating:
|
|||
)
|
||||
|
||||
assert adapter._should_process_message(message) is False
|
||||
|
||||
def test_guest_mode_allows_bot_command_entity_outside_allowed_chats(self):
|
||||
"""``/cmd@botname`` is a ``bot_command`` entity, not ``mention``."""
|
||||
adapter = _guest_test_adapter(guest_mode=True, allowed_chats=["-100200"])
|
||||
text = "/status@hermes_bot"
|
||||
message = _guest_group_message(
|
||||
text,
|
||||
chat_id=-100201,
|
||||
entities=[SimpleNamespace(type="bot_command", offset=0, length=len(text))],
|
||||
)
|
||||
|
||||
assert adapter._should_process_message(message) is True
|
||||
|
||||
def test_guest_mode_allows_text_mention_entity_outside_allowed_chats(self):
|
||||
"""MessageEntity(type=text_mention) tags a user by ID — recognised as mention."""
|
||||
adapter = _guest_test_adapter(guest_mode=True, allowed_chats=["-100200"])
|
||||
message = _guest_group_message(
|
||||
"hey there",
|
||||
chat_id=-100201,
|
||||
entities=[SimpleNamespace(type="text_mention", offset=0, length=3, user=SimpleNamespace(id=999))],
|
||||
)
|
||||
|
||||
assert adapter._should_process_message(message) is True
|
||||
|
||||
def test_guest_mode_allows_mention_in_caption_outside_allowed_chats(self):
|
||||
"""Media caption @mention should bypass allowed_chats via guest_mode."""
|
||||
adapter = _guest_test_adapter(guest_mode=True, allowed_chats=["-100200"])
|
||||
text = "look @hermes_bot"
|
||||
message = _guest_group_message(
|
||||
text="",
|
||||
chat_id=-100201,
|
||||
entities=[],
|
||||
)
|
||||
message.caption = text
|
||||
message.caption_entities = [_guest_mention_entity(text)]
|
||||
|
||||
assert adapter._should_process_message(message) is True
|
||||
|
|
|
|||
|
|
@ -186,6 +186,23 @@ def test_guest_mode_defaults_to_false_for_allowed_chat_bypass():
|
|||
assert adapter._should_process_message(mentioned) is False
|
||||
|
||||
|
||||
def test_guest_mode_mention_dropped_in_ignored_thread():
|
||||
"""A guest mention in an ignored thread is still dropped — thread gate runs first."""
|
||||
adapter = _make_adapter(
|
||||
require_mention=True,
|
||||
allowed_chats=["-200"],
|
||||
guest_mode=True,
|
||||
ignored_threads=[42],
|
||||
)
|
||||
mentioned = _group_message(
|
||||
"hi @hermes_bot",
|
||||
chat_id=-201,
|
||||
entities=[_mention_entity("hi @hermes_bot")],
|
||||
thread_id=42,
|
||||
)
|
||||
assert adapter._should_process_message(mentioned) is False
|
||||
|
||||
|
||||
def test_ignored_threads_drop_group_messages_before_other_gates():
|
||||
adapter = _make_adapter(require_mention=False, free_response_chats=["-200"], ignored_threads=[31, "42"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue