signal-bot/tests/stats_seed.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

65 lines
1.9 KiB
Python

# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
"""A deterministic history to run the period, record and streak queries over.
Not a conftest fixture: it is a builder several test modules call with a
different history each, rather than one shared shape. Counts come from
arithmetic, never from ``random`` -- a fixture that changes between runs turns
a real failure into a flake.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
from signal_bot.stats.events import MessageEvent
if TYPE_CHECKING:
from signal_bot.store import Store
GROUP = "group-a=="
ALA = ("u-ala", "Ala")
KUHY = ("u-kuhy", "kuhy")
BASIA = ("u-basia", "Basia")
@dataclass(frozen=True, slots=True)
class Shape:
"""The optional detail of a seeded day, so ``wrote`` stays legible."""
media: int = 0
hour: int = 12
chars: int = 10
commands: int = 0
group_id: str = GROUP
def wrote(
store: Store,
day: str,
who: tuple[str, str],
count: int,
shape: Shape | None = None,
) -> None:
"""Put ``count`` messages from one person into one group on one day."""
shape = shape or Shape()
uuid, name = who
for index in range(count):
store.events.record(
MessageEvent(
group_id=shape.group_id,
uuid=uuid,
display_name=name,
# Unique within (group, uuid) so the primary key does not
# absorb them, and stable so two runs agree.
sent_at_ms=int(day.replace("-", "")) * 1000 + index,
day=day,
local_hour=shape.hour,
media_kind="image" if index < shape.media else "",
media_count=1 if index < shape.media else 0,
char_len=shape.chars,
is_command=index < shape.commands,
)
)
store.events.note_person(shape.group_id, uuid, name, "", day)