"""Tests for project-wide constants in local_deep_research.constants."""

import json

from local_deep_research.constants import DEFAULT_SEARCH_TOOL
from local_deep_research.defaults import DEFAULTS_DIR


def test_default_search_tool_matches_registry():
    """DEFAULT_SEARCH_TOOL (the code-side fallback every reader imports for a
    missing ``search.tool`` setting) must equal the registered default in
    defaults/default_settings.json.

    This single test replaces scattered ``"searxng"`` fallback literals and
    is what prevents the code/registry drift that let the old ``"auto"``
    default linger across ~30 sites. Mirrors
    test_egress_policy::test_default_scope_constant_matches_registry.
    """
    path = DEFAULTS_DIR / "default_settings.json"
    assert path.exists()
    with open(path, encoding="utf-8-sig") as f:
        registry = json.load(f)
    assert registry["search.tool"]["value"] == DEFAULT_SEARCH_TOOL


def test_default_search_tool_is_a_registered_option():
    """The default must be one of the engines offered in the settings UI."""
    path = DEFAULTS_DIR / "default_settings.json"
    with open(path, encoding="utf-8-sig") as f:
        registry = json.load(f)
    option_values = {opt["value"] for opt in registry["search.tool"]["options"]}
    assert DEFAULT_SEARCH_TOOL in option_values
