Skip to content

The agent that grows with you

Merge updated tool metrics into skill metrics

Alex Fournier884c2daa1cfa
diff --cc tests/tools/test_skills_hub.py
index 133a728c80a,6703644f621..f894e8adff7
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@@ -1159,45 -1157,283 +1159,322 @@@ class TestInstallPathSafety
assert not (skills_dir / "bad-skill" / "leak.txt").exists()
assert secret.read_text() == "data exfiltration payload\n"
+ def test_install_from_quarantine_rejects_category_bucket_overwrite(self, tmp_path):
+ """Installing a skill whose name matches an existing category directory
+ that contains other skills must NOT silently wipe that entire directory.
+
+ Regression test for GitHub issue #75983: ``hermes skills install … --name
+ research`` deleted the whole ``skills/research/`` category bucket,
+ destroying 16 unrelated skills.
+ """
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ skills_dir.mkdir()
+
+ # Simulate a user-created category bucket with multiple skills.
+ category = skills_dir / "research"
+ category.mkdir()
+ for skill in ("alpha", "bravo", "charlie"):
+ (category / skill).mkdir()
+ (category / skill / "SKILL.md").write_text(f"name: {skill}")
+
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: research\n---\n")
+
+ bundle = hub.SkillBundle(
+ name="research",
+ files={"SKILL.md": "---\nname: research\n---\n"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="research",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ with pytest.raises(ValueError, match="Refusing to overwrite category directory"):
+ hub.install_from_quarantine(
+ q_dir, "research", "", bundle, scan_result,
+ )
+
+ # Verify the category bucket and its skills are intact.
+ assert (category / "alpha" / "SKILL.md").exists()
+ assert (category / "bravo" / "SKILL.md").exists()
+ assert (category / "charlie" / "SKILL.md").exists()
+
+ def test_install_from_quarantine_allows_existing_skill_overwrite(self, tmp_path):
+ """Installing over an existing skill directory (containing SKILL.md) is
+ still allowed — that scenario is already guarded by the lock-file check
+ in do_install()."""
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ skills_dir.mkdir()
+
+ # Existing skill directory with SKILL.md.
+ existing = skills_dir / "my-skill"
+ existing.mkdir()
+ (existing / "SKILL.md").write_text("old content")
+ (existing / "refs").mkdir()
+ (existing / "refs" / "guide.md").write_text("old guide")
+
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: my-skill\n---\nnew")
+ (q_dir / "refs").mkdir()
+ (q_dir / "refs" / "guide.md").write_text("new guide")
+
+ bundle = hub.SkillBundle(
+ name="my-skill",
+ files={"SKILL.md": "---\nname: my-skill\n---\nnew"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="my-skill",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ installed = hub.install_from_quarantine(
+ q_dir, "my-skill", "", bundle, scan_result,
+ )
+
+ # The old directory was replaced by the new one.
+ assert installed.exists()
+ assert (installed / "SKILL.md").read_text().strip() == "---\nname: my-skill\n---\nnew"
+
+ def test_install_from_quarantine_allows_empty_category_dir(self, tmp_path):
+ """Installing into an existing but empty category directory is allowed
+ (no sibling skills to destroy)."""
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ skills_dir.mkdir()
+
+ # Empty category directory (no skills inside).
+ category = skills_dir / "research"
+ category.mkdir()
+
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: research\n---\n")
+
+ bundle = hub.SkillBundle(
+ name="research",
+ files={"SKILL.md": "---\nname: research\n---\n"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="research",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ installed = hub.install_from_quarantine(
+ q_dir, "research", "", bundle, scan_result,
+ )
+
+ assert installed.exists()
+ assert (installed / "SKILL.md").exists()
+
+ def test_install_from_quarantine_rejects_nested_only_category(self, tmp_path):
+ """A category whose skills live only in sub-categories (depth >= 2,
+ e.g. ``mlops/training/<skill>``) must also be protected — the guard
+ must not be fooled by the absence of direct-child skills (#75983)."""
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ # Nested-only category: no skill directly under mlops/, skills at depth 2.
+ for sub, name in (("training", "trl"), ("inference", "vllm")):
+ skill = skills_dir / "mlops" / sub / name
+ skill.mkdir(parents=True)
+ (skill / "SKILL.md").write_text(f"---\nname: {name}\n---\n")
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: mlops\n---\n")
+
+ bundle = hub.SkillBundle(
+ name="mlops",
+ files={"SKILL.md": "---\nname: mlops\n---\n"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="mlops",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ with pytest.raises(ValueError, match="category directory"):
+ hub.install_from_quarantine(
+ q_dir, "mlops", "", bundle, scan_result,
+ )
+
+ # Every nested skill must survive.
+ assert (skills_dir / "mlops" / "training" / "trl" / "SKILL.md").is_file()
+ assert (skills_dir / "mlops" / "inference" / "vllm" / "SKILL.md").is_file()
+
+ def test_install_from_quarantine_rejects_category_inside_skill(self, tmp_path):
+ """Installing with --category naming an existing *skill* directory must
+ be refused: it would create a hybrid skill-plus-category dir whose later
+ update/uninstall rmtree would destroy the nested skill (#75983 sibling)."""
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ # Existing normal skill directory.
+ outer = skills_dir / "devops"
+ outer.mkdir(parents=True)
+ (outer / "SKILL.md").write_text("---\nname: devops\n---\n")
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: docker\n---\n")
+
+ bundle = hub.SkillBundle(
+ name="docker",
+ files={"SKILL.md": "---\nname: docker\n---\n"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="docker",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ with pytest.raises(ValueError, match="existing skill directory"):
+ hub.install_from_quarantine(
+ q_dir, "docker", "devops", bundle, scan_result,
+ )
+
+ # The outer skill is untouched and no hybrid child was created.
+ assert (outer / "SKILL.md").is_file()
+ assert not (outer / "docker").exists()
+
+ def test_install_from_quarantine_rejects_regular_file_collision(self, tmp_path):
+ """A stray regular file at the install path must produce the caller's
+ ValueError contract, not an uncaught NotADirectoryError from iterdir/rmtree."""
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ quarantine_root.mkdir(parents=True)
+
+ (skills_dir / "notes").write_text("not a directory")
+
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir()
+ (q_dir / "SKILL.md").write_text("---\nname: notes\n---\n")
+
+ bundle = hub.SkillBundle(
+ name="notes",
+ files={"SKILL.md": "---\nname: notes\n---\n"},
+ source="community",
+ identifier="x",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="notes",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root):
+ with pytest.raises(ValueError, match="not a directory"):
+ hub.install_from_quarantine(
+ q_dir, "notes", "", bundle, scan_result,
+ )
+
+ assert (skills_dir / "notes").read_text() == "not a directory"
+
+ def test_install_from_quarantine_records_successful_install(self, tmp_path):
+ import tools.skills_hub as hub
+ from tools.skills_guard import ScanResult
+
+ skills_dir = tmp_path / "skills"
+ quarantine_root = skills_dir / ".hub" / "quarantine"
+ q_dir = quarantine_root / "pending"
+ q_dir.mkdir(parents=True)
+ skill_md = "---\nname: good-skill\n---\n\n# Good skill\n"
+ (q_dir / "SKILL.md").write_text(skill_md, encoding="utf-8")
+ bundle = hub.SkillBundle(
+ name="good-skill",
+ files={"SKILL.md": skill_md},
+ source="community",
+ identifier="good/source",
+ trust_level="community",
+ )
+ scan_result = ScanResult(
+ skill_name="good-skill",
+ source="community",
+ trust_level="community",
+ verdict="safe",
+ )
+
+ with patch.object(hub, "SKILLS_DIR", skills_dir), \
+ patch.object(hub, "QUARANTINE_DIR", quarantine_root), \
+ patch("tools.skill_usage.record_installed") as record_installed:
+ installed = hub.install_from_quarantine(
+ q_dir,
+ "good-skill",
+ "",
+ bundle,
+ scan_result,
+ )
+
+ assert installed == skills_dir / "good-skill"
+ assert installed.is_dir()
+ record_installed.assert_called_once_with("good-skill")
+
# ---------------------------------------------------------------------------
# parallel_search_sources — overall_timeout must be honoured even when a