Coverage for src / lilbee / providers / worker / wire_kinds.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-05-15 20:55 +0000

1"""Wire-protocol message kinds shared by every worker subprocess. 

2 

3Every per-role worker (embed, chat, rerank, vision) and the parent-side 

4``transport_pipe`` channel send/receive ``(kind, payload)`` tuples. The 

5``kind`` strings live here so a typo in one module (``"PING"`` vs 

6``"ping"``) becomes an :class:`AttributeError` instead of a silent 

7protocol mismatch that surfaces only when the worker actually crashes. 

8 

9``WireKind`` is a :class:`enum.StrEnum`, so its members compare equal to 

10the underlying string and cross the pipe as plain ``str`` without the 

11parent and child needing matched class identity. ``test_wire_kinds.py`` 

12enforces single-source-of-truth via a ``grep`` against literal 

13redefinitions in worker modules. 

14""" 

15 

16from __future__ import annotations 

17 

18from enum import StrEnum 

19 

20 

21class WireKind(StrEnum): 

22 """One enum for every kind that can appear on the worker wire.""" 

23 

24 # Generic envelope kinds. 

25 PING = "ping" 

26 PONG = "pong" 

27 SHUTDOWN = "shutdown" 

28 ACK = "ack" 

29 RESULT = "result" 

30 ERROR = "error" 

31 

32 # Streaming kinds (chat). 

33 STREAM_CHUNK = "stream_chunk" 

34 STREAM_END = "stream_end" 

35 

36 # Per-role request kinds. 

37 EMBED = "embed" 

38 CHAT = "chat" 

39 RERANK = "rerank" 

40 VISION = "vision_ocr" 

41 PDF_OCR = "pdf_ocr" 

42 

43 

44__all__ = ["WireKind"]