Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(skill): reject missing skill names (#1874)

Qin Haojie902010ade4d4
diff --git a/openviking/utils/skill_processor.py b/openviking/utils/skill_processor.py
index a4f40b652..ad9cb5035 100644
--- a/openviking/utils/skill_processor.py
+++ b/openviking/utils/skill_processor.py
@@ -214,14 +214,20 @@ class SkillProcessor:
else:
raise ValueError(f"Unsupported data type: {type(data)}")
+ self._validate_skill_dict(skill_dict)
return skill_dict, auxiliary_files, base_path
@staticmethod
def _validate_skill_dict(skill_dict: Dict[str, Any]) -> None:
"""Validate normalized skill metadata before storage/indexing."""
name = skill_dict.get("name")
+ if name is None:
+ raise InvalidArgumentError("Skill must have 'name' field", details={"field": "name"})
if not isinstance(name, str) or not name.strip():
- raise InvalidArgumentError("Skill data must include a non-empty 'name' field")
+ raise InvalidArgumentError(
+ "Skill 'name' must be a non-empty string",
+ details={"field": "name"},
+ )
@staticmethod
def _build_skill_abstract(skill_dict: Dict[str, Any]) -> str:
diff --git a/tests/server/test_api_resources.py b/tests/server/test_api_resources.py
index 523780762..7f9f73491 100644
--- a/tests/server/test_api_resources.py
+++ b/tests/server/test_api_resources.py
@@ -190,6 +190,26 @@ async def test_add_skill_business_error_uses_error_envelope(
assert body["error"]["message"] == "Skill parse error: boom"
+async def test_add_skill_missing_name_returns_invalid_argument(client: httpx.AsyncClient):
+ resp = await client.post(
+ "/api/v1/skills",
+ json={
+ "data": {
+ "description": "Skill without name",
+ "content": "# No Name Skill\nTest content.",
+ },
+ "wait": True,
+ },
+ )
+
+ assert resp.status_code == 400
+ body = resp.json()
+ assert body["status"] == "error"
+ assert "result" not in body or body["result"] is None
+ assert body["error"]["code"] == "INVALID_ARGUMENT"
+ assert body["error"]["message"] == "Skill must have 'name' field"
+
+
async def test_add_skill_empty_dict_returns_invalid_argument(client: httpx.AsyncClient):
resp = await client.post(
"/api/v1/skills",
diff --git a/tests/unit/test_skill_processor_none.py b/tests/unit/test_skill_processor_none.py
index 018580c64..7e054c88b 100644
--- a/tests/unit/test_skill_processor_none.py
+++ b/tests/unit/test_skill_processor_none.py
@@ -39,11 +39,18 @@ class TestParseSkillNoneData:
assert aux_files == []
assert base_path is None
- @pytest.mark.parametrize("skill_dict", [{}, {"description": "missing name"}, {"name": ""}])
- def test_validate_skill_dict_requires_name(self, skill_dict):
+ @pytest.mark.parametrize("skill_dict", [{}, {"description": "missing name"}])
+ def test_validate_skill_dict_requires_name_field(self, skill_dict):
"""Dict skill data should fail fast when required metadata is missing."""
processor = SkillProcessor(vikingdb=None)
- with pytest.raises(InvalidArgumentError, match="non-empty 'name' field"):
+ with pytest.raises(InvalidArgumentError, match="Skill must have 'name' field"):
+ processor._validate_skill_dict(skill_dict)
+
+ @pytest.mark.parametrize("skill_dict", [{"name": ""}, {"name": " "}, {"name": 123}])
+ def test_validate_skill_dict_requires_non_empty_name_string(self, skill_dict):
+ """Dict skill data should reject empty or non-string skill names."""
+ processor = SkillProcessor(vikingdb=None)
+ with pytest.raises(InvalidArgumentError, match="Skill 'name' must be a non-empty string"):
processor._validate_skill_dict(skill_dict)
def test_parse_skill_unsupported_type_still_raises(self):