Files
hermes-agent/tests/test_plugin_compat_warning.py
Teknium 0a5164cebe compat(plugins): tell users which installed plugins break on 2026-09-14, and stop loading them after
hermes_cli/plugin_compat.py is now the single source of truth for the compat window:
  COMPAT_REMOVAL_DATE = 2026-09-14; scan_plugin() statically finds `from F import n`, `import F` + `F.n`,
  alias forms and string targets against compat_manifest.json; compat_report() aggregates over the user's
  ENABLED external (non-bundled) plugins; disable_reason() decides the loader's skip.

Surfaces (all read from that one report):
  * CLI: yellow block under the banner naming plugins + date + `hermes plugins compat` (red + DISABLED after)
  * `hermes plugins compat [--json] [path]`: file:line, old -> new per hit; exit 1 while anything remains;
    `path` lets a plugin author scan their own checkout
  * `hermes doctor`: "Plugin import paths (removed Sep 14, 2026)" section next to the xAI retirement check
  * `hermes update`: post-update notice alongside the FTS/curator notices
  * Desktop: compat_report() writes HERMES_HOME/.plugin-compat-report.json (deleted when clean); Electron
    shows ONE warning dialog per distinct report after the backend is up and persists the dismissal in
    userData/plugin-compat-dismissed.json. A new affected plugin, or the date passing, is a new report.

From the date, PluginManager skips a hitting external plugin before importing it, with the reason in
LoadedPlugin.error ("uses N import path(s) removed on 2026-09-14; run `hermes plugins compat` ...") — the
same path a plugin with a broken register() takes, so nothing else is affected. Escape hatch:
plugins.allow_deprecated_imports: true (config_defaults), which only helps until the compat commit is
actually reverted.

Docs: COMPAT_MANIFEST.md (removal date, what-happens table, author instructions), plugin dev guide section.
Tests: tests/test_plugin_compat_notice.py (scanner forms, report scope, date gate + escape hatch, summary
text, report file lifecycle, loader skip via a real PluginManager), electron/plugin-compat-notice.test.ts
(show once, re-show on a different set or on the date passing, malformed file ignored).

Live A/B on this box with a demo plugin on old paths: before the date it loads and the banner/doctor/report
name it; with today=2026-09-14 it is skipped with the reason and the banner turns red; with the escape
hatch it loads again.
2026-09-04 01:28:31 -07:00

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 on 2026-09-14" 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)]