Coverage for src/copytrading_engine/shared/raw_message.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-16 16:55 +0000

1"""Validated values shared by capture and persistence, independent of Discord and SQL.""" 

2 

3from typing import Literal 

4 

5from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, StrictInt 

6 

7 

8class RawMessage(BaseModel): 

9 """Producer validation for the published raw-message v1 contract.""" 

10 

11 model_config = ConfigDict(extra="forbid", frozen=True, hide_input_in_errors=True) 

12 schema_version: StrictInt = Field(ge=1, le=1) 

13 event_type: Literal["raw_message"] 

14 source: str = Field(pattern=r"^[a-z][a-z0-9_-]*$") 

15 channel_id: str = Field(pattern=r"^[a-zA-Z0-9_-]+$") 

16 author_id: str | None = Field(default=None, pattern=r"^[0-9]{1,32}$") 

17 id: str = Field(pattern=r"^[a-zA-Z0-9_-]+$") 

18 timestamp: AwareDatetime 

19 text: str = Field(max_length=10_000) 

20 image_count: StrictInt = Field(default=0, ge=0) 

21 

22 @property 

23 def identity(self) -> str: 

24 return f"{self.source}:{self.channel_id}:{self.id}"