""" Tests for Issue #55: Schema-based draft generation This test module implements comprehensive tests for enhanced schema-based draft generation that utilizes content field instructions and schema metadata. Following TDD8 methodology - these tests are written before implementation. """ import json import pytest from pathlib import Path from tempfile import NamedTemporaryFile from click.testing import CliRunner from markitect.cli import cli from markitect.stub_generator import StubGenerator class TestIssue55SchemaBasedDraftGeneration: """Test suite for enhanced schema-based draft generation functionality.""" def setup_method(self): """Set up test fixtures.""" self.stub_generator = StubGenerator() self.runner = CliRunner() def test_generate_stub_uses_content_instructions_from_schema(self): """Test that generate-stub uses content instructions instead of generic placeholders.""" # Arrange schema_with_instructions = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "title": "API Documentation", "x-markitect-content-instructions-enabled": True, "properties": { "headings": { "type": "object", "properties": { "level_1": { "type": "array", "items": { "type": "object", "properties": { "content": {"type": "string"}, "level": {"type": "integer"}, "x-markitect-content-instructions": { "type": "string", "const": "Write the main API documentation title" }, "x-markitect-instruction-type": { "type": "string", "enum": ["description"] } } }, "minItems": 1, "maxItems": 1 }, "level_2": { "type": "array", "items": { "type": "object", "properties": { "content": {"type": "string"}, "level": {"type": "integer"}, "x-markitect-content-instructions": { "type": "string", "const": "Describe each API endpoint section" }, "x-markitect-instruction-type": { "type": "string", "enum": ["description"] } } }, "minItems": 2, "maxItems": 2 } } } } } with NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f: json.dump(schema_with_instructions, f, indent=2) schema_file = Path(f.name) try: # Act result = self.runner.invoke(cli, [ 'generate-stub', str(schema_file) ]) # Assert assert result.exit_code == 0 output = result.output # Should use specific content instructions, not generic placeholders assert "Write the main API documentation title" in output assert "Describe each API endpoint section" in output # Should NOT contain generic placeholder text assert "TODO: Add content for" not in output assert "section_level_2 section" not in output finally: schema_file.unlink() def test_generate_stub_includes_schema_reference_metadata(self): """Test that generated drafts include reference to their source schema.""" # Arrange schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "title": "Requirements Document", "x-markitect-content-instructions-enabled": True, "properties": { "headings": { "type": "object", "properties": { "level_1": { "type": "array", "items": { "type": "object", "properties": { "content": {"type": "string"}, "x-markitect-content-instructions": { "type": "string", "const": "Provide the document title" } } }, "minItems": 1, "maxItems": 1 } } } } } with NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f: json.dump(schema, f, indent=2) schema_file = Path(f.name) try: # Act result = self.runner.invoke(cli, [ 'generate-stub', str(schema_file) ]) # Assert assert result.exit_code == 0 output = result.output # Should include schema reference metadata assert "