d63e380324
Every PLUGIN-COMPAT __getattr__ now calls hermes_cli.plugin_compat.warn_once(facade, name, target) before
resolving, emitting a HermesPluginCompatWarning (FutureWarning) once per process per name: old path, new
path, removal target. Importing a facade for its live API stays silent; only resolving a moved name warns.
COMPAT_MANIFEST.md documents the warning and how to silence it during migration.
Verified the runtime never routes through a pointer: every entry point (run_agent, cli, hermes_cli.main,
gateway.run, tui_gateway.server, web_server, model_tools + tool discovery, hermes_state, cron.scheduler,
browser_tool, mcp_tool, kanban, auth) imports clean and `hermes doctor` runs end to end with the warning
promoted to an error.
Also restores the check_compat_pointers CI step to .github/workflows/lint.yml, which a0be177aac dropped
when the compat layer was regenerated (the lint script itself was present; the workflow step was not).
hermes_cli/plugin_compat.py, tests/test_plugin_compat_warning.py and the two-line insert per facade are
part of the compat layer and go away with it.
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""The plugin-compat layer tells plugin authors where a name went, once, and internal code never trips it.
|
|
|
|
Kept alongside the compat layer (tests/test_compat_manifest_targets.py); both are deleted with it.
|
|
"""
|
|
import importlib
|
|
import json
|
|
import warnings
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
MANIFEST = ROOT / "compat_manifest.json"
|
|
pytestmark = pytest.mark.skipif(not MANIFEST.exists(), reason="compat layer removed (scheduled revert)")
|
|
|
|
|
|
def _a_lazy_entry():
|
|
entries = json.loads(MANIFEST.read_text())["entries"]
|
|
e = next(x for x in entries if x["kind"] == "moved-lazy" and x["facade"] == "tools.web_tools")
|
|
return e["facade"], e["name"]
|
|
|
|
|
|
def test_compat_resolution_warns_once_per_name_with_the_new_location():
|
|
from hermes_cli.plugin_compat import HermesPluginCompatWarning, _seen
|
|
facade, name = _a_lazy_entry()
|
|
_seen.discard((facade, name))
|
|
mod = importlib.import_module(facade)
|
|
with warnings.catch_warnings(record=True) as rec:
|
|
warnings.simplefilter("always")
|
|
getattr(mod, name)
|
|
getattr(mod, name)
|
|
ours = [w for w in rec if issubclass(w.category, HermesPluginCompatWarning)]
|
|
assert len(ours) == 1, [str(w.message) for w in rec]
|
|
msg = str(ours[0].message)
|
|
assert f"`{facade}.{name}` moved to `" in msg and "removed in" in msg
|
|
|
|
|
|
def test_importing_the_facade_itself_does_not_warn():
|
|
"""Only RESOLVING a compat name warns; plugins that import the module for its live API stay silent."""
|
|
from hermes_cli.plugin_compat import HermesPluginCompatWarning
|
|
import sys
|
|
sys.modules.pop("tools.web_tools", None)
|
|
with warnings.catch_warnings(record=True) as rec:
|
|
warnings.simplefilter("always")
|
|
importlib.import_module("tools.web_tools")
|
|
assert not [w for w in rec if issubclass(w.category, HermesPluginCompatWarning)]
|