mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-10 20:37:03 +01:00
Per-person photo commands, where the mechanism is public and the album is not. Nothing identifying is in this repository: who the people are, what fires their photos and which file shows whom all live in one directory outside it, and the tests, the docs and the offline e2e run use three invented people instead. Several names in one message intersect -- "!alfa beta" is a photo with both -- and where an entry offers a choice the bot picks among the readings that actually have a photo, so a question the album could answer is not refused. A combination nobody photographed gets one line rather than silence, which from the group's side is indistinguishable from a broken bot. Scoping is enforced in the dispatcher, not in the handler: a command the group is not allowed resolves to nothing, so it is not answered, not counted as a command, and never named in a log line outside its own groups. A handler that quietly returned would leak all three. Commands are named by pseudonym (pack:p1), so the journal and command_uses say somebody asked for a photo and nothing about whose. Video works: the attachment goes out as data:video/mp4;filename=...;base64, which is the container's own spelling, read off its /swagger/doc.json. Told it is a photo, Signal renders a clip as an unplayable file. tool/tagger.py serves one page on loopback to fill the album in -- names are typed into the page, never as arguments, and it prints how many photos each command would have when it stops, because a command with zero is dead on arrival. Also renames the real people who were still sitting in the stats test fixtures. They remain in the history; the point is that nothing new is added to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017w1HZ3cZ7neL3rFdQ6VMBA
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""How an attachment is spelled on the wire.
|
|
|
|
Split out of test_transport_rest.py, which reached the 250-line cap. The
|
|
data-URI form is the container's own, read off its /swagger/doc.json rather
|
|
than remembered: api.SendMessageV2 documents base64_attachments as taking
|
|
bare base64, "data:<MIME-TYPE>;base64,<DATA>" or
|
|
"data:<MIME-TYPE>;filename=<FILENAME>;base64,<DATA>".
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import TYPE_CHECKING
|
|
|
|
import httpx
|
|
|
|
from tests.test_transport_rest import MockHandler, _transport
|
|
|
|
if TYPE_CHECKING:
|
|
from signal_bot.config import Config
|
|
|
|
|
|
def _recorder(seen: list[dict[str, object]]) -> MockHandler:
|
|
"""A handler that keeps every payload it is sent."""
|
|
|
|
def record(request: httpx.Request) -> httpx.Response:
|
|
seen.append(json.loads(request.content))
|
|
return httpx.Response(201)
|
|
|
|
return record
|
|
|
|
|
|
async def test_an_image_send_is_unchanged_by_the_media_path(config: Config) -> None:
|
|
"""send_image delegates now; the payload must still be bare base64."""
|
|
seen: list[dict[str, object]] = []
|
|
|
|
def record(request: httpx.Request) -> httpx.Response:
|
|
seen.append(__import__("json").loads(request.content))
|
|
return httpx.Response(201)
|
|
|
|
transport = _transport(config, record)
|
|
await transport.send_image("QUJD", "group-a==", caption="hi")
|
|
|
|
assert seen[0]["base64_attachments"] == ["QUJD"]
|
|
assert seen[0]["message"] == "hi"
|
|
|
|
|
|
async def test_a_typed_attachment_travels_as_a_data_uri(config: Config) -> None:
|
|
"""The spelling is the container's own, from its /swagger/doc.json."""
|
|
seen: list[dict[str, object]] = []
|
|
|
|
def record(request: httpx.Request) -> httpx.Response:
|
|
seen.append(__import__("json").loads(request.content))
|
|
return httpx.Response(201)
|
|
|
|
transport = _transport(config, record)
|
|
await transport.send_media("QUJD", "group-a==", media_type="video/mp4", filename="clip.mp4")
|
|
|
|
assert seen[0]["base64_attachments"] == ["data:video/mp4;filename=clip.mp4;base64,QUJD"]
|
|
|
|
|
|
async def test_a_type_without_a_filename_still_names_the_type(config: Config) -> None:
|
|
seen: list[dict[str, object]] = []
|
|
|
|
def record(request: httpx.Request) -> httpx.Response:
|
|
seen.append(__import__("json").loads(request.content))
|
|
return httpx.Response(201)
|
|
|
|
transport = _transport(config, record)
|
|
await transport.send_media("QUJD", "group-a==", media_type="image/png")
|
|
|
|
assert seen[0]["base64_attachments"] == ["data:image/png;base64,QUJD"]
|