fix(skills): resolve skill_view by frontmatter name when dir name differs
skills_list() surfaces each skill's frontmatter `name:`, but skill_view() only matched on the on-disk directory name (Strategy 2). When a skill's directory is a shorter category/alias that differs from its frontmatter name, skill_view(name) failed to find it. Extend the recursive Strategy-2 walk to also match frontmatter `name:`, guarded by a try/except so an unreadable/malformed SKILL.md can't break discovery. Adds a regression test that creates a skill whose directory name differs from its frontmatter name and asserts skill_view resolves it (fails on current main, passes with this change). Salvaged the skill_view fix from #39682 onto current main as a standalone, single-concern change with the test the original PR lacked. Co-authored-by: foras910521-lab <foras910521-lab@users.noreply.github.com>
This commit is contained in:
co-authored by
foras910521-lab
parent
bf7abc2f73
commit
9caa12f4ec
@@ -373,6 +373,26 @@ class TestSkillView:
|
||||
assert result["name"] == "my-skill"
|
||||
assert "Step 1" in result["content"]
|
||||
|
||||
def test_view_skill_by_frontmatter_name_when_dir_differs(self, tmp_path):
|
||||
# The on-disk directory ("alias-dir") differs from the skill's
|
||||
# frontmatter name ("real-skill-name"). skills_list() exposes the
|
||||
# frontmatter name, so skill_view(name) must resolve it too.
|
||||
skill_dir = tmp_path / "alias-dir"
|
||||
skill_dir.mkdir(parents=True, exist_ok=True)
|
||||
(skill_dir / "SKILL.md").write_text(
|
||||
"---\n"
|
||||
"name: real-skill-name\n"
|
||||
"description: A skill whose directory name differs from its name.\n"
|
||||
"---\n\n"
|
||||
"# real-skill-name\n\n"
|
||||
"Step 1: Do the thing.\n"
|
||||
)
|
||||
with patch("tools.skills_tool.SKILLS_DIR", tmp_path):
|
||||
raw = skill_view("real-skill-name")
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is True
|
||||
assert "Step 1" in result["content"]
|
||||
|
||||
def test_skill_view_applies_template_vars(self, tmp_path):
|
||||
with (
|
||||
patch("tools.skills_tool.SKILLS_DIR", tmp_path),
|
||||
|
||||
Reference in New Issue
Block a user