simulateInbound reproduces the relay's decisions for a single inbound message: it parses threading info, gates the X-E2A-Conversation-ID header on the envelope domain, and picks the display sender the way deliverToAgent does. lookup can be nil to simulate "no prior thread in DB".
(t *testing.T, raw []byte, envelopeFrom string, lookup func(ctx context.Context, ids []string) (string, error))
| 30 | // on the envelope domain, and picks the display sender the way deliverToAgent |
| 31 | // does. lookup can be nil to simulate "no prior thread in DB". |
| 32 | func simulateInbound(t *testing.T, raw []byte, envelopeFrom string, lookup func(ctx context.Context, ids []string) (string, error)) (sender, conversationID string) { |
| 33 | t.Helper() |
| 34 | info := extractThreadInfo(raw) |
| 35 | trusted := strings.EqualFold(extractDomain(envelopeFrom), relayFromDomain) |
| 36 | sender = info.From |
| 37 | if len(info.ReplyTo) > 0 { |
| 38 | sender = info.ReplyTo[0] |
| 39 | } |
| 40 | conversationID = resolveConversationID(context.Background(), info, trusted, lookup) |
| 41 | return sender, conversationID |
| 42 | } |
| 43 | |
| 44 | // composeAgentOutbound mirrors what sender.go does for a real agent send or |
| 45 | // reply: "{display} via e2a" <agent@send.e2a.dev> for From, agent's real |
no test coverage detected