EMAIL-WP-0005-T04: end-to-end send-and-scan tests, and two fixes they found
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 2s

Adds tests/test_integration_send_scan.py: 7 harness-gated cases covering
delivery and Message-ID correlation, scanner ingestion without a delivery
claim, idempotency, resend, suppression, rejected requests never reaching the
provider, and verification mail carrying no authorization.

Fixes the reply heuristic, which matched against headers as well as body. The
Received: trace that every MTA-handled message carries matched its "received"
keyword, so ordinary mail was classified human_reply with a
success.reply_received assessment at medium confidence -- the exact overclaim
this repo exists to prevent. Hand-written fixtures have no Received headers,
so only real scanned mail exposed it. The heuristic now takes the body alone;
DSN detection still sees headers, which it needs. Regression test is offline.

Fixes the provider reference: SMTPProvider set no Message-ID, so send() fell
back to abs(hash((recipient, subject))) -- randomized per process and colliding
for equal recipient/subject. Outgoing mail now carries a proper RFC 5322
Message-ID, returned as the reference, which is what makes send-to-scan
correlation testable.

Suite: 72 passed with the harness up, 62 passed + 10 skipped with it down.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
tegwick 2026-08-14 01:54:56 +02:00
parent 442a574cf9
commit e9609b4024
7 changed files with 301 additions and 5 deletions

View file

@ -92,6 +92,21 @@ class ParserTests(unittest.TestCase):
self.assertIn("action=failed", parsed.notes)
self.assertIn("diagnostic_code=smtp; 550 5.1.1 User unknown", parsed.notes)
def test_mta_received_headers_do_not_make_a_message_a_reply(self) -> None:
"""Regression: the reply heuristic used to match the Received: trace.
Every message that traverses an MTA carries `Received:` headers, and the
word "received" was enough to classify ordinary mail as a human reply
with a success.reply_received assessment. Hand-written fixtures have no
Received headers, so only real scanned mail exposed it.
"""
transit = Path(__file__).parent / "fixtures" / "mailbox_transit" / "ordinary_transit.eml"
_inbound, parsed, candidate = parse_message_file(transit, mailbox_id="test")
self.assertNotEqual(parsed.message_class, MessageClass.HUMAN_REPLY)
if candidate is not None:
self.assertNotEqual(candidate.event_type, "interaction.reply_received")
if __name__ == "__main__":
unittest.main()