Skip to content

The agent that grows with you

refactor(desktop): write the installed-app record only when it changes

kshitijk4pooraea6f7a66010
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.py
index 586c206eb29..6a506cf7db0 100644
--- a/hermes_cli/main_desktop.py
+++ b/hermes_cli/main_desktop.py
@@ -982,6 +982,8 @@ def _install_rebuilt_desktop_app(desktop_dir: Path, candidates: list[Path]) -> t
def _refresh_installed_desktop_apps(desktop_dir: Path) -> None:
"""Install the rebuilt bundle over stale or missing installed copies, report each outcome, and
record which copies this update keeps current."""
+ if not _owns_installed_desktop_apps():
+ return
owned = _installed_desktop_apps()
missing = {app for app in owned if not app.exists()}
installed, problems = _install_rebuilt_desktop_app(desktop_dir, owned)
@@ -993,13 +995,15 @@ def _refresh_installed_desktop_apps(desktop_dir: Path) -> None:
print(f" ✓ Installed the rebuilt Desktop app at {app}")
for problem in problems:
print(f" ⚠ {problem}")
- if not _owns_installed_desktop_apps():
- return
from hermes_cli.gui_uninstall import desktop_install_record # noqa: PLC0415
- from utils import atomic_json_write # noqa: PLC0415
+ from utils import atomic_json_write, read_json_or_empty # noqa: PLC0415
+ # A copy that failed to reinstall stays recorded, so the next update retries it. Every
+ # `hermes desktop` launch lands here: write only when the set changed.
+ apps = [str(app) for app in owned]
+ if read_json_or_empty(desktop_install_record()).get("apps", []) == apps:
+ return
try:
- # A copy that failed to reinstall stays recorded, so the next update retries it.
- atomic_json_write(desktop_install_record(), {"apps": [str(app) for app in owned]})
+ atomic_json_write(desktop_install_record(), {"apps": apps})
except OSError as exc:
print(f" ⚠ Could not record the installed Desktop app ({exc})")
@@ -1049,7 +1053,9 @@ def _installed_desktop_apps() -> list[Path]:
candidates = packaged_gui_app_paths()
if owned := _update_owned_macos_bundles(candidates):
return owned
- recorded = read_json_or_empty(desktop_install_record()).get("apps", [])
+ recorded = read_json_or_empty(desktop_install_record()).get("apps")
+ if not isinstance(recorded, list):
+ return []
return [app for app in candidates if str(app) in recorded and not app.exists()]
diff --git a/tests/hermes_cli/test_desktop_install_after_update.py b/tests/hermes_cli/test_desktop_install_after_update.py
index 4f289596999..be57ed6bccd 100644
--- a/tests/hermes_cli/test_desktop_install_after_update.py
+++ b/tests/hermes_cli/test_desktop_install_after_update.py
@@ -103,11 +103,13 @@ def test_recorded_app_that_went_missing_comes_back_until_gui_uninstall(rebuilt,
shutil.rmtree(user_app)
main_desktop._refresh_installed_desktop_apps(tmp_path)
assert _asar(user_app) == b"rebuilt" and not app.exists()
- assert main_desktop._update_owned_macos_bundles([user_app]) == [user_app]
- shutil.rmtree(user_app) # the reinstalled copy is owned again, so it comes back every time
+ gui_uninstall.desktop_install_record().unlink() # the reinstalled copy carries its own stamp,
+ main_desktop._refresh_installed_desktop_apps(tmp_path) # so it is recorded again from the copy
+ shutil.rmtree(user_app)
main_desktop._refresh_installed_desktop_apps(tmp_path)
assert _asar(user_app) == b"rebuilt"
gui_uninstall.uninstall_gui(tmp_path / "profile-home") # the record is machine-wide
main_desktop._refresh_installed_desktop_apps(tmp_path)
assert not user_app.exists()
+ assert not gui_uninstall.desktop_install_record().exists()