Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

248 lines
7.8 KiB
Python

#!/usr/bin/env python3
"""
Test programmatic access to Local Deep Research without database dependencies.
"""
from unittest.mock import Mock
from langchain_core.retrievers import Document
def test_import_without_database():
"""Test that we can import AdvancedSearchSystem without database initialization."""
# This should not fail with database errors
from local_deep_research.search_system import AdvancedSearchSystem
# Should be able to create an instance with mock components
llm = Mock()
search = Mock()
# Create settings snapshot without programmatic_mode
settings_snapshot = {
"search.iterations": {"value": 1, "type": "int"},
"search.questions_per_iteration": {"value": 2, "type": "int"},
"search.strategy": {"value": "direct", "type": "str"},
"search.max_results_per_query": {"value": 10, "type": "int"},
"search.source_strategy.diversity_threshold": {
"value": 0.8,
"type": "float",
},
"search.source_strategy.min_relevance_score": {
"value": 0.5,
"type": "float",
},
"search.source_strategy.max_sources_per_topic": {
"value": 5,
"type": "int",
},
"search.source_strategy.enable_clustering": {
"value": False,
"type": "bool",
},
"search.cross_engine_max_results": {"value": 100, "type": "int"},
}
# Pass programmatic_mode as explicit parameter
system = AdvancedSearchSystem(
llm=llm,
search=search,
settings_snapshot=settings_snapshot,
programmatic_mode=True,
)
assert system is not None
assert system.model == llm
assert system.search == search
assert system.programmatic_mode is True
def test_analyze_topic_without_database():
"""Test analyze_topic function without database."""
from local_deep_research.search_system import AdvancedSearchSystem
# Create mock LLM
llm = Mock()
llm.invoke.return_value = Mock(
content="This is a summary about AI research."
)
# Create mock search engine
search = Mock()
search.run.return_value = [
{
"title": "AI Research Paper",
"link": "http://example.com/ai",
"snippet": "Recent advances in AI...",
"full_content": "Full content about AI research...",
"rank": 1,
}
]
# Create settings snapshot without programmatic_mode
settings_snapshot = {
"search.iterations": {"value": 1, "type": "int"},
"search.questions_per_iteration": {"value": 2, "type": "int"},
"search.strategy": {"value": "direct", "type": "str"},
"search.max_results_per_query": {"value": 10, "type": "int"},
"search.source_strategy.diversity_threshold": {
"value": 0.8,
"type": "float",
},
"search.source_strategy.min_relevance_score": {
"value": 0.5,
"type": "float",
},
"search.source_strategy.max_sources_per_topic": {
"value": 5,
"type": "int",
},
"search.source_strategy.enable_clustering": {
"value": False,
"type": "bool",
},
"search.cross_engine_max_results": {"value": 100, "type": "int"},
}
# Create system with programmatic_mode as parameter
system = AdvancedSearchSystem(
llm=llm,
search=search,
settings_snapshot=settings_snapshot,
programmatic_mode=True,
)
# Should be able to call analyze_topic
result = system.analyze_topic("What is AI?")
print(f"Result: {result}")
print(f"Search called: {search.run.called}")
print(f"Search call count: {search.run.call_count}")
assert result is not None
assert "findings" in result
def test_search_with_retriever():
"""Test using a retriever as search engine."""
from local_deep_research.search_system import AdvancedSearchSystem
from langchain_community.vectorstores import FAISS
from langchain_community.embeddings import FakeEmbeddings
# Create a simple retriever
documents = [
Document(
page_content="Machine learning is a subset of artificial intelligence.",
metadata={"source": "ml_intro.txt"},
),
Document(
page_content="Deep learning uses neural networks with multiple layers.",
metadata={"source": "dl_intro.txt"},
),
]
embeddings = FakeEmbeddings(size=10)
vectorstore = FAISS.from_documents(documents, embeddings)
retriever = vectorstore.as_retriever()
# Create retriever wrapper
class SimpleRetrieverWrapper:
def __init__(self, retriever, settings_snapshot=None):
self.retriever = retriever
self.include_full_content = True
self.settings_snapshot = settings_snapshot or {}
def run(self, query, research_context=None):
docs = self.retriever.get_relevant_documents(query)
results = []
for i, doc in enumerate(docs):
results.append(
{
"title": f"Result {i + 1}",
"link": doc.metadata.get("source", "unknown"),
"snippet": doc.page_content[:200],
"full_content": doc.page_content
if self.include_full_content
else None,
"rank": i + 1,
}
)
return results
# Create mock LLM
llm = Mock()
llm.invoke.return_value = Mock(content="Summary about machine learning.")
# Create settings without programmatic_mode
settings_snapshot = {
"search.iterations": {"value": 1, "type": "int"},
"search.questions_per_iteration": {"value": 2, "type": "int"},
"search.strategy": {"value": "direct", "type": "str"},
"search.max_results_per_query": {"value": 10, "type": "int"},
"search.source_strategy.diversity_threshold": {
"value": 0.8,
"type": "float",
},
"search.source_strategy.min_relevance_score": {
"value": 0.5,
"type": "float",
},
"search.source_strategy.max_sources_per_topic": {
"value": 5,
"type": "int",
},
"search.source_strategy.enable_clustering": {
"value": False,
"type": "bool",
},
"search.cross_engine_max_results": {"value": 100, "type": "int"},
}
# Create search wrapper with settings
search = SimpleRetrieverWrapper(retriever, settings_snapshot)
# Create system with programmatic_mode as parameter
system = AdvancedSearchSystem(
llm=llm,
search=search,
settings_snapshot=settings_snapshot,
programmatic_mode=True,
)
# Run a search
result = system.analyze_topic("What is machine learning?")
assert result is not None
assert "findings" in result
assert len(result["findings"]) > 0
def test_thread_context_without_database():
"""Test that thread context utilities work without database."""
from local_deep_research.utilities.thread_context import (
preserve_research_context,
)
# This should not fail even without database
@preserve_research_context
def sample_function():
return "success"
result = sample_function()
assert result == "success"
if __name__ == "__main__":
# Run tests
test_import_without_database()
print("✓ Import test passed")
test_analyze_topic_without_database()
print("✓ Analyze topic test passed")
test_search_with_retriever()
print("✓ Retriever search test passed")
test_thread_context_without_database()
print("✓ Thread context test passed")
print("\nAll tests passed! Programmatic access works without database.")