Skip to content

refactor: remove 19 duplicate _ensure_telegram_mock() copies from gateway tests - #91401

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:refactor/dedupe-telegram-mock
Aug 21, 2026
Merged

kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:refactor/dedupe-telegram-mock

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Removed 27 redundant _ensure_telegram_mock() copies from gateway test files — the comprehensive version in tests/gateway/conftest.py (installed at collection time, line 330) already covers all of them.

Changes

  • 27 test files: removed per-file _ensure_telegram_mock() function def + module-level call + now-unused imports (sys, MagicMock where no longer referenced) + dangling comment blocks that referenced the deleted mock
  • Untouched: tests/gateway/conftest.py (canonical source) and tests/e2e/conftest.py (separate conftest tree)

The conftest version is strictly superior to every per-file copy:

  • Uses _fake_str_enum for PTB-faithful StrEnum semantics (plain strings break repr() assertions)
  • Uses sys.modules[name] = mod (overwrite) instead of setdefault (wins over partial/broken imports)
  • Full error hierarchy: TelegramError, NetworkError, TimedOut, BadRequest, Forbidden, InvalidToken, RetryAfter, Conflict
  • Includes Update.ALL_TYPES used in start_polling()

Per-file copies were simpler subsets (plain strings, setdefault, fewer error classes) that could drift independently — test_telegram_voice_duration.py already had a variant that omitted ChatType/ContextTypes/ParseMode.

Validation

Before After
Test files with duplicate _ensure_telegram_mock 27 0
Lines of duplicated mock code ~597 0
Targeted tests (27 files + siblings) 328 passed 328 passed
Ruff Clean Clean
CI 31 checks green

Found by /simplify-code review of PR #90560. Expanded from initial 19 to 27 files after /simplify-code Phase 2 on this PR found 8 more copies.

@alt-glitch alt-glitch added type/test Test coverage or test infrastructure comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P3 Low — cosmetic, nice to have labels Aug 21, 2026
@kshitijk4poor
kshitijk4poor force-pushed the refactor/dedupe-telegram-mock branch from 5a7c574 to a9d18db Compare August 21, 2026 10:50
…eway tests

tests/gateway/conftest.py already installs a comprehensive telegram mock
at collection time (line 330), before any test module's imports run.
The per-file copies were fully redundant — each was a simpler subset
(plain strings, setdefault, fewer error classes) of the conftest version
(which uses _fake_str_enum for PTB-faithful StrEnum semantics, sys.modules
overwrite to win over partial/broken imports, and a full error hierarchy
including BadRequest, Forbidden, RetryAfter, Conflict, InvalidToken).

Removed: function def + module-level call + now-unused imports (sys,
MagicMock where no longer referenced) + dangling comment blocks that
referenced the deleted mock, in 27 test files.
Left untouched: tests/gateway/conftest.py (canonical source) and
tests/e2e/conftest.py (separate conftest tree that may run in isolation).

Found by /simplify-code review of PR NousResearch#90560.
@kshitijk4poor
kshitijk4poor force-pushed the refactor/dedupe-telegram-mock branch from a9d18db to c1693d7 Compare August 21, 2026 10:55
@kshitijk4poor
kshitijk4poor merged commit 17d1095 into NousResearch:main Aug 21, 2026
47 checks passed
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…upe-telegram-mock

refactor: remove 19 duplicate _ensure_telegram_mock() copies from gateway tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants