import pytest from pydantic import ValidationError from mcp_docugen.models import ( GenerationResult, ImageVariable, TemplateFrontmatter, TemplateVariable, TokenUsage, ) def test_template_variable_string(): v = TemplateVariable(name="cliente", type="string") assert v.name == "cliente" assert v.type == "string" def test_template_variable_image(): v = TemplateVariable(name="foto", type="image") assert v.type == "image" def test_template_variable_rejects_unknown_type(): with pytest.raises(ValidationError): TemplateVariable(name="x", type="number") def test_template_variable_rejects_empty_name(): with pytest.raises(ValidationError): TemplateVariable(name="", type="string") def test_frontmatter_minimal(): fm = TemplateFrontmatter(name="fattura", description="Fattura commerciale") assert fm.name == "fattura" assert fm.required_variables == [] assert fm.model is None assert fm.instructions_hint is None def test_frontmatter_with_variables(): fm = TemplateFrontmatter( name="fattura", description="...", model="anthropic/claude-sonnet-4", required_variables=[ {"name": "cliente", "type": "string"}, {"name": "foto", "type": "image"}, ], instructions_hint="tono formale", ) assert len(fm.required_variables) == 2 assert fm.required_variables[1].type == "image" def test_frontmatter_name_slug_rules(): with pytest.raises(ValidationError): TemplateFrontmatter(name="Fattura Commerciale", description="x") with pytest.raises(ValidationError): TemplateFrontmatter(name="../escape", description="x") with pytest.raises(ValidationError): TemplateFrontmatter(name="-starts-with-dash", description="x") def test_image_variable(): img = ImageVariable(kind="image", data_b64="aGVsbG8=", mime="image/png") assert img.mime == "image/png" def test_image_variable_rejects_unsupported_mime(): with pytest.raises(ValidationError): ImageVariable(kind="image", data_b64="aGVsbG8=", mime="image/bmp") def test_image_variable_rejects_wrong_kind(): with pytest.raises(ValidationError): ImageVariable(kind="file", data_b64="aGVsbG8=", mime="image/png") def test_generation_result_shape(): result = GenerationResult( generation_id="abc-123", markdown="# hello", model="anthropic/claude-sonnet-4", tokens=TokenUsage(input=100, output=200), cost_usd=0.01, ephemeral_assets_urls=[], ephemeral_expires_at=None, ) assert result.generation_id == "abc-123" assert result.tokens.input == 100