9fb101282f
* fix: --config flag now fully overrides ~/.strix/cli-config.json (fixes #377) Previously, env vars applied from the default config at module import time were not cleared when --config was later processed, causing settings from ~/.strix/cli-config.json to leak into runs that specified a custom config. Track which vars were applied by the initial default-config load in Config._applied_from_default. In apply_config_override, clear those vars before applying the custom config so only the custom file's settings take effect. * Add config override regression test * Make config override test setup explicit --------- Co-authored-by: octo-patch <octo-patch@github.com> Co-authored-by: bearsyankees <bearsyankees@gmail.com>
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import json
|
|
import os
|
|
|
|
from strix.config.config import Config, apply_saved_config
|
|
|
|
|
|
def test_apply_config_override_clears_default_only_vars(monkeypatch, tmp_path) -> None:
|
|
from strix.interface.main import apply_config_override
|
|
|
|
default_cfg = tmp_path / "cli-config.json"
|
|
default_cfg.write_text(
|
|
json.dumps({"env": {"LLM_API_BASE": "https://default.api", "STRIX_LLM": "default-model"}}),
|
|
encoding="utf-8",
|
|
)
|
|
custom_cfg = tmp_path / "custom.json"
|
|
custom_cfg.write_text(json.dumps({"env": {"STRIX_LLM": "custom-model"}}), encoding="utf-8")
|
|
|
|
monkeypatch.setattr(Config, "_config_file_override", None)
|
|
monkeypatch.setattr(Config, "_applied_from_default", {})
|
|
monkeypatch.setattr(Config, "config_dir", classmethod(lambda cls: tmp_path))
|
|
for var_name in Config._llm_env_vars():
|
|
monkeypatch.delenv(var_name, raising=False)
|
|
|
|
apply_saved_config()
|
|
|
|
assert os.environ.get("LLM_API_BASE") == "https://default.api"
|
|
|
|
apply_config_override(str(custom_cfg))
|
|
|
|
assert os.environ.get("STRIX_LLM") == "custom-model"
|
|
assert "LLM_API_BASE" not in os.environ
|