|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from pathlib import Path |
3 | 4 | from unittest.mock import MagicMock |
4 | 5 | from unittest.mock import create_autospec |
5 | 6 | from unittest.mock import patch |
@@ -292,3 +293,46 @@ def test_mcp_servers_and_shell_skills_coexist(self, tmp_path, monkeypatch): |
292 | 293 | assert len(agent.agent.mcp_servers) == 1 |
293 | 294 | shell_tools = [t for t in agent.agent.tools if isinstance(t, ShellTool)] |
294 | 295 | assert len(shell_tools) == 1 |
| 296 | + |
| 297 | + def test_unreadable_utf8_skill_file_is_skipped(self, tmp_path, monkeypatch): |
| 298 | + bad = tmp_path / "bad-skill" |
| 299 | + bad.mkdir() |
| 300 | + (bad / "SKILL.md").write_bytes(b"\xff\xfe\x00\x00") |
| 301 | + |
| 302 | + good = tmp_path / "good-skill" |
| 303 | + good.mkdir() |
| 304 | + (good / "SKILL.md").write_text("---\nname: good-skill\ndescription: good\n---\n") |
| 305 | + |
| 306 | + monkeypatch.setattr("bot.agents.SKILLS_DIR", tmp_path) |
| 307 | + |
| 308 | + agent = OpenAIAgent.from_dict("test", {"mcpServers": {}}) |
| 309 | + shell_tool = next(t for t in agent.agent.tools if isinstance(t, ShellTool)) |
| 310 | + skills = shell_tool.environment["skills"] |
| 311 | + assert len(skills) == 1 |
| 312 | + assert skills[0]["name"] == "good-skill" |
| 313 | + |
| 314 | + def test_oserror_reading_skill_file_is_skipped(self, tmp_path, monkeypatch): |
| 315 | + bad = tmp_path / "bad-skill" |
| 316 | + bad.mkdir() |
| 317 | + bad_file = bad / "SKILL.md" |
| 318 | + bad_file.write_text("---\nname: bad\ndescription: bad\n---\n") |
| 319 | + |
| 320 | + good = tmp_path / "good-skill" |
| 321 | + good.mkdir() |
| 322 | + (good / "SKILL.md").write_text("---\nname: good-skill\ndescription: good\n---\n") |
| 323 | + |
| 324 | + original_read_text = Path.read_text |
| 325 | + |
| 326 | + def _read_text(self: Path, *args, **kwargs): |
| 327 | + if self == bad_file: |
| 328 | + raise OSError("permission denied") |
| 329 | + return original_read_text(self, *args, **kwargs) |
| 330 | + |
| 331 | + monkeypatch.setattr("bot.agents.SKILLS_DIR", tmp_path) |
| 332 | + monkeypatch.setattr(Path, "read_text", _read_text) |
| 333 | + |
| 334 | + agent = OpenAIAgent.from_dict("test", {"mcpServers": {}}) |
| 335 | + shell_tool = next(t for t in agent.agent.tools if isinstance(t, ShellTool)) |
| 336 | + skills = shell_tool.environment["skills"] |
| 337 | + assert len(skills) == 1 |
| 338 | + assert skills[0]["name"] == "good-skill" |
0 commit comments