"""High-value tests for web/warning_checks/hardware.py - Hardware Warnings."""

from local_deep_research.web.warning_checks.hardware import (
    check_high_context,
    check_model_mismatch,
    LOCAL_PROVIDERS,
)


# ---------------------------------------------------------------------------
# LOCAL_PROVIDERS
# ---------------------------------------------------------------------------


class TestLocalProviders:
    def test_is_frozenset(self):
        assert isinstance(LOCAL_PROVIDERS, frozenset)

    def test_expected_providers(self):
        assert LOCAL_PROVIDERS == {"ollama", "llamacpp", "lmstudio"}


# ---------------------------------------------------------------------------
# check_high_context()
# ---------------------------------------------------------------------------


class TestCheckHighContext:
    """High context warning for local providers."""

    def test_non_local_provider_returns_none(self):
        assert check_high_context("openai", 16384, False) is None

    def test_context_at_threshold_returns_none(self):
        assert check_high_context("ollama", 8192, False) is None

    def test_context_below_threshold_returns_none(self):
        assert check_high_context("ollama", 4096, False) is None

    def test_dismissed_returns_none(self):
        assert check_high_context("ollama", 16384, True) is None

    def test_ollama_high_context_returns_warning(self):
        result = check_high_context("ollama", 16384, False)
        assert result is not None
        assert result["type"] == "high_context"
        assert "16,384" in result["message"]
        assert "ollama" in result["message"]

    def test_llamacpp_high_context(self):
        result = check_high_context("llamacpp", 32768, False)
        assert result is not None
        assert result["type"] == "high_context"

    def test_lmstudio_high_context(self):
        result = check_high_context("lmstudio", 10000, False)
        assert result is not None
        assert result["type"] == "high_context"

    def test_warning_has_dismiss_key(self):
        result = check_high_context("ollama", 16384, False)
        assert "dismissKey" in result

    def test_warning_has_icon(self):
        result = check_high_context("ollama", 16384, False)
        assert "icon" in result

    def test_anthropic_not_local(self):
        assert check_high_context("anthropic", 100000, False) is None

    def test_boundary_8193_triggers_warning(self):
        result = check_high_context("ollama", 8193, False)
        assert result is not None
        assert result["title"] == "High Context Warning"


# ---------------------------------------------------------------------------
# check_model_mismatch()
# ---------------------------------------------------------------------------


class TestCheckModelMismatch:
    """Model mismatch warning for large models with high context."""

    def test_empty_model_returns_none(self):
        assert check_model_mismatch("ollama", "", 16384, False) is None

    def test_none_model_returns_none(self):
        assert check_model_mismatch("ollama", None, 16384, False) is None

    def test_non_local_provider_returns_none(self):
        assert (
            check_model_mismatch("openai", "llama3-70b", 16384, False) is None
        )

    def test_non_70b_model_returns_none(self):
        assert check_model_mismatch("ollama", "llama3-7b", 16384, False) is None

    def test_low_context_returns_none(self):
        assert check_model_mismatch("ollama", "llama3-70b", 8192, False) is None

    def test_dismissed_returns_none(self):
        assert check_model_mismatch("ollama", "llama3-70b", 16384, True) is None

    def test_70b_high_context_returns_warning(self):
        result = check_model_mismatch("ollama", "llama3-70b", 16384, False)
        assert result is not None
        assert result["type"] == "model_mismatch"
        assert "llama3-70b" in result["message"]
        assert "16,384" in result["message"]

    def test_case_insensitive_70b(self):
        result = check_model_mismatch("ollama", "Llama3-70B-Q4", 16384, False)
        assert result is not None

    def test_boundary_8193_triggers_warning(self):
        result = check_model_mismatch("ollama", "llama3-70b", 8193, False)
        assert result is not None
        assert result["title"] == "Model & Context Warning"

    def test_warning_has_dismiss_key(self):
        result = check_model_mismatch("ollama", "model-70b", 16384, False)
        assert "dismissKey" in result

    def test_warning_has_icon(self):
        result = check_model_mismatch("ollama", "model-70b", 16384, False)
        assert "icon" in result
