From 67d6c3ff50182fec756023f8d310251f5ac23ca3 Mon Sep 17 00:00:00 2001 From: hermes Date: Fri, 18 Sep 2026 16:57:17 +0100 Subject: [PATCH] Add regression test for cached profile-name-string resolution branch _resolve_profile_home_param has two branches feeding the same _cached_safe_resolve_profile_home() memoization: an explicit Path, and a logical profile-name string resolved via get_hermes_home_for_profile(). The existing regression test only covered the Path branch. Add a matching test that repeatedly resolves a profile-name string and confirms it returns the correct home and that _safe_resolve is invoked only once across repeated calls, i.e. the cache is genuinely hit for the string-keyed path too. Co-Authored-By: Claude Sonnet 5 --- tests/test_profile_home_resolve_caching.py | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_profile_home_resolve_caching.py b/tests/test_profile_home_resolve_caching.py index f2a16587..ccc8f63f 100644 --- a/tests/test_profile_home_resolve_caching.py +++ b/tests/test_profile_home_resolve_caching.py @@ -32,3 +32,30 @@ def test_resolve_profile_home_param_caches_repeated_path_argument(tmp_path): "expected the filesystem resolve() to run once and be served from " f"cache thereafter, but it ran {spy.call_count} times" ) + + +def test_resolve_profile_home_param_caches_repeated_profile_name_argument(tmp_path): + """Same fix, second branch: a logical profile-NAME STRING (not a Path) + + resolves through `get_hermes_home_for_profile()` before hitting the same + `_cached_safe_resolve_profile_home()` memoization. This mirrors the + Path-argument test above but drives the string branch (workspace.py's + ``isinstance(profile, Path)`` check is False), confirming the cache is + genuinely hit -- not just for explicit Path callers -- and that the + resolved home is correct. + """ + ws._PROFILE_HOME_RESOLVE_CACHE.clear() + home_dir = tmp_path / "named_profile_home" + home_dir.mkdir() + + with patch("api.profiles.get_hermes_home_for_profile", return_value=home_dir), \ + patch.object(ws, "_safe_resolve", wraps=ws._safe_resolve) as spy: + first = ws._resolve_profile_home_param("myprofile") + second = ws._resolve_profile_home_param("myprofile") + third = ws._resolve_profile_home_param("myprofile") + + assert first == second == third == home_dir.resolve() + assert spy.call_count == 1, ( + "expected the filesystem resolve() to run once and be served from " + f"cache thereafter, but it ran {spy.call_count} times" + )