Files
deerflow-factory/deer-flow/backend/tests/test_reflection_resolvers.py
DATA 6de0bf9f5b Initial commit: hardened DeerFlow factory
Vendored deer-flow upstream (bytedance/deer-flow) plus prompt-injection
hardening:

- New deerflow.security package: content_delimiter, html_cleaner,
  sanitizer (8 layers — invisible chars, control chars, symbols, NFC,
  PUA, tag chars, horizontal whitespace collapse with newline/tab
  preservation, length cap)
- New deerflow.community.searx package: web_search, web_fetch,
  image_search backed by a private SearX instance, every external
  string sanitized and wrapped in <<<EXTERNAL_UNTRUSTED_CONTENT>>>
  delimiters
- All native community web providers (ddg_search, tavily, exa,
  firecrawl, jina_ai, infoquest, image_search) replaced with hard-fail
  stubs that raise NativeWebToolDisabledError at import time, so a
  misconfigured tool.use path fails loud rather than silently falling
  back to unsanitized output
- Native client back-doors (jina_client.py, infoquest_client.py)
  stubbed too
- Native-tool tests quarantined under tests/_disabled_native/
  (collect_ignore_glob via local conftest.py)
- Sanitizer Layer 7 fix: only collapse horizontal whitespace, preserve
  newlines and tabs so list/table structure survives
- Hardened runtime config.yaml references only the searx-backed tools
- Factory overlay (backend/) kept in sync with deer-flow tree as a
  reference / source

See HARDENING.md for the full audit trail and verification steps.
2026-04-12 14:23:57 +02:00

50 lines
1.9 KiB
Python

"""Tests for reflection resolvers."""
import pytest
from deerflow.reflection import resolvers
from deerflow.reflection.resolvers import resolve_variable
def test_resolve_variable_reports_install_hint_for_missing_google_provider(monkeypatch: pytest.MonkeyPatch):
"""Missing google provider should return actionable install guidance."""
def fake_import_module(module_path: str):
raise ModuleNotFoundError(f"No module named '{module_path}'", name=module_path)
monkeypatch.setattr(resolvers, "import_module", fake_import_module)
with pytest.raises(ImportError) as exc_info:
resolve_variable("langchain_google_genai:ChatGoogleGenerativeAI")
message = str(exc_info.value)
assert "Could not import module langchain_google_genai" in message
assert "uv add langchain-google-genai" in message
def test_resolve_variable_reports_install_hint_for_missing_google_transitive_dependency(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Missing transitive dependency should still return actionable install guidance."""
def fake_import_module(module_path: str):
# Simulate provider module existing but a transitive dependency (e.g. `google`) missing.
raise ModuleNotFoundError("No module named 'google'", name="google")
monkeypatch.setattr(resolvers, "import_module", fake_import_module)
with pytest.raises(ImportError) as exc_info:
resolve_variable("langchain_google_genai:ChatGoogleGenerativeAI")
message = str(exc_info.value)
# Even when a transitive dependency is missing, the hint should still point to the provider package.
assert "uv add langchain-google-genai" in message
def test_resolve_variable_invalid_path_format():
"""Invalid variable path should fail with format guidance."""
with pytest.raises(ImportError) as exc_info:
resolve_variable("invalid.variable.path")
assert "doesn't look like a variable path" in str(exc_info.value)