feat: add image attachments to messages

- upload, metadata and download endpoints for PNG/JPEG attachments:
  limits before reading and decompression, type by content,
  structural integrity check without decoding pixels, safe filename
- write order: pending row with object key -> PUT to S3 -> ready;
  per-step DB sessions so no pool connection is held during transfers
- attachment_ids in messages (validation, idempotency hash, history);
  whitespace-only text allowed with an attachment (teacher, 2026-10-20)
- migration: attachments and message_attachments tables, text length
  CHECK relaxed with NOT VALID
- student tests, fault checks and driver commands for attachments;
  rollout profile starts from e1161f7 and checks the commit first
- sync attachments deltas into main specs; rules, AGENTS.md, PLAN.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 01:08:56 +03:00
co-authored by Claude Opus 5.5
parent 73779f7acd
commit 116d8d3bf0
72 changed files with 5546 additions and 247 deletions
+35 -1
View File
@@ -4,9 +4,12 @@
`spec_coverage.py`.
"""
from typing import Any
import pytest
from api_client import API, Actor, Api
import images
from api_client import API, Actor, Api, new_key
from contract import assert_ok
@@ -35,3 +38,34 @@ def test_member_order_kept(api: Api, alice: Actor, bob: Actor) -> None:
for chat in page["items"]
}
assert listed[created["id"]] == expected
@pytest.mark.spec("data-storage", "Порядок вложений")
def test_attachment_order_kept(
api: Api,
alice: Actor,
chat: dict[str, Any],
) -> None:
a, b, c = (
api.upload(alice, chat["id"], images.sample_png())["id"]
for _ in range(3)
)
key = new_key()
order = [c, a, b]
sent = api.send_message(
alice,
chat["id"],
"порядок",
key=key,
attachment_ids=order,
)
assert sent["attachment_ids"] == order
assert api.all_messages(alice, chat["id"]) == [sent]
replay = api.send_message(
alice,
chat["id"],
"порядок",
key=key,
attachment_ids=order,
)
assert replay["attachment_ids"] == order