Skip to content

The agent that grows with you

fix(skills): validate a batch create's category before the snapshot

kshitijk4poor85ac36f2ec4f
diff --git a/tests/tools/test_skill_manage_batch.py b/tests/tools/test_skill_manage_batch.py
index 252b9b8c8f4..a676c99158b 100644
--- a/tests/tools/test_skill_manage_batch.py
+++ b/tests/tools/test_skill_manage_batch.py
@@ -10,6 +10,7 @@ import shutil
import sys
import tempfile
import unittest
+from unittest.mock import patch
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
@@ -105,6 +106,14 @@ class TestSkillManageBatch(unittest.TestCase):
{"action": "create", "content": SK.format(n="x")},
])
self.assertFalse(r["success"])
+ # a non-string create category is a JSON error (never a TypeError) and, rejected
+ # pre-effect, leaves no skill_batch_ snapshot tempdir behind.
+ with tempfile.TemporaryDirectory(prefix="skmbatch_tmp_") as tmp, \
+ patch.dict(os.environ, {"TMPDIR": tmp}), patch.object(tempfile, "tempdir", None):
+ r = self._call("x", [{"action": "create", "content": SK.format(n="x"), "category": 5}])
+ self.assertFalse(r["success"])
+ self.assertIn("Category must be a string", r["error"])
+ self.assertEqual(os.listdir(tmp), [])
# empty / capped
r = self._call("x", [])
self.assertFalse(r["success"])
@@ -183,8 +192,7 @@ class TestSkillManageBatch(unittest.TestCase):
open(os.path.join(gamma, "dropped.txt"), "w").write("keep me")
return real_from(payload, **kw)
- from unittest.mock import patch as _patch
- with _patch.object(self.smt, "_skill_manage_from", side_effect=drop_file_before_failing_op):
+ with patch.object(self.smt, "_skill_manage_from", side_effect=drop_file_before_failing_op):
r = json.loads(self.smt.skill_manage(action="", name="", operations=[
{"name": "alpha", "action": "patch",
"old_string": "Step 1.", "new_string": "Step A."},
diff --git a/tools/skill_manager_batch.py b/tools/skill_manager_batch.py
index 1e36f0ca52d..79f9543658a 100644
--- a/tools/skill_manager_batch.py
+++ b/tools/skill_manager_batch.py
@@ -86,6 +86,7 @@ def _op_shape_error(action: str, args: dict):
def _validate_batch_ops(operations, default_name, tool_error):
"""Shape checks with no side effects. Returns (names, None) or (None, error_json)."""
from tools.skill_manager_guards import _background_review_preflight
+ from tools.skill_manager_tool import _validate_category
def fail(i, msg):
return None, tool_error(f"operations[{i}]{msg}", success=False)
names = []
@@ -103,6 +104,10 @@ def _validate_batch_ops(operations, default_name, tool_error):
# op[1] would first apply op[0] and then roll the whole batch back.
if (shape_err := _op_shape_error(act, op)) is not None:
return fail(i, f" ({act} on '{nm}'): {shape_err}")
+ # create's category is resolved to a target dir before the snapshot: reject a bad one here
+ # so it returns a JSON error (not a TypeError) and never leaks the snapshot tempdir.
+ if act == "create" and (cat_err := _validate_category(op.get("category"))) is not None:
+ return fail(i, f" ({act} on '{nm}'): {cat_err}")
names.append(nm)
if act == "create" and nm in names[:-1]:
return fail(i, f": create for '{nm}' must precede that skill's other ops.")