From de5fe2fa7d6da868d18d5cd1cc846922fbb12a84 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Mon, 8 Jun 2026 00:00:01 -0700 Subject: [PATCH] test(gateway): repoint slash-command mocks after mixin extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests for the extracted handlers mocked symbols at gateway.run.*; the handlers now resolve top-level-imported deps (atomic_json_write, fetch_account_usage, render_account_usage_lines) and __file__ from gateway.slash_commands. Repoint those mocks. run.py-resident methods (_increment_restart_failure_counts, _clear_restart_failure_count) keep their gateway.run.atomic_json_write mock — only the moved handlers' mocks change. tests/gateway/ 6415 passed / 0 failed. --- tests/gateway/test_restart_notification.py | 4 ++++ tests/gateway/test_update_command.py | 11 +++++++---- tests/gateway/test_usage_command.py | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/gateway/test_restart_notification.py b/tests/gateway/test_restart_notification.py index 0f0dadc42b8..b090503c5b1 100644 --- a/tests/gateway/test_restart_notification.py +++ b/tests/gateway/test_restart_notification.py @@ -153,6 +153,10 @@ async def test_restart_command_uses_atomic_json_writes_for_marker_files(tmp_path def _fake_atomic_json_write(path, payload, **kwargs): calls.append((Path(path).name, payload, kwargs)) + # _handle_restart_command lives in gateway/slash_commands.py (extracted from + # run.py); it uses that module's top-level atomic_json_write import. + import gateway.slash_commands as gateway_slash + monkeypatch.setattr(gateway_slash, "atomic_json_write", _fake_atomic_json_write) monkeypatch.setattr(gateway_run, "atomic_json_write", _fake_atomic_json_write) runner, _adapter = make_restart_runner() diff --git a/tests/gateway/test_update_command.py b/tests/gateway/test_update_command.py index 17c466f9612..fa223a42fbd 100644 --- a/tests/gateway/test_update_command.py +++ b/tests/gateway/test_update_command.py @@ -86,12 +86,15 @@ class TestHandleUpdateCommand: class FakePath(type(Path())): pass - # Actually, simplest: just patch the specific file attr - fake_file = str(fake_root / "gateway" / "run.py") + # Actually, simplest: just patch the specific file attr. + # The _handle_update_command handler lives in gateway/slash_commands.py + # (extracted from run.py in the god-file decomposition); it resolves + # project_root via Path(__file__).parent.parent, so fake that file. + fake_file = str(fake_root / "gateway" / "slash_commands.py") (fake_root / "gateway").mkdir(parents=True) - (fake_root / "gateway" / "run.py").touch() + (fake_root / "gateway" / "slash_commands.py").touch() - with patch("gateway.run.__file__", fake_file): + with patch("gateway.slash_commands.__file__", fake_file): result = await runner._handle_update_command(event) assert "Not a git repository" in result diff --git a/tests/gateway/test_usage_command.py b/tests/gateway/test_usage_command.py index 2775e72f9d7..9fbb80e3123 100644 --- a/tests/gateway/test_usage_command.py +++ b/tests/gateway/test_usage_command.py @@ -188,11 +188,11 @@ class TestUsageAccountSection: event = MagicMock() monkeypatch.setattr( - "gateway.run.fetch_account_usage", + "gateway.slash_commands.fetch_account_usage", lambda provider, base_url=None, api_key=None: object(), ) monkeypatch.setattr( - "gateway.run.render_account_usage_lines", + "gateway.slash_commands.render_account_usage_lines", lambda snapshot, markdown=False: [ "📈 **Account limits**", "Provider: openai-codex (Pro)", @@ -235,11 +235,11 @@ class TestUsageAccountSection: monkeypatch.setattr("gateway.run.asyncio.to_thread", _fake_to_thread) monkeypatch.setattr( - "gateway.run.fetch_account_usage", + "gateway.slash_commands.fetch_account_usage", lambda provider, base_url=None, api_key=None: object(), ) monkeypatch.setattr( - "gateway.run.render_account_usage_lines", + "gateway.slash_commands.render_account_usage_lines", lambda snapshot, markdown=False: [ "📈 **Account limits**", "Provider: openai-codex (Pro)",