Fix skill frontmatter with UTF-8 BOM (#4533)

🤖 Generated with Codex
This commit is contained in:
苏紫辰 2026-07-22 01:48:40 +08:00 committed by GitHub
commit 16a09f0151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -39,6 +39,8 @@ def parse_frontmatter(content: str) -> tuple[dict[str, Any], str]:
Returns:
Tuple of (frontmatter dict, remaining content)
"""
content = content.removeprefix("\ufeff")
if not content.startswith("---"):
return {}, content

View file

@ -92,6 +92,26 @@ This is my skill content.
assert provider.skill_info.description == "A test skill"
assert len(provider.skill_info.files) == 3
def test_loads_frontmatter_from_utf8_bom_skill(self, tmp_path: Path):
skill_dir = tmp_path / "bom-skill"
skill_dir.mkdir()
(skill_dir / "SKILL.md").write_text(
"\ufeff---\n"
"name: bom-skill\n"
"description: Skill saved with a UTF-8 BOM\n"
"---\n"
"# BOM Skill\n",
encoding="utf-8",
)
provider = SkillProvider(skill_path=skill_dir)
assert provider.skill_info.description == "Skill saved with a UTF-8 BOM"
assert provider.skill_info.frontmatter == {
"name": "bom-skill",
"description": "Skill saved with a UTF-8 BOM",
}
def test_raises_if_directory_missing(self, tmp_path: Path):
with pytest.raises(FileNotFoundError, match="Skill directory not found"):
SkillProvider(skill_path=tmp_path / "nonexistent")