test: make memo pins pre-fix-safe (raising=False resets)

(cherry picked from commit 4822daed5d9238348c50bfbdf8c3c4795adc4986)
This commit is contained in:
spfcraze
2026-08-03 15:37:28 -04:00
committed by Teknium
parent 4bd746c6e9
commit 47400fe2af
2 changed files with 27 additions and 8 deletions
@@ -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]":
+17 -5
View File
@@ -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"
)