66import pytest
77import yaml
88
9- from codegate .config import Config , ConfigurationError , LogFormat , LogLevel
9+ from codegate .config import DEFAULT_PROVIDER_URLS , Config , ConfigurationError , LogFormat , LogLevel
1010
1111
1212def test_default_config (default_config : Config ) -> None :
@@ -15,6 +15,7 @@ def test_default_config(default_config: Config) -> None:
1515 assert default_config .host == "localhost"
1616 assert default_config .log_level == LogLevel .INFO
1717 assert default_config .log_format == LogFormat .JSON
18+ assert default_config .provider_urls == DEFAULT_PROVIDER_URLS
1819
1920
2021def test_config_from_file (temp_config_file : Path ) -> None :
@@ -24,6 +25,7 @@ def test_config_from_file(temp_config_file: Path) -> None:
2425 assert config .host == "localhost"
2526 assert config .log_level == LogLevel .DEBUG
2627 assert config .log_format == LogFormat .JSON
28+ assert config .provider_urls == DEFAULT_PROVIDER_URLS
2729
2830
2931def test_config_from_invalid_file (tmp_path : Path ) -> None :
@@ -49,6 +51,7 @@ def test_config_from_env(env_vars: None) -> None:
4951 assert config .host == "localhost"
5052 assert config .log_level == LogLevel .WARNING
5153 assert config .log_format == LogFormat .TEXT
54+ assert config .provider_urls == DEFAULT_PROVIDER_URLS
5255
5356
5457def test_config_priority_resolution (temp_config_file : Path , env_vars : None ) -> None :
@@ -60,18 +63,21 @@ def test_config_priority_resolution(temp_config_file: Path, env_vars: None) -> N
6063 cli_host = "example.com" ,
6164 cli_log_level = "WARNING" ,
6265 cli_log_format = "TEXT" ,
66+ cli_provider_urls = {"vllm" : "https://custom.vllm.server" },
6367 )
6468 assert config .port == 8080
6569 assert config .host == "example.com"
6670 assert config .log_level == LogLevel .WARNING
6771 assert config .log_format == LogFormat .TEXT
72+ assert config .provider_urls ["vllm" ] == "https://custom.vllm.server"
6873
6974 # Env vars should override config file
7075 config = Config .load (config_path = temp_config_file )
7176 assert config .port == 8989 # from env
7277 assert config .host == "localhost" # from env
7378 assert config .log_level == LogLevel .WARNING # from env
7479 assert config .log_format == LogFormat .TEXT # from env
80+ assert config .provider_urls == DEFAULT_PROVIDER_URLS # no env override
7581
7682 # Config file should override defaults
7783 os .environ .clear () # Remove env vars
@@ -80,6 +86,34 @@ def test_config_priority_resolution(temp_config_file: Path, env_vars: None) -> N
8086 assert config .host == "localhost" # from file
8187 assert config .log_level == LogLevel .DEBUG # from file
8288 assert config .log_format == LogFormat .JSON # from file
89+ assert config .provider_urls == DEFAULT_PROVIDER_URLS # default values
90+
91+
92+ def test_provider_urls_from_config (tmp_path : Path ) -> None :
93+ """Test loading provider URLs from config file."""
94+ config_file = tmp_path / "config.yaml"
95+ custom_urls = {
96+ "vllm" : "https://custom.vllm.server" ,
97+ "openai" : "https://custom.openai.server" ,
98+ }
99+ with open (config_file , "w" ) as f :
100+ yaml .dump ({"provider_urls" : custom_urls }, f )
101+
102+ config = Config .from_file (config_file )
103+ assert config .provider_urls ["vllm" ] == custom_urls ["vllm" ]
104+ assert config .provider_urls ["openai" ] == custom_urls ["openai" ]
105+ assert config .provider_urls ["anthropic" ] == DEFAULT_PROVIDER_URLS ["anthropic" ]
106+
107+
108+ def test_provider_urls_from_env () -> None :
109+ """Test loading provider URLs from environment variables."""
110+ os .environ ["CODEGATE_PROVIDER_VLLM_URL" ] = "https://custom.vllm.server"
111+ try :
112+ config = Config .from_env ()
113+ assert config .provider_urls ["vllm" ] == "https://custom.vllm.server"
114+ assert config .provider_urls ["openai" ] == DEFAULT_PROVIDER_URLS ["openai" ]
115+ finally :
116+ del os .environ ["CODEGATE_PROVIDER_VLLM_URL" ]
83117
84118
85119def test_invalid_log_level () -> None :
0 commit comments