from typing import Any
import pytest
import os
import sys

# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))

from src import ai_client
from src import project_manager

def test_credentials_error_mentions_deepseek(monkeypatch: pytest.MonkeyPatch) -> None:
 """
 
  
      Verify that the error message shown when credentials.toml is missing
      includes deepseek instructions.
 """
 # Monkeypatch SLOP_CREDENTIALS to a non-existent file
 monkeypatch.setenv("SLOP_CREDENTIALS", "non_existent_credentials_file.toml")
 with pytest.raises(FileNotFoundError) as excinfo:
  ai_client._load_credentials()
 err_msg = str(excinfo.value)
 assert "[deepseek]" in err_msg
 assert "api_key" in err_msg

def test_default_project_includes_reasoning_role() -> None:
 """
 
  
      Verify that 'Reasoning' is included in the default discussion roles
      to support DeepSeek-R1 reasoning traces.
 """
 proj = project_manager.default_project("test")
 roles = proj["discussion"]["roles"]
 assert "Reasoning" in roles

def test_gui_providers_list() -> None:
 """
 
  
      Check if 'deepseek' is in the GUI's provider list.
 """
 from src.models import PROVIDERS
 assert "deepseek" in PROVIDERS

def test_deepseek_model_listing() -> None:
 """
 
  
      Verify that list_models for deepseek returns expected models.
 """
 models = ai_client.list_models("deepseek")
 assert "deepseek-chat" in models
 assert "deepseek-reasoner" in models

def test_gui_provider_list_via_hooks(live_gui: Any) -> None:
 """
 
  
      Verify 'deepseek' is present in the GUI provider list using API hooks.
 """
 from api_hook_client import ApiHookClient
 import time
 client = ApiHookClient()
 assert client.wait_for_server(timeout=10)
 # Attempt to set provider to deepseek to verify it's an allowed value
 client.set_value('current_provider', 'deepseek')
 time.sleep(0.5)
 assert client.get_value('current_provider') == 'deepseek'