~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test(langgraph-agent): cover fetch_content collector registration (#3457) (#3526)
LearningCircuitb17e6fa19882
diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.pyindex 59c1623c10..44c204fa0f 100644--- a/tests/strategies/test_langgraph_agent_strategy.py+++ b/tests/strategies/test_langgraph_agent_strategy.py@@ -504,3 +504,145 @@ class TestFactoryIntegration:assert strategy.max_iterations == 20assert strategy.max_sub_iterations == 3assert strategy.include_sub_research is False+++# ---------------------------------------------------------------------------+# fetch_content collector registration (regression for PR #3457)+# ---------------------------------------------------------------------------+++class TestFetchContentCollectorRegistration:+ """Regression coverage for PR #3457.++ Prior to the fix, ``_make_fetch_content_tool`` accepted ``collector`` but+ never used it, so every URL opened via the LLM's ``fetch_content`` tool+ was silently dropped from the final Sources section and citation system.+ These tests pin the fix: a successful fetch must register the URL, a+ duplicate fetch must reuse the existing citation index, and a failed+ fetch must not register anything.+ """++ def _make_collector(self):+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (+ SearchResultsCollector,+ )++ return SearchResultsCollector([])++ def _fetcher_cm(+ self, *, status="success", title="Page", content="Body", error=None+ ):+ """Return a MagicMock that behaves like ``ContentFetcher(...)``."""+ result = {"status": status, "title": title, "content": content}+ if error is not None:+ result["error"] = error+ fetcher = MagicMock()+ fetcher.fetch.return_value = result+ cm = MagicMock()+ cm.__enter__.return_value = fetcher+ cm.__exit__.return_value = False+ return cm++ def _make_tool(self, collector):+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (+ _make_fetch_content_tool,+ )++ return _make_fetch_content_tool(collector)++ def test_successful_fetch_registers_url_in_collector(self):+ collector = self._make_collector()+ tool = self._make_tool(collector)+ cm = self._fetcher_cm(title="Hello", content="some body text")++ with patch(+ "local_deep_research.content_fetcher.ContentFetcher",+ return_value=cm,+ ):+ output = tool.invoke({"url": "http://example.com/page"})++ assert "http://example.com/page" in collector.sources+ assert len(collector.results) == 1+ entry = collector.results[0]+ assert entry["link"] == "http://example.com/page"+ assert entry["title"] == "Hello"+ assert entry["source_engine"] == "fetch"+ # Tool return is prefixed with the 1-based citation index so the+ # agent can cite fetched pages the same way it cites web_search hits.+ assert output.startswith("[1] ")++ def test_repeated_fetch_of_same_url_reuses_citation_index(self):+ collector = self._make_collector()+ # Simulate web_search having already captured this URL.+ collector.add_results(+ [+ {+ "title": "From search",+ "link": "http://example.com/page",+ "snippet": "snip",+ }+ ],+ engine_name="web",+ )+ assert len(collector.results) == 1++ tool = self._make_tool(collector)+ cm = self._fetcher_cm(title="From fetch", content="full body")++ with patch(+ "local_deep_research.content_fetcher.ContentFetcher",+ return_value=cm,+ ):+ output = tool.invoke({"url": "http://example.com/page"})++ # No duplicate entry; the fetch reuses the existing citation slot.+ assert len(collector.results) == 1+ assert output.startswith("[1] ")++ def test_failed_fetch_does_not_register_url(self):+ collector = self._make_collector()+ tool = self._make_tool(collector)+ cm = self._fetcher_cm(+ status="error", title="", content="", error="timeout"+ )++ with patch(+ "local_deep_research.content_fetcher.ContentFetcher",+ return_value=cm,+ ):+ output = tool.invoke({"url": "http://broken.example/page"})++ assert collector.results == []+ assert collector.sources == []+ assert "Failed to fetch" in output++ def test_long_content_snippet_is_truncated_with_ellipsis(self):+ collector = self._make_collector()+ tool = self._make_tool(collector)+ cm = self._fetcher_cm(title="Long", content="A" * 500)++ with patch(+ "local_deep_research.content_fetcher.ContentFetcher",+ return_value=cm,+ ):+ tool.invoke({"url": "http://example.com/long"})++ snippet = collector.results[0]["snippet"]+ assert snippet.endswith("...")+ assert len(snippet) == 203 # 200 chars + "..."++ def test_find_by_url_returns_index_when_present(self):+ collector = self._make_collector()+ collector.add_results(+ [{"title": "A", "link": "http://a.com", "snippet": "a"}],+ engine_name="web",+ )+ assert collector.find_by_url("http://a.com") == 1++ def test_find_by_url_returns_none_when_absent(self):+ collector = self._make_collector()+ collector.add_results(+ [{"title": "A", "link": "http://a.com", "snippet": "a"}],+ engine_name="web",+ )+ assert collector.find_by_url("http://missing.com") is None