import unittest from pathlib import Path from tempfile import TemporaryDirectory from render_config import build_config, oauth_ready class ConfigTests(unittest.TestCase): catalog = { 'zenmux': {'claude-sonnet-latest': 'anthropic/claude-sonnet-5.5'}, 'openrouter': {'glm-latest': 'z-ai/glm-5.3-prime'}, 'google_ai_studio': {'gemini-latest': 'gemini-test'}, 'google_vertex': {'gemini-vertex': 'gemini-vertex-test'}, 'chatgpt': {'codex-latest': 'gpt-test'}, 'xai': {'grok-latest': 'grok-test'}, } def test_missing_credentials_exclude_routes(self): self.assertEqual(build_config(self.catalog, {}, lambda _: False)['model_list'], []) def test_env_ui_login_disabled(self): settings = build_config(self.catalog, {}, lambda _: False)['general_settings'] self.assertTrue(settings['disable_env_credential_login']) def test_subscription_preserves_vendor_prefix(self): routes = build_config(self.catalog, {'ZENMUX_SUBSCRIPTION_API_KEY': 'secret'}, lambda _: False)['model_list'] self.assertEqual(routes[0]['litellm_params']['model'], 'anthropic/anthropic/claude-sonnet-5.5') self.assertNotIn('secret', str(routes)) def test_payg_separate_alias(self): routes = build_config(self.catalog, {'ZENMUX_PAYG_API_KEY': 'secret'}, lambda _: False)['model_list'] self.assertEqual(routes[0]['model_name'], 'claude-sonnet-latest-payg') def test_oauth_requires_persistent_file(self): routes = build_config(self.catalog, {}, lambda path: str(path) == '/tokens/xai/auth.json')['model_list'] self.assertEqual(len(routes), 1) self.assertTrue(routes[0]['litellm_params']['use_xai_oauth']) self.assertNotIn('api_key', routes[0]['litellm_params']) def test_pending_oauth_is_not_ready(self): with TemporaryDirectory() as folder: path = Path(folder) / 'auth.json' self.assertFalse(oauth_ready(path)) path.write_text('{"device_code_requested_at": 1}') self.assertFalse(oauth_ready(path)) path.write_text('{"access_token": "fixture-only"}') self.assertTrue(oauth_ready(path)) def test_vertex_requires_explicit_enable_and_project(self): for env in ({'VERTEXAI_PROJECT': 'test-project'}, {'VERTEXAI_ENABLED': 'true'}): self.assertEqual(build_config(self.catalog, env, lambda _: False)['model_list'], []) routes = build_config(self.catalog, {'VERTEXAI_ENABLED': 'true', 'VERTEXAI_PROJECT': 'test-project'}, lambda _: False)['model_list'] self.assertEqual(routes[0]['litellm_params']['model'], 'vertex_ai/gemini-vertex-test') self.assertEqual(routes[0]['litellm_params']['vertex_project'], 'os.environ/VERTEXAI_PROJECT') self.assertNotIn('api_key', routes[0]['litellm_params']) if __name__ == '__main__': unittest.main()