fix(tests): add autouse cache-isolation fixture to get_available_models test files
Fixes the CI failure introduced by #817: test_model_resolver::test_custom_endpoint_uses_model_config_api_key_for_model_discovery was failing with KeyError: 'auth' due to the 60s TTL cache in get_available_models() being populated by test_byok_model_dropdown.py tests that ran earlier. Added autouse _isolate_models_cache fixture to 5 test files. Full suite 1747/1747, QA harness green.
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user