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.

test(langgraph): pin search.fetch.mode and engine-name guard branches (#4089)

LearningCircuitdbb5c292c4ed
diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.py
index da1e977a94..ef682f6379 100644
--- a/tests/strategies/test_langgraph_agent_strategy.py
+++ b/tests/strategies/test_langgraph_agent_strategy.py
@@ -656,3 +656,133 @@ class TestFetchContentCollectorRegistration:
engine_name="web",
)
assert collector.find_by_url("http://missing.com") is None
+
+
+class TestFetchModeSettingResolution:
+ """``LangGraphAgentStrategy.__init__`` reads the ``search.fetch.mode``
+ setting (added in #3680; default changed to ``summary_focus_query``
+ in #3793) and feeds it to ``build_fetch_tool``. The constructor must:
+
+ - Accept any value in ``FETCH_MODES`` verbatim.
+ - Reject any other value, log a warning, and fall back to
+ ``summary_focus_query`` rather than crashing or letting an unknown
+ mode reach ``build_fetch_tool``.
+
+ The existing tests covered the constructor and tool-building paths
+ but not this guard.
+ """
+
+ def _make_strategy(self, **overrides):
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ LangGraphAgentStrategy,
+ )
+
+ defaults = {
+ "model": MagicMock(),
+ "search": MagicMock(),
+ "all_links_of_system": [],
+ "settings_snapshot": {"search.tool": "duckduckgo"},
+ }
+ defaults.update(overrides)
+ return LangGraphAgentStrategy(**defaults)
+
+ def test_known_fetch_mode_accepted_verbatim(self):
+ """``summary_focus`` (one of the ``FETCH_MODES``) must round-trip
+ through the constructor unchanged.
+ """
+ strategy = self._make_strategy(
+ settings_snapshot={
+ "search.tool": "duckduckgo",
+ "search.fetch.mode": "summary_focus",
+ }
+ )
+ assert strategy.fetch_mode == "summary_focus"
+
+ def test_unknown_fetch_mode_falls_back_to_default_with_warning(
+ self, loguru_caplog
+ ):
+ """A misconfigured setting must not crash the constructor or
+ propagate an unknown mode into ``build_fetch_tool``. The guard
+ at the top of ``__init__`` logs a warning and substitutes the
+ default. Anyone removing the guard would surface as the mode
+ leaking through unchanged AND the warning going missing.
+ """
+ with loguru_caplog.at_level("WARNING"):
+ strategy = self._make_strategy(
+ settings_snapshot={
+ "search.tool": "duckduckgo",
+ "search.fetch.mode": "definitely-not-a-real-mode",
+ }
+ )
+
+ assert strategy.fetch_mode == "summary_focus_query"
+ assert "Unknown search.fetch.mode" in loguru_caplog.text
+ assert "definitely-not-a-real-mode" in loguru_caplog.text
+
+ def test_disabled_fetch_mode_omits_fetch_tool(self):
+ """``fetch_mode='disabled'`` must produce a tool list with NO
+ fetch tool — ``build_fetch_tool`` returns ``None`` and the
+ ``if fetch is not None`` guard skips the append. A regression
+ that always-appended would surface here as an extra tool.
+ """
+ strategy = self._make_strategy(
+ settings_snapshot={
+ "search.tool": "duckduckgo",
+ "search.fetch.mode": "disabled",
+ }
+ )
+
+ tools = strategy._build_tools(overall_query="anything")
+
+ tool_names = {
+ getattr(t, "name", None) or getattr(t, "__name__", None)
+ for t in tools
+ }
+ # No tool whose name contains 'fetch'.
+ assert all(
+ "fetch" not in (name or "").lower() for name in tool_names
+ ), (
+ f"Expected no fetch tool with fetch_mode='disabled' but got "
+ f"tools: {tool_names}"
+ )
+
+
+class TestResolveEngineNameIgnoresNonString:
+ """``_resolve_engine_name`` short-circuits to the settings value only
+ when it is a string (``isinstance(tool_setting, str)``); anything
+ else — a list, a dict without a ``value`` key, an int — falls
+ through to the class-name heuristic. The existing tests covered
+ the success path and the bare-class fallback but didn't pin the
+ non-string guard against realistic misconfiguration shapes.
+ """
+
+ def _make_strategy_with_search_tool_value(self, search_tool_value):
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ LangGraphAgentStrategy,
+ )
+
+ mock_search = MagicMock()
+ mock_search.__class__.__name__ = "BraveSearchEngine"
+ return LangGraphAgentStrategy(
+ model=MagicMock(),
+ search=mock_search,
+ all_links_of_system=[],
+ settings_snapshot={"search.tool": search_tool_value},
+ )
+
+ def test_list_settings_value_falls_through_to_class_heuristic(self):
+ """A list at ``search.tool`` is not a valid engine name — the
+ ``isinstance(..., str)`` guard rejects it and the class-name
+ heuristic kicks in.
+ """
+ strategy = self._make_strategy_with_search_tool_value(
+ ["this is not a string"]
+ )
+ assert strategy._search_engine_name == "brave"
+
+ def test_int_settings_value_falls_through_to_class_heuristic(self):
+ """Numeric values likewise fall through — pins that the guard
+ rejects any non-string type, not just dicts.
+ """
+ strategy = self._make_strategy_with_search_tool_value(42)
+ assert strategy._search_engine_name == "brave"