Files
hermes-agent/tests/hermes_cli/test_single_query_plugin_cli_ref.py
teknium1 07347414ed fix: keep cron-provider plugins out of the general PluginManager
With `chronos` in plugins.enabled every start warned
"Failed to load plugin 'chronos': 'PluginContext' object has no attribute
'register_cron_scheduler'": collect_directory_manifests skipped the bundled
memory/context_engine/model-providers categories but not cron_providers, and a
user-installed cron provider under ~/.hermes/plugins/<name> was never
auto-coerced to kind=exclusive. Cron providers activate through
plugins.cron_providers (cron.provider config), so the general manager must only
record them, exactly like memory providers.

Fixes #62951
credit: @wdmason #100362 (slim redo; #100396 is the consolidated duplicate)
2026-09-21 23:38:16 -07:00

49 lines
1.9 KiB
Python

"""``hermes chat -q``/``-Q`` runs give plugins the CLI reference like the interactive loop does.
Only ``HermesCLI.run()`` set ``PluginManager._cli_ref``, so a plugin tool dispatched from a one-shot
turn saw ``_cli_ref is None`` and ``PluginContext.dispatch_tool`` injected no ``parent_agent`` (#67597).
"""
from __future__ import annotations
from types import SimpleNamespace
import pytest
import cli
from hermes_cli.plugins import get_plugin_manager
@pytest.fixture(autouse=True)
def _one_shot_seams(monkeypatch):
monkeypatch.delenv("HERMES_KANBAN_GOAL_MODE", raising=False)
monkeypatch.setattr(cli, "_should_seed_interactive", lambda *a, **k: False)
monkeypatch.setattr(cli, "_collect_query_images", lambda q, i: (q, []))
monkeypatch.setattr(cli, "_collect_kanban_task_images", lambda imgs: [])
monkeypatch.setattr(cli, "_finalize_single_query", lambda c: None)
monkeypatch.setattr(get_plugin_manager(), "_cli_ref", None)
def _stub(**extra):
return SimpleNamespace(
_single_query_mode=False, _claim_active_session=lambda *a, **k: True,
console=SimpleNamespace(print=lambda *a, **k: None), _show_security_advisories=lambda: None,
chat=lambda *a, **k: "response", _print_exit_summary=lambda **k: None,
_last_turn_result={"failed": False}, **extra,
)
def test_one_shot_turn_binds_the_cli_for_plugins():
stub = _stub()
with pytest.raises(SystemExit):
cli._run_single_query_mode(stub, "do the thing", None, False, True)
assert get_plugin_manager()._cli_ref is stub
def test_quiet_turn_binds_the_cli_for_plugins():
stub = _stub(_ensure_runtime_credentials=lambda: False, _credentials_rate_limited=False,
session_id="s1", model="m")
with pytest.raises(SystemExit):
cli._run_single_query_mode(stub, "do the thing", None, True, True)
assert get_plugin_manager()._cli_ref is stub