The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(update): trust the npm closure through pm.ensure(verify=False)
kshitijk4poorc3b06d144384
diff --git a/hermes_cli/source_build.py b/hermes_cli/source_build.pyindex c8f672c78a1..606208b715c 100644--- a/hermes_cli/source_build.py+++ b/hermes_cli/source_build.py@@ -26,7 +26,7 @@ def source_product_current(project_root: Path, product: str, out: Path) -> bool:return False-def source_build_env(base_env: dict | None = None, *, explicit: bool = False) -> dict[str, str]:+def source_build_env(base_env: dict | None = None, *, explicit: bool = False, verify: bool = True) -> dict[str, str]:from pm import ensurefrom pm.environments import project_python, running_from_selected_environmentfrom pm.paths import repo_root@@ -43,15 +43,7 @@ def source_build_env(base_env: dict | None = None, *, explicit: bool = False) ->npmrc = get_hermes_home() / "npmrc"if npmrc.is_file():env.setdefault("NPM_CONFIG_USERCONFIG", str(npmrc))- return ensure("npm", base_env=env, explicit=explicit).env---def _tools_recorded(name: str) -> bool:- """Every package in ``name``'s closure has a current recorded install (no re-hash)."""- from pm.install import is_installed- from pm.registry import walk-- return all(is_installed(package.name) for package in walk([name]))+ return ensure("npm", base_env=env, explicit=explicit, verify=verify).envdef run_in_custody(project_root: Path, command: list, label: str, **kwargs):@@ -167,9 +159,9 @@ def build_update_products(project_root: Path, *, desktop: bool) -> None:def node_dependencies() -> None:# Acquiring npm is part of this step: its failure must be reported like the install's.- # The install/update's own PM step verified these tools moments ago; recorded facts- # are enough here, as at startup. Only a missing tool takes the explicit install.- env.update(source_build_env(explicit=not _tools_recorded("npm")))+ # A recorded install is trusted as at startup (re-hashing node+npm costs ~2 s per+ # tail); a missing one is still installed explicitly.+ env.update(source_build_env(explicit=True, verify=False))prepare_source_dependencies(project_root, workspaces, env=env, explicit=True)# Every product compiles from these node_modules: without them there is nothing to build.diff --git a/pm/client.py b/pm/client.pyindex eb5ceee784b..bce938e8676 100644--- a/pm/client.py+++ b/pm/client.py@@ -178,13 +178,14 @@ def _request(operation, arguments, *, callbacks=None, pause_event=None, project_process.wait(timeout=5)-def ensure(name, *, base_env=None, explicit=False, progress=None, pause_event=None, download_progress=None) -> Runner:+def ensure(name, *, base_env=None, explicit=False, verify=True, progress=None, pause_event=None,+ download_progress=None) -> Runner:from pm.install import env_forfrom pm.registry import get_packageif is_runtime():from pm.install import ensure as direct- return direct(name, base_env=base_env, explicit=explicit, progress=progress,+ return direct(name, base_env=base_env, explicit=explicit, verify=verify, progress=progress,pause_event=pause_event, download_progress=download_progress)if not explicit and not isinstance(get_package(name), StatePackage):if not _missing_or_refuse(name):@@ -198,7 +199,9 @@ def ensure(name, *, base_env=None, explicit=False, progress=None, pause_event=Noif download_progress is not None:callbacks["download_progress"] = lambda done, total, ranges: download_progress(done, total, {key: [tuple(row) for row in rows] for key, rows in ranges.items()})- _request("ensure", {"name": name, "explicit": explicit}, callbacks=callbacks, pause_event=pause_event)+ # The worker's default is verify=True: only a lowered check travels in the request.+ _request("ensure", {"name": name, "explicit": explicit, **({} if verify else {"verify": False})},+ callbacks=callbacks, pause_event=pause_event)return Runner(name, env_for(name, base_env=base_env))diff --git a/pm/install.py b/pm/install.pyindex 89b5c210d6f..224d6eaca56 100644--- a/pm/install.py+++ b/pm/install.py@@ -530,8 +530,9 @@ def ensure(``verify`` re-hashes an already-recorded entry and repairs it when thebytes moved. A deliberate install keeps that check. Shell activation- passes ``False``. It trusts the recorded digest, the same check startup- uses, because hashing every tool tree costs seconds per shell.+ and the source-build tail (moments after the install/update's own PM+ step) pass ``False``. It trusts the recorded digest, the same check+ startup uses, because hashing every tool tree costs seconds per call.``progress(stage, done, total, label)`` reports the slow parts of aninstall to a UI, including ordered multi-archive labels.diff --git a/tests/hermes_cli/test_bundled_desktop_launch.py b/tests/hermes_cli/test_bundled_desktop_launch.pyindex 23e8303afc7..496a6d134cb 100644--- a/tests/hermes_cli/test_bundled_desktop_launch.py+++ b/tests/hermes_cli/test_bundled_desktop_launch.py@@ -243,7 +243,7 @@ class TestCmdGuiOnABundle:import pmmonkeypatch.setattr(cli_main, "PROJECT_ROOT", repo)monkeypatch.setattr(source_build, "source_build_env", lambda env, **kwargs: dict(env))- monkeypatch.setattr(pm, "ensure", lambda name, *, base_env: SimpleNamespace(env=base_env))+ monkeypatch.setattr(pm, "ensure", lambda name, *, base_env, **_: SimpleNamespace(env=base_env))monkeypatch.setattr(main_desktop, "_desktop_build_needed", lambda *a, **k: True)monkeypatch.setattr(main_desktop, "_stop_desktop_processes_locking_build", lambda *a, **k: [])monkeypatch.setattr(main_desktop, "_desktop_linux_sandbox_fixup", lambda *a, **k: launcher_ok)diff --git a/tests/hermes_cli/test_desktop_build_git_windows.py b/tests/hermes_cli/test_desktop_build_git_windows.pyindex e4c6096ecc7..9c2aa489498 100644--- a/tests/hermes_cli/test_desktop_build_git_windows.py+++ b/tests/hermes_cli/test_desktop_build_git_windows.py@@ -27,7 +27,7 @@ def test_packaged_desktop_build_restores_pm_git_for_stamp_and_pack(def run(command: list[str], *, env: dict[str, str], **_kwargs: object) -> None:calls.append((command, env))- monkeypatch.setattr(pm, "ensure", lambda *names, base_env: SimpleNamespace(env=installed_git(*names, base_env=base_env)))+ monkeypatch.setattr(pm, "ensure", lambda *names, base_env, **_: SimpleNamespace(env=installed_git(*names, base_env=base_env)))monkeypatch.setattr(main_desktop.subprocess, "run", run)monkeypatch.setattr(main_desktop, "_promote_staged_desktop_app", lambda *_args: desktop / "Hermes.exe")main_desktop.build_prepared_desktop(desktop, source_mode=False, npm="C:\\node\\npm.cmd", env=original)diff --git a/tests/hermes_cli/test_source_build.py b/tests/hermes_cli/test_source_build.pyindex 3593ca5909e..237759c1201 100644--- a/tests/hermes_cli/test_source_build.py+++ b/tests/hermes_cli/test_source_build.py@@ -69,7 +69,7 @@ def test_automatic_build_preserves_pm_admission_intent(monkeypatch):from hermes_cli.source_build import source_build_envintent = []- def acquire(name, *, base_env, explicit):+ def acquire(name, *, base_env, explicit, verify=True):intent.append(explicit)return Runner(name, base_env)monkeypatch.setattr(pm, "ensure", acquire)@@ -108,7 +108,7 @@ def source_checkout(tmp_path, monkeypatch):monkeypatch.delenv("NPM_CONFIG_USERCONFIG", raising=False)acquired = []- def acquire(name, *, base_env=None, explicit=False):+ def acquire(name, *, base_env=None, explicit=False, verify=True):acquired.append(name)assert name == "npm"diff --git a/tests/hermes_cli/test_update_finish.py b/tests/hermes_cli/test_update_finish.pyindex fe2874c2e04..b8dbf12b141 100644--- a/tests/hermes_cli/test_update_finish.py+++ b/tests/hermes_cli/test_update_finish.py@@ -166,8 +166,8 @@ def completion(tmp_path, monkeypatch):from pm.environments import project_python- def provision(name, *, base_env, explicit):- assert name == 'npm' and explicit+ def provision(name, *, base_env, explicit, verify=True):+ assert name == 'npm' and explicit and not verifyassert shutil.which('node', path=base_env['PATH'])assert shutil.which('npm', path=base_env['PATH'])assert base_env['HERMES_PYTHON'] == str(project_python(root))