Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-feedback/src/lexigram/ai/feedback/module.py: 87%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1"""Feedback module for dependency injection.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6 

7from lexigram.contracts.ai.feedback import FeedbackProtocol 

8from lexigram.di.module import DynamicModule, Module, module 

9 

10if TYPE_CHECKING: 

11 from lexigram.ai.feedback.config import FeedbackConfig 

12 

13 

14@module() 

15class FeedbackModule(Module): 

16 """AI Feedback collection and processing integration. 

17 

18 Call :meth:`configure` to register a 

19 :class:`~lexigram.contracts.ai.feedback.FeedbackProtocol` implementation 

20 along with the processor registry and storage backend for injection. 

21 

22 Usage:: 

23 

24 from lexigram.ai.feedback.config import FeedbackConfig 

25 

26 @module( 

27 imports=[ 

28 FeedbackModule.configure( 

29 FeedbackConfig(async_processing=False) 

30 ) 

31 ] 

32 ) 

33 class AppModule(Module): 

34 pass 

35 

36 Error Handling:: 

37 

38 The feedback services use the Result pattern for expected failures. 

39 Domain errors are available via the exported exception hierarchy:: 

40 

41 from lexigram.ai.feedback.exceptions import ( 

42 FeedbackError, # base — catch-all 

43 FeedbackProcessingError, # processor pipeline failure 

44 FeedbackValidationError, # schema / data-validation failure 

45 ) 

46 

47 Exports: 

48 :class:`~lexigram.contracts.ai.feedback.FeedbackProtocol`, 

49 :class:`~lexigram.ai.feedback.exceptions.FeedbackError`, 

50 :class:`~lexigram.ai.feedback.exceptions.FeedbackProcessingError`, 

51 :class:`~lexigram.ai.feedback.exceptions.FeedbackValidationError` 

52 """ 

53 

54 @classmethod 

55 def configure(cls, config: FeedbackConfig | None = None) -> DynamicModule: 

56 """Create a FeedbackModule with the given configuration. 

57 

58 Args: 

59 config: :class:`~lexigram.ai.feedback.config.FeedbackConfig`, a 

60 plain ``dict`` of the same keys, or ``None`` for framework 

61 defaults. 

62 

63 Returns: 

64 A :class:`~lexigram.di.module.DynamicModule` descriptor. 

65 """ 

66 from lexigram.ai.feedback.di.provider import FeedbackProvider 

67 

68 return DynamicModule( 

69 module=cls, 

70 providers=[FeedbackProvider(config=config)], 

71 exports=[ 

72 FeedbackProtocol, 

73 ], 

74 ) 

75 

76 @classmethod 

77 def stub(cls, config: FeedbackConfig | None = None) -> DynamicModule: 

78 """Create a FeedbackModule suitable for unit and integration testing. 

79 

80 Uses in-memory or no-op implementations with minimal side effects. 

81 

82 Args: 

83 config: Optional config override. Uses safe test defaults when None. 

84 

85 Returns: 

86 A :class:`~lexigram.di.module.DynamicModule` descriptor. 

87 """ 

88 from lexigram.ai.feedback.di.provider import FeedbackProvider 

89 

90 return DynamicModule( 

91 module=cls, 

92 providers=[FeedbackProvider(config=config)], 

93 exports=[ 

94 FeedbackProtocol, 

95 ], 

96 ) 

97 

98 

99__all__ = ["FeedbackModule"]