From bc47fcd3f927abcd1ec281078bc56348e37a2ec0 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 24 Aug 2026 20:09:17 -0700 Subject: [PATCH] fix(tests): e2e group-restart test no longer flakes on cold SessionDB init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /goal post-turn hook constructs a real SessionDB on an executor thread at the turn boundary. On a cold or loaded CI runner that state.db init can exceed send_and_capture's 2s poll window, so the send lands after the assertion and the test reports the bare 'Expected mock to have been called once. Called 0 times.' (#92130). Mock _run_post_turn_hooks in the e2e runner — these tests exercise gateway command dispatch, not goal hooks. Also scrub TELEGRAM_GROUP_ALLOWED_CHATS / *_GROUP_ALLOWED_USERS / QQ allowlist env vars in the hermetic conftest: a developer shell with those set flips _get_unauthorized_dm_behavior to 'ignore' and fails the pairing e2e test locally. --- tests/conftest.py | 4 ++++ tests/e2e/conftest.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 00644ab7e6..56c92149fb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -347,6 +347,10 @@ _HERMES_BEHAVIORAL_VARS = frozenset({ # (user shell, earlier leaky test, CI env), they change gateway auth # behavior and flake button-authorization tests. "TELEGRAM_ALLOWED_USERS", + "TELEGRAM_GROUP_ALLOWED_USERS", + "TELEGRAM_GROUP_ALLOWED_CHATS", + "QQ_ALLOWED_USERS", + "QQ_GROUP_ALLOWED_USERS", "DISCORD_ALLOWED_USERS", "WHATSAPP_ALLOWED_USERS", "SLACK_ALLOWED_USERS", diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 46c98b5d08..682054f842 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -235,6 +235,17 @@ def make_runner(platform: Platform, session_entry: SessionEntry = None) -> "Gate # telegram param only — first parametrization pays the cold-resolution cost). runner._reset_notice_session_info = lambda source: "" + # Keep the agent-turn path hermetic: _run_post_turn_hooks runs the /goal + # continuation, whose SessionDB warm-up constructs a REAL SessionDB on an + # executor thread at the turn boundary. On a cold/loaded CI runner that + # state.db init can exceed send_and_capture's 2s poll window, so the send + # lands after the assertion — the "Expected 'mock' to have been called + # once. Called 0 times." flake on + # test_plaintext_restart_gateway_in_group_stays_plain_text[telegram] + # (issue #92130; e.g. runs 32802504263 / 32799192528 / 32796821900). + # e2e tests exercise gateway command dispatch, not post-turn goal hooks. + runner._run_post_turn_hooks = AsyncMock() + runner.pairing_store = MagicMock() runner.pairing_store._is_rate_limited = MagicMock(return_value=False) runner.pairing_store.generate_code = MagicMock(return_value="ABC123")