signal-bot/tool/e2e_pack.py
Krzysztof kuhy Rudnicki 35102be863 release: 0.2.0 «Urbanus I» — a private photo album, and a tagger for it
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
2026-08-30 22:35:41 +02:00

69 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
"""Write a synthetic photo pack for the offline end-to-end run.
The real album is private and lives outside this repository, so the e2e
script cannot use it -- and must not need to. This builds a pack of three
invented people, one "both of them" combination and one video, which is
enough to exercise every path the real one uses.
python tool/e2e_pack.py --dir /tmp/pack --group 'group.abc='
"""
from __future__ import annotations
import argparse
import base64
import json
import sys
from pathlib import Path
from typing import Final
# A 1x1 PNG, inline so that no binary file enters the repository.
PIXEL: Final = base64.b64decode(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
)
# Not playable, and it does not have to be: nothing decodes it, the point is
# that it leaves as video/mp4 rather than as a photo.
CLIP: Final = b"\x00\x00\x00\x18ftypmp42fake"
PEOPLE: Final = [
{"key": "p1", "triggers": ["!alfa"]},
{"key": "p2", "triggers": ["!beta"]},
{"key": "p3", "triggers": ["!gamma"]},
{"key": "p4", "triggers": ["!wideo"]},
]
COMBOS: Final = [{"key": "c1", "triggers": ["!oboje"], "all_of": ["p1", "p2"]}]
TAGS: Final = {
"alfa.png": ["p1"],
"both.png": ["p1", "p2"],
"gamma.png": ["p3"],
"clip.mp4": ["p4"],
}
def write(directory: Path, group: str) -> None:
"""Write the manifest, the tags and the files themselves."""
album = directory / "media"
album.mkdir(parents=True, exist_ok=True)
for name in TAGS:
(album / name).write_bytes(CLIP if name.endswith(".mp4") else PIXEL)
manifest = {"groups": [group], "people": PEOPLE, "combos": COMBOS}
(directory / "people.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8")
(directory / "tags.json").write_text(json.dumps(TAGS, indent=2), encoding="utf-8")
def main() -> int:
"""Build the pack asked for on the command line."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--dir", required=True, type=Path, help="where to write the pack")
parser.add_argument("--group", required=True, help="the group id the pack belongs to")
arguments = parser.parse_args()
write(arguments.dir, arguments.group)
sys.stdout.write(f"== wrote a synthetic pack to {arguments.dir}\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())