human hand off
This commit is contained in:
parent
d0fee5c8f7
commit
7af776196a
34 changed files with 2941 additions and 195 deletions
|
|
@ -1,13 +1,74 @@
|
|||
from app.services.human_handoff_service import MESSAGE_SCOPE_EXTERNAL, MESSAGE_SCOPE_HANDOFF
|
||||
from app.services.human_handoff_service import (
|
||||
MESSAGE_SCOPE_EXTERNAL,
|
||||
MESSAGE_SCOPE_HANDOFF,
|
||||
build_handoff_subject,
|
||||
maybe_trigger_handoff,
|
||||
process_human_reply,
|
||||
redact_human_address,
|
||||
resolve_handoff_from_inbound,
|
||||
select_matching_handoff_rule,
|
||||
)
|
||||
|
||||
|
||||
def test_scope_constants_are_distinct():
|
||||
assert MESSAGE_SCOPE_EXTERNAL != MESSAGE_SCOPE_HANDOFF
|
||||
|
||||
|
||||
def test_human_handoff_runtime_is_disabled():
|
||||
import app.services.human_handoff_service as module
|
||||
def test_human_handoff_runtime_is_enabled():
|
||||
assert callable(maybe_trigger_handoff)
|
||||
assert callable(process_human_reply)
|
||||
assert callable(resolve_handoff_from_inbound)
|
||||
|
||||
assert not hasattr(module, "maybe_trigger_handoff")
|
||||
assert not hasattr(module, "process_human_reply")
|
||||
assert not hasattr(module, "resolve_handoff_from_inbound")
|
||||
|
||||
def test_private_subject_contains_rule_sender_and_external_subject():
|
||||
subject = build_handoff_subject(
|
||||
rule_name="Finance approvals",
|
||||
external_sender="customer@example.com",
|
||||
external_subject="Invoice 42",
|
||||
)
|
||||
assert subject == (
|
||||
"Finance approvals · handoff · customer@example.com · Invoice 42"
|
||||
)
|
||||
|
||||
|
||||
def test_private_subject_removes_header_line_breaks():
|
||||
subject = build_handoff_subject(
|
||||
rule_name="Urgent\r\nBcc: attacker@example.com",
|
||||
external_sender="customer@example.com",
|
||||
external_subject="Help",
|
||||
)
|
||||
assert "\r" not in subject
|
||||
assert "\n" not in subject
|
||||
|
||||
|
||||
def test_human_address_is_replaced_before_external_relay():
|
||||
value = "Regards,\nOwner <private.owner@example.com>"
|
||||
assert redact_human_address(
|
||||
value,
|
||||
human_email="private.owner@example.com",
|
||||
agent_email="agent@gentic.email",
|
||||
) == "Regards,\nOwner <agent@gentic.email>"
|
||||
|
||||
|
||||
def test_lowest_priority_matching_rule_wins():
|
||||
rules = [
|
||||
{
|
||||
"name": "Backup",
|
||||
"priority": 20,
|
||||
"labels": ["All mail"],
|
||||
"email_types": ["all"],
|
||||
"instructions": "",
|
||||
},
|
||||
{
|
||||
"name": "Primary",
|
||||
"priority": 1,
|
||||
"labels": ["All mail"],
|
||||
"email_types": ["all"],
|
||||
"instructions": "",
|
||||
},
|
||||
]
|
||||
selected = select_matching_handoff_rule(
|
||||
rules,
|
||||
email={"subject": "Hello", "body_text": "Need help"},
|
||||
)
|
||||
assert selected["name"] == "Primary"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue