Coverage for src/copytrading_engine/control/audit.py: 100%

9 statements  

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

1"""One audit record per control decision, and the port that keeps them.""" 

2 

3import datetime as dt 

4from dataclasses import dataclass 

5from typing import Literal, Protocol 

6 

7from copytrading_engine.control.policy import Tier 

8 

9type Actor = Literal["agent", "owner"] 

10 

11 

12@dataclass(frozen=True, slots=True) 

13class AuditEntry: 

14 """Identifiers only: no request text, source text, or secrets.""" 

15 

16 at: dt.datetime 

17 actor: Actor 

18 caller_pid: int | None 

19 caller_path: str | None 

20 operation: str 

21 tier: Tier | None 

22 outcome: str 

23 proposal_id: str | None = None 

24 

25 

26class ControlAudit(Protocol): 

27 async def record(self, entry: AuditEntry) -> None: ... 

28 

29 async def recent(self, limit: int) -> tuple[AuditEntry, ...]: ...