fix: preserve persisted config environment

This commit is contained in:
Alex Schapiro
2026-08-20 16:14:11 +00:00
parent 6f88b7d7d5
commit 7a736da465
2 changed files with 61 additions and 2 deletions
+37
View File
@@ -208,6 +208,43 @@ def test_persist_current_writes_env_block(tmp_path: Path, monkeypatch: pytest.Mo
}
def test_persist_current_preserves_keys_missing_from_env(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("STRIX_LLM", raising=False)
monkeypatch.delenv("LLM_API_KEY", raising=False)
monkeypatch.setenv("OPENAI_API_KEY", "env-key")
target = tmp_path / "cli-config.json"
target.write_text(
json.dumps({"env": {"STRIX_LLM": "file-model", "STRIX_FUTURE_KEY": "keep-me"}}),
encoding="utf-8",
)
loader.apply_config_override(target)
loader.persist_current()
assert json.loads(target.read_text(encoding="utf-8")) == {
"env": {
"STRIX_LLM": "file-model",
"STRIX_FUTURE_KEY": "keep-me",
"OPENAI_API_KEY": "env-key",
}
}
def test_persist_current_env_wins_over_persisted_value(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("STRIX_LLM", "env-model")
target = tmp_path / "cli-config.json"
target.write_text(json.dumps({"env": {"STRIX_LLM": "file-model"}}), encoding="utf-8")
loader.apply_config_override(target)
loader.persist_current()
assert json.loads(target.read_text(encoding="utf-8"))["env"]["STRIX_LLM"] == "env-model"
def test_persist_current_sets_0600_mode(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("STRIX_LLM", "persisted-model")
target = tmp_path / "cli-config.json"