diff --git a/src/nooa/skill.py b/src/nooa/skill.py index 8773d7e4c..a85ea19f8 100644 --- a/src/nooa/skill.py +++ b/src/nooa/skill.py @@ -208,7 +208,7 @@ def _parse_skill_md(path: Path) -> tuple[str, str, str]: props = _read_skill_properties(path) description = props.description or path.name - _, body = _parse_frontmatter(skill_md.read_text()) + _, body = _parse_frontmatter(skill_md.read_text(encoding="utf-8")) return skill_id, description, body.strip() diff --git a/tests/unit/test_skill.py b/tests/unit/test_skill.py index 61c917e41..f0c26d960 100644 --- a/tests/unit/test_skill.py +++ b/tests/unit/test_skill.py @@ -29,12 +29,27 @@ def test_skill_path_loads_id(skill_dir): def test_skill_path_creates_dynamic_subclass(skill_dir): + """A path-loaded skill exposes its description through a generated skill subclass.""" skill = TextSkill(path=skill_dir) assert type(skill).__name__ != "Skill" assert "Best practices for Git" in (type(skill).__doc__ or "") +def test_skill_body_preserves_utf8_with_legacy_default(skill_dir, monkeypatch): + """UTF-8 instructions reach the skill docstring unchanged under a legacy locale.""" + body = "Budget: 50€ → café 中文 🚀" + (skill_dir / "SKILL.md").write_text( + f"---\nname: git-workflow\ndescription: Unicode instructions\n---\n{body}\n", + encoding="utf-8", + ) + monkeypatch.setattr("io.text_encoding", lambda encoding, stacklevel=2: encoding or "cp1252") + skill = TextSkill(path=skill_dir) + assert skill.description == "Unicode instructions" + assert (type(skill).__doc__ or "").split("\n---\n", 1)[1] == body + + def test_skill_content_constructor(): + """Direct text construction exposes the provided instructions in the skill docstring.""" skill = Skill(content="A helpful skill.") assert "A helpful skill." in (type(skill).__doc__ or "")