Coverage for src/prosemark/ports/compile/service.py: 100%

12 statements  

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

1"""Contract definition for CompileServicePort. 

2 

3This module defines the port interface for the compile service, 

4following hexagonal architecture principles. 

5""" 

6 

7from abc import ABC, abstractmethod 

8 

9from prosemark.domain.compile.models import CompileRequest, CompileResult 

10from prosemark.domain.models import NodeId 

11 

12 

13class CompileServicePort(ABC): 

14 """Port interface for compile operations. 

15 

16 This port defines the contract for compiling node subtrees 

17 into concatenated text output. 

18 """ 

19 

20 @abstractmethod 

21 def compile_subtree(self, request: CompileRequest) -> CompileResult: 

22 """Compile a node and all its descendants into plain text. 

23 

24 Args: 

25 request: The compile request with target node and options 

26 

27 Returns: 

28 CompileResult containing the concatenated content and statistics 

29 

30 Raises: 

31 NodeNotFoundError: If the specified node_id doesn't exist 

32 CompileError: If compilation fails for any other reason 

33 

34 """ 

35 ... 

36 

37 

38class NodeNotFoundError(Exception): 

39 """Raised when the specified node cannot be found.""" 

40 

41 def __init__(self, node_id: NodeId) -> None: 

42 self.node_id = node_id 

43 super().__init__(f'Node not found: {node_id}') 

44 

45 

46class CompileError(Exception): 

47 """Base exception for compilation errors."""