Skip to content

The agent that grows with you

test(skills): fold the occupied-directory create tests into the module's test file

kshitijk4poor334f40ee3125
diff --git a/tests/tools/test_skill_create_occupied_directory.py b/tests/tools/test_skill_create_occupied_directory.py
deleted file mode 100644
index c1dedef7ca5..00000000000
--- a/tests/tools/test_skill_create_occupied_directory.py
+++ /dev/null
@@ -1,100 +0,0 @@
-"""Ownership contracts for creating skills in occupied paths."""
-
-from contextlib import contextmanager
-import os
-import sys
-from unittest.mock import patch
-
-from tools.skill_manager_tool import _create_skill
-
-
-VALID_CONTENT = """\
----
-name: new-skill
-description: Use when testing skill creation.
----
-
-# New Skill
-
-Create the thing.
-"""
-
-
-@contextmanager
-def _skill_dir(tmp_path):
- with patch("tools.skill_manager_tool.SKILLS_DIR", tmp_path), \
- patch("agent.skill_utils.get_all_skills_dirs", return_value=[tmp_path]):
- yield
-
-
-def _can_make_unreadable_dir() -> bool:
- # chmod 0 is ignored for root and has no directory-listing effect on Windows.
- return sys.platform != "win32" and hasattr(os, "geteuid") and os.geteuid() != 0
-
-
-def test_occupied_directory_is_preserved_when_scan_blocks(tmp_path):
- with _skill_dir(tmp_path), patch("tools.skill_manager_tool._security_scan_skill", return_value="blocked"):
- target = tmp_path / "new-skill"
- target.mkdir()
- data = target / "data.bin"
- data.write_bytes(b"keep me")
- result = _create_skill("new-skill", VALID_CONTENT)
-
- # An EMPTY pre-existing directory (leftover of an earlier failed create) is a valid target;
- # a blocked scan removes what create wrote and the then-empty dir (rmdir, never rmtree).
- empty = tmp_path / "empty-skill"
- empty.mkdir()
- empty_result = _create_skill("empty-skill", VALID_CONTENT)
-
- # A directory create made itself is its own to remove when the scan blocks.
- fresh_result = _create_skill("fresh-skill", VALID_CONTENT)
-
- # A directory create cannot even list is somebody's: refuse cleanly, never raise.
- unreadable_result = None
- if _can_make_unreadable_dir():
- unreadable = tmp_path / "unreadable-skill"
- unreadable.mkdir()
- unreadable.chmod(0)
- try:
- unreadable_result = _create_skill("unreadable-skill", VALID_CONTENT)
- finally:
- unreadable.chmod(0o700)
-
- assert result["success"] is False
- assert "Choose another name" in result["error"]
- assert data.read_bytes() == b"keep me"
- assert target.is_dir()
- assert not (target / "SKILL.md").exists()
-
- assert empty_result["success"] is False
- assert not empty.exists()
-
- assert fresh_result["success"] is False
- assert not (tmp_path / "fresh-skill").exists()
-
- if unreadable_result is not None:
- assert unreadable_result["success"] is False
- assert "Choose another name" in unreadable_result["error"]
- assert not (unreadable / "SKILL.md").exists()
-
-
-def test_occupied_directory_is_refused_and_empty_leftover_is_reused(tmp_path):
- with _skill_dir(tmp_path), patch("tools.skill_manager_tool._security_scan_skill", return_value=None):
- category = tmp_path / "category"
- category.mkdir()
- nested = category / "nested-skill.md"
- nested.write_bytes(b"nested")
- result = _create_skill("category", VALID_CONTENT)
-
- # Empty pre-existing directory + clean scan: create succeeds (retry after a leftover works).
- empty = tmp_path / "empty-skill"
- empty.mkdir()
- empty_result = _create_skill("empty-skill", VALID_CONTENT)
-
- assert result["success"] is False
- assert "Choose another name" in result["error"]
- assert nested.read_bytes() == b"nested"
- assert not (category / "SKILL.md").exists()
-
- assert empty_result["success"] is True
- assert (empty / "SKILL.md").exists()
diff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.py
index e86873200bd..caa003a366a 100644
--- a/tests/tools/test_skill_manager_tool.py
+++ b/tests/tools/test_skill_manager_tool.py
@@ -1,6 +1,8 @@
"""Tests for tools/skill_manager_tool.py — skill creation, editing, and deletion."""
import json
+import os
+import sys
import threading
from contextlib import contextmanager
from contextvars import copy_context
@@ -143,6 +145,11 @@ class TestValidateFilePath:
# ---------------------------------------------------------------------------
+def _can_make_unreadable_dir() -> bool:
+ # chmod 0 is ignored for root and has no directory-listing effect on Windows.
+ return sys.platform != "win32" and hasattr(os, "geteuid") and os.geteuid() != 0
+
+
class TestCreateSkill:
def test_create_skill(self, tmp_path):
with _skill_dir(tmp_path):
@@ -168,6 +175,71 @@ class TestCreateSkill:
assert result["success"] is False
assert not (tmp_path / "escape").exists()
+ def test_occupied_directory_is_preserved_when_scan_blocks(self, tmp_path):
+ with _skill_dir(tmp_path), patch("tools.skill_manager_tool._security_scan_skill", return_value="blocked"):
+ target = tmp_path / "new-skill"
+ target.mkdir()
+ data = target / "data.bin"
+ data.write_bytes(b"keep me")
+ result = _create_skill("new-skill", VALID_SKILL_CONTENT)
+
+ # An EMPTY pre-existing directory (leftover of an earlier failed create) is a valid target;
+ # a blocked scan removes what create wrote and the then-empty dir (rmdir, never rmtree).
+ empty = tmp_path / "empty-skill"
+ empty.mkdir()
+ empty_result = _create_skill("empty-skill", VALID_SKILL_CONTENT)
+
+ # A directory create made itself is its own to remove when the scan blocks.
+ fresh_result = _create_skill("fresh-skill", VALID_SKILL_CONTENT)
+
+ # A directory create cannot even list is somebody's: refuse cleanly, never raise.
+ unreadable_result = None
+ if _can_make_unreadable_dir():
+ unreadable = tmp_path / "unreadable-skill"
+ unreadable.mkdir()
+ unreadable.chmod(0)
+ try:
+ unreadable_result = _create_skill("unreadable-skill", VALID_SKILL_CONTENT)
+ finally:
+ unreadable.chmod(0o700)
+
+ assert result["success"] is False
+ assert "Choose another name" in result["error"]
+ assert data.read_bytes() == b"keep me"
+ assert target.is_dir()
+ assert not (target / "SKILL.md").exists()
+
+ assert empty_result["success"] is False
+ assert not empty.exists()
+
+ assert fresh_result["success"] is False
+ assert not (tmp_path / "fresh-skill").exists()
+
+ if unreadable_result is not None:
+ assert unreadable_result["success"] is False
+ assert "Choose another name" in unreadable_result["error"]
+ assert not (unreadable / "SKILL.md").exists()
+
+ def test_occupied_directory_is_refused_and_empty_leftover_is_reused(self, tmp_path):
+ with _skill_dir(tmp_path), patch("tools.skill_manager_tool._security_scan_skill", return_value=None):
+ category = tmp_path / "category"
+ category.mkdir()
+ nested = category / "nested-skill.md"
+ nested.write_bytes(b"nested")
+ result = _create_skill("category", VALID_SKILL_CONTENT)
+
+ # Empty pre-existing directory + clean scan: create succeeds (retry after a leftover works).
+ empty = tmp_path / "empty-skill"
+ empty.mkdir()
+ empty_result = _create_skill("empty-skill", VALID_SKILL_CONTENT)
+
+ assert result["success"] is False
+ assert "Choose another name" in result["error"]
+ assert nested.read_bytes() == b"nested"
+ assert not (category / "SKILL.md").exists()
+
+ assert empty_result["success"] is True
+ assert (empty / "SKILL.md").exists()
def test_edit_long_desc_still_allowed_with_preview(self, tmp_path):
"""Edit/patch paths stay permissive so existing over-limit skills