poka-yoke: add contextual skill-manager errors
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 25s

This commit is contained in:
Timmy
2026-04-14 15:29:33 -04:00
parent 3f525dd5a1
commit f12e1e69a7
3 changed files with 127 additions and 31 deletions

View File

@@ -6,7 +6,7 @@ Verifies that error messages include file paths, context, and suggestions.
import pytest
from pathlib import Path
from unittest.mock import patch, MagicMock
from tools.skill_manager_tool import _format_error, _edit_skill, _patch_skill
from tools.skill_manager_tool import _format_error, _edit_skill, _patch_skill, skill_manage
class TestFormatError:
@@ -79,6 +79,25 @@ Body content here.
assert "nonexistent" in result["error"]
assert "skills_list()" in result.get("suggestion", "")
@patch('tools.skill_manager_tool._find_skill')
def test_yaml_parse_error_includes_file_path_and_line_number(self, mock_find, tmp_path):
"""Invalid YAML should report target file path and parser line information."""
skill_dir = tmp_path / "my-skill"
skill_dir.mkdir()
(skill_dir / "SKILL.md").write_text("old", encoding="utf-8")
mock_find.return_value = {"path": skill_dir}
bad_content = """---
name: my-skill
description: [broken
---
Body.
"""
result = _edit_skill("my-skill", bad_content)
assert result["success"] is False
assert str(skill_dir / "SKILL.md") in result["error"]
assert "line" in result["error"].lower()
class TestPatchSkillErrors:
"""Test improved error messages in _patch_skill."""
@@ -106,6 +125,28 @@ class TestPatchSkillErrors:
assert "nonexistent" in result["error"]
assert "skills_list()" in result.get("suggestion", "")
@patch('tools.skill_manager_tool._find_skill')
def test_pattern_match_error_includes_state_info(self, mock_find, tmp_path):
"""Patch failures should include file path and patch state info."""
skill_dir = tmp_path / "state-skill"
skill_dir.mkdir()
target = skill_dir / "SKILL.md"
target.write_text("---\nname: state-skill\ndescription: desc\n---\n\nBody content here.\n", encoding="utf-8")
mock_find.return_value = {"path": skill_dir}
result = _patch_skill("state-skill", "missing pattern", "new text", replace_all=False)
assert result["success"] is False
assert str(target) in result["error"]
assert "replace_all" in result["error"]
assert "False" in result["error"]
class TestSkillManageEntryPoint:
def test_patch_missing_old_string_returns_json_error(self):
result = skill_manage(action="patch", name="demo-skill", old_string="", new_string="x")
assert isinstance(result, str)
assert "old_string is required" in result
if __name__ == "__main__":
pytest.main([__file__, "-v"])