Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(server): validate skill metadata (#1891)
Qin Haojie458e17a449ac
diff --git a/openviking/utils/skill_processor.py b/openviking/utils/skill_processor.pyindex 164b143b4..a4f40b652 100644--- a/openviking/utils/skill_processor.py+++ b/openviking/utils/skill_processor.py@@ -31,6 +31,7 @@ from openviking.storage.viking_fs import VikingFSfrom openviking.telemetry import get_current_telemetryfrom openviking.telemetry.request_wait_tracker import get_request_wait_trackerfrom openviking.utils.zip_safe import safe_extract_zip+from openviking_cli.exceptions import InvalidArgumentErrorfrom openviking_cli.utils import get_loggerfrom openviking_cli.utils.config import get_openviking_config@@ -88,6 +89,7 @@ class SkillProcessor:data,allow_local_path_resolution=allow_local_path_resolution,)+ self._validate_skill_dict(skill_dict)telemetry.set("skill.parse.duration_ms", round((time.perf_counter() - parse_start) * 1000, 3))@@ -214,6 +216,13 @@ class SkillProcessor: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 not isinstance(name, str) or not name.strip():+ raise InvalidArgumentError("Skill data must include a non-empty 'name' field")+@staticmethoddef _build_skill_abstract(skill_dict: Dict[str, Any]) -> str:"""Build the L0 skill abstract from normalized SKILL.md header metadata."""diff --git a/tests/server/test_api_resources.py b/tests/server/test_api_resources.pyindex ebb4bdb23..523780762 100644--- a/tests/server/test_api_resources.py+++ b/tests/server/test_api_resources.py@@ -190,6 +190,19 @@ async def test_add_skill_business_error_uses_error_envelope(assert body["error"]["message"] == "Skill parse error: boom"+async def test_add_skill_empty_dict_returns_invalid_argument(client: httpx.AsyncClient):+ resp = await client.post(+ "/api/v1/skills",+ json={"data": {}, "wait": True},+ )++ assert resp.status_code == 400+ body = resp.json()+ assert body["status"] == "error"+ assert body["error"]["code"] == "INVALID_ARGUMENT"+ assert "name" in body["error"]["message"]++async def test_add_resource_with_summary_only_telemetry(client: httpx.AsyncClient,sample_markdown_file,diff --git a/tests/unit/test_skill_processor_none.py b/tests/unit/test_skill_processor_none.pyindex d5e3ee26d..018580c64 100644--- a/tests/unit/test_skill_processor_none.py+++ b/tests/unit/test_skill_processor_none.py@@ -10,6 +10,7 @@ skill data is None, instead of falling through to the genericimport pytestfrom openviking.utils.skill_processor import SkillProcessor+from openviking_cli.exceptions import InvalidArgumentErrorclass TestParseSkillNoneData:@@ -38,6 +39,13 @@ 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):+ """Dict skill data should fail fast when required metadata is missing."""+ processor = SkillProcessor(vikingdb=None)+ with pytest.raises(InvalidArgumentError, match="non-empty 'name' field"):+ processor._validate_skill_dict(skill_dict)+def test_parse_skill_unsupported_type_still_raises(self):"""Non-None unsupported types should still raise with type info."""processor = SkillProcessor(vikingdb=None)