返回 last30days-skill
test_skill_md_support_paths.py
根目录 / tests / hermes / test_skill_md_support_paths.py
1 """Regression guard: every support path SKILL.md mentions must be a file.
2
3 Hermes (NousResearch/hermes-agent, tools/skills_hub_models.py
4 `_referenced_support_paths`) scans SKILL.md for path-like tokens under
5 references/, templates/, scripts/, assets/ and examples/. When one of them is
6 a directory in the repo tree rather than a file, Hermes treats it like a
7 symlink escape and rejects the whole bundle. The user then sees "listed in the
8 skills-sh index, but its files no longer exist upstream" from
9 `hermes skills install mvanhorn/last30days-skill/skills/last30days`, which is
10 what kept #1502 broken after the scanner fix: SKILL.md named `scripts/lib/`
11 and `scripts/lib/vendor/bird-search/`.
12
13 The regexes are copied verbatim from hermes-agent 27e38935. Mention a folder
14 in prose without the leading support-dir prefix (for example "the `lib`
15 folder"), or name a file inside it.
16 """
17 from __future__ import annotations
18
19 import re
20 from pathlib import Path
21
22 SKILL_ROOT = Path(__file__).resolve().parents[2] / "skills" / "last30days"
23
24 _ALLOWED_SUPPORT_DIRS = frozenset({"references", "templates", "scripts", "assets", "examples"})
25 _LOCAL_LINK_RE = re.compile(
26 r"(?:\]\(|`|(?:^|[\s\"']))((?:references|templates|scripts|assets|examples)/[^\s)`\"'<>]+)", re.MULTILINE)
27
28
29 def _referenced_paths(text: str) -> set[str]:
30 paths = set()
31 for match in _LOCAL_LINK_RE.finditer(text.replace("\\", "/")):
32 candidate = match.group(1).rstrip(".,;:").split("?", 1)[0].split("#", 1)[0]
33 safe = candidate.strip("/")
34 if safe.split("/", 1)[0] not in _ALLOWED_SUPPORT_DIRS:
35 continue
36 base = safe.rsplit("/", 1)[-1]
37 if re.search(r"[*?<>]", safe) or not re.search(r"[A-Za-z0-9]$", base):
38 continue
39 paths.add(safe)
40 return paths
41
42
43 def test_skill_md_support_paths_are_files():
44 referenced = _referenced_paths((SKILL_ROOT / "SKILL.md").read_text(encoding="utf-8"))
45 assert referenced, "expected SKILL.md to reference its support files"
46 not_files = sorted(p for p in referenced if (SKILL_ROOT / p).exists() and not (SKILL_ROOT / p).is_file())
47 assert not not_files, (
48 "SKILL.md names these as support paths but they are directories; Hermes rejects the whole "
49 "install bundle for this:\n " + "\n ".join(not_files)
50 )
51
52
53 def test_extractor_matches_hermes_on_directory_mentions():
54 found = _referenced_paths("Bundled: `scripts/lib/` and `scripts/lib/vendor/bird-search/` and `scripts/last30days.py`")
55 assert found == {"scripts/lib", "scripts/lib/vendor/bird-search", "scripts/last30days.py"}
56
56 lines PYTHON