Skip to content

The agent that grows with you

fix(plugins): do not copy a home that merely contains a plugin checkout

xxxigm831637fe8d58
diff --git a/hermes_cli/plugin_dev.py b/hermes_cli/plugin_dev.py
index 80224ce6410..329d08aa885 100644
--- a/hermes_cli/plugin_dev.py
+++ b/hermes_cli/plugin_dev.py
@@ -212,19 +212,33 @@ def _has_manifest(path: Path) -> bool:
return any((path / name).exists() or (path / name).is_symlink() for name in _MANIFEST_NAMES)
+def _ignored_category_child(name: str) -> bool:
+ """Cache and VCS dirs are not plugin siblings. ``.hermes`` is: a home that
+ contains it next to a checkout is not a category layout."""
+ return name in {".git", ".pytest_cache"} or (
+ name.startswith("__") and name.endswith("__")
+ )
+
+
def _holds_plugin(path: Path) -> bool:
"""True when discovery would find a manifest in *path* or one immediate subdirectory (category
layout), mirroring ``PluginManager._scan_directory``. Doctor copies the resolved directory
- wholesale, so resolving an arbitrary directory (e.g. the default ``.``) would be a disk bug."""
+ wholesale, so resolving an arbitrary directory (e.g. the default ``.``) would be a disk bug.
+
+ A category's immediate subdirectories are plugins. One plugin checkout next to other
+ directories, such as ``$HOME`` beside ``.hermes``, is not a category."""
if not path.is_dir():
return False
if _has_manifest(path):
return True
try:
- children = sorted(path.iterdir())
+ children = [
+ child for child in path.iterdir()
+ if child.is_dir() and not _ignored_category_child(child.name)
+ ]
except OSError:
return False
- return any(child.is_dir() and _has_manifest(child) for child in children)
+ return bool(children) and all(_has_manifest(child) for child in children)
def _is_plugin_id(raw: str) -> bool:
diff --git a/tests/hermes_cli/test_plugin_dev.py b/tests/hermes_cli/test_plugin_dev.py
index 472e0aaa642..068be7ff45c 100644
--- a/tests/hermes_cli/test_plugin_dev.py
+++ b/tests/hermes_cli/test_plugin_dev.py
@@ -150,6 +150,41 @@ def test_doctor_default_target_does_not_copy_cwd(
assert copied == []
+def test_doctor_does_not_copy_home_with_a_plugin_checkout(
+ tmp_path: Path, monkeypatch
+) -> None:
+ """A home with one plugin checkout next to other directories is not a category.
+
+ ``_holds_plugin`` used to accept any immediate child manifest, so
+ ``hermes plugins doctor`` from ``$HOME`` resolved to the home and
+ ``copytree`` copied it. A category directory's children are plugins.
+ """
+ import os
+
+ from hermes_cli import plugin_dev
+
+ home = tmp_path / "fake-home"
+ (home / ".hermes" / "cache" / "scratch").mkdir(parents=True)
+ plugin = home / "plugin-checkout"
+ plugin.mkdir()
+ (plugin / "plugin.yaml").write_text("name: checkout\n", encoding="utf-8")
+ monkeypatch.chdir(home)
+
+ copied: list[str] = []
+
+ def _stub(src, dst, *args, **kwargs):
+ copied.append(os.fspath(src))
+ raise RuntimeError("copytree must not run")
+
+ monkeypatch.setattr(plugin_dev.shutil, "copytree", _stub)
+
+ assert plugin_dev.resolve_plugin_path(plugin) == plugin.resolve()
+ report = plugin_dev.doctor_plugin(".")
+ assert copied == []
+ assert report.ok is False
+ assert "holds no plugin manifest" in report.format_text()
+
+
def test_resolve_accepts_category_layout(tmp_path: Path) -> None:
"""A category directory holds no manifest itself but discovery finds one."""
from hermes_cli.plugin_dev import resolve_plugin_path