97 lines
2.8 KiB
Python
97 lines
2.8 KiB
Python
"""Tests for agent/skill_utils.py."""
|
|
|
|
from agent.skill_utils import extract_skill_conditions, iter_skill_index_files
|
|
|
|
|
|
def test_metadata_as_dict_with_hermes():
|
|
"""Normal case: metadata is a dict containing hermes keys."""
|
|
frontmatter = {
|
|
"metadata": {
|
|
"hermes": {
|
|
"fallback_for_toolsets": ["toolset_a"],
|
|
"requires_toolsets": ["toolset_b"],
|
|
"fallback_for_tools": ["tool_x"],
|
|
"requires_tools": ["tool_y"],
|
|
}
|
|
}
|
|
}
|
|
result = extract_skill_conditions(frontmatter)
|
|
assert result["fallback_for_toolsets"] == ["toolset_a"]
|
|
assert result["requires_toolsets"] == ["toolset_b"]
|
|
assert result["fallback_for_tools"] == ["tool_x"]
|
|
assert result["requires_tools"] == ["tool_y"]
|
|
|
|
|
|
def test_metadata_as_string_does_not_crash():
|
|
"""Bug case: metadata is a non-dict truthy value (e.g. a YAML string)."""
|
|
frontmatter = {"metadata": "some text"}
|
|
result = extract_skill_conditions(frontmatter)
|
|
assert result == {
|
|
"fallback_for_toolsets": [],
|
|
"requires_toolsets": [],
|
|
"fallback_for_tools": [],
|
|
"requires_tools": [],
|
|
}
|
|
|
|
|
|
def test_metadata_as_none():
|
|
"""metadata key is present but set to null/None."""
|
|
frontmatter = {"metadata": None}
|
|
result = extract_skill_conditions(frontmatter)
|
|
assert result == {
|
|
"fallback_for_toolsets": [],
|
|
"requires_toolsets": [],
|
|
"fallback_for_tools": [],
|
|
"requires_tools": [],
|
|
}
|
|
|
|
|
|
def test_metadata_missing_entirely():
|
|
"""metadata key is absent from frontmatter."""
|
|
frontmatter = {"name": "my-skill", "description": "Does stuff."}
|
|
result = extract_skill_conditions(frontmatter)
|
|
assert result == {
|
|
"fallback_for_toolsets": [],
|
|
"requires_toolsets": [],
|
|
"fallback_for_tools": [],
|
|
"requires_tools": [],
|
|
}
|
|
|
|
|
|
def test_iter_skill_index_files_prunes_dependency_dirs(tmp_path):
|
|
real = tmp_path / "real-skill"
|
|
real.mkdir()
|
|
(real / "SKILL.md").write_text("---\nname: real-skill\n---\n", encoding="utf-8")
|
|
|
|
nested = (
|
|
tmp_path
|
|
/ "bring"
|
|
/ "scripts"
|
|
/ ".venv"
|
|
/ "lib"
|
|
/ "python3.13"
|
|
/ "site-packages"
|
|
/ "typer"
|
|
/ ".agents"
|
|
/ "skills"
|
|
/ "typer"
|
|
)
|
|
nested.mkdir(parents=True)
|
|
(nested / "SKILL.md").write_text("---\nname: typer\n---\n", encoding="utf-8")
|
|
|
|
node_module = (
|
|
tmp_path
|
|
/ "web-skill"
|
|
/ "node_modules"
|
|
/ "dep"
|
|
/ ".agents"
|
|
/ "skills"
|
|
/ "dep"
|
|
)
|
|
node_module.mkdir(parents=True)
|
|
(node_module / "SKILL.md").write_text("---\nname: dep\n---\n", encoding="utf-8")
|
|
|
|
found = list(iter_skill_index_files(tmp_path, "SKILL.md"))
|
|
|
|
assert found == [real / "SKILL.md"]
|