--- Flow 1: Human → Agent → Human --------------------------------------
(t *testing.T)
| 74 | // --- Flow 1: Human → Agent → Human -------------------------------------- |
| 75 | |
| 76 | func TestFlow1_HumanAgentHuman(t *testing.T) { |
| 77 | const ( |
| 78 | human = "user@gmail.com" |
| 79 | agent = "bot@agent.mnexa.ai" |
| 80 | convID = "conv-flow1" |
| 81 | msg2SES = "<msg2-ses-id@send.e2a.dev>" // SES-assigned ID on the agent's outbound (msg 2) |
| 82 | ) |
| 83 | |
| 84 | // Msg 1: Human → Agent. New thread, no X-E2A header, envelope from Gmail. |
| 85 | msg1 := composeHumanOutbound(t, human, agent, "Hello agent", "Question for you", "") |
| 86 | sender1, conv1 := simulateInbound(t, msg1, "bounce@gmail.com", nil /* no prior thread */) |
| 87 | if sender1 != human { |
| 88 | t.Errorf("msg 1 sender = %q, want %q", sender1, human) |
| 89 | } |
| 90 | if conv1 != "" { |
| 91 | t.Errorf("msg 1 conv_id = %q, want empty (human has no conv_id concept)", conv1) |
| 92 | } |
| 93 | |
| 94 | // Agent now picks conversation_id=convID locally and replies. |
| 95 | |
| 96 | // Msg 2: Agent → Human via reply (In-Reply-To + X-E2A header). |
| 97 | // Human's Gmail just displays it — we don't simulate inbound here. The |
| 98 | // header presence on outbound is already covered in compose_test.go. |
| 99 | _ = composeAgentOutbound(t, agent, []string{human}, "Re: Hello agent", "Reply body", |
| 100 | "<human-msg-id@gmail.com>" /* In-Reply-To */, convID) |
| 101 | |
| 102 | // Msg 3: Human → Agent, replying to msg 2 (Gmail sets In-Reply-To = msg 2's SES id). |
| 103 | // Envelope from Gmail, so X-E2A header gate fails; conv_id recovers via lookup. |
| 104 | msg3 := composeHumanOutbound(t, human, agent, "Re: Hello agent", "Follow-up", msg2SES) |
| 105 | lookup := func(ctx context.Context, ids []string) (string, error) { |
| 106 | for _, id := range ids { |
| 107 | if id == msg2SES { |
| 108 | return convID, nil // the DB finds msg 2 and returns its conv_id |
| 109 | } |
| 110 | } |
| 111 | return "", fmt.Errorf("not found") |
| 112 | } |
| 113 | sender3, conv3 := simulateInbound(t, msg3, "bounce@gmail.com", lookup) |
| 114 | if sender3 != human { |
| 115 | t.Errorf("msg 3 sender = %q, want %q", sender3, human) |
| 116 | } |
| 117 | if conv3 != convID { |
| 118 | t.Errorf("msg 3 conv_id = %q, want %q (recovered via In-Reply-To)", conv3, convID) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // --- Flow 2: Agent A → Agent B → Agent A -------------------------------- |
| 123 |
nothing calls this directly
no test coverage detected