diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 8c3f8b55a6..6514a55819 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -2898,16 +2898,29 @@ def _restore_stashed_changes( return True def _invalidate_update_cache(): - """Delete the update-check cache so ``hermes --version`` doesn't - report a stale "commits behind" count after a successful update.""" - try: - cache_file = Path(os.getenv( - "HERMES_HOME", Path.home() / ".hermes" - )) / ".update_check" - if cache_file.exists(): - cache_file.unlink() - except Exception: - pass + """Delete the update-check cache for ALL profiles so no banner + reports a stale "commits behind" count after a successful update. + + The git repo is shared across profiles — when one profile runs + ``hermes update``, every profile is now current. + """ + homes = [] + # Default profile home + default_home = Path.home() / ".hermes" + homes.append(default_home) + # Named profiles under ~/.hermes/profiles/ + profiles_root = default_home / "profiles" + if profiles_root.is_dir(): + for entry in profiles_root.iterdir(): + if entry.is_dir(): + homes.append(entry) + for home in homes: + try: + cache_file = home / ".update_check" + if cache_file.exists(): + cache_file.unlink() + except Exception: + pass def _load_installable_optional_extras() -> list[str]: diff --git a/tests/hermes_cli/test_update_check.py b/tests/hermes_cli/test_update_check.py index 08ed342694..b7d6de6ff0 100644 --- a/tests/hermes_cli/test_update_check.py +++ b/tests/hermes_cli/test_update_check.py @@ -133,3 +133,41 @@ def test_get_update_result_timeout(): # Should have waited ~0.1s and returned None assert result is None assert elapsed < 0.5 + + +def test_invalidate_update_cache_clears_all_profiles(tmp_path): + """_invalidate_update_cache() should delete .update_check from ALL profiles.""" + from hermes_cli.main import _invalidate_update_cache + + # Build a fake ~/.hermes with default + two named profiles + default_home = tmp_path / ".hermes" + default_home.mkdir() + (default_home / ".update_check").write_text('{"ts":1,"behind":50}') + + profiles_root = default_home / "profiles" + for name in ("ops", "dev"): + p = profiles_root / name + p.mkdir(parents=True) + (p / ".update_check").write_text('{"ts":1,"behind":50}') + + with patch.object(Path, "home", return_value=tmp_path): + _invalidate_update_cache() + + # All three caches should be gone + assert not (default_home / ".update_check").exists(), "default profile cache not cleared" + assert not (profiles_root / "ops" / ".update_check").exists(), "ops profile cache not cleared" + assert not (profiles_root / "dev" / ".update_check").exists(), "dev profile cache not cleared" + + +def test_invalidate_update_cache_no_profiles_dir(tmp_path): + """Works fine when no profiles directory exists (single-profile setup).""" + from hermes_cli.main import _invalidate_update_cache + + default_home = tmp_path / ".hermes" + default_home.mkdir() + (default_home / ".update_check").write_text('{"ts":1,"behind":5}') + + with patch.object(Path, "home", return_value=tmp_path): + _invalidate_update_cache() + + assert not (default_home / ".update_check").exists()