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.3 KB
Raw Blame
"""Regression coverage for shared rate-limit storage isolation."""

from inspect import unwrap

import pytest
from limits import parse

from local_deep_research.web.dependencies import rate_limit
from tests import conftest as shared_fixtures


@pytest.mark.parametrize("enabled", [True, False], ids=["enabled", "disabled"])
def test_shared_fixture_resets_storage_without_changing_enforcement(
    monkeypatch: pytest.MonkeyPatch, enabled: bool
) -> None:
    """Both fixture phases clear storage without changing enforcement settings."""
    limiter = rate_limit.limiter
    monkeypatch.setattr(limiter, "enabled", enabled)
    rate = parse("1 per hour")
    scope = "route-fixture-reset-regression"
    limiter.reset()
    reset_fixture = unwrap(shared_fixtures.reset_all_singletons)()

    try:
        assert limiter._limiter.hit(rate, scope)
        assert not limiter._limiter.hit(rate, scope)

        next(reset_fixture)

        assert limiter._limiter.hit(rate, scope)
        assert not limiter._limiter.hit(rate, scope)
        assert limiter.enabled is enabled

        with pytest.raises(StopIteration):
            next(reset_fixture)

        assert limiter._limiter.hit(rate, scope)
        assert not limiter._limiter.hit(rate, scope)
        assert limiter.enabled is enabled
    finally:
        reset_fixture.close()
        limiter.reset()