mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-01 07:01:41 +00:00
Remove unused imports (F401) and duplicate/shadowed import redefinitions (F811) across the codebase using ruff's safe autofixes. No behavioral changes -- imports only. - ~1400 safe autofixes applied across 644 files (net -1072 lines) - __init__.py re-exports preserved (excluded from F401 removal so public re-export surfaces stay intact) - Re-exports that are imported or monkeypatched by tests but look unused in their defining module are kept with explicit # noqa: F401 (gateway/run.py load_dotenv; run_agent re-exports from agent.message_sanitization, agent.context_compressor, agent.retry_utils, agent.prompt_builder, agent.process_bootstrap, agent.codex_responses_adapter) - Unsafe F841 (unused-variable) fixes deliberately skipped -- those can change behavior when the RHS has side effects - ruff lints remain disabled in pyproject.toml (only PLW1514 is selected); this is a one-time cleanup, not a config change Verification: - python -m compileall: clean - pytest --collect-only: all 27161 tests collect (zero import errors) - core entry points import clean (run_agent, model_tools, cli, toolsets, hermes_state, batch_runner, gateway) - static scan: every name any test imports directly from an edited module still resolves
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
"""Tests for TelegramPlatform._merge_caption caption deduplication logic."""
|
|
|
|
|
|
from gateway.platforms.telegram 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"
|