import pytest
import os
from pathlib import Path


def test_config_loads_from_env(tmp_path, monkeypatch):
    env_file = tmp_path / ".env"
    env_file.write_text(
        "LLM_BASE_URL=https://openrouter.ai/api/v1\n"
        "LLM_API_KEY=test_key_123\n"
        "LLM_MODEL_NAME=qwen/qwen3.5-35b-a3b\n"
        "EMBEDDING_MODEL=qwen/qwen3-embedding-4b\n"
        "EMBEDDING_BASE_URL=https://openrouter.ai/api/v1\n"
        "CHROMA_DB_PATH=./test_chroma\n"
    )
    
    monkeypatch.chdir(tmp_path)
    from app.core.config import Settings
    
    settings = Settings()
    assert settings.llm_base_url == "https://openrouter.ai/api/v1"
    assert settings.llm_api_key == "test_key_123"
    assert settings.llm_model_name == "qwen/qwen3.5-35b-a3b"
    assert settings.chroma_db_path == "./test_chroma"


def test_config_default_values(monkeypatch):
    monkeypatch.delenv("LLM_BASE_URL", raising=False)
    from app.core.config import Settings
    
    settings = Settings()
    assert settings.llm_base_url == "https://openrouter.ai/api/v1"
    assert settings.llm_model_name == "qwen/qwen3.5-35b-a3b"
