#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""AI recommendation route Ollama-first display contract."""


def test_initial_ai_status_sanitizes_cached_gemini_recommendation(monkeypatch):
    import routes.ai_routes as ai_routes

    monkeypatch.setattr(
        ai_routes.ai_provider_service,
        "_status_cache",
        {
            "data": {
                "default_provider": "gemini",
                "recommended_provider": "gemini",
                "ollama": {"connected": None},
                "gemini": {"connected": True},
            }
        },
    )

    status = ai_routes._get_ai_status_for_initial_render()

    assert status["default_provider"] == "ollama"
    assert status["recommended_provider"] == "ollama"

def test_initial_ai_status_never_recommends_gemini_without_cache(monkeypatch):
    import routes.ai_routes as ai_routes

    class FakeProvider:
        default_provider = "gemini"
        _status_cache = {}

    monkeypatch.setattr(ai_routes, "ai_provider_service", FakeProvider())

    status = ai_routes._get_ai_status_for_initial_render()

    assert status["default_provider"] == "ollama"
    assert status["recommended_provider"] == "ollama"
