mail-address-semantics/tests/test_email_evidence.py
tegwick aef4c5dd71 Map a MAS gateway event into the email-connect evidence ceiling.
mas-email-evidence 0.1 reports MX acceptance, a bounce, or a reply, and
refuses the claim that a person read the message. Ordinary product mail
stays in email-connect. A product speaks the mode contract.

Assistant: grok
Assistant-Session: 01a198fa-fd27-7e41-a0a2-57355c3e4efd
2026-11-01 23:13:04 +01:00

60 lines
2.3 KiB
Python

"""MAS gateway event to email-connect evidence ceiling (mas-email-evidence 0.1)."""
from mas_gateway.email_evidence import from_gateway_event
def event(**message):
base = {"from": "a@example.org", "subject": "hello", "text": "body"}
base.update(message)
return {
"mas_event_version": "0.1",
"recipient": "ticket=GS-1@mas.coulomb.social",
"mas": {"valid": True},
"message": base,
}
def test_ordinary_mail_is_mx_acceptance_only():
got = from_gateway_event(event())
assert got["outcome"] == "mx_accepted"
assert got["event_type"] == "notification.endpoint.accepted"
assert got["assessment_subclass"] == "undef.endpoint_accepted_only"
assert got["evidence_ceiling"]["can_prove_human_awareness"] is False
assert got["evidence_ceiling"]["max_positive_strength"] == "medium"
def test_reply_is_medium_and_does_not_prove_a_person_read_it():
got = from_gateway_event(event(in_reply_to="<m@x>", text="I saw this"))
assert got["outcome"] == "reply_received"
assert got["evidence_strength"] == "medium"
assert "does not prove" in got["normalized_meaning"]
assert got["evidence_ceiling"]["can_prove_human_awareness"] is False
def test_automatic_reply_is_not_a_human_reply():
got = from_gateway_event(event(in_reply_to="<m@x>", auto_submitted="auto-replied", text="away"))
assert got["outcome"] == "out_of_office"
assert got["event_type"] == "interaction.out_of_office_received"
def test_permanent_and_temporary_bounces():
hard = from_gateway_event(event(**{
"from": "mailer-daemon@mx.example",
"subject": "Undelivered Mail Returned to Sender",
"text": "Final-Recipient: rfc822; b@example.org\nStatus: 5.1.1\nuser unknown",
}))
soft = from_gateway_event(event(**{
"from": "mailer-daemon@mx.example",
"subject": "Delivery Status Notification",
"text": "Final-Recipient: rfc822; b@example.org\nStatus: 4.2.2\nmailbox full",
}))
assert hard["outcome"] == "bounced_permanent"
assert soft["outcome"] == "bounced_temporary"
assert hard["evidence_ceiling"] == soft["evidence_ceiling"]
def test_a_non_event_makes_no_channel_claim():
got = from_gateway_event({"hello": "no"})
assert got["outcome"] == "parse_failed"
assert got["evidence_strength"] == "none"
assert got["recipient"] is None