From 9bb8cb8d835979efc295c416d8dee01c9bf16087 Mon Sep 17 00:00:00 2001 From: KUSH42 Date: Fri, 10 Apr 2026 01:35:48 +0200 Subject: [PATCH] fix(tests): repair three pre-existing gateway test failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_background_autocompletes: pytest.importorskip("prompt_toolkit") so the test skips gracefully where the CLI dep is absent - test_run_agent_progress_stays_in_originating_topic: update stale emoji 💻 → ⚙️ to match get_tool_emoji("terminal", default="⚙️") in run.py - test_internal_event_bypass{_authorization,_pairing}: mock _handle_message_with_agent to raise immediately; avoids the 300s run_in_executor hang that caused the tests to time out --- tests/gateway/test_background_command.py | 1 + .../test_internal_event_bypass_pairing.py | 22 ++++++++++++++----- tests/gateway/test_run_progress_topics.py | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/gateway/test_background_command.py b/tests/gateway/test_background_command.py index c4c15a5ce9..90303c41c6 100644 --- a/tests/gateway/test_background_command.py +++ b/tests/gateway/test_background_command.py @@ -308,6 +308,7 @@ class TestBackgroundInCLICommands: def test_background_autocompletes(self): """The /background command appears in autocomplete results.""" + pytest.importorskip("prompt_toolkit") from hermes_cli.commands import SlashCommandCompleter from prompt_toolkit.document import Document diff --git a/tests/gateway/test_internal_event_bypass_pairing.py b/tests/gateway/test_internal_event_bypass_pairing.py index 19ecd7059e..05b093b04a 100644 --- a/tests/gateway/test_internal_event_bypass_pairing.py +++ b/tests/gateway/test_internal_event_bypass_pairing.py @@ -128,12 +128,16 @@ async def test_internal_event_bypasses_authorization(monkeypatch, tmp_path): monkeypatch.setattr(GatewayRunner, "_is_user_authorized", tracking_auth) - # _handle_message will proceed past auth check and eventually fail on - # downstream logic. We just need to verify auth is skipped. + # Stop execution before the agent runner so the test doesn't block in + # run_in_executor. Auth check happens before _handle_message_with_agent. + async def _raise(*_a, **_kw): + raise RuntimeError("sentinel — stop here") + monkeypatch.setattr(GatewayRunner, "_handle_message_with_agent", _raise) + try: await runner._handle_message(event) - except Exception: - pass # Expected — downstream code needs more setup + except RuntimeError: + pass # Expected sentinel assert not auth_called, ( "_is_user_authorized should NOT be called for internal events" @@ -175,10 +179,16 @@ async def test_internal_event_does_not_trigger_pairing(monkeypatch, tmp_path): runner.pairing_store.generate_code = tracking_generate + # Stop execution before the agent runner so the test doesn't block in + # run_in_executor. Pairing check happens before _handle_message_with_agent. + async def _raise(*_a, **_kw): + raise RuntimeError("sentinel — stop here") + monkeypatch.setattr(GatewayRunner, "_handle_message_with_agent", _raise) + try: await runner._handle_message(event) - except Exception: - pass # Expected — downstream code needs more setup + except RuntimeError: + pass # Expected sentinel assert not generate_called, ( "Pairing code should NOT be generated for internal events" diff --git a/tests/gateway/test_run_progress_topics.py b/tests/gateway/test_run_progress_topics.py index f3ff90512f..c28317d7e4 100644 --- a/tests/gateway/test_run_progress_topics.py +++ b/tests/gateway/test_run_progress_topics.py @@ -144,7 +144,7 @@ async def test_run_agent_progress_stays_in_originating_topic(monkeypatch, tmp_pa assert adapter.sent == [ { "chat_id": "-1001", - "content": '💻 terminal: "pwd"', + "content": '⚙️ terminal: "pwd"', "reply_to": None, "metadata": {"thread_id": "17585"}, }