mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
test(tui_gateway): pin goal-command config home against collection-time _hermes_home freeze
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.
This commit is contained in:
parent
7216ca19a6
commit
0860b9804f
1 changed files with 16 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue