mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-21 04:09:45 +03:00
fix(plugins): a widened pin on the auto-apply tick logs one review line, not a traceback
The tick's default apply is now update_one with no terminal (plugins_auto_update.apply_unattended), so refusals reach the tick as exceptions instead of cmd_update's SystemExit. RepinConsentRequired logs one INFO line naming `hermes plugins update X`; other refusals log one line.
This commit is contained in:
@@ -66,6 +66,18 @@ def held_with_ref(record: Any) -> bool:
|
||||
return isinstance(block, dict) and record.get("pinned") is True and not block.get("pin")
|
||||
|
||||
|
||||
def apply_unattended(name: str) -> None:
|
||||
"""The gateway auto-apply tick's update of one plugin: ``update_one`` with no terminal. Refusals
|
||||
raise (``RepinConsentRequired`` for a widened pin, ``PluginOperationError``) so the tick can tell
|
||||
a pending review from a failure; ``cmd_update`` would turn both into an exit."""
|
||||
from hermes_cli.plugins_cmd_update import update_one
|
||||
pc = _pc()
|
||||
target = pc._user_installed_plugin_dir(name)
|
||||
if target is None:
|
||||
raise pc.PluginOperationError(f"Plugin '{name}' is no longer installed.")
|
||||
update_one(name, target, pc._console(), interactive=False)
|
||||
|
||||
|
||||
# ── the auto-update switch ────────────────────────────────────────────────────────────────────
|
||||
|
||||
def auto_update_state() -> dict[str, Any]:
|
||||
|
||||
@@ -192,8 +192,11 @@ def run_scheduled_check(
|
||||
|
||||
def _auto_apply(updates: list, checked_installs: dict, apply_updates_fn: Callable[[str], None], log) -> None:
|
||||
"""Apply each update row the opt-in tick may move. A catalog install held with ``--ref`` is left
|
||||
where the user put it."""
|
||||
where the user put it. A widened catalog pin is a pending review, not a failure: one line naming
|
||||
the command that walks it, no traceback every tick; other refusals are one line too."""
|
||||
from hermes_cli.plugins_auto_update import HELD_WITH_REF, held_with_ref
|
||||
from hermes_cli.plugins_cmd import PluginOperationError
|
||||
from hermes_cli.plugins_cmd_catalog import RepinConsentRequired
|
||||
|
||||
for r in updates:
|
||||
if getattr(r, "klass", "") not in ("git", "catalog"):
|
||||
@@ -203,6 +206,11 @@ def _auto_apply(updates: list, checked_installs: dict, apply_updates_fn: Callabl
|
||||
continue
|
||||
try:
|
||||
apply_updates_fn(r.name)
|
||||
except RepinConsentRequired:
|
||||
log.info("plugin %s has an update that needs your review: run `hermes plugins update %s`",
|
||||
r.name, r.name)
|
||||
except PluginOperationError as exc:
|
||||
log.warning("auto-apply of %s not applied: %s", r.name, exc)
|
||||
except (Exception, SystemExit):
|
||||
log.warning("auto-apply of %s failed", r.name, exc_info=True)
|
||||
|
||||
@@ -315,10 +323,10 @@ def maybe_run_gateway_check(
|
||||
|
||||
run_checks_fn = run_checks
|
||||
if apply_updates_fn is None:
|
||||
from hermes_cli import plugins_cmd
|
||||
# update_one with no terminal, refusals raised (cmd_update would turn them into an exit)
|
||||
from hermes_cli import plugins_auto_update
|
||||
|
||||
from functools import partial
|
||||
apply_updates_fn = partial(plugins_cmd.cmd_update, interactive=False)
|
||||
apply_updates_fn = plugins_auto_update.apply_unattended
|
||||
return run_scheduled_check(
|
||||
run_checks_fn=run_checks_fn,
|
||||
plugins_dir=plugins_dir,
|
||||
|
||||
@@ -156,3 +156,40 @@ def test_update_all_and_hermes_update_notice_skip_a_held_catalog_install(home, m
|
||||
description="d", maintainer="m") for n in ("held", "behind")]
|
||||
monkeypatch.setattr(plugin_catalog, "load_catalog", lambda catalog_dir=None: entries)
|
||||
assert catalog_pins_behind(home) == ["behind"]
|
||||
|
||||
|
||||
def test_widened_pin_is_one_review_line_not_a_traceback(home, caplog):
|
||||
"""The real tick seam lets a widened catalog pin surface as a pending review naming the command."""
|
||||
from hermes_cli import plugins_auto_update, plugins_cadence as cad
|
||||
from hermes_cli.plugins_cmd_catalog import RepinConsentRequired
|
||||
|
||||
def widened(name):
|
||||
raise RepinConsentRequired(name, "c" * 40, {"tools": ["new_tool"]})
|
||||
|
||||
with caplog.at_level("INFO"):
|
||||
cad.run_scheduled_check(run_checks_fn=lambda _dir: [_Row("wide", "catalog")], plugins_dir=home / "plugins",
|
||||
apply_updates_fn=widened,
|
||||
config_get=lambda _s, key: True if key == "auto_apply" else 24)
|
||||
lines = [r for r in caplog.records if "wide" in r.getMessage()]
|
||||
assert [r.getMessage() for r in lines if "review" in r.getMessage()] == [
|
||||
"plugin wide has an update that needs your review: run `hermes plugins update wide`"]
|
||||
assert not any(r.exc_info for r in lines)
|
||||
|
||||
|
||||
def test_gateway_tick_seam_raises_the_review_instead_of_exiting(home, monkeypatch):
|
||||
"""`maybe_run_gateway_check`'s default apply hands the refusal back (cmd_update turned it into
|
||||
SystemExit, which the tick logged as a failure with a traceback)."""
|
||||
from hermes_cli import plugins_auto_update, plugins_cmd_update
|
||||
from hermes_cli.plugins_cmd_catalog import RepinConsentRequired
|
||||
|
||||
(home / "plugins" / "wide").mkdir()
|
||||
calls = []
|
||||
|
||||
def update_one(name, target, console, *, interactive):
|
||||
calls.append((name, target.name, interactive))
|
||||
raise RepinConsentRequired(name, "c" * 40, {"tools": ["new_tool"]})
|
||||
|
||||
monkeypatch.setattr(plugins_cmd_update, "update_one", update_one)
|
||||
with pytest.raises(RepinConsentRequired):
|
||||
plugins_auto_update.apply_unattended("wide")
|
||||
assert calls == [("wide", "wide", False)]
|
||||
|
||||
@@ -112,7 +112,7 @@ def test_auto_apply_selects_only_updateable_git_and_persists_receipt(homed, enab
|
||||
@pytest.mark.parametrize('failed', [False, True])
|
||||
def test_housekeeping_runs_real_cadence_and_backs_off(homed, monkeypatch, caplog, failed):
|
||||
import gateway.run as gateway
|
||||
from hermes_cli import plugins_updates, plugins_cmd
|
||||
from hermes_cli import plugins_auto_update, plugins_updates, plugins_cmd
|
||||
from pm import receipt
|
||||
|
||||
calls, applied = [], []
|
||||
@@ -123,12 +123,12 @@ def test_housekeeping_runs_real_cadence_and_backs_off(homed, monkeypatch, caplog
|
||||
return [_Result('plug', update_available=True)]
|
||||
monkeypatch.setattr(plugins_updates, 'run_checks', checks)
|
||||
monkeypatch.setattr(plugins_cmd, '_plugins_dir', lambda: homed / 'plugins')
|
||||
monkeypatch.setattr(plugins_cmd, 'cmd_update', lambda name, **kwargs: applied.append((name, kwargs)))
|
||||
monkeypatch.setattr(plugins_auto_update, 'apply_unattended', lambda name, **kwargs: applied.append((name, kwargs)))
|
||||
monkeypatch.setattr(cad, 'auto_apply_enabled', lambda *_: True)
|
||||
for _ in range(2):
|
||||
gateway._housekeeping_chore('Plugin update check', gateway._housekeeping_plugin_update_check)
|
||||
assert calls == [homed / 'plugins']
|
||||
assert applied == ([] if failed else [('plug', {'interactive': False})])
|
||||
assert applied == ([] if failed else [('plug', {})])
|
||||
saved = receipt.latest()
|
||||
assert saved['outcome'] == ('failed' if failed else 'updates-available')
|
||||
assert saved['exit_code'] == int(failed)
|
||||
|
||||
Reference in New Issue
Block a user