From 0860b9804fa912c760b3f9e8a491d451d4a61145 Mon Sep 17 00:00:00 2001 From: Jeff Watts <186512915+lEWFkRAD@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:14:58 -0700 Subject: [PATCH] test(tui_gateway): pin goal-command config home against collection-time _hermes_home freeze MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sibling files (test_billing_rpc etc.) import tui_gateway.server at collection time, freezing module-level _hermes_home = get_hermes_home() (server.py:54) to the developer's real home before conftest isolation runs. _load_cfg() then reads the REAL ~/.hermes/config.yaml — e.g. a local MoA preset — instead of what _write_moa_config wrote. The server fixture now monkeypatches _hermes_home to the isolated HERMES_HOME and resets the mtime-keyed cfg cache (_cfg_cache/_cfg_mtime/ _cfg_path); monkeypatch restores originals on teardown. Complementary to the #57066 autouse teardown, which only restores the cfg cache to its pre-test value and never re-points _hermes_home. Combined tests/tui_gateway + tests/test_tui_gateway_server.py: 792 passed. Salvaged from PR #63981 by @lEWFkRAD. --- tests/tui_gateway/test_goal_command.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/tui_gateway/test_goal_command.py b/tests/tui_gateway/test_goal_command.py index f67e54a5376..ad2cb9f3449 100644 --- a/tests/tui_gateway/test_goal_command.py +++ b/tests/tui_gateway/test_goal_command.py @@ -34,7 +34,7 @@ def hermes_home(tmp_path, monkeypatch): @pytest.fixture() -def server(hermes_home): +def server(hermes_home, monkeypatch): # Mocks are scoped to the initial import only (see # tests/tui_gateway/test_protocol.py for the rationale). with patch.dict( @@ -46,6 +46,21 @@ def server(hermes_home): ): mod = importlib.import_module("tui_gateway.server") + # Pin config resolution to the isolated HERMES_HOME. Sibling test + # files (test_billing_rpc, test_delegation_session_lifecycle, + # test_gateway_owned_session_reap, ...) import tui_gateway.server at + # collection time — BEFORE the conftest env isolation runs — so the + # module-level ``_hermes_home = get_hermes_home()`` snapshot freezes + # the developer's real home. When any of them precede this file in + # the same process, ``importlib.import_module`` returns that cached + # module and ``_load_cfg()`` would read the REAL config.yaml (e.g. a + # local MoA preset) instead of the one ``_write_moa_config`` writes. + # Also reset the mtime-keyed config cache; monkeypatch restores the + # originals on teardown so nothing leaks to later tests either. + monkeypatch.setattr(mod, "_hermes_home", hermes_home) + monkeypatch.setattr(mod, "_cfg_cache", None) + monkeypatch.setattr(mod, "_cfg_mtime", None) + monkeypatch.setattr(mod, "_cfg_path", None) yield mod # Reset module-level session state without re-importing. importlib.reload # would re-register the module's atexit hooks (ThreadPoolExecutor