Skip to content

The agent that grows with you

fix(update): clear the desktop install stamp before each attempt; one stamp comparator

kshitijk4poord5b80c637730
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.py
index 176144a4037..fe8d9aee1bf 100644
--- a/hermes_cli/main_desktop.py
+++ b/hermes_cli/main_desktop.py
@@ -1423,13 +1423,14 @@ 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_cli.update_cmd_deps import _desktop_deps_changed, _record_npm_lockfile_hash
+ from hermes_cli.update_cmd_deps import _clear_npm_lockfile_hash, _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...")
+ _clear_npm_lockfile_hash(hermes_root, "_desktop")
_remove_half_installed_get_windows(PROJECT_ROOT)
# Managed Node on PATH so npm's child scripts that shell out to bare `node`
# (e.g. electron-winstaller's select-7z-arch.js) resolve it even when the
diff --git a/hermes_cli/update_cmd_deps.py b/hermes_cli/update_cmd_deps.py
index 3916ceb09b2..10d12229e69 100644
--- a/hermes_cli/update_cmd_deps.py
+++ b/hermes_cli/update_cmd_deps.py
@@ -6,6 +6,7 @@ import logging
from contextlib import suppress
import hashlib
import json
+import contextlib
import os
import shutil
import subprocess
@@ -528,13 +529,7 @@ def _npm_lockfile_changed(hermes_root: Path) -> bool:
if (web_dir / "package.json").is_file() and not _web_build_toolchain_ready(
*_web_toolchain_roots(web_dir)):
return True
- try:
- cache_file = _npm_lock_cache_file(hermes_root)
- if not cache_file.exists():
- return True
- return cache_file.read_text(encoding="utf-8").strip() != current
- except OSError:
- return True
+ return not _npm_stamp_matches(hermes_root, current)
def _npm_lock_cache_file(hermes_root: Path, scope: str = "") -> Path:
@@ -545,6 +540,21 @@ def _npm_lock_cache_file(hermes_root: Path, scope: str = "") -> Path:
return hermes_root / f".npm_lock_hash_{cache_key}{scope}"
+def _npm_stamp_matches(hermes_root: Path, current: str, scope: str = "") -> bool:
+ """True when the recorded digest for *scope* equals *current*; a missing/unreadable stamp never matches."""
+ try:
+ return _npm_lock_cache_file(hermes_root, scope).read_text(encoding="utf-8").strip() == current
+ except OSError:
+ return False
+
+
+def _clear_npm_lockfile_hash(hermes_root: Path, scope: str = "") -> None:
+ """Drop the stamp before an install attempt: it is written on success only, so a stale one must not
+ outlive a failed reinstall (or the next update would skip the repair)."""
+ with contextlib.suppress(OSError):
+ _npm_lock_cache_file(hermes_root, scope).unlink()
+
+
def _record_npm_lockfile_hash(hermes_root: Path, scope: str = "") -> None:
digest = _npm_manifests_digest()
if digest is None:
@@ -563,10 +573,7 @@ def _desktop_deps_changed(hermes_root: Path) -> bool:
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
+ return not _npm_stamp_matches(hermes_root, current, "_desktop")
def _repair_node_deps_on_current_checkout(
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 5b810071b67..524d5ad9af9 100644
--- a/tests/hermes_cli/test_desktop_half_installed_get_windows.py
+++ b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
@@ -69,3 +69,37 @@ def test_install_is_skipped_while_manifests_and_electron_are_unchanged(tmp_path,
(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"
+
+
+def test_failed_reinstall_drops_the_stamp_so_the_next_update_repairs(tmp_path, monkeypatch):
+ """The stamp is written on success only; an interrupted full `npm ci` after a code-only update
+ must not leave an older matching stamp behind, or the half-installed tree is never revisited."""
+ import pytest
+
+ 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")
+ electron = tmp_path / "node_modules" / "electron"
+ electron.mkdir(parents=True)
+ (electron / "package.json").write_text("{}", encoding="utf-8")
+ codes = [0, 1, 0]
+ monkeypatch.setattr(web_build, "_run_npm_install_deterministic",
+ lambda npm, cwd, **kw: type("R", (), {"returncode": codes.pop(0)})())
+
+ main_desktop._install_desktop_workspace_deps("npm", {}) # success → stamp
+ (electron / "package.json").unlink() # pass 1 pruned Electron → full install needed
+ with pytest.raises(SystemExit):
+ main_desktop._install_desktop_workspace_deps("npm", {}) # interrupted mid-extract
+ (electron / "package.json").write_text("{}", encoding="utf-8") # partially reified tree
+
+ assert not list(get_default_hermes_root().glob(".npm_lock_hash_*_desktop"))
+ main_desktop._install_desktop_workspace_deps("npm", {})
+ assert codes == [], "the next update must run the install again, not skip on the stale stamp"