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: expand env vars when loading ov.conf JSON config files (#908)
IT Lackey41a2609cb282
diff --git a/bot/vikingbot/config/loader.py b/bot/vikingbot/config/loader.pyindex e57c38797..b7bebb7ee 100644--- a/bot/vikingbot/config/loader.py+++ b/bot/vikingbot/config/loader.py@@ -75,7 +75,13 @@ def load_config() -> Config:if path.exists():try:with open(path) as f:- full_data = json.load(f)+ raw = f.read()++ # Expand $VAR and ${VAR} inside the JSON text (useful for container deployments).+ # Unset variables are left unchanged by expandvars().+ raw = os.path.expandvars(raw)++ full_data = json.loads(raw)# Extract bot sectionbot_data = full_data.get("bot", {})diff --git a/openviking_cli/doctor.py b/openviking_cli/doctor.pyindex e9e42dd78..130fd262a 100644--- a/openviking_cli/doctor.py+++ b/openviking_cli/doctor.py@@ -10,6 +10,7 @@ native vector engine, AGFS, embedding provider, VLM provider, and disk space.from __future__ import annotationsimport json+import osimport platformimport shutilimport sys@@ -43,6 +44,7 @@ def _dim(text: str) -> str:# Individual check functions# ---------------------------------------------------------------------------+def _find_config() -> Optional[Path]:return resolve_config_path(None, OPENVIKING_CONFIG_ENV, "ov.conf")@@ -50,7 +52,9 @@ def _find_config() -> Optional[Path]: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"))+ raw = config_path.read_text(encoding="utf-8")+ raw = os.path.expandvars(raw)+ return json.loads(raw)except (OSError, json.JSONDecodeError):return None@@ -66,7 +70,9 @@ def check_config() -> tuple[bool, str, Optional[str]]:)try:- data = json.loads(config_path.read_text(encoding="utf-8"))+ raw = config_path.read_text(encoding="utf-8")+ raw = os.path.expandvars(raw)+ data = json.loads(raw)except json.JSONDecodeError as exc:return False, f"Invalid JSON in {config_path}", f"Fix syntax error: {exc}"diff --git a/openviking_cli/utils/config/config_loader.py b/openviking_cli/utils/config/config_loader.pyindex 4d3e558ce..d95aaf8f7 100644--- a/openviking_cli/utils/config/config_loader.py+++ b/openviking_cli/utils/config/config_loader.py@@ -81,11 +81,17 @@ def load_json_config(path: Path) -> Dict[str, Any]:raise FileNotFoundError(f"Config file does not exist: {path}")with open(path, "r", encoding="utf-8-sig") as f:- try:- print(f"Loading config file: {path}")- return json.load(f)- except json.JSONDecodeError as e:- raise ValueError(f"Invalid JSON in config file {path}: {e}") from e+ raw = f.read()++ # Expand $VAR and ${VAR} inside the JSON text (useful for container deployments).+ # Unset variables are left unchanged by expandvars().+ raw = os.path.expandvars(raw)++ try:+ print(f"Loading config file: {path}")+ return json.loads(raw)+ except json.JSONDecodeError as e:+ raise ValueError(f"Invalid JSON in config file {path}: {e}") from edef require_config(diff --git a/openviking_cli/utils/config/open_viking_config.py b/openviking_cli/utils/config/open_viking_config.pyindex d83ba2117..78ff81f54 100644--- a/openviking_cli/utils/config/open_viking_config.py+++ b/openviking_cli/utils/config/open_viking_config.py@@ -1,6 +1,7 @@# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.# SPDX-License-Identifier: Apache-2.0import json+import osfrom pathlib import Pathfrom threading import Lockfrom typing import Any, Dict, Optional@@ -290,7 +291,12 @@ class OpenVikingConfigSingleton:raise FileNotFoundError(f"Config file does not exist: {config_file}")with open(config_path, "r", encoding="utf-8") as f:- config_data = json.load(f)+ raw = f.read()++ # Expand $VAR and ${VAR} inside the JSON text (useful for container deployments).+ # Unset variables are left unchanged by expandvars().+ raw = os.path.expandvars(raw)+ config_data = json.loads(raw)return OpenVikingConfig.from_dict(config_data)except json.JSONDecodeError as e:diff --git a/tests/cli/test_doctor.py b/tests/cli/test_doctor.pyindex aefd0b8d9..8a580f17f 100644--- a/tests/cli/test_doctor.py+++ b/tests/cli/test_doctor.py@@ -145,6 +145,27 @@ class TestCheckEmbedding:assert okassert "openai" in detail+ def test_pass_with_api_key_from_environment_variable(self, tmp_path: Path):+ config = tmp_path / "ov.conf"+ config.write_text(+ json.dumps(+ {+ "embedding": {+ "dense": {+ "provider": "openai",+ "model": "text-embedding-3-small",+ "api_key": "${OPENAI_API_KEY}",+ }+ }+ }+ )+ )+ with patch("openviking_cli.doctor._find_config", return_value=config):+ with patch.dict(os.environ, {"OPENAI_API_KEY": "sk-env-123"}, clear=False):+ ok, detail, fix = check_embedding()+ assert ok+ assert "openai" in detail+def test_fail_no_api_key(self, tmp_path: Path):config = tmp_path / "ov.conf"config.write_text(diff --git a/tests/test_config_loader.py b/tests/test_config_loader.pyindex db86305cb..69ba6b0e7 100644--- a/tests/test_config_loader.py+++ b/tests/test_config_loader.py@@ -84,6 +84,15 @@ class TestLoadJsonConfig:with pytest.raises(ValueError, match="Invalid JSON"):load_json_config(conf)+ def test_expands_environment_variables(self, tmp_path, monkeypatch):+ conf = tmp_path / "env.conf"+ conf.write_text('{"api_key": "${TEST_API_KEY}"}')+ monkeypatch.setenv("TEST_API_KEY", "sk-test-123")++ data = load_json_config(conf)++ assert data == {"api_key": "sk-test-123"}+class TestRequireConfig:"""Tests for require_config."""