refactor(plugins): unify provider registration and unload paths in hermes_cli/plugins.py
hermes_cli/plugins.py (7193 -> 4961): - _register_scoped_provider: one body for the 8 scope-keyed register_*_provider methods; _track_callback/_track_mapping_entry unify manager-mapping lease tracking (4 sites); _track_scoped_registration for the ownership ledger. Public method names, signatures, return values and warning strings unchanged. - Manifest v2 type checks table-driven (_manifest_field_of_type); _unload_scoped split into _unload_target_keys + _reset_after_unload_all; _gate_manifest/_record_placeholder out of _discover_and_load_inner; _track_tool_override_policy/_attribute_registrations out of _load_plugin_scoped; bounded hook worker lifted into _run_hook_callback_bounded; prompt-section rendering extracted; resolve_pre_tool_block delegates to _dispatch_pre_tool_call_hooks; _evict_modules (3 sites); _remove_name_if_unowned and _nowait_plugin_set unify unowned-name cleanup and *_nowait probes. - Dead (zero references outside their own test): unload_plugins, has_portable_mcp_servers, _classify_entrypoint_kind, _reset_event_bus, get_plugin_subscriptions, get_telegram_handler_factories, pass-through _restore_* helpers; _env_enabled is now an alias of utils.env_var_enabled (plugins/memory still imports it). - Docstrings/comments compacted; contract sentences and rationale kept (multi-profile ledger keying, persistent auth-provider registration, capability declaration is not a grant).
This commit is contained in:
+1199
-3431
File diff suppressed because it is too large
Load Diff
@@ -138,8 +138,6 @@ class TestTelegramAlias:
|
||||
assert mgr.get_platform_handler_factories("telegram") == [
|
||||
(factory, "test_plugin")
|
||||
]
|
||||
# Legacy accessor still works.
|
||||
assert mgr.get_telegram_handler_factories() == [(factory, "test_plugin")]
|
||||
|
||||
def test_alias_non_callable_raises(self):
|
||||
_, ctx = _make_ctx()
|
||||
|
||||
@@ -26,7 +26,6 @@ from hermes_cli.plugins import (
|
||||
PluginContext,
|
||||
PluginManager,
|
||||
PluginManifest,
|
||||
get_plugin_subscriptions,
|
||||
)
|
||||
|
||||
|
||||
@@ -339,35 +338,6 @@ def test_owner_removal_cancels_callback_already_snapshotted_in_queue():
|
||||
assert observed == []
|
||||
|
||||
|
||||
def test_event_bus_reset_cancels_queued_generation():
|
||||
manager = _fresh_manager()
|
||||
ctx_gate = _make_ctx(manager, "gate", key="gate")
|
||||
ctx_a = _make_ctx(manager, "plugin_a", key="a")
|
||||
ctx_b = _make_ctx(manager, "plugin_b", key="b")
|
||||
entered = threading.Event()
|
||||
release = threading.Event()
|
||||
observed = []
|
||||
|
||||
def blocking(**payload):
|
||||
entered.set()
|
||||
release.wait(timeout=2.0)
|
||||
|
||||
ctx_gate.subscribe("b:ping", blocking)
|
||||
ctx_a.subscribe("b:ping", lambda **payload: observed.append(payload))
|
||||
assert ctx_b.emit("ping", {"value": 1}) == 2
|
||||
assert entered.wait(timeout=1.0)
|
||||
old_worker = manager._event_worker
|
||||
|
||||
manager._reset_event_bus()
|
||||
release.set()
|
||||
assert old_worker is not None
|
||||
old_worker.join(timeout=2.0)
|
||||
|
||||
assert not old_worker.is_alive()
|
||||
assert observed == []
|
||||
assert manager._subscriptions == {}
|
||||
|
||||
|
||||
# ── 5. Recursion cap ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -465,23 +435,6 @@ def test_manifest_parse_absent_emits_listens(tmp_path):
|
||||
assert manifest.listens == []
|
||||
|
||||
|
||||
# ── Module-level accessor ────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_get_plugin_subscriptions_accessor(monkeypatch):
|
||||
from hermes_cli import plugins as plugins_mod
|
||||
|
||||
fresh = _fresh_manager()
|
||||
monkeypatch.setattr(plugins_mod, "_ensure_plugins_discovered", lambda force=False: fresh)
|
||||
|
||||
ctx = _make_ctx(fresh, "plugin_a", key="a")
|
||||
ctx.subscribe("b:ping", lambda **p: None)
|
||||
|
||||
subs = get_plugin_subscriptions()
|
||||
assert "b:ping" in subs
|
||||
assert len(subs["b:ping"]) == 1
|
||||
|
||||
|
||||
# ── 7. plugins show output includes emits/listens ────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user