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
"""Configuration failures must survive background snapshot reads."""

import pytest

from local_deep_research.config.thread_settings import get_setting_from_snapshot
from local_deep_research.settings.exceptions import SettingsValueError


@pytest.mark.parametrize("read_key", ["search.iterations", "search"])
def test_invalid_environment_stops_exact_and_namespace_snapshot_reads(
    monkeypatch, read_key
):
    monkeypatch.setenv("LDR_SEARCH_ITERATIONS", "invalid-private-value")
    snapshot = {"search.iterations": {"value": 5, "ui_element": "number"}}

    with pytest.raises(SettingsValueError) as caught:
        get_setting_from_snapshot(read_key, 2, settings_snapshot=snapshot)

    assert caught.value.key == "search.iterations"
    assert caught.value.source == "environment"
    assert "invalid-private-value" not in str(caught.value)
    assert caught.value.__context__ is None
    assert caught.value.__cause__ is None
    assert snapshot["search.iterations"]["value"] == 5


def test_namespace_override_uses_full_setting_name(monkeypatch):
    monkeypatch.setenv("LDR_SEARCH_ITERATIONS", "7")
    monkeypatch.setenv("LDR_ITERATIONS", "invalid-unrelated-value")
    snapshot = {"search.iterations": {"value": 5, "ui_element": "number"}}

    assert get_setting_from_snapshot("search", settings_snapshot=snapshot) == {
        "iterations": 7
    }


@pytest.mark.parametrize("read_key", ["search.iterations", "search"])
def test_invalid_stored_snapshot_cannot_use_caller_default(
    monkeypatch, read_key
):
    monkeypatch.delenv("LDR_SEARCH_ITERATIONS", raising=False)
    snapshot = {
        "search.iterations": {"value": "invalid", "ui_element": "number"}
    }

    with pytest.raises(SettingsValueError):
        get_setting_from_snapshot(read_key, 2, settings_snapshot=snapshot)