Files
archie/internal/infrastructure/gatewayrpc/values_media_test.go
T
sam 2ed9cb7455 feat(telegram): carry inbound media through the chat turn
Telegram dropped every incoming photo, document, video and audio
message: the default handler required message text, and nothing on the
turn path knew media existed. The receiving path now closes the gap
end to end.

- telegram: extract the attachment from the update (largest photo, plus
  document, video, video-note, audio and voice kinds), download its
  bytes on the turn lane through getFile + the Bot API file link with a
  20 MB gate, submit the turn with the attachment, and answer
  unsupported content kinds (sticker, location, contact, poll) with a
  clear notice instead of silence
- messaging: Inbound carries turn-scoped transport media and
  MediaAttachment a Data field for in-process bytes; Message gains
  Media attachment metadata which stores persist (Postgres jsonb via
 migration 0020, memory store) with Data stripped at the persist
  boundary, and pb.Message carries the metadata on the gateway wire
- gateway: TurnModelRequest threads the turn's media to the model seam
- archied: the chat turn model merges the attachments into the final
  user message as ai-sdk image/file part entries, so vision-capable
  models see the file for the turn it arrived in; stored history keeps
  the placeholder note plus caption

Session log: messages carry what was sent as data (the attachment
metadata), not just prose. Transcript rendering of attachments and a
re-look capability are tracked as archie-core-jaba.
2026-09-30 03:07:54 +10:00

63 lines
2.3 KiB
Go

package gatewayrpc
import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
// TestStoredMediaRoundTrip: a message's attachment metadata must survive
// the wire both ways, while the in-process bytes -- turn-scoped by
// contract -- must never be marshalled onto it.
func TestStoredMediaRoundTrip(t *testing.T) {
size, width := int64(2048), 640
in := messaging.Message{
ID: messaging.MessageID("m1"),
Role: messaging.RoleUser, Text: "[document: notes.txt]",
Media: []messaging.MediaAttachment{{
Type: "document", FileID: "tg-f1", URL: "https://example.invalid/notes",
Path: "/tmp/never-here", MIMEType: "text/plain", FileName: "notes.txt",
FileSize: &size, Width: &width, Data: []byte("file bytes"),
}},
}
out := storedValue(storedProto(in))
if len(out.Media) != 1 {
t.Fatalf("round-tripped media = %#v, want one attachment", out.Media)
}
att := out.Media[0]
if att.Type != "document" || att.FileName != "notes.txt" || att.MIMEType != "text/plain" {
t.Errorf("attachment = %#v, want its metadata preserved", att)
}
if att.FileID != "tg-f1" {
t.Errorf("FileID = %q, want tg-f1", att.FileID)
}
if att.FileSize == nil || *att.FileSize != size || att.Width == nil || *att.Width != width {
t.Errorf("numeric metadata = %#v, want size and width preserved", att)
}
if att.URL != "https://example.invalid/notes" {
t.Errorf("URL = %q, want preserved", att.URL)
}
if len(att.Data) != 0 {
t.Errorf("attachment bytes crossed the wire, want them stripped")
}
}
// TestInboundMediaRoundTrip mirrors the stored direction for the inbound
// transport context: a frontend that names attachments on Route gets them
// back on the daemon side, minus the bytes which it must carry itself.
func TestInboundMediaRoundTrip(t *testing.T) {
in := messaging.Inbound{
Message: messaging.Message{Text: "hi", Sender: "sam"},
Media: []messaging.MediaAttachment{
{Type: "image", FileID: "f1", MIMEType: "image/jpeg", Data: []byte("jpeg")},
},
}
out := inboundValue(inboundProto(in))
if len(out.Media) != 1 || out.Media[0].FileID != "f1" || out.Media[0].Type != "image" {
t.Fatalf("round-tripped inbound media = %#v, want the sender attachment", out.Media)
}
if len(out.Media[0].Data) != 0 {
t.Errorf("inbound attachment bytes crossed the wire, want them stripped")
}
}