test(gateway): fix order-dependent telegram-mock flake cluster - #68873
Closed
mehmetkr-31 wants to merge 1 commit into
Closed
test(gateway): fix order-dependent telegram-mock flake cluster#68873mehmetkr-31 wants to merge 1 commit into
mehmetkr-31 wants to merge 1 commit into
Conversation
Eight telegram gateway tests (test_telegram_slash_confirm, _approval_buttons,
_model_picker, _network_reconnect) pass in isolation but fail in a full
tests/gateway run. Root cause: test_dm_topics.py installed its telegram
sys.modules mock UNCONDITIONALLY (no real-library guard) and force-reimported
the adapter against it. Its stub also diverged from every other telegram
test's mock — a separate string-valued telegram.constants module (so
ParseMode members were plain strings, not PTB StrEnum-faithful) and a bare
MagicMock telegram.error (no real exception hierarchy). Whichever order
collected test_dm_topics first, that divergent stub leaked into sys.modules
for the rest of the session, so later tests asserting real-PTB semantics
(ParseMode repr, isinstance against telegram.error, str(ChatType)
normalization) failed.
Fixes:
- test_dm_topics.py now uses the shared tests/gateway/conftest.py
_ensure_telegram_mock (guarded on the real library, comprehensive error
hierarchy) instead of a divergent local stub.
- conftest's mock now models ParseMode/ChatType as PTB-faithful StrEnum
members via a small _FakeEnumMember: str(x)/equality give the value
('supergroup') while repr(x) shows the qualified name (<ChatType.SUPERGROUP>),
so both the adapter's str() normalization and tests' repr assertions agree
regardless of which file's mock installed first.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
teknium1
pushed a commit
that referenced
this pull request
Jul 30, 2026
The file-local telegram mock in test_dm_topics.py installed unconditionally (no __file__ guard), registered a separate string-valued telegram.constants module, and force-popped the adapter — poisoning the session for any later telegram test in the same process (assert 'MARKDOWN_V2' in "'MarkdownV2'"). Fix at the source: - conftest: _FakeEnumMember(str) with PTB-faithful str()==value and repr()==<ChatType.X: 'x'>, satisfying both repr assertions and the adapter's str(chat.type) normalization; the same object is bound to mod.ParseMode and mod.constants.ParseMode. - test_dm_topics.py: delete the divergent local mock installer; import the shared conftest one. - release.py: mailmap entry for the author. Verified: the 5-failure cluster repro (dm_topics + slash_confirm + approval_buttons + model_picker + network_reconnect + telegram_format in one process) goes 83/83 green (3x); full tests/gateway single-process run drops 10 -> 5 failed, the remainder being pre-existing discord order-dep failures out of scope here. Salvaged from #68873. Credit to @liuhao1024 for the earliest root-cause diagnosis of this str-enum mock class in PR #33875, two months earlier. Fixes the telegram-mock order-dependent flake cluster.
Contributor
|
Merged via the round-3 stability PR #74576 (commit 4673d27, your authorship preserved; the release.py hunk was rerouted to contributors/emails/ since the legacy map is frozen). Your fix landed at the poison source — PTB-faithful _FakeEnumMember in the shared conftest + removal of dm_topics' divergent local mock; the telegram cluster failures are gone (5→0). @liuhao1024 is credited in the commit as the earliest diagnoser of the class (#33875). Thanks @mehmetkr-31! |
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
The file-local telegram mock in test_dm_topics.py installed unconditionally (no __file__ guard), registered a separate string-valued telegram.constants module, and force-popped the adapter — poisoning the session for any later telegram test in the same process (assert 'MARKDOWN_V2' in "'MarkdownV2'"). Fix at the source: - conftest: _FakeEnumMember(str) with PTB-faithful str()==value and repr()==<ChatType.X: 'x'>, satisfying both repr assertions and the adapter's str(chat.type) normalization; the same object is bound to mod.ParseMode and mod.constants.ParseMode. - test_dm_topics.py: delete the divergent local mock installer; import the shared conftest one. - release.py: mailmap entry for the author. Verified: the 5-failure cluster repro (dm_topics + slash_confirm + approval_buttons + model_picker + network_reconnect + telegram_format in one process) goes 83/83 green (3x); full tests/gateway single-process run drops 10 -> 5 failed, the remainder being pre-existing discord order-dep failures out of scope here. Salvaged from NousResearch#68873. Credit to @liuhao1024 for the earliest root-cause diagnosis of this str-enum mock class in PR NousResearch#33875, two months earlier. Fixes the telegram-mock order-dependent flake cluster.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…ontributors/emails/ The NousResearch#68873 salvage re-added a line to the frozen dict; the canonical mapping (contributors/emails/mehmet.kar@std.yildiz.edu.tr) already exists from the NousResearch#68872 salvage.
33hodl
pushed a commit
to 33hodl/hermes-agent
that referenced
this pull request
Aug 12, 2026
The file-local telegram mock in test_dm_topics.py installed unconditionally (no __file__ guard), registered a separate string-valued telegram.constants module, and force-popped the adapter — poisoning the session for any later telegram test in the same process (assert 'MARKDOWN_V2' in "'MarkdownV2'"). Fix at the source: - conftest: _FakeEnumMember(str) with PTB-faithful str()==value and repr()==<ChatType.X: 'x'>, satisfying both repr assertions and the adapter's str(chat.type) normalization; the same object is bound to mod.ParseMode and mod.constants.ParseMode. - test_dm_topics.py: delete the divergent local mock installer; import the shared conftest one. - release.py: mailmap entry for the author. Verified: the 5-failure cluster repro (dm_topics + slash_confirm + approval_buttons + model_picker + network_reconnect + telegram_format in one process) goes 83/83 green (3x); full tests/gateway single-process run drops 10 -> 5 failed, the remainder being pre-existing discord order-dep failures out of scope here. Salvaged from NousResearch#68873. Credit to @liuhao1024 for the earliest root-cause diagnosis of this str-enum mock class in PR NousResearch#33875, two months earlier. Fixes the telegram-mock order-dependent flake cluster.
33hodl
pushed a commit
to 33hodl/hermes-agent
that referenced
this pull request
Aug 12, 2026
…ontributors/emails/ The NousResearch#68873 salvage re-added a line to the frozen dict; the canonical mapping (contributors/emails/mehmet.kar@std.yildiz.edu.tr) already exists from the NousResearch#68872 salvage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eight telegram gateway tests pass in isolation and in their own files but fail in a full
tests/gatewayrun — a long-standing order-dependent flake cluster:test_telegram_slash_confirm.py::TestSendSlashConfirm::test_uses_markdown_v2_and_escapes_special_charstest_telegram_approval_buttons.py(2 tests)test_telegram_model_picker.py(3 tests)test_telegram_network_reconnect.py::test_network_error_classifier_matches_ptb_semantics(2 params)Root cause
tests/gateway/test_dm_topics.pyinstalled its telegramsys.modulesmock unconditionally — nohasattr(sys.modules["telegram"], "__file__")real-library guard like every other telegram test — and force-reimported the adapter against it (sys.modules.pop("plugins.platforms.telegram.adapter")). Its stub also diverged from the shared one in two ways:telegram.constantsmodule, soParseMode.MARKDOWN_V2was the plain string"MarkdownV2"— itsrepr()is'MarkdownV2', which fails assertions like"MARKDOWN_V2" in repr(parse_mode)that expect PTB'sStrEnumrepr (<ParseMode.MARKDOWN_V2>).telegram.errorwas a bareMagicMock, soisinstance(exc, telegram.error.TimedOut)checks intest_telegram_network_reconnect.pybroke.Because the stub installed unconditionally and force-reimported the adapter, whichever collection order reached
test_dm_topicsfirst leaked that divergent stub intosys.modulesfor the rest of the session — so later telegram tests asserting real-PTB semantics failed order-dependently while passing alone.Fix (test-only)
test_dm_topics.pynow uses the sharedtests/gateway/conftest.py::_ensure_telegram_mock(guarded on the real library, comprehensivetelegram.errorhierarchy) instead of a divergent local stub. It was the only file that unconditionally overwrote the telegram mock.ParseMode/ChatTypeas PTB-faithfulStrEnummembers via a small_FakeEnumMember(str):str(x)and equality return the value ("supergroup") whilerepr(x)shows the qualified name (<ChatType.SUPERGROUP: 'supergroup'>). That satisfies both the adapter'sstr(chat.type)normalization in_build_message_eventand the tests'repr-based assertions, regardless of which file's mock installed first.Verification
A full
tests/gatewayrun drops from 20 order-dependent failures to only the pre-existing non-telegram flakes (test_wecom_callback,test_systemd_notify,test_channel_directory, …) that also fail on pristinemainand are unrelated to this change (separate root causes, out of scope here).🤖 Generated with Claude Code