# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """A synthetic photo pack, built in a temp directory. Deliberately not a fixture: several test modules want packs of different shapes, and a builder says which shape a test needs in the test itself. The people are alfa, beta and gamma -- the real album's names are private and must never appear in this repository, which is the whole reason the pack lives outside it. """ from __future__ import annotations import base64 import json from typing import TYPE_CHECKING, Any from tests.conftest import WATCHED_GROUP if TYPE_CHECKING: from pathlib import Path # A 1x1 PNG, inline so no binary file enters the repo -- the same trick # fake_signal.state uses for the fixture image it serves. PIXEL = base64.b64decode( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" ) # Not a playable file, and it does not need to be: nothing in the bot decodes # a video, it only has to be named and typed correctly on the way out. CLIP = b"\x00\x00\x00\x18ftypmp42fake" PEOPLE: list[dict[str, Any]] = [ {"key": "p1", "triggers": ["!alfa", "!alfka"]}, {"key": "p2", "triggers": ["!beta"]}, {"key": "p3", "triggers": ["!gamma", "!gammÄ…"]}, ] COMBOS: list[dict[str, Any]] = [ {"key": "c1", "triggers": ["!oboje"], "all_of": ["p1", "p2"]}, {"key": "c2", "triggers": ["!ktokolwiek"], "any_of": ["p2", "p3"]}, ] TAGS: dict[str, list[str]] = { "alfa.png": ["p1"], "both.png": ["p1", "p2"], "gamma.png": ["p3"], "clip.mp4": ["p1"], } def build( root: Path, *, people: list[dict[str, Any]] | None = None, combos: list[dict[str, Any]] | None = None, tags: dict[str, list[str]] | None = None, groups: list[str] | None = None, media: dict[str, bytes] | None = None, write_tags: bool = True, ) -> Path: """Write a pack into ``root`` and return the directory.""" manifest: dict[str, Any] = { "groups": [WATCHED_GROUP] if groups is None else groups, "people": PEOPLE if people is None else people, "combos": COMBOS if combos is None else combos, } tagged = TAGS if tags is None else tags root.mkdir(parents=True, exist_ok=True) (root / "people.json").write_text(json.dumps(manifest), encoding="utf-8") if write_tags: (root / "tags.json").write_text(json.dumps(tagged), encoding="utf-8") album = root / "media" album.mkdir(exist_ok=True) # `is None`, not `or`: an empty mapping is a pack whose files are gone, # which is a case the loader has to refuse and a test has to be able to ask for. default = {name: CLIP if name.endswith(".mp4") else PIXEL for name in tagged} files = default if media is None else media for name, payload in files.items(): (album / name).write_bytes(payload) return root