import pytest from pydantic import ValidationError from mcp_docugen.config import Settings def test_settings_loads_from_env(monkeypatch, tmp_path): monkeypatch.setenv("API_KEY", "test-api-key") monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-test") monkeypatch.setenv("PUBLIC_BASE_URL", "https://mcp.example.com") monkeypatch.setenv("DATA_DIR", str(tmp_path)) settings = Settings() assert settings.api_key == "test-api-key" assert settings.openrouter_api_key == "sk-or-test" assert settings.public_base_url == "https://mcp.example.com" assert settings.data_dir == tmp_path assert settings.llm_model_default == "anthropic/claude-sonnet-4" assert settings.asset_ttl_days == 30 assert settings.max_image_size_mb == 10 assert settings.llm_timeout_seconds == 60 assert settings.openrouter_base_url == "https://openrouter.ai/api/v1" def test_settings_missing_required_fails(monkeypatch, tmp_path): monkeypatch.delenv("API_KEY", raising=False) monkeypatch.delenv("OPENROUTER_API_KEY", raising=False) monkeypatch.delenv("PUBLIC_BASE_URL", raising=False) monkeypatch.setenv("DATA_DIR", str(tmp_path)) with pytest.raises(ValidationError): Settings(_env_file=None) def test_public_base_url_strips_trailing_slash(monkeypatch, tmp_path): monkeypatch.setenv("API_KEY", "k-with-long-enough") monkeypatch.setenv("OPENROUTER_API_KEY", "sk-long-enough") monkeypatch.setenv("PUBLIC_BASE_URL", "https://mcp.example.com/") monkeypatch.setenv("DATA_DIR", str(tmp_path)) settings = Settings() assert settings.public_base_url == "https://mcp.example.com"