Coverage for src/lexigram/notification/config/inbox.py: 100%

15 statements  

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

1"""Inbox configuration.""" 

2 

3from __future__ import annotations 

4 

5from dataclasses import dataclass 

6from typing import ClassVar 

7 

8from lexigram.config.base import BaseConfig 

9from lexigram.validation import ConfigDict, Field 

10 

11_INBOX_ENV_PREFIX = "LEX_NOTIFICATION__INBOX__" 

12_INBOX_ENV_NESTED_DELIMITER = "__" 

13 

14 

15@dataclass(init=False) 

16class InboxConfig(BaseConfig): 

17 """Top-level inbox configuration. 

18 

19 Loaded from the ``inbox:`` key in application.yaml, with environment 

20 variable overrides via ``LEX_NOTIFICATION__INBOX__*`` prefix. 

21 

22 Attributes: 

23 store_backend: Storage backend to use. One of ``'database'`` or 

24 ``'memory'``. Defaults to ``'database'``. 

25 max_page_size: Maximum number of messages returned per page. 

26 retention_days: Number of days to retain inbox messages before 

27 they are eligible for pruning. 

28 mark_read_on_fetch: When ``True`` messages are automatically marked 

29 as read when fetched via :meth:`~InboxService.get_inbox`. 

30 """ 

31 

32 model_config: ClassVar[ConfigDict] = ConfigDict( # type: ignore[typeddict-unknown-key] 

33 env_prefix=_INBOX_ENV_PREFIX, 

34 env_nested_delimiter=_INBOX_ENV_NESTED_DELIMITER, 

35 extra="ignore", 

36 ) 

37 

38 store_backend: str = Field( 

39 default="database", 

40 description="Storage backend. One of 'database' or 'memory'.", 

41 ) 

42 max_page_size: int = Field( 

43 default=50, 

44 ge=1, 

45 description="Maximum messages returned per page.", 

46 ) 

47 retention_days: int = Field( 

48 default=30, 

49 ge=1, 

50 description="Days to retain inbox messages before pruning.", 

51 ) 

52 mark_read_on_fetch: bool = Field( 

53 default=False, 

54 description="Automatically mark messages as read when fetched.", 

55 ) 

56 

57 

58__all__ = [ 

59 "InboxConfig", 

60]