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
refactor(cli): centralize ov.conf JSON loading in ov doctor (#913)
everforge0b9df76eeb3d
diff --git a/openviking_cli/doctor.py b/openviking_cli/doctor.pyindex f84032392..e9e42dd78 100644--- a/openviking_cli/doctor.py+++ b/openviking_cli/doctor.py@@ -47,6 +47,14 @@ def _find_config() -> Optional[Path]:return resolve_config_path(None, OPENVIKING_CONFIG_ENV, "ov.conf")+def _load_config_json(config_path: Path) -> Optional[dict]:+ """Parse ov.conf as JSON. Returns None if the file is unreadable or not valid JSON."""+ try:+ return json.loads(config_path.read_text(encoding="utf-8"))+ except (OSError, json.JSONDecodeError):+ return None++def check_config() -> tuple[bool, str, Optional[str]]:"""Validate ov.conf exists and is valid JSON with required sections."""config_path = _find_config()@@ -133,9 +141,8 @@ def check_embedding() -> tuple[bool, str, Optional[str]]:if config_path is None:return False, "Cannot check (no config file)", None- try:- data = json.loads(config_path.read_text(encoding="utf-8"))- except Exception:+ data = _load_config_json(config_path)+ if data is None:return False, "Cannot check (config unreadable)", Noneembedding = data.get("embedding", {})@@ -163,9 +170,8 @@ def check_vlm() -> tuple[bool, str, Optional[str]]:if config_path is None:return False, "Cannot check (no config file)", None- try:- data = json.loads(config_path.read_text(encoding="utf-8"))- except Exception:+ data = _load_config_json(config_path)+ if data is None:return False, "Cannot check (config unreadable)", Nonevlm = data.get("vlm", {})@@ -192,13 +198,11 @@ def check_disk() -> tuple[bool, str, Optional[str]]:workspace = Path.home() / ".openviking"if config_path:- try:- data = json.loads(config_path.read_text(encoding="utf-8"))+ data = _load_config_json(config_path)+ if data is not None:ws = data.get("storage", {}).get("workspace", "")if ws:workspace = Path(ws).expanduser()- except Exception:- passcheck_path = workspace if workspace.exists() else Path.home()diff --git a/pyproject.toml b/pyproject.tomlindex a60fc73ae..a57085a46 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -221,7 +221,7 @@ addopts = "-v --cov=openviking --cov-report=term-missing"[tool.ruff]line-length = 100exclude = ["third_party"]-target-version = "py39"+target-version = "py310"[tool.ruff.lint]select = [diff --git a/tests/cli/test_doctor.py b/tests/cli/test_doctor.pyindex 878002a09..aefd0b8d9 100644--- a/tests/cli/test_doctor.py+++ b/tests/cli/test_doctor.py@@ -167,6 +167,14 @@ class TestCheckEmbedding:assert not okassert "no API key" in detail+ def test_fail_invalid_json(self, tmp_path: Path):+ config = tmp_path / "ov.conf"+ config.write_text("{not valid json")+ with patch("openviking_cli.doctor._find_config", return_value=config):+ ok, detail, fix = check_embedding()+ assert not ok+ assert "unreadable" in detail+class TestCheckVlm:def test_pass_with_config(self, tmp_path: Path):@@ -187,6 +195,14 @@ class TestCheckVlm:ok, detail, fix = check_vlm()assert not ok+ def test_fail_invalid_json(self, tmp_path: Path):+ config = tmp_path / "ov.conf"+ config.write_text("{not valid json")+ with patch("openviking_cli.doctor._find_config", return_value=config):+ ok, detail, fix = check_vlm()+ assert not ok+ assert "unreadable" in detail+class TestCheckDisk:def test_pass_normal_disk(self):