Skip to content

The agent that grows with you

perf(desktop): gate the desktop root npm ci on the manifests digest and Electron presence

kshitijk4poor8231ea137a08
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.py
index d4135170d19..176144a4037 100644
--- a/hermes_cli/main_desktop.py
+++ b/hermes_cli/main_desktop.py
@@ -1423,7 +1423,12 @@ def _install_desktop_workspace_deps(npm: str, env: dict) -> None:
"""npm-install the desktop workspace; exits on a failure that isn't a repairable missing Electron dist."""
from hermes_cli.main import PROJECT_ROOT
from hermes_cli.main_web_build import _run_npm_install_deterministic
- from hermes_constants import with_hermes_node_path
+ from hermes_cli.update_cmd_deps import _desktop_deps_changed, _record_npm_lockfile_hash
+ from hermes_constants import get_default_hermes_root, with_hermes_node_path
+ hermes_root = get_default_hermes_root()
+ if not _desktop_deps_changed(hermes_root):
+ print("→ Desktop workspace dependencies unchanged, skipping install")
+ return
print("→ Installing desktop workspace dependencies...")
_remove_half_installed_get_windows(PROJECT_ROOT)
# Managed Node on PATH so npm's child scripts that shell out to bare `node`
@@ -1433,6 +1438,7 @@ def _install_desktop_workspace_deps(npm: str, env: dict) -> None:
nixos_env = with_hermes_node_path(_nixos_build_env())
install_result = _run_npm_install_deterministic(npm, PROJECT_ROOT, capture_output=False, env=nixos_env)
if install_result.returncode == 0:
+ _record_npm_lockfile_hash(hermes_root, "_desktop")
return
if not _electron_pkg_staged_missing_dist(PROJECT_ROOT):
print(f"✗ Desktop dependency install failed\n Run manually: cd {PROJECT_ROOT} && npm ci")
diff --git a/hermes_cli/update_cmd_deps.py b/hermes_cli/update_cmd_deps.py
index 05de64256b7..3916ceb09b2 100644
--- a/hermes_cli/update_cmd_deps.py
+++ b/hermes_cli/update_cmd_deps.py
@@ -537,23 +537,38 @@ def _npm_lockfile_changed(hermes_root: Path) -> bool:
return True
-def _npm_lock_cache_file(hermes_root: Path) -> Path:
- """Per-checkout cache path: keyed by PROJECT_ROOT so parallel worktrees don't collide."""
+def _npm_lock_cache_file(hermes_root: Path, scope: str = "") -> Path:
+ """Per-checkout cache path: keyed by PROJECT_ROOT so parallel worktrees don't collide.
+ *scope* separates install closures that share the digest (workspace-scoped vs. full desktop)."""
from hermes_cli.update_cmd import _m
cache_key = hashlib.sha256(str(_m().PROJECT_ROOT).encode()).hexdigest()[:12]
- return hermes_root / f".npm_lock_hash_{cache_key}"
+ return hermes_root / f".npm_lock_hash_{cache_key}{scope}"
-def _record_npm_lockfile_hash(hermes_root: Path) -> None:
+def _record_npm_lockfile_hash(hermes_root: Path, scope: str = "") -> None:
digest = _npm_manifests_digest()
if digest is None:
return
try:
- _npm_lock_cache_file(hermes_root).write_text(digest, encoding="utf-8")
+ _npm_lock_cache_file(hermes_root, scope).write_text(digest, encoding="utf-8")
except OSError:
logger.debug("Could not write npm lockfile hash cache")
+def _desktop_deps_changed(hermes_root: Path) -> bool:
+ """True when the full-graph root ``npm ci`` the desktop build needs must run again: manifests
+ changed since its last success, or Electron is gone (the workspace-scoped pass-1 install prunes
+ it whenever it runs). See #43837."""
+ from hermes_cli.update_cmd import _m
+ current = _npm_manifests_digest()
+ if current is None or not (_m().PROJECT_ROOT / "node_modules" / "electron" / "package.json").is_file():
+ return True
+ try:
+ return _npm_lock_cache_file(hermes_root, "_desktop").read_text(encoding="utf-8").strip() != current
+ except OSError:
+ return True
+
+
def _repair_node_deps_on_current_checkout(
print_completion,
*,
diff --git a/tests/hermes_cli/test_desktop_half_installed_get_windows.py b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
index 7554534946c..5b810071b67 100644
--- a/tests/hermes_cli/test_desktop_half_installed_get_windows.py
+++ b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
@@ -40,3 +40,32 @@ def test_install_removes_the_half_installed_dir_before_npm_runs(tmp_path, monkey
main_desktop._install_desktop_workspace_deps("npm", {})
assert seen == [False], "npm must run only after the stale dir is gone"
+
+
+def test_install_is_skipped_while_manifests_and_electron_are_unchanged(tmp_path, monkeypatch):
+ """Root `npm ci` re-reifies the whole graph; only manifest changes or a pruned Electron warrant it. See #43837."""
+ import hermes_cli.main as main_mod
+ import hermes_cli.main_web_build as web_build
+ from hermes_constants import get_default_hermes_root
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))
+ (tmp_path / "home").mkdir()
+ monkeypatch.setattr(main_mod, "PROJECT_ROOT", tmp_path)
+ monkeypatch.setattr(main_desktop, "_nixos_build_env", lambda: {})
+ (tmp_path / "package.json").write_text('{"workspaces": ["apps/*"]}', encoding="utf-8")
+ (tmp_path / "package-lock.json").write_text("{}", encoding="utf-8")
+ (tmp_path / "apps" / "desktop").mkdir(parents=True)
+ (tmp_path / "apps" / "desktop" / "package.json").write_text("{}", encoding="utf-8")
+ (tmp_path / "node_modules" / "electron").mkdir(parents=True)
+ (tmp_path / "node_modules" / "electron" / "package.json").write_text("{}", encoding="utf-8")
+ calls: list[Path] = []
+ monkeypatch.setattr(web_build, "_run_npm_install_deterministic",
+ lambda npm, cwd, **kw: calls.append(cwd) or type("R", (), {"returncode": 0})())
+
+ main_desktop._install_desktop_workspace_deps("npm", {})
+ main_desktop._install_desktop_workspace_deps("npm", {})
+ assert calls == [tmp_path], "second build with unchanged manifests must not npm ci again"
+ assert list(get_default_hermes_root().glob(".npm_lock_hash_*_desktop")), "stamp lives beside pass 1's"
+
+ (tmp_path / "apps" / "desktop" / "package.json").write_text('{"name": "bumped"}', encoding="utf-8")
+ main_desktop._install_desktop_workspace_deps("npm", {})
+ assert calls == [tmp_path, tmp_path], "a changed manifest must reinstall"