The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): fail current-checkout runtime verification
fangliquanflq4f19808915d7
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex d710f560b63..a7e10d08067 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -4044,7 +4044,7 @@ def _repair_node_deps_on_current_checkout(gateway_mode: bool = False,pre_update_snapshot_id: str | None = None,completion_message: str = "✓ Already up to date!",-) -> None:+) -> bool:"""Repair Node deps on the ``commit_count == 0`` path (#77211).A current checkout does not imply healthy Node deps: a previous npm@@ -4064,7 +4064,7 @@ def _repair_node_deps_on_current_checkout(print_completion("⚠ Checkout is current, but Node.js dependencies could not be repaired.")- return+ return False# Pair the refresh with the web build like every other# _update_node_dependencies call site; it staleness-checks internally,# so this is a no-op when nothing changed.@@ -4074,7 +4074,7 @@ def _repair_node_deps_on_current_checkout(gateway_mode=gateway_mode,pre_update_snapshot_id=pre_update_snapshot_id,)- print_completion(completion_message)+ return bool(print_completion(completion_message))def _update_node_dependencies() -> list[str]:@@ -8612,6 +8612,7 @@ def _cmd_update_impl(args, gateway_mode: bool):# "Already up to date!" and exits without doing the one job it# was spawned for.handed_off_sync = os.environ.get(_m()._UPDATE_REEXEC_ENV) == "1"+ current_checkout_complete = Trueif handed_off_sync:print("→ Finishing the dependency install handed off by hermes.exe...")elif not healthy:@@ -8687,7 +8688,7 @@ def _cmd_update_impl(args, gateway_mode: bool):print(f"⚠ Venv still unhealthy after repair: {detail_after}")print(" Close all Hermes windows/gateways and re-run: hermes update")else:- _repair_node_deps_on_current_checkout(+ current_checkout_complete = _repair_node_deps_on_current_checkout(_print_verified_update_completion,assume_yes=assume_yes,gateway_mode=gateway_mode,@@ -8709,6 +8710,19 @@ def _cmd_update_impl(args, gateway_mode: bool):)print(" Restart each of them to pick up the repaired runtime.")_m()._resume_windows_gateways_after_update(_windows_gateway_resume)+ if not current_checkout_complete:+ if gateway_mode:+ _write_gateway_update_exit_code(False)+ try:+ from hermes_cli.update_receipt import finalize_update_receipt++ finalize_update_receipt("partial")+ except Exception as _receipt_exc:+ logger.debug(+ "Update receipt finalize (current checkout) failed: %s",+ _receipt_exc,+ )+ sys.exit(1)# Git is current, but a prior pull may still owe the fleet a# restart (#95294). Catch up even on the "Already up to date"# path — that early return is what left the gateway on stalediff --git a/tests/hermes_cli/test_cmd_update.py b/tests/hermes_cli/test_cmd_update.pyindex b889832a5fe..0ca3a52c6c1 100644--- a/tests/hermes_cli/test_cmd_update.py+++ b/tests/hermes_cli/test_cmd_update.py@@ -353,6 +353,42 @@ class TestCmdUpdateBranchFallback:assert "official repo not checked" in captured.outassert "Already up to date!" not in captured.out+ @patch("shutil.which", return_value=None)+ @patch("subprocess.run")+ def test_current_checkout_verification_failure_is_durable(+ self, mock_run, _mock_which, mock_args+ ):+ """A failed runtime check must fail receipts and gateway automation."""+ from hermes_cli import main as hm+ from hermes_cli import update_cmd++ mock_args.gateway = True+ mock_run.side_effect = _make_run_side_effect(+ branch="main", verify_ok=True, commit_count="0"+ )++ with patch.object(+ hm,+ "_get_origin_url",+ return_value="https://github.com/example/hermes-agent.git",+ ), patch.object(hm, "_sync_with_upstream_if_needed"), patch.object(+ update_cmd,+ "_repair_node_deps_on_current_checkout",+ return_value=False,+ ), patch.object(+ update_cmd, "_write_gateway_update_exit_code"+ ) as write_gateway_exit, patch(+ "hermes_cli.update_receipt.finalize_update_receipt"+ ) as finalize_receipt, patch(+ "hermes_cli.update_receipt.finalize_pending_update_receipt"+ ):+ with pytest.raises(SystemExit) as exit_info:+ cmd_update(mock_args)++ assert exit_info.value.code == 1+ write_gateway_exit.assert_called_once_with(False)+ finalize_receipt.assert_called_once_with("partial")+@patch("shutil.which", return_value=None)@patch("subprocess.run")def test_fork_upstream_sync_that_moves_head_runs_post_update_steps(diff --git a/tests/hermes_cli/test_update_sqlite_remediation.py b/tests/hermes_cli/test_update_sqlite_remediation.pyindex ac020aeec57..13d60567046 100644--- a/tests/hermes_cli/test_update_sqlite_remediation.py+++ b/tests/hermes_cli/test_update_sqlite_remediation.py@@ -65,3 +65,14 @@ def test_current_checkout_completion_is_verified_before_success(capsys, monkeypaassert complete is Falseassert "Already up to date" not in outassert "SQLite 3.46.1" in out+++def test_current_checkout_repair_returns_verified_completion_result(monkeypatch):+ monkeypatch.setattr(update_cmd, "_update_node_dependencies", lambda: [])+ monkeypatch.setattr(update_cmd._m(), "_build_web_ui", lambda _path: None)++ complete = update_cmd._repair_node_deps_on_current_checkout(+ lambda _message: False+ )++ assert complete is False