Skip to content

The agent that grows with you

fix(deps): refuse runtime lazy installer update takeovers

funky-xamarin5e6165562b23
diff --git a/tests/hermes_cli/test_old_updater_shims.py b/tests/hermes_cli/test_old_updater_shims.py
index 66d8a757ab5..522ceaecea7 100644
--- a/tests/hermes_cli/test_old_updater_shims.py
+++ b/tests/hermes_cli/test_old_updater_shims.py
@@ -98,8 +98,7 @@ from tests.compat.old_updater_support import (
("hermes_cli.update_cmd", "get_default_hermes_root", (), {}, None),
("hermes_cli.tools_config", "_pip_install", (["--quiet", "honcho-ai"],), {}, None),
("hermes_cli.tools_config", "_pip_install", (["--quiet", "honcho-ai"],), {"timeout": 120, "capture_output": False}, None),
- ("tools.lazy_deps", "install_specs", ([],), {"timeout": 120}, None),
- ("tools.lazy_deps", "install_specs", (["honcho-ai"],), {"timeout": 120}, None),
+
],
)
def test_retired_dependency_entrypoints_handoff_without_fallback(module, name, args, kwargs, cached, fresh_child, monkeypatch):
@@ -121,6 +120,21 @@ def test_retired_dependency_entrypoints_handoff_without_fallback(module, name, a
assert (args, kwargs) == before
[email protected]("module", ["hermes_cli.main", "hermes_cli.update_cmd"])
[email protected]("name", ["cmd_update", "_cmd_update_impl"])
[email protected]("specs", [[], ["honcho-ai"]])
[email protected]("status", [0, 19])
+def test_lazy_installer_inside_historical_update_hands_off(module, name, specs, status, fresh_child):
+ from tools.lazy_deps import install_specs
+
+ # Run a frozen old-caller-shaped function, not a mocked context detector.
+ namespace = {"__name__": module, "install_specs": install_specs}
+ exec(f"def {name}(specs):\n install_specs(specs, timeout=120)\n raise AssertionError('old fallback resumed')\n", namespace)
+ fresh_child.returncode = status
+ with fresh_child.exits():
+ namespace[name](specs)
+
+
@pytest.mark.parametrize("unpack", [False, True], ids=["path-era", "tuple-era"])
@pytest.mark.parametrize("status", [0, 19])
def test_ensure_uv_stops_both_historical_return_contracts(unpack, status, fresh_child):
diff --git a/tests/tools/test_lazy_deps_runtime.py b/tests/tools/test_lazy_deps_runtime.py
new file mode 100644
index 00000000000..8bf249ac6b5
--- /dev/null
+++ b/tests/tools/test_lazy_deps_runtime.py
@@ -0,0 +1,61 @@
+"""Retired runtime installers must not turn agent construction into an update."""
+from unittest.mock import Mock
+
+import pytest
+
+
[email protected]("specs", [[], ["hindsight-all"], ("honcho-ai",)])
[email protected]("timeout", [0, 120, 300])
+def test_install_specs_reports_unavailable_without_update(specs, timeout, monkeypatch):
+ from hermes_cli import _old_updater
+ from tools.lazy_deps import install_specs
+
+ # Exercise the public API and real handoff code, stopping only at its child
+ # boundary so an unfixed checkout cannot run a real install or Desktop build.
+ child = Mock(return_value=(0, {}))
+ monkeypatch.setattr(_old_updater, "_run_child", child)
+ monkeypatch.setattr(_old_updater, "_result", None)
+ failure = None
+ try:
+ install_specs(specs, timeout=timeout)
+ except BaseException as exc:
+ failure = exc
+ assert isinstance(failure, ImportError), repr(failure)
+ child.assert_not_called()
+
+
[email protected]("module,name", [
+ ("community_plugin", "cmd_update"),
+ ("hermes_cli.main", "serve"),
+ ("hermes_cli.update_cmd", "unrelated"),
+])
+def test_runtime_lookalikes_do_not_start_updates(module, name, monkeypatch):
+ from hermes_cli import _old_updater
+ from tools.lazy_deps import install_specs
+
+ child = Mock(return_value=(0, {}))
+ monkeypatch.setattr(_old_updater, "_run_child", child)
+ monkeypatch.setattr(_old_updater, "_result", None)
+ namespace = {"__name__": module, "install_specs": install_specs}
+ exec(f"def {name}():\n install_specs(['hindsight-all'])\n", namespace)
+ with pytest.raises(ImportError, match="retired"):
+ namespace[name]()
+ child.assert_not_called()
+
+
+def test_runtime_caller_can_keep_running_after_retired_installer(monkeypatch):
+ from hermes_cli import _old_updater
+ from tools.lazy_deps import install_specs
+
+ child = Mock(return_value=(0, {}))
+ monkeypatch.setattr(_old_updater, "_run_child", child)
+ monkeypatch.setattr(_old_updater, "_result", None)
+ # The plugin's ordinary exception handler must see failure, not SystemExit.
+ try:
+ install_specs(["hindsight-all"])
+ except Exception:
+ available = False
+ else:
+ available = True
+ assert available is False
+ child.assert_not_called()
diff --git a/tools/lazy_deps.py b/tools/lazy_deps.py
index d106d2a2121..0a438337d4f 100644
--- a/tools/lazy_deps.py
+++ b/tools/lazy_deps.py
@@ -1,5 +1,6 @@
"""Shims to suppress old updater work until relaunch. New code must not use these."""
+import sys
from typing import NoReturn
from hermes_cli._old_updater import stop_for_relaunch
@@ -12,5 +13,19 @@ def ensure(feature: str, *, prompt: bool = True) -> NoReturn:
def install_specs(specs: list[str] | tuple[str, ...], *, timeout: int = 300) -> NoReturn:
- # Shim to suppress old updater work until relaunch. Do not install or report success.
- stop_for_relaunch()
+ # Plugins still call this retired API during normal agent construction.
+ # Only an actual updater call stack may transfer control to the updater;
+ # argv can still say "serve" or "gateway" when /update runs in-process.
+ frame = sys._getframe(1)
+ try:
+ while frame is not None:
+ if (frame.f_globals.get("__name__") in ("hermes_cli.update_cmd", "hermes_cli.main")
+ and frame.f_code.co_name in ("_cmd_update_impl", "cmd_update")):
+ stop_for_relaunch()
+ frame = frame.f_back
+ finally:
+ del frame
+ raise ImportError(
+ "tools.lazy_deps.install_specs is retired; runtime dependency installation "
+ "is unavailable. Update the plugin to use Hermes package management."
+ )