Coverage for src/prosemark/templates/ports/template_validator_port.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-30 23:09 +0000

1"""Template Validator Port Contract. 

2 

3Defines the interface for template content validation operations. 

4""" 

5 

6from abc import ABC, abstractmethod 

7 

8from prosemark.templates.domain.entities.placeholder import Placeholder 

9from prosemark.templates.domain.entities.template import Template 

10from prosemark.templates.domain.entities.template_directory import TemplateDirectory 

11 

12 

13class TemplateValidatorPort(ABC): 

14 """Port for template content validation operations.""" 

15 

16 @abstractmethod 

17 def validate_template_structure(self, content: str) -> bool: 

18 """Validate that template content has valid structure. 

19 

20 Args: 

21 content: Raw template content 

22 

23 Returns: 

24 True if structure is valid 

25 

26 Raises: 

27 TemplateParseError: If YAML frontmatter is invalid 

28 TemplateValidationError: If content violates prosemark format 

29 

30 """ 

31 

32 @abstractmethod 

33 def validate_prosemark_format(self, content: str) -> bool: 

34 """Validate that template follows prosemark node format. 

35 

36 Args: 

37 content: Raw template content 

38 

39 Returns: 

40 True if format is valid 

41 

42 Raises: 

43 TemplateValidationError: If content violates prosemark format requirements 

44 

45 """ 

46 

47 @abstractmethod 

48 def extract_placeholders(self, content: str) -> list[Placeholder]: 

49 """Extract all placeholders from template content. 

50 

51 Args: 

52 content: Template content containing placeholders 

53 

54 Returns: 

55 List of Placeholder instances found in content 

56 

57 Raises: 

58 InvalidPlaceholderError: If placeholder syntax is malformed 

59 

60 """ 

61 

62 @abstractmethod 

63 def validate_placeholder_syntax(self, placeholder_text: str) -> bool: 

64 """Validate that a placeholder has correct syntax. 

65 

66 Args: 

67 placeholder_text: Placeholder pattern (e.g., "{{variable_name}}") 

68 

69 Returns: 

70 True if syntax is valid 

71 

72 Raises: 

73 InvalidPlaceholderError: If syntax is malformed 

74 

75 """ 

76 

77 @abstractmethod 

78 def validate_template(self, template: Template) -> list[str]: 

79 """Validate a template and return any validation errors. 

80 

81 Args: 

82 template: Template to validate 

83 

84 Returns: 

85 List of validation error messages (empty if valid) 

86 

87 """ 

88 

89 @abstractmethod 

90 def validate_template_directory(self, template_directory: TemplateDirectory) -> list[str]: 

91 """Validate a template directory and return any validation errors. 

92 

93 Args: 

94 template_directory: Template directory to validate 

95 

96 Returns: 

97 List of validation error messages (empty if valid) 

98 

99 """ 

100 

101 @abstractmethod 

102 def validate_template_dependencies(self, template: Template) -> bool: 

103 """Validate that template dependencies are resolvable. 

104 

105 Args: 

106 template: Template to validate dependencies for 

107 

108 Returns: 

109 True if all dependencies are valid 

110 

111 Raises: 

112 TemplateValidationError: If dependencies cannot be resolved 

113 

114 """