diff --git a/tests/test_custom_provider_display_name.py b/tests/test_custom_provider_display_name.py index fca1842..f8c1771 100644 --- a/tests/test_custom_provider_display_name.py +++ b/tests/test_custom_provider_display_name.py @@ -5,9 +5,24 @@ When a custom_providers entry carries a `name` field (e.g. "Agent37"), the web UI model picker should show that name as the group header rather than the generic "Custom" label. """ +import pytest import api.config as config +@pytest.fixture(autouse=True) +def _isolate_models_cache(): + """Invalidate the models TTL cache before and after every test in this file.""" + try: + config.invalidate_models_cache() + except Exception: + pass + yield + try: + config.invalidate_models_cache() + except Exception: + pass + + def _models_with_cfg(model_cfg=None, custom_providers=None, active_provider=None): """Temporarily patch config.cfg, call get_available_models(), restore. diff --git a/tests/test_issue644.py b/tests/test_issue644.py index 6cd4df2..73ba5b3 100644 --- a/tests/test_issue644.py +++ b/tests/test_issue644.py @@ -3,6 +3,20 @@ import pytest import api.config as _cfg +@pytest.fixture(autouse=True) +def _isolate_models_cache(): + """Invalidate the models TTL cache before and after every test in this file.""" + try: + _cfg.invalidate_models_cache() + except Exception: + pass + yield + try: + _cfg.invalidate_models_cache() + except Exception: + pass + + def _available_models_with_cfg(cfg_override): """Helper: temporarily patch config.cfg, call get_available_models(), restore.""" old_cfg = dict(_cfg.cfg) diff --git a/tests/test_minimax_provider.py b/tests/test_minimax_provider.py index 27c594d..c483786 100644 --- a/tests/test_minimax_provider.py +++ b/tests/test_minimax_provider.py @@ -8,9 +8,24 @@ Covers: - minimax/MiniMax-M2.7 (slash format) is routed via openrouter when active provider differs """ import os +import pytest import api.config as config +@pytest.fixture(autouse=True) +def _isolate_models_cache(): + """Invalidate the models TTL cache before and after every test in this file.""" + try: + config.invalidate_models_cache() + except Exception: + pass + yield + try: + config.invalidate_models_cache() + except Exception: + pass + + # ── Helper ──────────────────────────────────────────────────────────────────── def _resolve_with_config(model_id, provider=None, base_url=None): diff --git a/tests/test_model_resolver.py b/tests/test_model_resolver.py index f6958f9..4f1ca53 100644 --- a/tests/test_model_resolver.py +++ b/tests/test_model_resolver.py @@ -3,6 +3,7 @@ Tests for resolve_model_provider() model routing logic. Verifies that model IDs are correctly resolved to (model, provider, base_url) tuples for different provider configurations. """ +import pytest import api.config as config @@ -160,6 +161,30 @@ def test_custom_provider_model_with_slash_routes_to_named_custom_provider(): # ── get_available_models() @provider: hint behaviour ────────────────────── + +@pytest.fixture(autouse=True) +def _isolate_models_cache(): + """Invalidate the models TTL cache before and after every test in this file. + + Several helpers here mutate ``config.cfg`` in-memory and call + ``get_available_models()``. Without this guard, a prior test that called + ``get_available_models()`` leaves a 60-second TTL cache entry; the next + test that mutates cfg and calls the function gets a cache hit instead of + running the function body, causing silently wrong results (e.g. the + ``test_custom_endpoint_uses_model_config_api_key_for_model_discovery`` + ``KeyError: 'auth'`` on CI where ``urlopen`` is never reached). + """ + try: + config.invalidate_models_cache() + except Exception: + pass + yield + try: + config.invalidate_models_cache() + except Exception: + pass + + def _available_models_with_provider(provider): """Helper: temporarily set active_provider in config.""" old_cfg = dict(config.cfg) diff --git a/tests/test_opencode_providers.py b/tests/test_opencode_providers.py index 7880b7d..33303d4 100644 --- a/tests/test_opencode_providers.py +++ b/tests/test_opencode_providers.py @@ -6,9 +6,24 @@ env-var fallback detection. import os import sys import types +import pytest import api.config as config +@pytest.fixture(autouse=True) +def _isolate_models_cache(): + """Invalidate the models TTL cache before and after every test in this file.""" + try: + config.invalidate_models_cache() + except Exception: + pass + yield + try: + config.invalidate_models_cache() + except Exception: + pass + + # ── Provider registration ───────────────────────────────────────────── def test_opencode_zen_in_provider_display():