mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-24 10:52:21 +00:00
Salvage of PR #41284 onto current main. Relocates the last 9 inline messaging adapters (+ satellites: telegram_network, feishu_comment/_rules/meeting_invite, wecom_crypto, wecom_callback) from gateway/platforms/ into self-contained bundled plugins under plugins/platforms/<x>/, discovered via the platform registry. Strips the per-platform core touchpoints from gateway/run.py, gateway/config.py, hermes_cli/gateway.py, hermes_cli/setup.py, and tools/send_message_tool.py. Carries forward the migration fixes (explicit enabled:false honored, get_connected_platforms forces discovery, plugin is_connected via gateway.get_env_value, logs --component gateway matches plugins.platforms.*, matrix hidden on Windows). Additionally ports config keys main added since the PR base: the matrix plugin's _apply_yaml_config now also covers allowed_users, ignore_user_patterns, process_notices, and session_scope (the inline gateway/config.py matrix block gained these in the 1340 commits the PR sat open; they would otherwise have been silently dropped on deletion).
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
"""Tests for TelegramPlatform._merge_caption caption deduplication logic."""
|
|
|
|
|
|
from plugins.platforms.telegram.adapter import TelegramAdapter
|
|
|
|
merge = TelegramAdapter._merge_caption
|
|
|
|
|
|
class TestMergeCaptionBasic:
|
|
def test_no_existing_text(self):
|
|
assert merge(None, "Hello") == "Hello"
|
|
|
|
def test_empty_existing_text(self):
|
|
assert merge("", "Hello") == "Hello"
|
|
|
|
def test_exact_duplicate_dropped(self):
|
|
assert merge("Revenue", "Revenue") == "Revenue"
|
|
|
|
def test_different_captions_merged(self):
|
|
result = merge("Q3 Results", "Q4 Projections")
|
|
assert result == "Q3 Results\n\nQ4 Projections"
|
|
|
|
|
|
class TestMergeCaptionSubstringBug:
|
|
"""These are the exact scenarios that the old substring check got wrong."""
|
|
|
|
def test_shorter_caption_not_dropped_when_substring(self):
|
|
# Bug: "Meeting" in "Meeting agenda" → True → caption was silently lost
|
|
result = merge("Meeting agenda", "Meeting")
|
|
assert result == "Meeting agenda\n\nMeeting"
|
|
|
|
def test_longer_caption_not_dropped_when_contains_existing(self):
|
|
# "Revenue and Profit" contains "Revenue", but they are different captions
|
|
result = merge("Revenue", "Revenue and Profit")
|
|
assert result == "Revenue\n\nRevenue and Profit"
|
|
|
|
def test_prefix_caption_not_dropped(self):
|
|
result = merge("Q3 Results - Revenue", "Q3 Results")
|
|
assert result == "Q3 Results - Revenue\n\nQ3 Results"
|
|
|
|
|
|
class TestMergeCaptionWhitespace:
|
|
def test_trailing_space_treated_as_duplicate(self):
|
|
assert merge("Revenue", "Revenue ") == "Revenue"
|
|
|
|
def test_leading_space_treated_as_duplicate(self):
|
|
assert merge("Revenue", " Revenue") == "Revenue"
|
|
|
|
def test_whitespace_only_new_text_not_added(self):
|
|
# strip() makes it empty string → falsy check in callers guards this,
|
|
# but _merge_caption itself: strip matches "" which is not in list → would merge.
|
|
# Callers already guard with `if event.text:` so this is an edge case.
|
|
result = merge("Revenue", " ")
|
|
# " ".strip() == "" → not in ["Revenue"] → gets merged (caller guards prevent this)
|
|
assert "\n\n" in result or result == "Revenue"
|
|
|
|
|
|
class TestMergeCaptionMultipleItems:
|
|
def test_three_unique_captions_all_present(self):
|
|
text = merge(None, "A")
|
|
text = merge(text, "B")
|
|
text = merge(text, "C")
|
|
assert text == "A\n\nB\n\nC"
|
|
|
|
def test_duplicate_in_middle_dropped(self):
|
|
text = merge(None, "A")
|
|
text = merge(text, "B")
|
|
text = merge(text, "A") # duplicate
|
|
assert text == "A\n\nB"
|
|
|
|
def test_album_scenario_revenue_profit(self):
|
|
# Album Item 1: "Revenue and Profit", Item 2: "Revenue"
|
|
# Old bug: "Revenue" in ["Revenue and Profit"] → True → lost
|
|
text = merge(None, "Revenue and Profit")
|
|
text = merge(text, "Revenue")
|
|
assert text == "Revenue and Profit\n\nRevenue"
|