7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
155 lines
4.8 KiB
Python
155 lines
4.8 KiB
Python
"""Extra coverage tests for config/llm_config.py — context window and provider selection.
|
|
|
|
Targets uncovered branches:
|
|
- _get_context_window_for_provider() all branches
|
|
- get_selected_llm_provider()
|
|
"""
|
|
|
|
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"
|
|
|
|
|
|
# ===========================================================================
|
|
# _get_context_window_for_provider
|
|
# ===========================================================================
|
|
|
|
|
|
class TestGetContextWindowForProvider:
|
|
def test_local_provider_default(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=4096
|
|
):
|
|
result = _get_context_window_for_provider("ollama")
|
|
|
|
assert result == 4096
|
|
|
|
def test_local_provider_custom_size(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=8192
|
|
):
|
|
result = _get_context_window_for_provider("llamacpp")
|
|
|
|
assert result == 8192
|
|
|
|
def test_local_provider_none_returns_default(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=None
|
|
):
|
|
result = _get_context_window_for_provider("lmstudio")
|
|
|
|
assert result == 8192
|
|
|
|
def test_cloud_provider_unrestricted(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot", return_value=True
|
|
):
|
|
result = _get_context_window_for_provider("openai")
|
|
|
|
assert result is None
|
|
|
|
def test_cloud_provider_restricted_custom_size(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
call_count = 0
|
|
|
|
def setting_side_effect(key, default=None, **kwargs):
|
|
nonlocal call_count
|
|
call_count += 1
|
|
if call_count == 1:
|
|
return False # unrestricted = False
|
|
return 64000 # custom window size
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot",
|
|
side_effect=setting_side_effect,
|
|
):
|
|
result = _get_context_window_for_provider("anthropic")
|
|
|
|
assert result == 64000
|
|
|
|
def test_cloud_provider_restricted_none_returns_default(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
call_count = 0
|
|
|
|
def setting_side_effect(key, default=None, **kwargs):
|
|
nonlocal call_count
|
|
call_count += 1
|
|
if call_count == 1:
|
|
return False # unrestricted = False
|
|
return None # no custom size
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot",
|
|
side_effect=setting_side_effect,
|
|
):
|
|
result = _get_context_window_for_provider("openrouter")
|
|
|
|
assert result == 128000
|
|
|
|
def test_local_provider_string_converted(self):
|
|
from local_deep_research.config.llm_config import (
|
|
_get_context_window_for_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{THREAD_SETTINGS}.get_setting_from_snapshot",
|
|
return_value="16384",
|
|
):
|
|
result = _get_context_window_for_provider("ollama")
|
|
|
|
assert result == 16384
|
|
|
|
|
|
# ===========================================================================
|
|
# get_selected_llm_provider
|
|
# ===========================================================================
|
|
|
|
|
|
class TestGetSelectedLlmProvider:
|
|
def test_returns_lowercase(self):
|
|
from local_deep_research.config.llm_config import (
|
|
get_selected_llm_provider,
|
|
)
|
|
|
|
with patch(
|
|
f"{MODULE}.get_setting_from_snapshot", return_value="OLLAMA"
|
|
):
|
|
assert get_selected_llm_provider() == "ollama"
|
|
|
|
def test_default_ollama(self):
|
|
from local_deep_research.config.llm_config import (
|
|
get_selected_llm_provider,
|
|
)
|
|
|
|
result = get_selected_llm_provider(
|
|
settings_snapshot={"llm.provider": "anthropic"}
|
|
)
|
|
assert result == "anthropic"
|