The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(update): fold the post-repair restore into the healthy branch; trim tests
teknium156b9b19a503a
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 3e96f897ee6..72ca4be62d9 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -670,8 +670,8 @@ def _repair_current_checkout(# python-build-standalone refreshes the embedded SQLite; keep the boundary hook here too.from hermes_cli.managed_uv import ensure_uv, update_managed_uvruntime_repairs = []- updated_uv = update_managed_uv(repair_observer=runtime_repairs.append)- ensured_uv = ensure_uv(repair_observer=runtime_repairs.append)+ update_managed_uv(repair_observer=runtime_repairs.append)+ repair_uv = ensure_uv(repair_observer=runtime_repairs.append)runtime_repaired = next((result for result in runtime_repairs if result.repaired), None)# A current checkout does NOT imply a healthy install (a prior sync may have died@@ -694,24 +694,17 @@ def _repair_current_checkout(active_lazy_features=active_lazy_features,active_tool_dependencies=active_tool_dependencies,_windows_gateway_resume=_windows_gateway_resume)- elif runtime_repaired is not None:- # A successful SQLite repair atomically replaces the venv. Core imports can therefore- # be healthy while lazily-installed backends and ``hermes tools`` dependencies vanished.- # Restore the snapshots captured before the cutover without reinstalling the already- # healthy core environment.- repair_prefix, repair_env = _pip_install_prefix(ensured_uv or updated_uv)- _m()._refresh_active_lazy_features(- repair_prefix, env=repair_env, features=active_lazy_features)- _m()._restore_active_tool_dependencies(- active_tool_dependencies, repair_prefix, env=repair_env)- current_checkout_complete = _repair_node_deps_on_current_checkout(- _print_verified_update_completion, assume_yes=assume_yes, gateway_mode=gateway_mode,- pre_update_snapshot_id=pre_update_snapshot_id,- completion_message=(- "✓ Already up to date!" if upstream_checked- else "✓ Up to date with your fork (official repo not checked)."),- had_desktop_app_before_update=had_desktop_app_before_update)else:+ if runtime_repaired is not None:+ # A successful SQLite repair swaps in a venv built from uv.lock alone, so core+ # imports pass while lazily-installed backends and ``hermes tools`` dependencies+ # are gone (#112571). Restore the pre-cutover snapshots exactly as the pull path+ # and the unhealthy-venv repair do; the healthy core set needs no reinstall.+ repair_prefix, repair_env = _pip_install_prefix(repair_uv)+ _m()._refresh_active_lazy_features(+ repair_prefix, env=repair_env, features=active_lazy_features)+ _m()._restore_active_tool_dependencies(+ active_tool_dependencies, repair_prefix, env=repair_env)current_checkout_complete = _repair_node_deps_on_current_checkout(_print_verified_update_completion, assume_yes=assume_yes, gateway_mode=gateway_mode,pre_update_snapshot_id=pre_update_snapshot_id,diff --git a/tests/hermes_cli/test_cmd_update.py b/tests/hermes_cli/test_cmd_update.pyindex 91e33b21b5e..fa5df5d8701 100644--- a/tests/hermes_cli/test_cmd_update.py+++ b/tests/hermes_cli/test_cmd_update.py@@ -263,11 +263,11 @@ class TestUpdateManagedPythonEnvIsolation:assert uv_env.get("UV_NO_CONFIG") == "1"-class TestCmdUpdateBranchFallback:- def test_current_checkout_restores_optional_dependencies_after_runtime_repair(- self, monkeypatch- ):- """A SQLite venv replacement must retain lazy and Hermes Tools installs."""+class TestRepairCurrentCheckoutRuntimeRepair:+ """Already-up-to-date path after a managed SQLite runtime repair (#112571)."""++ @staticmethod+ def _run(monkeypatch, *, repaired: bool):from hermes_cli.managed_uv import RuntimeRepairResultfrom hermes_cli import main as hm@@ -294,12 +294,13 @@ class TestCmdUpdateBranchFallback:update_cmd, "_repair_node_deps_on_current_checkout", lambda *args, **kwargs: True)- def repair(*, repair_observer):- repair_observer(RuntimeRepairResult("repaired"))+ def ensure(*, repair_observer, **_kwargs):+ if repaired:+ repair_observer(RuntimeRepairResult("repaired"))return "uv"- monkeypatch.setattr("hermes_cli.managed_uv.update_managed_uv", repair)- monkeypatch.setattr("hermes_cli.managed_uv.ensure_uv", repair)+ monkeypatch.setattr("hermes_cli.managed_uv.update_managed_uv", ensure)+ monkeypatch.setattr("hermes_cli.managed_uv.ensure_uv", ensure)assert update_cmd._repair_current_checkout(assume_yes=True,@@ -311,12 +312,26 @@ class TestCmdUpdateBranchFallback:upstream_checked=True,_windows_gateway_resume=None,)+ return restored, lazy_features, tool_dependencies+ def test_restores_optional_dependencies_after_runtime_repair(self, monkeypatch):+ """A SQLite venv replacement passes the core-import probe, yet the swapped-in venv was+ built from uv.lock alone: the captured lazy backends and Hermes Tools deps must be+ restored into it, once each, with the repaired installer prefix."""+ restored, lazy_features, tool_dependencies = self._run(monkeypatch, repaired=True)assert restored == [("lazy", ["uv", "pip"], {"VIRTUAL_ENV": "venv"}, lazy_features),("tools", ["uv", "pip"], {"VIRTUAL_ENV": "venv"}, tool_dependencies),]+ def test_healthy_venv_without_runtime_repair_is_left_alone(self, monkeypatch):+ """Control: no repair + healthy core imports = the venv was never replaced, so nothing+ is reinstalled (the up-to-date path stays a no-op for Python deps)."""+ restored, _, _ = self._run(monkeypatch, repaired=False)+ assert restored == []+++class TestCmdUpdateBranchFallback:"""cmd_update falls back to main when current branch has no remote counterpart."""