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.

fix: update tests for new list_reports ABC method, auto-discovered providers, and collection_type (#3013)

LearningCircuitc6a30f4b4d20
diff --git a/tests/research_library/routes/test_rag_routes_coverage.py b/tests/research_library/routes/test_rag_routes_coverage.py
index 8fed168fcd..1c9a06ddfb 100644
--- a/tests/research_library/routes/test_rag_routes_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_coverage.py
@@ -1354,6 +1354,7 @@ class TestGetCollectionDocuments:
mock_coll.distance_metric = "cosine"
mock_coll.index_type = "flat"
mock_coll.normalize_vectors = True
+ mock_coll.collection_type = "user_uploads"
mock_link = Mock()
mock_link.indexed = True
@@ -1419,6 +1420,7 @@ class TestGetCollectionDocuments:
mock_coll.distance_metric = None
mock_coll.index_type = None
mock_coll.normalize_vectors = None
+ mock_coll.collection_type = "user_uploads"
db_session = _make_db_session()
call_count = [0]
diff --git a/tests/research_library/routes/test_rag_routes_deep_coverage.py b/tests/research_library/routes/test_rag_routes_deep_coverage.py
index 7a0096dade..e056645f72 100644
--- a/tests/research_library/routes/test_rag_routes_deep_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_deep_coverage.py
@@ -1096,6 +1096,7 @@ class TestCollectionDocumentsNoIndex:
mock_coll.distance_metric = None
mock_coll.index_type = None
mock_coll.normalize_vectors = None
+ mock_coll.collection_type = "user_uploads"
db_session = _make_db_session()
call_count = {"n": 0}
diff --git a/tests/research_library/routes/test_rag_routes_upload_coverage.py b/tests/research_library/routes/test_rag_routes_upload_coverage.py
index e7ce07a12c..85a488a6b1 100644
--- a/tests/research_library/routes/test_rag_routes_upload_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_upload_coverage.py
@@ -875,6 +875,7 @@ class TestGetCollectionDocuments:
mock_coll.distance_metric = None
mock_coll.index_type = None
mock_coll.normalize_vectors = None
+ mock_coll.collection_type = "user_uploads"
# Create a temporary file to act as the index path
with tempfile.NamedTemporaryFile(delete=False, suffix=".index") as tmp:
diff --git a/tests/storage/test_base_storage_coverage.py b/tests/storage/test_base_storage_coverage.py
index ec8a796533..fba0a596e5 100644
--- a/tests/storage/test_base_storage_coverage.py
+++ b/tests/storage/test_base_storage_coverage.py
@@ -33,13 +33,14 @@ class TestReportStorageIsAbstract:
"""ReportStorage inherits from ABC."""
assert issubclass(ReportStorage, ABC)
- def test_has_five_abstract_methods(self):
- """All five public methods are declared abstract."""
+ def test_has_six_abstract_methods(self):
+ """All six public methods are declared abstract."""
expected = {
"save_report",
"get_report",
"get_report_with_metadata",
"delete_report",
+ "list_reports",
"report_exists",
}
assert ReportStorage.__abstractmethods__ == expected
@@ -64,6 +65,9 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, research_id, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, research_id, username=None):
return False
@@ -83,6 +87,9 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, research_id, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, research_id, username=None):
return False
@@ -102,6 +109,9 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, research_id, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, research_id, username=None):
return False
@@ -121,6 +131,9 @@ class TestPartialImplementationRaisesTypeError:
def get_report_with_metadata(self, research_id, username=None):
return None
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, research_id, username=None):
return False
@@ -143,6 +156,31 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, research_id, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
+ with pytest.raises(TypeError):
+ Incomplete()
+
+ def test_missing_list_reports(self):
+ class Incomplete(ReportStorage):
+ def save_report(
+ self, research_id, content, metadata=None, username=None
+ ):
+ return True
+
+ def get_report(self, research_id, username=None):
+ return None
+
+ def get_report_with_metadata(self, research_id, username=None):
+ return None
+
+ def delete_report(self, research_id, username=None):
+ return False
+
+ def report_exists(self, research_id, username=None):
+ return False
+
with pytest.raises(TypeError):
Incomplete()
@@ -197,6 +235,10 @@ class InMemoryReportStorage(ReportStorage):
return True
return False
+ def list_reports(self, username=None):
+ prefix = f"{username or ''}::"
+ return [{"id": k} for k in self._reports if k.startswith(prefix)]
+
def report_exists(
self, research_id: str, username: Optional[str] = None
) -> bool:
diff --git a/tests/storage/test_base_storage_deep_coverage.py b/tests/storage/test_base_storage_deep_coverage.py
index 69f05ed58e..4324e218cf 100644
--- a/tests/storage/test_base_storage_deep_coverage.py
+++ b/tests/storage/test_base_storage_deep_coverage.py
@@ -42,6 +42,9 @@ class ConcreteStorage(ReportStorage):
return True
return False
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, research_id, username=None):
return research_id in self._store
@@ -96,6 +99,7 @@ class TestAbstractMethodsSetExact:
"get_report",
"get_report_with_metadata",
"delete_report",
+ "list_reports",
"report_exists",
}
assert ReportStorage.__abstractmethods__ == expected
@@ -118,6 +122,9 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, rid, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
def report_exists(self, rid, username=None):
return False
@@ -138,6 +145,9 @@ class TestPartialImplementationRaisesTypeError:
def delete_report(self, rid, username=None):
return False
+ def list_reports(self, username=None):
+ return []
+
with pytest.raises(TypeError):
Incomplete()
diff --git a/tests/storage/test_storage_high_value.py b/tests/storage/test_storage_high_value.py
index 59c7f29016..8b904d1284 100644
--- a/tests/storage/test_storage_high_value.py
+++ b/tests/storage/test_storage_high_value.py
@@ -52,6 +52,9 @@ class TestReportStorageABC:
def delete_report(self, *a, **kw):
return True
+ def list_reports(self, *a, **kw):
+ return []
+
def report_exists(self, *a, **kw):
return False
diff --git a/tests/test_llm_provider_integration.py b/tests/test_llm_provider_integration.py
index 44097b5c13..c3fb9ee337 100644
--- a/tests/test_llm_provider_integration.py
+++ b/tests/test_llm_provider_integration.py
@@ -5,6 +5,7 @@ Tests the full flow from API key configuration to research execution.
import pytest
from unittest.mock import Mock, patch
+from langchain_core.language_models import BaseChatModel
from local_deep_research.settings import SettingsManager
@@ -157,15 +158,17 @@ class TestLLMProviderIntegration:
== "sk-openrouter-test-key"
)
- # Mock the LLM and search
+ # Mock the LLM and search — patch at provider level since auto-discovery
+ # registers providers in the LLM registry, bypassing llm_config's
+ # hardcoded ChatOpenAI path.
with patch(
- "local_deep_research.config.llm_config.ChatOpenAI"
+ "local_deep_research.llm.providers.openai_base.ChatOpenAI"
) as mock_openai:
with patch(
"local_deep_research.api.research_functions.AdvancedSearchSystem"
) as mock_search_system:
- # Setup mock LLM
- mock_llm_instance = Mock()
+ # Setup mock LLM (spec=BaseChatModel so isinstance check passes)
+ mock_llm_instance = Mock(spec=BaseChatModel)
mock_response = Mock()
mock_response.content = "Based on my research: Test topic is important because..."
mock_llm_instance.invoke.return_value = mock_response
@@ -200,7 +203,7 @@ class TestLLMProviderIntegration:
call_args.kwargs["api_key"] == "sk-openrouter-test-key"
)
assert (
- call_args.kwargs["openai_api_base"]
+ call_args.kwargs["base_url"]
== "https://openrouter.ai/api/v1"
)
assert call_args.kwargs["model"] == "claude-3-sonnet"
@@ -231,6 +234,10 @@ class TestLLMProviderIntegration:
settings_manager = SettingsManager(None)
# Test 1: OpenRouter configuration
+ # Patch at provider level — auto-discovery registers providers
+ # in the LLM registry, so get_llm() calls the provider's
+ # create_llm factory (in openai_base.py) instead of the
+ # hardcoded ChatOpenAI in llm_config.py.
settings_manager.set_setting(
"llm.provider", "openai_endpoint"
)
@@ -240,9 +247,9 @@ class TestLLMProviderIntegration:
settings_snapshot = settings_manager.get_all_settings()
with patch(
- "local_deep_research.config.llm_config.ChatOpenAI"
+ "local_deep_research.llm.providers.openai_base.ChatOpenAI"
) as mock_openai:
- mock_openai.return_value = Mock()
+ mock_openai.return_value = Mock(spec=BaseChatModel)
get_llm(settings_snapshot=settings_snapshot)
assert (
mock_openai.call_args.kwargs["api_key"]
@@ -257,9 +264,9 @@ class TestLLMProviderIntegration:
settings_snapshot = settings_manager.get_all_settings()
with patch(
- "local_deep_research.config.llm_config.ChatOpenAI"
+ "local_deep_research.llm.providers.implementations.openai.ChatOpenAI"
) as mock_openai:
- mock_openai.return_value = Mock()
+ mock_openai.return_value = Mock(spec=BaseChatModel)
get_llm(settings_snapshot=settings_snapshot)
assert (
mock_openai.call_args.kwargs["api_key"]
@@ -278,9 +285,9 @@ class TestLLMProviderIntegration:
settings_snapshot = settings_manager.get_all_settings()
with patch(
- "local_deep_research.config.llm_config.ChatAnthropic"
+ "local_deep_research.llm.providers.implementations.anthropic.ChatAnthropic"
) as mock_anthropic:
- mock_anthropic.return_value = Mock()
+ mock_anthropic.return_value = Mock(spec=BaseChatModel)
get_llm(settings_snapshot=settings_snapshot)
assert (
mock_anthropic.call_args.kwargs["anthropic_api_key"]
@@ -370,7 +377,7 @@ class TestLLMProviderIntegration:
with patch(
"local_deep_research.config.llm_config.ChatOpenAI"
) as mock_openai:
- mock_openai.return_value = Mock()
+ mock_openai.return_value = Mock(spec=BaseChatModel)
from local_deep_research.config.llm_config import (
get_llm,
diff --git a/tests/utilities/test_db_utils_deep_coverage.py b/tests/utilities/test_db_utils_deep_coverage.py
index d6ed0b4742..a490655970 100644
--- a/tests/utilities/test_db_utils_deep_coverage.py
+++ b/tests/utilities/test_db_utils_deep_coverage.py
@@ -34,7 +34,8 @@ class TestGetDbSessionFlaskSessionUsername:
"local_deep_research.utilities.db_utils.db_manager"
) as mock_mgr:
mock_mgr.get_session.return_value = mock_session
- result = get_db_session()
+ # Use unique _namespace to avoid cache hits from other tests
+ result = get_db_session(_namespace="test_flask_session")
assert result == mock_session
mock_mgr.get_session.assert_called_with("testuser")