88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
from app.services.handoff_email_templates import external_reply_subject
|
|
from app.services.reply_extractor import extract_new_reply_content, validate_external_reply_body
|
|
|
|
SCREENSHOT_REPLY = """ahan, did you receive a response?
|
|
|
|
On Tue, Oct 6, 2026 at 2:11 AM <suyash@gentic.email> wrote:
|
|
|
|
> Human Handoff
|
|
>
|
|
> A conversation needs your attention.
|
|
>
|
|
> From
|
|
> 091rabbytes@gmail.com
|
|
>
|
|
> Subject
|
|
> are you ready?
|
|
>
|
|
> Latest message
|
|
> "lets start a threaddddd"
|
|
>
|
|
> Why this was handed off
|
|
> No handoff instructions were set, so this step passes.
|
|
>
|
|
> Reply to this email to respond to the original sender through suyash@gentic.email.
|
|
>
|
|
> Your reply will be sent to the customer.
|
|
>
|
|
> Gentic Human Handoff"""
|
|
|
|
|
|
def test_extracts_new_reply_from_gmail_quote():
|
|
result = extract_new_reply_content(body_text=SCREENSHOT_REPLY)
|
|
assert result["new_reply_content"] == "ahan, did you receive a response?"
|
|
assert "Human Handoff" in result["quoted_content"]
|
|
assert "091rabbytes@gmail.com" in result["quoted_content"]
|
|
|
|
|
|
def test_extracted_reply_passes_leakage_guard():
|
|
result = extract_new_reply_content(body_text=SCREENSHOT_REPLY)
|
|
assert validate_external_reply_body(result["new_reply_content"]) is True
|
|
|
|
|
|
def test_leakage_guard_blocks_private_template():
|
|
assert validate_external_reply_body(SCREENSHOT_REPLY) is False
|
|
|
|
|
|
def test_external_reply_subject_uses_customer_subject():
|
|
assert external_reply_subject("are you ready?") == "Re: are you ready?"
|
|
assert external_reply_subject("Human Handoff · are you ready?") == "Re: are you ready?"
|
|
|
|
|
|
def test_extracts_reply_before_blockquote_lines():
|
|
body = """responder: B
|
|
> sender: A"""
|
|
result = extract_new_reply_content(body_text=body)
|
|
assert result["new_reply_content"] == "responder: B"
|
|
assert "sender: A" in result["quoted_content"]
|
|
|
|
|
|
def test_extracts_reply_from_gmail_on_wrote_without_blank_line():
|
|
body = """sender: C
|
|
On Tue, Oct 6, 2026 at 4:29 AM <suyash@gentic.email> wrote:
|
|
> Responder: B
|
|
> sender: A"""
|
|
result = extract_new_reply_content(body_text=body)
|
|
assert result["new_reply_content"] == "sender: C"
|
|
assert "Responder: B" in result["quoted_content"]
|
|
|
|
|
|
def test_build_reply_display_uses_clean_snippet():
|
|
from app.services.reply_extractor import build_reply_display
|
|
|
|
body = """responder: D
|
|
On Tue, Oct 6, 2026 at 4:29 AM wrote:
|
|
> sender: C"""
|
|
result = build_reply_display(body_text=body)
|
|
assert result["snippet"] == "responder: D"
|
|
assert result["has_quoted_text"] is True
|
|
|
|
|
|
def test_outlook_original_message_split():
|
|
body = """Thanks for the update.
|
|
|
|
-----Original Message-----
|
|
From: support@gentic.email
|
|
Subject: Human Handoff"""
|
|
result = extract_new_reply_content(body_text=body)
|
|
assert result["new_reply_content"] == "Thanks for the update."
|