Coverage for src / lexigram / contracts / ai / relay / store.py: 0%

13 statements  

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

1"""Durable relay channel store contracts. 

2 

3Statically configured channels remain the default; a host may bind a 

4durable store at boot and the gateway reconciles its registry from it. 

5All mutations compare-and-set on ``revision`` so stale writers are 

6rejected instead of overwriting newer state. 

7""" 

8 

9from __future__ import annotations 

10 

11from dataclasses import dataclass 

12from typing import Protocol, runtime_checkable 

13 

14from lexigram.contracts.ai.relay.gateway import RelayChannel 

15 

16 

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

18class RelayChannelSnapshot: 

19 """One durable channel row with its revision.""" 

20 

21 channel: RelayChannel 

22 revision: int 

23 created_at: str 

24 updated_at: str 

25 

26 

27@runtime_checkable 

28class RelayChannelStoreProtocol(Protocol): 

29 """CRUD over durable relay channel rows. 

30 

31 ``upsert`` matches on ``channel.name``; it returns the new revision 

32 on success and ``None`` when ``expected_revision`` does not match 

33 (stale write). ``delete`` returns ``False`` when the channel does 

34 not exist. 

35 """ 

36 

37 async def list_channels(self) -> list[RelayChannelSnapshot]: ... 

38 

39 async def upsert( 

40 self, channel: RelayChannel, *, expected_revision: int | None = None 

41 ) -> int | None: ... 

42 

43 async def delete(self, name: str, *, expected_revision: int) -> bool: ... 

44 

45 

46__all__ = ["RelayChannelSnapshot", "RelayChannelStoreProtocol"]