handoff fixes
This commit is contained in:
parent
89ddebdb60
commit
8d5e9712a6
20 changed files with 1056 additions and 141 deletions
82
backend/tests/test_handoff_threading.py
Normal file
82
backend/tests/test_handoff_threading.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
"""Integration-style tests for Human Handoff → Customer RFC threading."""
|
||||
|
||||
from bson import ObjectId
|
||||
|
||||
from app.services.external_reply_service import (
|
||||
build_external_reply_plan,
|
||||
internet_message_id_of,
|
||||
)
|
||||
from app.services.mail_sender import build_message, sign_message
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
def test_handoff_bridge_first_reply_threads_against_customer_a():
|
||||
customer_a_id = "<CAHabc123@mail.gmail.com>"
|
||||
customer_a = {
|
||||
"_id": ObjectId(),
|
||||
"internet_message_id": customer_a_id,
|
||||
"message_id": customer_a_id,
|
||||
"message_scope": "EXTERNAL",
|
||||
"direction": "inbound",
|
||||
"references": [],
|
||||
"subject": "fresh test",
|
||||
}
|
||||
plan = build_external_reply_plan(
|
||||
parent_external_message=customer_a,
|
||||
body_text="human said B",
|
||||
recipients=["091rabbytes@gmail.com"],
|
||||
)
|
||||
assert plan.threading.in_reply_to == customer_a_id
|
||||
assert plan.threading.references == [customer_a_id]
|
||||
assert plan.threading.in_reply_to != "<H2@gmail.com>"
|
||||
assert "<H1@gentic.email>" not in plan.threading.references
|
||||
|
||||
|
||||
def test_lowercased_stored_id_recovered_via_raw_headers():
|
||||
customer_a_id = "<CAHabc123@mail.gmail.com>"
|
||||
parent = {
|
||||
"_id": ObjectId(),
|
||||
"internet_message_id": "<cahabc123@mail.gmail.com>",
|
||||
"message_id": "<cahabc123@mail.gmail.com>",
|
||||
"raw_headers": {"message_id": customer_a_id},
|
||||
"references": [],
|
||||
"subject": "fresh test",
|
||||
}
|
||||
plan = build_external_reply_plan(
|
||||
parent_external_message=parent,
|
||||
body_text="human said B",
|
||||
recipients=["customer@gmail.com"],
|
||||
parent_internet_id_override=internet_message_id_of(parent),
|
||||
)
|
||||
assert plan.threading.in_reply_to == customer_a_id
|
||||
assert plan.threading.references == [customer_a_id]
|
||||
|
||||
|
||||
def test_signed_mime_preserves_threading_headers():
|
||||
customer_a_id = "<CAHabc123@mail.gmail.com>"
|
||||
message = build_message(
|
||||
sender="suyash@gentic.email",
|
||||
recipients=["091rabbytes@gmail.com"],
|
||||
cc=[],
|
||||
subject="Re: fresh test",
|
||||
body_text="human said B",
|
||||
body_html=None,
|
||||
in_reply_to=customer_a_id,
|
||||
references=[customer_a_id],
|
||||
message_id="<B@gentic.email>",
|
||||
)
|
||||
domain = SimpleNamespace(
|
||||
domain_name="gentic.email",
|
||||
dkim_selector="agmail",
|
||||
dkim_private_key="private-key",
|
||||
)
|
||||
from unittest.mock import patch
|
||||
|
||||
with patch(
|
||||
"app.services.mail_sender.dkim.sign",
|
||||
return_value=b"DKIM-Signature: test\r\n",
|
||||
):
|
||||
signed = sign_message(message, domain)
|
||||
|
||||
assert f"In-Reply-To: {customer_a_id}".encode() in signed
|
||||
assert f"References: {customer_a_id}".encode() in signed
|
||||
Loading…
Add table
Add a link
Reference in a new issue