mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-24 21:46:31 +01:00
Some checks are pending
CI / check (push) Waiting to run
Adds !papież / !papiez / !pope: a random pope as a photo, captioned with his Latin name, reign and pl.wikipedia link. popes.json already carried a Commons portrait filename for all 267 and nothing had ever consumed it. The Latin name comes from the Latin column of Poczet papieży, not from the la.wikipedia sitelink. The sitelink resolved for all 267 and was still wrong: la.wikipedia numbers several popes differently, so #154 came out as "Stefan IX — Stephanus X" in a single caption, which reads as an off-by-one. The table's own column says "Stephanus Nonus" and cannot disagree with the name beside it. LATIN_OVERRIDES ships empty; it is a tripwire, not a backlog. Portraits are cached on disk under CacheDirectory=signal-bot, named from the ordinal so no upstream string ever reaches a path, and bounded at 267 entries so nothing needs evicting. Verified that CacheDirectory wins against ProtectHome=read-only before relying on it. Also adds POST /_selftest and scripts/selftest.sh. Signal never delivers an account its own sends, so no command has ever been exercised end-to-end without asking a human to type it. This injects a real frame into the live dispatcher; it is loopback-only and refuses any group not in SELFTEST_GROUPS, which is empty by default. Verified against the real endpoints, not just the fake: 267/267 portraits resolve on Commons, regeneration is byte-identical on every previously shipped field, and !papież was driven 7 times through the live dispatcher in testbot, returning distinct popes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015d48t4qsQLBJnDwDeo2Nom
79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
# 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
|
|
caption: str = ""
|
|
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,
|
|
caption: str = "",
|
|
) -> None:
|
|
"""Record an image send."""
|
|
self.sent.append(
|
|
SentMessage(
|
|
recipient=recipient, image_base64=image_base64, quote=quote, caption=caption
|
|
)
|
|
)
|
|
|
|
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]
|