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 for the PDF storage mode gate in the UI modal and library pages."""

from local_deep_research.web.template_config import templates
from starlette.requests import Request


class TestStorageModeModalGate:
    """Test that the filesystem storage option in storage_mode_modal.html is gated."""

    def test_modal_hides_filesystem_when_gate_off(self):
        t = templates.get_template("components/storage_mode_modal.html")
        html = t.render(
            filesystem_pdf_storage_allowed=False,
            pdf_storage_mode="database",
        )
        assert 'data-mode="filesystem"' not in html
        assert 'value="filesystem"' not in html
        assert 'data-mode="database"' in html
        assert 'data-mode="none"' in html

    def test_modal_shows_filesystem_when_gate_on(self):
        t = templates.get_template("components/storage_mode_modal.html")
        html = t.render(
            filesystem_pdf_storage_allowed=True,
            pdf_storage_mode="filesystem",
        )
        assert 'data-mode="filesystem"' in html
        assert 'value="filesystem"' in html
        assert "checked" in html
        assert 'data-mode="database"' in html
        assert 'data-mode="none"' in html

    def test_template_response_injects_gate_flag_when_off(self, monkeypatch):
        monkeypatch.delenv(
            "LDR_RESEARCH_LIBRARY_ALLOW_FILESYSTEM_PDF_STORAGE", raising=False
        )
        req = Request(scope={"type": "http", "session": {}})
        resp = templates.TemplateResponse(
            request=req,
            name="components/storage_mode_modal.html",
            context={"pdf_storage_mode": "database"},
        )
        body = resp.body.decode("utf-8")
        assert 'data-mode="filesystem"' not in body
        assert 'data-mode="database"' in body

    def test_template_response_injects_gate_flag_when_on(self, monkeypatch):
        monkeypatch.setenv(
            "LDR_RESEARCH_LIBRARY_ALLOW_FILESYSTEM_PDF_STORAGE", "true"
        )
        req = Request(scope={"type": "http", "session": {}})
        resp = templates.TemplateResponse(
            request=req,
            name="components/storage_mode_modal.html",
            context={"pdf_storage_mode": "filesystem"},
        )
        body = resp.body.decode("utf-8")
        assert 'data-mode="filesystem"' in body
        assert 'data-mode="database"' in body