From aefffb2fd99799aec2396afbbf50952ab75ac002 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Mon, 31 Aug 2026 11:20:00 +0200 Subject: [PATCH] feat: add a photo to the album from the chat, tagged, stripped and verified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send a photo captioned "!add_photo alfa wakacje" in one of the album's own groups and it lands in the pack tagged with both, retrievable through !alfa and the new !losowe immediately -- no restart, and no tagger session on the PC. A label matching nobody becomes a custom tag, and !losowe is the only door to one, which is what keeps a live swap a *data* swap: it can never register a trigger or widen a command's groups. No typed label travels. Labels become pseudonym keys in a new registry arg_resolver, at the dispatcher, before the line that logs the command name -- so no handler, journal entry, command_uses row or reply body ever holds a word somebody typed. The reply is counts and pseudonyms: "dodano · p1: 4 · t1: 1". Stripping is exiftool with a *positive* check on the output, never an exit code. ffmpeg was tried first and fails silently on photos: given a JPEG with a real APP1 Exif segment it returned a byte-identical file, GPS intact, exit 0. The surviving-tag allowlist is per tag *name* rather than per group, because measurement showed a group-level "must be empty" rule rejects every format except JPEG -- a valid PNG always reports its IHDR, an MP4 some fifty QuickTime tags that are the container itself. Codec configuration (CompressorName, VendorID, the HEVC parameter set) is on the list by decision: CompressorName lives in the avc1 sample description and exiftool cannot write it at all, so the alternative was refusing every video and every iPhone HEIC. Location and identity tags are still refused, and the e2e run re-reads the stored files to prove a QuickTime geotag did not survive. .webm and .svg stay on the format allowlist and are stored *unstripped*: exiftool 13.55 can write neither, and its SVG reader does not even surface . That is a deliberate, documented hole, not an oversight. Two things this had to defuse along the way: - personal_data_sources now reads custom.json, so "!add_photo kot " would have outlawed the word "kot" and refused every future commit, fixable only by hand-editing an album the committer cannot see. Minting now refuses a word that is already a command, and the gate subtracts the repo's own alias vocabulary from custom labels only -- curated people.json names are never excused. - signal_bot/external.py is now the single subprocess site in the repository, so ruff's S603 needs exactly one scoped per-file-ignore instead of one per module that shells out. A test asserts nothing else imports subprocess. A failed add changes nothing: media and the three manifests are written, the album is reloaded, and only a load that succeeds is published; a load that fails rolls all four back and keeps serving the pack that was already working, without raising -- Restart=always would turn a ConfigError into a loop. 977 tests, 100% branch coverage, no omits and no suppressions. scripts/e2e.sh gains 8 scenarios driven against the real exiftool on media generated at run time, and asserts the invariants a reply cannot: that a refused upload is not stored, that a message with no attachment leaves custom.json byte-identical, and that signal-cli's own copy of every ingested attachment is gone. Closes TODO-add-photo.md. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01JqqE22jp94B1ypwxppdr1o --- DOCS-commands.md | 8 + DOCS-photo-pack.md | 120 ++++++++- TODO-add-photo.md | 207 ---------------- fake_signal/routes_api.py | 34 ++- fake_signal/routes_control.py | 29 +++ fake_signal/scenario.py | 11 + fake_signal/scenarios/pack_add_custom.yaml | 9 + fake_signal/scenarios/pack_add_heic.yaml | 14 ++ .../scenarios/pack_add_no_attachment.yaml | 8 + fake_signal/scenarios/pack_add_person.yaml | 12 + fake_signal/scenarios/pack_add_rejected.yaml | 10 + fake_signal/scenarios/pack_add_scoping.yaml | 10 + fake_signal/scenarios/pack_add_svg.yaml | 12 + fake_signal/scenarios/pack_add_video.yaml | 15 ++ fake_signal/state.py | 6 + pyproject.toml | 6 + scripts/e2e.sh | 45 ++++ scripts/install_service.sh | 15 ++ scripts/personal_data_sources.py | 64 ++++- scripts/signal-bot.service | 4 + signal_bot/aliases.json | 13 + signal_bot/bot.py | 25 +- signal_bot/external.py | 79 ++++++ signal_bot/help_command.py | 21 +- signal_bot/media_sniff.py | 164 +++++++++++++ signal_bot/media_strip.py | 136 +++++++++++ signal_bot/media_tags.py | 230 ++++++++++++++++++ signal_bot/models.py | 36 ++- signal_bot/pack.py | 17 ++ signal_bot/pack_add.py | 174 +++++++++++++ signal_bot/pack_command.py | 30 ++- signal_bot/pack_custom.py | 183 ++++++++++++++ signal_bot/pack_holder.py | 61 +++++ signal_bot/pack_ingest.py | 134 ++++++++++ signal_bot/pack_load.py | 11 +- signal_bot/pack_random.py | 94 +++++++ signal_bot/pack_replies.py | 30 +++ signal_bot/pack_store.py | 146 +++++++++++ signal_bot/registry.py | 20 +- signal_bot/transport_base.py | 8 + signal_bot/transport_fake.py | 13 + signal_bot/transport_rest.py | 14 ++ tests/pack_add_fixture.py | 121 +++++++++ tests/test_external.py | 88 +++++++ tests/test_fake_server.py | 39 +++ tests/test_help_command.py | 54 +++- tests/test_media_sniff.py | 93 +++++++ tests/test_media_strip.py | 129 ++++++++++ tests/test_media_tags.py | 91 +++++++ tests/test_pack_add.py | 228 +++++++++++++++++ tests/test_pack_add_invariants.py | 227 +++++++++++++++++ tests/test_pack_command.py | 5 +- tests/test_pack_custom.py | 122 ++++++++++ tests/test_pack_holder.py | 55 +++++ tests/test_pack_random.py | 182 ++++++++++++++ tests/test_pack_store.py | 101 ++++++++ tests/test_personal_data_sources.py | 125 ++++++++++ tests/test_scenario.py | 27 ++ tests/test_transport_attachments.py | 76 ++++++ tests/test_transport_base.py | 1 + tests/test_transport_rest.py | 27 -- tool/e2e_fixtures.py | 184 ++++++++++++++ tool/e2e_media.py | 112 +++++++++ 63 files changed, 4091 insertions(+), 274 deletions(-) delete mode 100644 TODO-add-photo.md create mode 100644 fake_signal/scenarios/pack_add_custom.yaml create mode 100644 fake_signal/scenarios/pack_add_heic.yaml create mode 100644 fake_signal/scenarios/pack_add_no_attachment.yaml create mode 100644 fake_signal/scenarios/pack_add_person.yaml create mode 100644 fake_signal/scenarios/pack_add_rejected.yaml create mode 100644 fake_signal/scenarios/pack_add_scoping.yaml create mode 100644 fake_signal/scenarios/pack_add_svg.yaml create mode 100644 fake_signal/scenarios/pack_add_video.yaml create mode 100644 signal_bot/external.py create mode 100644 signal_bot/media_sniff.py create mode 100644 signal_bot/media_strip.py create mode 100644 signal_bot/media_tags.py create mode 100644 signal_bot/pack_add.py create mode 100644 signal_bot/pack_custom.py create mode 100644 signal_bot/pack_holder.py create mode 100644 signal_bot/pack_ingest.py create mode 100644 signal_bot/pack_random.py create mode 100644 signal_bot/pack_replies.py create mode 100644 signal_bot/pack_store.py create mode 100644 tests/pack_add_fixture.py create mode 100644 tests/test_external.py create mode 100644 tests/test_media_sniff.py create mode 100644 tests/test_media_strip.py create mode 100644 tests/test_media_tags.py create mode 100644 tests/test_pack_add.py create mode 100644 tests/test_pack_add_invariants.py create mode 100644 tests/test_pack_custom.py create mode 100644 tests/test_pack_holder.py create mode 100644 tests/test_pack_random.py create mode 100644 tests/test_pack_store.py create mode 100644 tests/test_personal_data_sources.py create mode 100644 tests/test_transport_attachments.py create mode 100755 tool/e2e_fixtures.py create mode 100755 tool/e2e_media.py diff --git a/DOCS-commands.md b/DOCS-commands.md index fd13e35..d6572f2 100644 --- a/DOCS-commands.md +++ b/DOCS-commands.md @@ -26,10 +26,18 @@ This file is the trigger reference — every spelling that resolves, which | stats_weekdays | `!dni` `!days` | | stats_me | `!ja` `!moje` `!mnie` | | help | `!pomoc` `!pomocy` `!help` `!komendy` `!commands` | +| add_photo | `!dodaj` `!dodaj_zdjecie` `!dodajzdjecie` `!add_photo` `!addphoto` | +| random | `!losowe` `!losuj` `!random` `!rand` | Aliases live in `signal_bot/aliases.json`, not in source, because they are data: adding one should never mean touching Python. +`add_photo` and `random` exist **only in the photo album's own groups**, and +only on an installation that has an album at all — everywhere else they are +not commands, not refused and never logged. Both take arguments, and those +arguments are resolved to pseudonym keys by the registry before any handler, +log line or `command_uses` row sees them. See `DOCS-photo-pack.md`. + ## Why `!pomoc` shows the first alias and not a trigger `Command.triggers` is a `frozenset` of **folded skeletons** — `folding.py` diff --git a/DOCS-photo-pack.md b/DOCS-photo-pack.md index b9ee917..c074e1d 100644 --- a/DOCS-photo-pack.md +++ b/DOCS-photo-pack.md @@ -82,6 +82,123 @@ Videos work. The attachment goes out as container's own, from its `/swagger/doc.json` — because told it is a photo, Signal renders a clip as a file nobody can play. +## custom.json + +```json +{"t1": ["wakacje2019"], "t2": ["gorybieszczady"]} +``` + +Labels `!add_photo` learned from the chat that match no person. The key is a +pseudonym in the same family as `p1` — it is what reaches `tags.json`, a log +line and a reply — and the label is the only place the typed word is kept. +Custom tags define **no commands**: `!random