Coverage for src / lexigram / contracts / infra / resources.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-15 18:57 +0800

1"""Resource-related protocols for cross-package boundaries. 

2 

3This module defines interfaces for resource managers (e.g. connection pools) 

4that other packages may interact with without depending on concrete 

5implementations from lexigram or lexigram-admin. 

6""" 

7 

8from __future__ import annotations 

9 

10from typing import Any, Protocol, runtime_checkable 

11 

12 

13@runtime_checkable 

14class PoolStatsProtocol(Protocol): 

15 """Snapshot of pool statistics.""" 

16 

17 pool_utilization: float 

18 last_health_check: Any 

19 total_connections: int 

20 active_connections: int 

21 idle_connections: int 

22 created_connections: int 

23 destroyed_connections: int 

24 

25 

26@runtime_checkable 

27class PoolProtocol(Protocol): 

28 """Protocol for an individual connection pool.""" 

29 

30 def get_stats(self) -> PoolStatsProtocol: ... 

31 

32 async def close(self) -> None: ... 

33 

34 

35@runtime_checkable 

36class PoolManagerProtocol(Protocol): 

37 """Manager that tracks pools by name.""" 

38 

39 def get_stats(self) -> dict[str, PoolStatsProtocol]: ... 

40 

41 async def get_pool(self, name: str) -> PoolProtocol: ... 

42 

43 

44__all__ = ["PoolManagerProtocol", "PoolProtocol", "PoolStatsProtocol"]