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
"""Tests that all FastAPI routers load without import errors."""

import importlib

import pytest


ROUTER_MODULES = [
    ".routers.auth",
    ".routers.research",
    ".routers.history",
    ".routers.settings",
    ".routers.metrics",
    ".routers.api",
    ".routers.context_overflow_api",
    ".routers.news_flask_api",
    ".routers.news_pages",
    ".routers.benchmark",
    ".routers.followup",
    ".routers.library",
    ".routers.rag",
    ".routers.library_delete",
    ".routers.library_search",
    ".routers.scheduler",
]


@pytest.mark.parametrize("module_path", ROUTER_MODULES)
def test_router_imports(module_path):
    """Each router module imports without errors and exposes a router."""
    mod = importlib.import_module(
        module_path, package="local_deep_research.web"
    )
    assert hasattr(mod, "router"), f"{module_path} has no 'router' attribute"


def test_full_app_creates():
    """The FastAPI app creates with all routers mounted."""
    from local_deep_research.web.fastapi_app import app

    routes = [r for r in app.routes if hasattr(r, "path")]
    assert len(routes) >= 200, f"Expected 200+ routes, got {len(routes)}"


def test_mount_all_raises_on_router_without_router_attr(monkeypatch):
    """
    Regression test: pre-fix, ``_mount_all`` silently swallowed any import
    failure or missing ``router`` attribute, leaving a whole feature
    serving 404 with no operator signal. Now any such failure must raise
    at startup so deploys fail loud.
    """
    from types import ModuleType

    from fastapi import FastAPI

    from local_deep_research.web.fastapi_app import _mount_all

    real_import = importlib.import_module

    def _broken_import(module_path, package=None):
        if module_path == ".routers.auth":
            # Stub module with intentionally NO `router` attribute.
            return ModuleType("local_deep_research.web.routers.auth")
        return real_import(module_path, package=package)

    # Patch the importlib module function — `_mount_all` does
    # `import importlib` locally then calls `importlib.import_module`,
    # so patching the global function affects that local binding too.
    monkeypatch.setattr(importlib, "import_module", _broken_import)

    test_app = FastAPI()
    with pytest.raises(RuntimeError, match="has no 'router' attribute"):
        _mount_all(test_app)