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.

1.8 KB
Raw Blame
"""has_encryption must be injected into every template render.

Main injected it via render_template_with_defaults; the FastAPI port
dropped it, so settings_dashboard.html's `{% if not has_encryption %}`
warning ("Database encryption is not available") rendered unconditionally
(Undefined is falsy → `not` → True) — a false security alarm on every
encrypted install.
"""

from unittest.mock import patch

from starlette.requests import Request

WARNING = "Database encryption is not available"


def _dummy_request():
    return Request(
        {
            "type": "http",
            "method": "GET",
            "path": "/",
            "headers": [],
            "session": {},
        }
    )


def _render_dashboard(has_encryption):
    from local_deep_research.web.template_config import templates

    with patch("local_deep_research.database.encrypted_db.db_manager") as dbm:
        dbm.has_encryption = has_encryption
        resp = templates.TemplateResponse(
            request=_dummy_request(),
            name="settings_dashboard.html",
            context={},
        )
    return resp.body.decode()


def test_warning_hidden_when_encryption_available():
    assert WARNING not in _render_dashboard(True)


def test_warning_shown_when_encryption_unavailable():
    assert WARNING in _render_dashboard(False)


def test_explicit_context_value_is_not_overwritten():
    from local_deep_research.web.template_config import templates

    # An explicit has_encryption in context wins over the injected default.
    with patch("local_deep_research.database.encrypted_db.db_manager") as dbm:
        dbm.has_encryption = False
        resp = templates.TemplateResponse(
            request=_dummy_request(),
            name="settings_dashboard.html",
            context={"has_encryption": True},
        )
    assert WARNING not in resp.body.decode()