# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """In-process transport double used by the unit tests. This is the fast path: no sockets, no server, no event loop scheduling games. The protocol-faithful HTTP/WebSocket fake lives in the ``fake_signal`` package and is what the end-to-end script drives. """ from __future__ import annotations from dataclasses import dataclass, field from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import AsyncIterator, Iterable from signal_bot.quoting import Quote @dataclass(frozen=True, slots=True) class SentMessage: """One outbound call captured by the fake.""" recipient: str text: str | None = None image_base64: str | None = None quote: Quote | None = None @dataclass class FakeTransport: """Replays canned frames and records everything the bot sends.""" frames: list[str] = field(default_factory=list) sent: list[SentMessage] = field(default_factory=list) attachments: list[str] = field(default_factory=list) deleted: list[str] = field(default_factory=list) def queue(self, frames: Iterable[str]) -> None: """Add frames to be yielded by the next receive() iteration.""" self.frames.extend(frames) async def receive(self) -> AsyncIterator[str]: """Yield every queued frame once, then stop.""" for frame in list(self.frames): yield frame async def send_text(self, text: str, recipient: str, quote: Quote | None = None) -> None: """Record a text send.""" self.sent.append(SentMessage(recipient=recipient, text=text, quote=quote)) async def send_image( self, image_base64: str, recipient: str, quote: Quote | None = None ) -> None: """Record an image send.""" self.sent.append(SentMessage(recipient=recipient, image_base64=image_base64, quote=quote)) async def list_attachments(self) -> list[str]: """Return the configured attachment ids.""" return list(self.attachments) async def delete_attachment(self, attachment_id: str) -> None: """Record an attachment deletion.""" self.deleted.append(attachment_id) @property def texts(self) -> list[str]: """Every text body sent so far, in order.""" return [m.text for m in self.sent if m.text is not None]