Coverage for src/prosemark/app/compile/use_cases.py: 100%

14 statements  

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

1"""Use cases for compile functionality. 

2 

3This module contains the application layer use cases that orchestrate 

4domain services and handle user interactions. 

5""" 

6 

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

8from prosemark.domain.compile.service import CompileService 

9from prosemark.ports.compile.service import CompileServicePort, NodeNotFoundError 

10from prosemark.ports.node_repo import NodeRepo 

11 

12 

13class CompileSubtreeUseCase(CompileServicePort): 

14 """Use case for compiling node subtrees. 

15 

16 This use case orchestrates the domain service and provides 

17 a clean interface for the adapter layer. 

18 """ 

19 

20 def __init__(self, node_repo: NodeRepo) -> None: 

21 """Initialize the use case. 

22 

23 Args: 

24 node_repo: Repository for accessing node metadata 

25 

26 """ 

27 self._compile_service = CompileService(node_repo) 

28 

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

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

31 

32 Args: 

33 request: The compile request with target node and options 

34 

35 Returns: 

36 CompileResult containing the concatenated content and statistics 

37 

38 Raises: 

39 NodeNotFoundError: If the specified node_id doesn't exist 

40 

41 """ 

42 try: 

43 return self._compile_service.compile_subtree(request) 

44 except Exception as e: 

45 # Re-raise as the appropriate port exception 

46 if 'not found' in str(e).lower(): 

47 raise NodeNotFoundError(request.node_id) from e 

48 raise