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.

3.0 KB
Raw Blame
"""Pin that metrics' strategy list derives from constants.AVAILABLE_STRATEGIES.

Regression coverage for a maintainer review comment on
src/local_deep_research/web/routers/metrics.py:458 ("It's annoying how this
will have to be kept in sync. Can we at least have one centralized source of
truth for this across the whole app?"). metrics.py used to hand-maintain its
own ~22-entry strategy list -- a stale copy that had already drifted from
constants.AVAILABLE_STRATEGIES (the list search_system_factory.create_strategy
and every other UI actually honors). These tests fail if a hardcoded,
independently-maintained list is ever reintroduced in metrics.py.
"""

import local_deep_research.constants as constants
from local_deep_research.web.routers import metrics


def test_metrics_strategy_names_and_descriptions_match_central_source():
    """metrics' names/descriptions mirror constants.AVAILABLE_STRATEGIES 1:1."""
    central = constants.get_available_strategies()
    result = metrics.get_available_strategies()

    assert [s["name"] for s in result] == [s["name"] for s in central]
    assert [s["description"] for s in result] == [
        s["description"] for s in central
    ]


def test_metrics_strategy_entries_keep_the_existing_wire_shape():
    """Response entries stay {"name", "description"} -- no "label" leaks in.

    constants.AVAILABLE_STRATEGIES also carries a "label" field (used by
    dropdown widgets elsewhere). metrics.get_available_strategies() must
    keep adapting the shape at the boundary rather than exposing "label",
    so this endpoint's existing wire contract is unchanged.
    """
    result = metrics.get_available_strategies()

    assert result, "expected at least one strategy"
    for entry in result:
        assert set(entry.keys()) == {"name", "description"}


def test_adding_a_strategy_to_the_constant_shows_up_in_metrics(monkeypatch):
    """Mutating AVAILABLE_STRATEGIES propagates into metrics's output.

    Proves the two data sets cannot drift apart: metrics no longer owns an
    independent copy, it derives from the constant on every call.
    """
    new_strategy = {
        "name": "__test_only_strategy__",
        "label": "Test Only Strategy",
        "description": "Exists only to prove metrics derives from constants.",
    }
    monkeypatch.setattr(
        constants,
        "AVAILABLE_STRATEGIES",
        constants.AVAILABLE_STRATEGIES + [new_strategy],
    )

    result = metrics.get_available_strategies()

    assert {
        "name": "__test_only_strategy__",
        "description": new_strategy["description"],
    } in result


def test_removing_a_strategy_from_the_constant_removes_it_from_metrics(
    monkeypatch,
):
    """The inverse: shrinking the constant shrinks metrics's output too."""
    original = constants.AVAILABLE_STRATEGIES
    removed_name = original[-1]["name"]
    monkeypatch.setattr(constants, "AVAILABLE_STRATEGIES", original[:-1])

    result = metrics.get_available_strategies()

    assert len(result) == len(original) - 1
    assert removed_name not in [s["name"] for s in result]