umpirix/otsone/tests/test_email.py
caelum0x 4847e35451 OpenJev: open-source typed decision service
Typed decision/classification service with an in-process gte-small ONNX
embedding engine and lexical fallback, JS/Python SDKs, adapters, and the
otsone model family. Apache-2.0 (sub-packages keep their MIT licenses).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 00:12:36 +03:00

54 lines
1.9 KiB
Python

"""Email cleaning: a disclaimer footer must not delete the sender's actual request.
Regression tests ported from upstream v0.3.5 (#94). `_DISCLAIMER` used to be applied to
whole paragraphs, so any paragraph that merely *mentioned* boilerplate was deleted outright.
"""
import pytest
from laya_mlx.email import clean_email_body, email_state
DISCLAIMER = "This email is confidential and intended solely for the named addressee."
@pytest.mark.parametrize(
"body,want",
[
# the request survives the footer
(
"My account is locked.\n%s\nPlease unlock it." % DISCLAIMER,
"My account is locked. Please unlock it.",
),
("My account is locked\n%s\nPlease unlock it." % DISCLAIMER, "Please unlock it."),
("My account is locked. %s" % DISCLAIMER, "My account is locked."),
# a pure footer is still removed
("My account is locked.\n\n%s" % DISCLAIMER, "My account is locked."),
(
"My account is locked.\n\nThis email and any files transmitted with it are\n"
"confidential and intended solely for the named addressee.",
"My account is locked.",
),
(
"Please reopen ticket 4411.\n\nIf you have received this message in error, delete it.",
"Please reopen ticket 4411.",
),
# unrelated cleaning is unchanged
(
"Thanks for the update.\nOn Mon, Sep 20, Bob wrote:\n> original text",
"Thanks for the update.",
),
(
"Hi team,\nCan you confirm the refund?\nRegards,\nAlice",
"Hi team,\nCan you confirm the refund?",
),
("", ""),
],
)
def test_clean_email_body(body, want):
assert clean_email_body(body) == want
def test_email_state_body_keeps_the_request():
state = email_state("Locked out", "My account is locked. %s" % DISCLAIMER)
assert state["body"] == "My account is locked."