From 47400fe2af5894830ffafcf0e83a1755151b8eff Mon Sep 17 00:00:00 2001 From: spfcraze Date: Mon, 3 Aug 2026 15:37:28 -0400 Subject: [PATCH] test: make memo pins pre-fix-safe (raising=False resets) (cherry picked from commit 4822daed5d9238348c50bfbdf8c3c4795adc4986) --- .../hermes_cli/test_global_auth_store_memo.py | 13 ++++++++--- tests/test_hermes_constants.py | 22 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tests/hermes_cli/test_global_auth_store_memo.py b/tests/hermes_cli/test_global_auth_store_memo.py index b49b00732d..a8f062cfce 100644 --- a/tests/hermes_cli/test_global_auth_store_memo.py +++ b/tests/hermes_cli/test_global_auth_store_memo.py @@ -20,10 +20,17 @@ import hermes_cli.auth as auth_mod @pytest.fixture(autouse=True) -def _reset_cache(): - auth_mod._global_auth_store_cache = None +def _reset_cache(monkeypatch): + # raising=False: on pre-fix code the memo attribute doesn't exist (that + # IS the fix); the reset is a no-op there so the measured-work assertions + # fail genuinely instead of erroring. + monkeypatch.setattr( + auth_mod, "_global_auth_store_cache", None, raising=False + ) yield - auth_mod._global_auth_store_cache = None + monkeypatch.setattr( + auth_mod, "_global_auth_store_cache", None, raising=False + ) def _make_global_store(tmp_path) -> "os.PathLike[str]": diff --git a/tests/test_hermes_constants.py b/tests/test_hermes_constants.py index fa0c047996..9df43e08ff 100644 --- a/tests/test_hermes_constants.py +++ b/tests/test_hermes_constants.py @@ -73,7 +73,12 @@ class TestGetDefaultHermesRoot: kanban, backup, gateway, update. The memo is keyed on (native home, HERMES_HOME) compared for free each call. """ - monkeypatch.delenv("HERMES_HOME", raising=False) + # HERMES_HOME set to a Docker-profile path: every call resolves the + # env path against the native home (the ~80us work the memo skips). + docker_root = tmp_path / "opt" / "data" + profile = docker_root / "profiles" / "coder" + profile.mkdir(parents=True) + monkeypatch.setenv("HERMES_HOME", str(profile)) monkeypatch.setattr(Path, "home", lambda: tmp_path) # Probe the expensive inner work: the memo check itself calls @@ -88,7 +93,12 @@ class TestGetDefaultHermesRoot: return orig_resolve(self, *a, **k) monkeypatch.setattr(Path, "resolve", counting_resolve) - hermes_constants._default_hermes_root_memo = None + # raising=False: on pre-fix code the memo attribute doesn't exist + # (that IS the fix); the reset is a no-op there so the measured-work + # assertion below fails genuinely instead of erroring. + monkeypatch.setattr( + hermes_constants, "_default_hermes_root_memo", None, raising=False + ) first = get_default_hermes_root() first_count = resolve_calls["n"] @@ -98,12 +108,14 @@ class TestGetDefaultHermesRoot: "repeated calls must be memo hits (no path resolution on hits), " f"resolve went {first_count} -> {resolve_calls['n']}" ) - assert first == tmp_path / ".hermes" + assert first == docker_root # HERMES_HOME change invalidates the memo (fresh resolution). - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "elsewhere")) + other_profile = docker_root / "profiles" / "writer" + other_profile.mkdir(parents=True) + monkeypatch.setenv("HERMES_HOME", str(other_profile)) before = resolve_calls["n"] - assert get_default_hermes_root() == tmp_path / "elsewhere" + assert get_default_hermes_root() == docker_root assert resolve_calls["n"] > before, ( "HERMES_HOME change must force a fresh resolution" )