47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from cognitive_agent.config_loader import load_local_env
|
|
|
|
|
|
class LocalEnvironmentLoaderTests(unittest.TestCase):
|
|
def test_file_replaces_blank_inherited_value_but_preserves_non_blank_override(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / ".env"
|
|
path.write_text(
|
|
"OPENAI_MODEL=gpt-5.6-sol\nOPENAI_BASE_URL=https://configured.example/v1\n",
|
|
encoding="utf-8",
|
|
)
|
|
with patch.dict(
|
|
os.environ,
|
|
{
|
|
"OPENAI_MODEL": "",
|
|
"OPENAI_BASE_URL": "https://explicit.example/v1",
|
|
},
|
|
clear=True,
|
|
):
|
|
load_local_env(path)
|
|
self.assertEqual(os.environ["OPENAI_MODEL"], "gpt-5.6-sol")
|
|
self.assertEqual(
|
|
os.environ["OPENAI_BASE_URL"], "https://explicit.example/v1"
|
|
)
|
|
|
|
def test_explicit_override_replaces_stale_non_blank_launcher_value(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / ".env"
|
|
path.write_text("OPENAI_MODEL=gpt-5.6-sol\n", encoding="utf-8")
|
|
with patch.dict(
|
|
os.environ, {"OPENAI_MODEL": "gpt-5-mini"}, clear=True
|
|
):
|
|
load_local_env(path, override=True)
|
|
self.assertEqual(os.environ["OPENAI_MODEL"], "gpt-5.6-sol")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|