Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openviking_cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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:
raw = config_path.read_text(encoding="utf-8")
raw = config_path.read_text(encoding="utf-8-sig")
raw = os.path.expandvars(raw)
return json.loads(raw)
except (OSError, json.JSONDecodeError):
Expand All @@ -72,7 +72,7 @@ def check_config() -> tuple[bool, str, Optional[str]]:
)

try:
raw = config_path.read_text(encoding="utf-8")
raw = config_path.read_text(encoding="utf-8-sig")
raw = os.path.expandvars(raw)
data = json.loads(raw)
except json.JSONDecodeError as exc:
Expand Down
2 changes: 1 addition & 1 deletion openviking_cli/utils/config/open_viking_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _load_from_file(cls, config_file: str) -> "OpenVikingConfig":
if not config_path.exists():
raise FileNotFoundError(f"Config file does not exist: {config_file}")

with open(config_path, "r", encoding="utf-8") as f:
with open(config_path, "r", encoding="utf-8-sig") as f:
raw = f.read()

# Expand $VAR and ${VAR} inside the JSON text (useful for container deployments).
Expand Down
8 changes: 8 additions & 0 deletions tests/cli/test_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def test_pass_with_valid_config(self, tmp_path: Path):
assert ok
assert str(config) in detail

def test_pass_with_utf8_bom_config(self, tmp_path: Path):
config = tmp_path / "ov.conf"
config.write_text("\ufeff" + json.dumps({"embedding": {"dense": {}}}))
with patch("openviking_cli.doctor._find_config", return_value=config):
ok, detail, fix = check_config()
assert ok
assert str(config) in detail

def test_fail_missing_config(self):
with patch("openviking_cli.doctor._find_config", return_value=None):
ok, detail, fix = check_config()
Expand Down
28 changes: 28 additions & 0 deletions tests/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ def test_openviking_config_singleton_preserves_value_error_for_bad_config(tmp_pa
OpenVikingConfigSingleton.reset_instance()


def test_openviking_config_singleton_loads_utf8_bom_config(tmp_path, monkeypatch):
monkeypatch.setenv(OPENVIKING_CONFIG_ENV, "/tmp/codex-no-config.json")

from openviking_cli.utils.config import open_viking_config as config_module

class _ConfigStub:
default_account = "default"

loaded = {}

def _from_dict(data):
loaded.update(data)
return _ConfigStub()

monkeypatch.setattr(config_module.OpenVikingConfig, "from_dict", _from_dict)

config_path = tmp_path / "ov.conf"
config_path.write_text("\ufeff{}", encoding="utf-8")

config_module.OpenVikingConfigSingleton.reset_instance()
config = config_module.OpenVikingConfigSingleton.initialize(config_path=str(config_path))

assert config.default_account == "default"
assert loaded == {}

config_module.OpenVikingConfigSingleton.reset_instance()


def test_require_config_missing_message_uses_openviking_ai_docs(tmp_path, monkeypatch):
import openviking_cli.utils.config.config_loader as loader

Expand Down
Loading