learningcircuit--local-deep-research
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
178 行
6.6 KiB
Python
178 行
6.6 KiB
Python
"""High-value tests for OpenAI-Compatible endpoint provider edge cases.
|
|
|
|
Focuses on the unique is_available logic (URL-based availability),
|
|
create_llm URL passthrough, and backward compatibility functions.
|
|
"""
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
from local_deep_research.llm.providers.implementations.custom_openai_endpoint import (
|
|
CustomOpenAIEndpointProvider,
|
|
)
|
|
from local_deep_research.llm.providers.openai_base import (
|
|
OpenAICompatibleProvider,
|
|
)
|
|
|
|
|
|
CUSTOM_MOD = (
|
|
"local_deep_research.llm.providers.implementations.custom_openai_endpoint"
|
|
)
|
|
GET_SETTING = f"{CUSTOM_MOD}.get_setting_from_snapshot"
|
|
PARENT_CREATE = "local_deep_research.llm.providers.openai_base.OpenAICompatibleProvider.create_llm"
|
|
|
|
|
|
class TestCustomOpenAIIsAvailable:
|
|
"""Tests for the unique is_available logic (api_key OR custom URL)."""
|
|
|
|
def test_available_with_api_key_only(self):
|
|
"""Provider is available when only API key is set."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return "my-key"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is True
|
|
|
|
def test_available_with_custom_url_only(self):
|
|
"""Provider is available when custom URL differs from default."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return None
|
|
if key == "llm.openai_endpoint.url":
|
|
return "http://localhost:8080/v1"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is True
|
|
|
|
def test_not_available_with_default_url_and_no_key(self):
|
|
"""Provider is NOT available when URL equals default and no API key."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return None
|
|
if key == "llm.openai_endpoint.url":
|
|
return "https://api.openai.com/v1"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is False
|
|
|
|
def test_not_available_with_none_url_and_no_key(self):
|
|
"""Provider is NOT available when both URL and key are None."""
|
|
with patch(GET_SETTING, return_value=None):
|
|
assert CustomOpenAIEndpointProvider.is_available() is False
|
|
|
|
def test_whitespace_api_key_not_available(self):
|
|
"""Whitespace-only API key does not make provider available."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return " "
|
|
if key == "llm.openai_endpoint.url":
|
|
return None
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is False
|
|
|
|
def test_whitespace_url_not_available(self):
|
|
"""Whitespace-only URL does not make provider available."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return None
|
|
if key == "llm.openai_endpoint.url":
|
|
return " "
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is False
|
|
|
|
def test_exception_in_api_key_check_falls_through_to_url(self):
|
|
"""Exception reading API key falls through to URL check."""
|
|
call_count = 0
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
nonlocal call_count
|
|
call_count += 1
|
|
if key == "llm.openai_endpoint.api_key":
|
|
raise RuntimeError("settings error")
|
|
if key == "llm.openai_endpoint.url":
|
|
return "http://myserver:5000/v1"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
assert CustomOpenAIEndpointProvider.is_available() is True
|
|
|
|
def test_both_exceptions_return_false(self):
|
|
"""Exceptions in both api_key and url checks return False."""
|
|
with patch(GET_SETTING, side_effect=RuntimeError("boom")):
|
|
assert CustomOpenAIEndpointProvider.is_available() is False
|
|
|
|
|
|
class TestCustomOpenAICreateLlm:
|
|
"""Tests for create_llm URL passthrough."""
|
|
|
|
def test_custom_url_passed_to_parent(self):
|
|
"""Custom URL from settings is passed as base_url to parent."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.url":
|
|
return "http://myserver:9000/v1"
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return "test-key"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
with patch(PARENT_CREATE) as mock_parent:
|
|
mock_parent.return_value = Mock()
|
|
CustomOpenAIEndpointProvider.create_llm()
|
|
_, kwargs = mock_parent.call_args
|
|
assert "base_url" in kwargs
|
|
|
|
def test_none_url_uses_default(self):
|
|
"""None URL falls back to default_base_url."""
|
|
|
|
def side_effect(key, default=None, **kwargs):
|
|
if key == "llm.openai_endpoint.url":
|
|
return None
|
|
if key == "llm.openai_endpoint.api_key":
|
|
return "test-key"
|
|
return default
|
|
|
|
with patch(GET_SETTING, side_effect=side_effect):
|
|
with patch(PARENT_CREATE) as mock_parent:
|
|
mock_parent.return_value = Mock()
|
|
CustomOpenAIEndpointProvider.create_llm()
|
|
_, kwargs = mock_parent.call_args
|
|
assert (
|
|
kwargs["base_url"]
|
|
== CustomOpenAIEndpointProvider.default_base_url
|
|
)
|
|
|
|
|
|
class TestCustomOpenAIClassAttributes:
|
|
"""Tests for class-level metadata."""
|
|
|
|
def test_inherits_from_openai_compatible(self):
|
|
"""Inherits from OpenAICompatibleProvider."""
|
|
assert issubclass(
|
|
CustomOpenAIEndpointProvider, OpenAICompatibleProvider
|
|
)
|
|
|
|
def test_provider_key(self):
|
|
"""Provider key is OPENAI_ENDPOINT."""
|
|
assert CustomOpenAIEndpointProvider.provider_key == "OPENAI_ENDPOINT"
|
|
|
|
def test_is_cloud_is_none(self):
|
|
"""is_cloud is None (could be local or cloud)."""
|
|
assert CustomOpenAIEndpointProvider.is_cloud is None
|
|
|
|
def test_requires_auth_for_models_returns_false(self):
|
|
"""Custom endpoints don't require auth for model listing."""
|
|
assert CustomOpenAIEndpointProvider.requires_auth_for_models() is False
|