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.6 KB
Raw Blame
"""Progress updates stay usable by the worker, queue and HTTP status readers."""

import pytest

from local_deep_research.web import research_state


@pytest.mark.parametrize(
    "update",
    [
        research_state.update_progress_if_higher,
        research_state.update_progress_and_check_active,
    ],
)
def test_progress_is_bounded_monotonic_and_does_not_change_status(update):
    research_id = "progress-bounds-test"
    research_state.set_active_research(
        research_id, {"progress": 0, "status": "in_progress"}
    )
    try:
        for value, expected in [
            (-10, 0),
            (42.5, 42.5),
            (12, 42.5),
            (float("nan"), 42.5),
            (136.66666666666666, 100),
            (100, 100),
            (None, 100),
        ]:
            result = update(research_id, value)
            assert result == expected or result == (expected, True)
            snapshot = research_state.get_active_research_snapshot(research_id)
            assert snapshot["progress"] == expected
            assert snapshot["status"] == "in_progress"
    finally:
        research_state.cleanup_research(research_id)


@pytest.mark.parametrize("stored,expected", [(-30, 50), (136.7, 100)])
def test_an_existing_out_of_range_value_cannot_poison_later_updates(
    stored, expected
):
    research_id = "previous-progress-bounds-test"
    research_state.set_active_research(
        research_id, {"progress": stored, "status": "in_progress"}
    )
    try:
        assert research_state.update_progress_and_check_active(
            research_id, 50
        ) == (expected, True)
    finally:
        research_state.cleanup_research(research_id)