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.

2.3 KB
Raw Blame
from unittest.mock import Mock, patch


MODULE = "local_deep_research.web_search_engines.engines.search_engine_federal_register"
LIST_URL = "https://www.federalregister.gov/api/v1/documents.json"
RAW_TEXT_URL = (
    "https://www.federalregister.gov/documents/full_text/text/2026/12345.txt"
)


def _response(json_data=None, text="", url=RAW_TEXT_URL):
    response = Mock()
    response.status_code = 200
    response.json.return_value = {} if json_data is None else json_data
    response.text = text
    # The engine re-checks the response's final URL against its host
    # allow-list, so a stubbed response has to carry one.
    response.url = url
    return response


def test_get_search_fetches_federal_register_full_content_when_snippets_disabled():
    from local_deep_research.web_search_engines.search_engine_factory import (
        get_search,
    )

    settings_snapshot = {
        "search.engine.web": {"federal_register": {"default_params": {}}},
        "rate_limiting.enabled": False,
    }
    document = {
        "document_number": "2026-12345",
        "title": "Clean Air Standards",
        "html_url": "https://www.federalregister.gov/documents/2026/12345",
        "abstract": "The agency updates emissions standards.",
        "type": "Rule",
        "agencies": [],
        "publication_date": "2026-01-15",
        "pdf_url": "https://www.federalregister.gov/documents/2026/12345.pdf",
    }
    detail_url = f"{LIST_URL.removesuffix('.json')}/2026-12345.json"

    with patch(
        f"{MODULE}.safe_get",
        side_effect=[
            _response({"results": [document]}),
            _response({"raw_text_url": RAW_TEXT_URL}),
            _response(text="Full Federal Register document text."),
        ],
    ) as mock_get:
        engine = get_search(
            search_tool="federal_register",
            llm_instance=None,
            max_results=1,
            search_snippets_only=False,
            settings_snapshot=settings_snapshot,
            programmatic_mode=True,
        )
        assert engine.rate_tracker.enabled is False
        results = engine.run("clean air")

    assert [call.args[0] for call in mock_get.call_args_list] == [
        LIST_URL,
        detail_url,
        RAW_TEXT_URL,
    ]
    assert results[0]["full_content"] == "Full Federal Register document text."