Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor(llm): make auto-discovery the single source of truth for providers (#4591)

LearningCircuitba20e38e31f0
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index 1ea4a9e902..f8adb88e02 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -17,19 +17,6 @@ from ..llm.providers.base import normalize_provider
from .thread_settings import get_setting_from_snapshot
from ..constants import DEFAULT_SEARCH_TOOL
-# Valid provider options
-VALID_PROVIDERS = [
- "ollama",
- "openai",
- "anthropic",
- "google",
- "openrouter",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
-]
-
def get_selected_llm_provider(settings_snapshot=None):
return normalize_provider(
@@ -40,45 +27,29 @@ def get_selected_llm_provider(settings_snapshot=None):
def _get_context_window_for_provider(provider_type, settings_snapshot=None):
- """Get context window size from settings based on provider type.
+ """Resolve the context window size for a provider.
- Local providers (ollama, llamacpp, lmstudio) use a smaller default to prevent
- memory issues. Cloud providers check if unrestricted mode is enabled.
+ Thin wrapper around the canonical
+ ``llm/providers/_helpers.get_context_window_for_provider`` so the
+ provider ``create_llm`` path and this path share a single source of
+ truth (the two were previously identical copies). Kept as a named
+ function because ``get_llm``/``wrap_llm_without_think_tags`` and tests
+ reference it by name and signature.
- NOTE: This is a near-duplicate of providers/_helpers.get_context_window_for_provider.
- Both copies are intentionally kept (rather than aliased): consolidating here
- breaks ~17 tests that patch ``llm_config.get_setting_from_snapshot`` directly,
- while the helpers module uses a function-local import. Until those tests
- migrate to patching the source module, the duplicate is the cheaper option.
+ NOTE: the helper reads settings through
+ ``thread_settings.get_setting_from_snapshot`` (a function-local import),
+ so tests exercising context-window resolution must patch
+ ``...config.thread_settings.get_setting_from_snapshot`` rather than
+ ``...config.llm_config.get_setting_from_snapshot``.
Returns:
int or None: The context window size, or None for unrestricted cloud providers.
"""
- if provider_type in ["ollama", "llamacpp", "lmstudio"]:
- # Local providers: use smaller default to prevent memory issues
- window_size = get_setting_from_snapshot(
- "llm.local_context_window_size",
- 8192,
- settings_snapshot=settings_snapshot,
- )
- # Ensure it's an integer
- return int(window_size) if window_size is not None else 8192
- # Cloud providers: check if unrestricted mode is enabled
- use_unrestricted = get_setting_from_snapshot(
- "llm.context_window_unrestricted",
- True,
- settings_snapshot=settings_snapshot,
- )
- if use_unrestricted:
- # Let cloud providers auto-handle context (return None or very large value)
- return None # Will be handled per provider
- # Use user-specified limit
- window_size = get_setting_from_snapshot(
- "llm.context_window_size",
- 128000,
- settings_snapshot=settings_snapshot,
+ from ..llm.providers._helpers import get_context_window_for_provider
+
+ return get_context_window_for_provider(
+ provider_type, settings_snapshot=settings_snapshot
)
- return int(window_size) if window_size is not None else 128000
def get_llm(
@@ -261,11 +232,29 @@ def get_llm(
settings_snapshot=settings_snapshot,
)
- # Validate provider
- if provider not in VALID_PROVIDERS:
+ # Validate the provider against the auto-discovered set — NOT a hardcoded
+ # list. Auto-discovery (discover_providers, run at module import) registers
+ # every llm/providers/implementations/*.py class, and the
+ # is_llm_registered() check above already serves them, so the registry /
+ # discovery IS the single source of truth for "valid provider".
+ #
+ # We deliberately do not keep a separate VALID_PROVIDERS constant: it was a
+ # third copy of the provider list (besides the implementations directory
+ # and the registry) and it silently drifted from auto-discovery (xai,
+ # ionos and deepseek were valid+registered yet missing from it). Deriving
+ # the set from discovery here means it can never drift. ('none' is the
+ # explicit "unset" sentinel, handled by the guard further down.)
+ from ..llm.providers import get_discovered_provider_options
+
+ valid_providers = {
+ normalize_provider(option["value"])
+ for option in get_discovered_provider_options()
+ } | {"none"}
+ if provider not in valid_providers:
logger.error(f"Invalid provider in settings: {provider}")
raise ValueError(
- f"Invalid provider: {provider}. Must be one of: {VALID_PROVIDERS}"
+ f"Invalid provider: {provider}. "
+ f"Must be one of: {sorted(valid_providers)}"
)
# Require an explicit model for built-in providers. Mirrors the
diff --git a/tests/config/test_context_window_provider.py b/tests/config/test_context_window_provider.py
index 2ca13e22e2..402171f8a6 100644
--- a/tests/config/test_context_window_provider.py
+++ b/tests/config/test_context_window_provider.py
@@ -20,7 +20,7 @@ class TestLocalProviders:
"""Local providers (ollama, llamacpp, lmstudio) use smaller default."""
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=4096,
)
def test_ollama_returns_default(self, mock_setting):
@@ -31,21 +31,21 @@ class TestLocalProviders:
)
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=4096,
)
def test_llamacpp_returns_default(self, mock_setting):
assert _get_fn()("llamacpp") == 4096
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=4096,
)
def test_lmstudio_returns_default(self, mock_setting):
assert _get_fn()("lmstudio") == 4096
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=8192,
)
def test_snapshot_overrides_local_window(self, mock_setting):
@@ -55,7 +55,7 @@ class TestLocalProviders:
assert result == 8192
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value="4096",
)
def test_string_coerced_to_int(self, mock_setting):
@@ -65,7 +65,7 @@ class TestLocalProviders:
assert isinstance(result, int)
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=None,
)
def test_none_falls_back_to_default_8192(self, mock_setting):
@@ -78,7 +78,7 @@ class TestCloudUnrestricted:
"""Cloud providers with unrestricted=True return None."""
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=True,
)
def test_openai_unrestricted_returns_none(self, mock_setting):
@@ -86,14 +86,14 @@ class TestCloudUnrestricted:
assert result is None
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=True,
)
def test_anthropic_unrestricted_returns_none(self, mock_setting):
assert _get_fn()("anthropic") is None
@patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
return_value=True,
)
def test_unknown_provider_treated_as_cloud(self, mock_setting):
@@ -118,7 +118,7 @@ class TestCloudRestricted:
return default
with patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
side_effect=fake_get_setting,
):
result = _get_fn()("openai")
@@ -135,7 +135,7 @@ class TestCloudRestricted:
return default
with patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
side_effect=fake_get_setting,
):
result = _get_fn()(
@@ -154,7 +154,7 @@ class TestCloudRestricted:
return default
with patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
side_effect=fake_get_setting,
):
result = _get_fn()("openai")
@@ -172,7 +172,7 @@ class TestCloudRestricted:
return default
with patch(
- "local_deep_research.config.llm_config.get_setting_from_snapshot",
+ "local_deep_research.config.thread_settings.get_setting_from_snapshot",
side_effect=fake_get_setting,
):
result = _get_fn()("openai")
diff --git a/tests/config/test_get_llm_dispatch_integration.py b/tests/config/test_get_llm_dispatch_integration.py
index 671d0ea27d..8ff0c4bc1a 100644
--- a/tests/config/test_get_llm_dispatch_integration.py
+++ b/tests/config/test_get_llm_dispatch_integration.py
@@ -19,8 +19,10 @@ from unittest.mock import patch
from langchain_core.language_models.fake_chat_models import FakeListChatModel
-from local_deep_research.config.llm_config import VALID_PROVIDERS, get_llm
+from local_deep_research.config.llm_config import get_llm
from local_deep_research.llm import is_llm_registered
+from local_deep_research.llm.providers import get_discovered_provider_options
+from local_deep_research.llm.providers.base import normalize_provider
OPENAI_CHAT = (
"local_deep_research.llm.providers.implementations.openai.ChatOpenAI"
@@ -65,12 +67,12 @@ class TestRegistryPopulation:
"""Every built-in provider must be reachable through the registry,
since get_llm() no longer has any per-provider construction code."""
- def test_all_valid_providers_are_registered(self):
- unregistered = [
- p
- for p in VALID_PROVIDERS
- if p != "none" and not is_llm_registered(p)
+ def test_all_discovered_providers_are_registered(self):
+ discovered = [
+ normalize_provider(option["value"])
+ for option in get_discovered_provider_options()
]
+ unregistered = [p for p in discovered if not is_llm_registered(p)]
assert unregistered == [], (
f"Providers missing from the LLM registry: {unregistered}. "
"get_llm() has no fallback construction path for these anymore."
diff --git a/tests/config/test_llm_config.py b/tests/config/test_llm_config.py
index 744bd5c220..9b6a5d9146 100644
--- a/tests/config/test_llm_config.py
+++ b/tests/config/test_llm_config.py
@@ -4,37 +4,12 @@ from unittest.mock import MagicMock, patch
from local_deep_research.config.llm_config import (
- VALID_PROVIDERS,
get_selected_llm_provider,
wrap_llm_without_think_tags,
get_llm,
)
-class TestValidProviders:
- """Tests for VALID_PROVIDERS constant."""
-
- def test_contains_expected_providers(self):
- """Should contain all expected providers."""
- expected = [
- "ollama",
- "openai",
- "anthropic",
- "google",
- "openrouter",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
- ]
- for provider in expected:
- assert provider in VALID_PROVIDERS
-
- def test_is_list(self):
- """Should be a list."""
- assert isinstance(VALID_PROVIDERS, list)
-
-
class TestGetSelectedLlmProvider:
"""Tests for get_selected_llm_provider function."""
diff --git a/tests/config/test_llm_config_behavior.py b/tests/config/test_llm_config_behavior.py
index 766379c672..5a8a75ae7c 100644
--- a/tests/config/test_llm_config_behavior.py
+++ b/tests/config/test_llm_config_behavior.py
@@ -92,16 +92,22 @@ class TestProviderValidation:
get_llm(provider="nonexistent_provider", settings_snapshot={})
def test_error_message_lists_valid_providers(self):
- """ValueError message includes the VALID_PROVIDERS list."""
- from local_deep_research.config.llm_config import (
- VALID_PROVIDERS,
- get_llm,
+ """ValueError message enumerates the auto-discovered providers.
+
+ The valid set is derived from auto-discovery (no hardcoded
+ VALID_PROVIDERS), so the error lists every discovered provider.
+ """
+ from local_deep_research.config.llm_config import get_llm
+ from local_deep_research.llm.providers import (
+ get_discovered_provider_options,
)
+ from local_deep_research.llm.providers.base import normalize_provider
with pytest.raises(ValueError) as exc_info:
get_llm(provider="bad_provider", settings_snapshot={})
- for p in VALID_PROVIDERS:
- assert p in str(exc_info.value)
+ message = str(exc_info.value)
+ for option in get_discovered_provider_options():
+ assert normalize_provider(option["value"]) in message
class TestModelAndProviderNameCleaning:
diff --git a/tests/config/test_llm_config_coverage.py b/tests/config/test_llm_config_coverage.py
index dac4095440..5472bb01e5 100644
--- a/tests/config/test_llm_config_coverage.py
+++ b/tests/config/test_llm_config_coverage.py
@@ -17,6 +17,11 @@ import pytest
# ---------------------------------------------------------------------------
MODULE = "local_deep_research.config.llm_config"
+# _get_context_window_for_provider delegates to the _helpers twin, which reads
+# settings via thread_settings.get_setting_from_snapshot (function-local
+# import). Context-window assertions must therefore patch this module, not
+# MODULE.
+THREAD_SETTINGS = "local_deep_research.config.thread_settings"
# ===================================================================
@@ -66,7 +71,7 @@ class TestGetContextWindowForProvider:
def test_openrouter_treated_as_cloud(self):
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
return_value=True,
):
from local_deep_research.config.llm_config import (
@@ -78,7 +83,7 @@ class TestGetContextWindowForProvider:
def test_local_provider_with_float_value(self):
"""Float value from settings is coerced to int."""
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
return_value=8192.7,
):
from local_deep_research.config.llm_config import (
@@ -102,7 +107,8 @@ class TestGetContextWindowForProvider:
return default
with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
):
from local_deep_research.config.llm_config import (
_get_context_window_for_provider,
@@ -262,8 +268,14 @@ class TestWrapLlmWithoutThinkTags:
return 4096
return default
- with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ with (
+ patch(
+ f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ ),
+ patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
@@ -286,8 +298,14 @@ class TestWrapLlmWithoutThinkTags:
return 4096
return default
- with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ with (
+ patch(
+ f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ ),
+ patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
@@ -310,8 +328,14 @@ class TestWrapLlmWithoutThinkTags:
return True
return default
- with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ with (
+ patch(
+ f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ ),
+ patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
@@ -478,38 +502,3 @@ class TestWrapLlmWithoutThinkTags:
wrap_llm_without_think_tags(llm, research_id=None)
# callbacks should remain None (nothing to attach)
assert llm.callbacks is None
-
-
-# ===================================================================
-# VALID_PROVIDERS constant
-# ===================================================================
-
-
-class TestValidProviders:
- """Sanity checks for the VALID_PROVIDERS list."""
-
- def test_contains_all_expected(self):
- from local_deep_research.config.llm_config import VALID_PROVIDERS
-
- expected = {
- "ollama",
- "openai",
- "anthropic",
- "google",
- "openrouter",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
- }
- assert set(VALID_PROVIDERS) == expected
-
- def test_is_list(self):
- from local_deep_research.config.llm_config import VALID_PROVIDERS
-
- assert isinstance(VALID_PROVIDERS, list)
-
- def test_no_duplicates(self):
- from local_deep_research.config.llm_config import VALID_PROVIDERS
-
- assert len(VALID_PROVIDERS) == len(set(VALID_PROVIDERS))
diff --git a/tests/config/test_llm_config_deep_coverage.py b/tests/config/test_llm_config_deep_coverage.py
index cb5892cdd9..82212ec621 100644
--- a/tests/config/test_llm_config_deep_coverage.py
+++ b/tests/config/test_llm_config_deep_coverage.py
@@ -13,6 +13,10 @@ import pytest
from langchain_core.language_models import BaseChatModel
MODULE = "local_deep_research.config.llm_config"
+# Context-window resolution delegates to the _helpers twin, which reads
+# settings via thread_settings.get_setting_from_snapshot. Patch this module
+# (not MODULE) for context-window tests.
+THREAD_SETTINGS = "local_deep_research.config.thread_settings"
def _make_settings_snapshot(provider="openai", model="gpt-4", **extra):
@@ -197,7 +201,7 @@ class TestContextWindowEdgeCases:
def test_none_window_size_for_local_provider_defaults_to_8192(self):
"""If local_context_window_size returns None, defaults to 8192."""
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
return_value=None,
):
from local_deep_research.config.llm_config import (
@@ -220,7 +224,8 @@ class TestContextWindowEdgeCases:
return default
with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
):
from local_deep_research.config.llm_config import (
_get_context_window_for_provider,
@@ -232,7 +237,7 @@ class TestContextWindowEdgeCases:
def test_llamacpp_is_local_provider(self):
"""llamacpp is in the local provider list."""
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
return_value=8192,
):
from local_deep_research.config.llm_config import (
diff --git a/tests/config/test_llm_config_extra_coverage.py b/tests/config/test_llm_config_extra_coverage.py
index 289990b751..e1a6fd1fdc 100644
--- a/tests/config/test_llm_config_extra_coverage.py
+++ b/tests/config/test_llm_config_extra_coverage.py
@@ -9,6 +9,10 @@ from unittest.mock import patch
MODULE = "local_deep_research.config.llm_config"
+# Context-window resolution delegates to the _helpers twin, which reads
+# settings via thread_settings.get_setting_from_snapshot. Patch this module
+# (not MODULE) for context-window tests.
+THREAD_SETTINGS = "local_deep_research.config.thread_settings"
# ===========================================================================
@@ -22,7 +26,9 @@ class TestGetContextWindowForProvider:
_get_context_window_for_provider,
)
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value=4096):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=4096
+ ):
result = _get_context_window_for_provider("ollama")
assert result == 4096
@@ -32,7 +38,9 @@ class TestGetContextWindowForProvider:
_get_context_window_for_provider,
)
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value=8192):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=8192
+ ):
result = _get_context_window_for_provider("llamacpp")
assert result == 8192
@@ -42,7 +50,9 @@ class TestGetContextWindowForProvider:
_get_context_window_for_provider,
)
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value=None):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=None
+ ):
result = _get_context_window_for_provider("lmstudio")
assert result == 8192
@@ -52,7 +62,9 @@ class TestGetContextWindowForProvider:
_get_context_window_for_provider,
)
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value=True):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=True
+ ):
result = _get_context_window_for_provider("openai")
assert result is None
@@ -72,7 +84,7 @@ class TestGetContextWindowForProvider:
return 64000 # custom window size
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
side_effect=setting_side_effect,
):
result = _get_context_window_for_provider("anthropic")
@@ -94,7 +106,7 @@ class TestGetContextWindowForProvider:
return None # no custom size
with patch(
- f"{MODULE}.get_setting_from_snapshot",
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
side_effect=setting_side_effect,
):
result = _get_context_window_for_provider("openrouter")
@@ -106,7 +118,10 @@ class TestGetContextWindowForProvider:
_get_context_window_for_provider,
)
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value="16384"):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ return_value="16384",
+ ):
result = _get_context_window_for_provider("ollama")
assert result == 16384
diff --git a/tests/config/test_llm_config_missing_coverage.py b/tests/config/test_llm_config_missing_coverage.py
index 2a78715655..390a784d92 100644
--- a/tests/config/test_llm_config_missing_coverage.py
+++ b/tests/config/test_llm_config_missing_coverage.py
@@ -16,6 +16,11 @@ from unittest.mock import MagicMock, patch
import pytest
MODULE = "local_deep_research.config.llm_config"
+# Context-window resolution delegates to the _helpers twin, which reads
+# settings via thread_settings.get_setting_from_snapshot. Patch this module
+# (not MODULE) for context-window reads; wrap_llm tests that also read
+# rate_limiting settings must patch BOTH.
+THREAD_SETTINGS = "local_deep_research.config.thread_settings"
def _settings_dict(overrides=None):
@@ -113,7 +118,8 @@ class TestGetContextWindowForProviderMissing:
return default
with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
):
from local_deep_research.config.llm_config import (
_get_context_window_for_provider,
@@ -125,7 +131,9 @@ class TestGetContextWindowForProviderMissing:
def test_local_provider_none_window_defaults_to_8192(self):
"""When local context window setting returns None, fallback to 8192."""
- with patch(f"{MODULE}.get_setting_from_snapshot", return_value=None):
+ with patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=None
+ ):
from local_deep_research.config.llm_config import (
_get_context_window_for_provider,
)
@@ -144,7 +152,8 @@ class TestGetContextWindowForProviderMissing:
return default
with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
):
from local_deep_research.config.llm_config import (
_get_context_window_for_provider,
@@ -169,8 +178,14 @@ class TestWrapLlmContextLimitInjection:
return 8192
return default
- with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ with (
+ patch(
+ f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ ),
+ patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
@@ -263,8 +278,14 @@ class TestWrapLlmContextLimitInjection:
return True
return default
- with patch(
- f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ with (
+ patch(
+ f"{MODULE}.get_setting_from_snapshot", side_effect=fake_setting
+ ),
+ patch(
+ f"{THREAD_SETTINGS}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
diff --git a/tests/config/test_llm_config_providers.py b/tests/config/test_llm_config_providers.py
deleted file mode 100644
index 36bd925bf9..0000000000
--- a/tests/config/test_llm_config_providers.py
+++ /dev/null
@@ -1,188 +0,0 @@
-"""
-Tests for LLM config provider instantiation.
-
-Tests cover:
-- Provider instantiation for various providers
-"""
-
-import pytest
-
-
-class TestProviderInstantiation:
- """Tests for provider instantiation."""
-
- def test_anthropic_instantiation_with_api_key(self):
- """Anthropic instantiation with API key."""
- api_key = "sk-ant-test-key" # pragma: allowlist secret
- model = "claude-3-opus-20240229"
-
- # Configuration check
- assert api_key is not None
- assert model.startswith("claude")
-
- params = {
- "model": model,
- "anthropic_api_key": api_key,
- "temperature": 0.7,
- }
-
- assert "anthropic_api_key" in params
- assert params["model"] == model
-
- def test_anthropic_instantiation_fallback_env(self):
- """Anthropic falls back to env var."""
- api_key_from_settings = None
- api_key_from_env = "sk-ant-env-key" # pragma: allowlist secret
-
- api_key = api_key_from_settings or api_key_from_env
-
- assert api_key == api_key_from_env
-
- def test_openai_optional_params_api_base(self):
- """OpenAI accepts custom API base."""
- api_base = "https://custom.openai.com/v1"
-
- params = {
- "model": "gpt-4",
- "api_key": "sk-test",
- } # pragma: allowlist secret
-
- if api_base:
- params["openai_api_base"] = api_base
-
- assert params["openai_api_base"] == api_base
-
- def test_openai_optional_params_organization(self):
- """OpenAI accepts organization ID."""
- organization = "org-12345"
-
- params = {
- "model": "gpt-4",
- "api_key": "sk-test",
- } # pragma: allowlist secret
-
- if organization:
- params["openai_organization"] = organization
-
- assert params["openai_organization"] == organization
-
- def test_openai_optional_params_streaming(self):
- """OpenAI accepts streaming parameter."""
- streaming = True
-
- params = {
- "model": "gpt-4",
- "api_key": "sk-test",
- } # pragma: allowlist secret
-
- if streaming is not None:
- params["streaming"] = streaming
-
- assert params["streaming"] is True
-
- def test_openai_endpoint_url_normalization(self):
- """OpenAI endpoint URL is normalized."""
- urls = [
- ("https://api.example.com/", "https://api.example.com"),
- ("https://api.example.com", "https://api.example.com"),
- ("http://localhost:8000/v1/", "http://localhost:8000/v1"),
- ]
-
- for raw_url, expected in urls:
- normalized = raw_url.rstrip("/")
- assert normalized == expected
-
- def test_lmstudio_chat_openai_wrapper(self):
- """LM Studio uses ChatOpenAI wrapper."""
- lmstudio_url = "http://localhost:1234/v1"
- model = "local-model"
-
- # LM Studio uses fake API key
- params = {
- "model": model,
- "api_key": "lm-studio", # pragma: allowlist secret
- "base_url": lmstudio_url,
- "temperature": 0.7,
- }
-
- assert params["api_key"] == "lm-studio" # pragma: allowlist secret
- assert params["base_url"] == lmstudio_url
-
-
-class TestProviderValidation:
- """Tests for provider validation."""
-
- def test_valid_providers_list(self):
- """VALID_PROVIDERS contains expected providers."""
- from local_deep_research.config.llm_config import VALID_PROVIDERS
-
- expected = [
- "ollama",
- "openai",
- "anthropic",
- "google",
- "openrouter",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
- ]
-
- for provider in expected:
- assert provider in VALID_PROVIDERS
-
- def test_invalid_provider_raises_error(self):
- """Invalid provider raises ValueError."""
- provider = "invalid_provider"
- valid_providers = ["ollama", "openai", "anthropic"]
-
- if provider not in valid_providers:
- with pytest.raises(ValueError):
- raise ValueError(f"Invalid provider: {provider}")
-
- def test_provider_name_cleaning(self):
- """Provider name is cleaned of whitespace and quotes."""
- dirty_names = [
- '" ollama "',
- "'openai'",
- " anthropic ",
- '"google"',
- ]
-
- for name in dirty_names:
- cleaned = name.strip().strip("\"'").strip()
- assert cleaned in ["ollama", "openai", "anthropic", "google"]
-
-
-class TestProviderAvailabilityChecks:
- """Tests for provider availability checks."""
-
- def test_openai_available_with_key(self):
- """OpenAI available when API key present."""
- api_key = "sk-test" # pragma: allowlist secret
-
- is_available = bool(api_key)
-
- assert is_available
-
- def test_anthropic_available_with_key(self):
- """Anthropic available when API key present."""
- api_key = "sk-ant-test" # pragma: allowlist secret
-
- is_available = bool(api_key)
-
- assert is_available
-
- def test_google_delegates_to_provider(self):
- """Google availability check delegates to GoogleProvider."""
- # Google provider has its own is_available method
- google_available = True # Simulated
-
- assert google_available is not None
-
- def test_openrouter_delegates_to_provider(self):
- """OpenRouter availability check delegates to provider."""
- # OpenRouter provider has its own is_available method
- openrouter_available = True # Simulated
-
- assert openrouter_available is not None
diff --git a/tests/conftest.py b/tests/conftest.py
index af14f77052..c0d1ce611f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -598,15 +598,6 @@ def mock_llm_config(monkeypatch):
return mock
mock_module.get_llm = get_llm
- mock_module.VALID_PROVIDERS = [
- "ollama",
- "openai",
- "anthropic",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
- ]
# Patch the module
monkeypatch.setitem(
diff --git a/tests/mock_modules.py b/tests/mock_modules.py
index d11c729bc4..771fcadf84 100644
--- a/tests/mock_modules.py
+++ b/tests/mock_modules.py
@@ -62,15 +62,6 @@ def create_mock_llm_config(monkeypatch):
attributes = {
"get_llm": get_llm,
- "VALID_PROVIDERS": [
- "ollama",
- "openai",
- "anthropic",
- "openai_endpoint",
- "lmstudio",
- "llamacpp",
- "none",
- ],
"DEFAULT_PROVIDER": "ollama",
"DEFAULT_MODEL": "gemma3:12b",
"DEFAULT_TEMPERATURE": 0.7,
diff --git a/tests/web_search_engines/test_search_engine_factory_branch_coverage.py b/tests/web_search_engines/test_search_engine_factory_branch_coverage.py
index b516af3988..569097df41 100644
--- a/tests/web_search_engines/test_search_engine_factory_branch_coverage.py
+++ b/tests/web_search_engines/test_search_engine_factory_branch_coverage.py
@@ -29,6 +29,10 @@ import pytest
_FACTORY_MOD = "local_deep_research.web_search_engines.search_engine_factory"
_LLM_MOD = "local_deep_research.config.llm_config"
+# wrap_llm reads rate_limiting via the llm_config binding; context-window
+# resolution now delegates to the _helpers twin which reads via
+# thread_settings. Cross-cutting wrap_llm tests therefore patch BOTH.
+_THREAD_SETTINGS_MOD = "local_deep_research.config.thread_settings"
def _make_engine_class(*param_names, class_attrs=None):
@@ -408,9 +412,15 @@ class TestWrapLlmContextLimitRegisteredProvider:
return 50000
return default
- with patch(
- f"{_LLM_MOD}.get_setting_from_snapshot",
- side_effect=fake_setting,
+ with (
+ patch(
+ f"{_LLM_MOD}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
+ patch(
+ f"{_THREAD_SETTINGS_MOD}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,
@@ -437,9 +447,15 @@ class TestWrapLlmContextLimitRegisteredProvider:
return True
return default
- with patch(
- f"{_LLM_MOD}.get_setting_from_snapshot",
- side_effect=fake_setting,
+ with (
+ patch(
+ f"{_LLM_MOD}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
+ patch(
+ f"{_THREAD_SETTINGS_MOD}.get_setting_from_snapshot",
+ side_effect=fake_setting,
+ ),
):
from local_deep_research.config.llm_config import (
wrap_llm_without_think_tags,