human hand off fix

This commit is contained in:
debu-2 2026-10-06 07:42:41 +05:30
parent 7b9e574b86
commit 0981262612
5 changed files with 154 additions and 24 deletions

View file

@ -49,6 +49,33 @@ def test_format_sender_with_name():
)
def test_quoted_history_uses_original_sender_not_human_owner():
from datetime import datetime, timezone
from app.services.handoff_email_templates import (
attach_quoted_history,
build_gmail_quote,
)
quoted_text, quoted_html = build_gmail_quote(
sender={"name": "Parth Dixit", "address": "parthdixit091@gmail.com"},
event_at=datetime(2026, 10, 6, 7, 29, tzinfo=timezone.utc),
body_text="sender: C",
body_html="<div>sender: C</div>",
)
body_text, body_html = attach_quoted_history(
new_text="responder: D",
new_html="<div>responder: D</div>",
quoted_text=quoted_text,
quoted_html=quoted_html,
)
assert body_text.startswith("responder: D")
assert "Parth Dixit <parthdixit091@gmail.com>" in body_text
assert "> sender: C" in body_text
assert "parthdixit091@gmail.com" in body_html
assert "Suyash AIML" not in body_text
def test_external_threading_headers_from_customer_message():
parent = {
"_id": "mongo-id",

View file

@ -278,12 +278,13 @@ def test_human_echo_and_agent_mirror_policy():
def test_private_subject_stays_off_the_external_plane():
private = build_handoff_subject(
rule_name="Finance approvals",
sender_name="Parth Dixit",
external_sender="customer@example.com",
external_subject="Invoice 42",
)
assert private.startswith("Finance approvals · handoff ·")
assert private.startswith("Parth Dixit · handoff ·")
assert "Invoice 42" in private
assert "Finance approvals" not in private
@pytest.mark.asyncio
@ -314,7 +315,7 @@ async def test_first_matching_rule_creates_a_new_linked_handoff():
"_id": source_id,
"message_scope": MESSAGE_SCOPE_EXTERNAL,
"direction": "inbound",
"sender": {"address": "customer@example.com"},
"sender": {"name": "Parth Dixit", "address": "customer@example.com"},
"subject": "Invoice 42",
"body_text": "please review this invoice",
"snippet": "please review this invoice",
@ -331,7 +332,7 @@ async def test_first_matching_rule_creates_a_new_linked_handoff():
assert result["rule_name"] == "Finance approvals"
assert result["external_thread_id"] == external_thread_id
assert result["handoff_thread_id"]
assert result["private_subject"].startswith("Finance approvals · handoff ·")
assert result["private_subject"].startswith("Parth Dixit · handoff ·")
assert database.handoff_delivery_jobs.items[0]["kind"] == "MIRROR_TO_HUMAN"

View file

@ -20,20 +20,20 @@ def test_human_handoff_runtime_is_enabled():
assert callable(resolve_handoff_from_inbound)
def test_private_subject_contains_rule_sender_and_external_subject():
def test_private_subject_contains_customer_name_and_external_subject():
subject = build_handoff_subject(
rule_name="Finance approvals",
external_sender="customer@example.com",
sender_name="Parth Dixit",
external_sender="parthdixit091@gmail.com",
external_subject="Invoice 42",
)
assert subject == (
"Finance approvals · handoff · customer@example.com · Invoice 42"
"Parth Dixit · handoff · parthdixit091@gmail.com · Invoice 42"
)
def test_private_subject_removes_header_line_breaks():
subject = build_handoff_subject(
rule_name="Urgent\r\nBcc: attacker@example.com",
sender_name="Urgent\r\nBcc: attacker@example.com",
external_sender="customer@example.com",
external_subject="Help",
)