feat(mcp-docugen): Task 1-3 config, models, auth middleware

- Settings con Pydantic Settings, validazione env obbligatori
- Shared models: TemplateVariable/Frontmatter, ImageVariable, TokenUsage, GenerationResult, TemplateSummary, TemplateAsset
- ApiKeyAuthMiddleware Bearer token con exempt paths

19 test, tutti passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-21 12:18:43 +02:00
parent c5e84a578b
commit d5c645bf17
6 changed files with 324 additions and 0 deletions
@@ -0,0 +1,44 @@
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"