feat(campaign): record unmatched file disposition

This commit is contained in:
2026-08-20 01:57:12 +02:00
parent b6af7665f4
commit f4fe534ee1
9 changed files with 177 additions and 3 deletions
+71
View File
@@ -340,6 +340,22 @@ class CampaignAttachmentBuildTests(unittest.TestCase):
)
self.assertEqual(len(result.report.messages), 2)
self.assertEqual(
{
"contract_version": "1",
"action": "route_report" if mode == "report" else "route_with_files",
"routing_mode": mode,
"validation_behavior": "block",
"watched_source_count": 1,
"residual_file_count": 1,
"recipient": {
"email": "operator@example.org",
"name": "Operator",
"type": "to",
},
},
result.report.residual_file_disposition,
)
normal, residual = result.report.messages
self.assertEqual(normal.validation_status.value, "ready")
self.assertEqual(residual.entry_id, "__residual_files__")
@@ -361,6 +377,61 @@ class CampaignAttachmentBuildTests(unittest.TestCase):
filenames = [part.get_filename() for part in mime.iter_attachments()]
self.assertEqual(filenames, ["residual.txt"] if mode == "attach" else [])
def test_residual_file_policy_evidence_normalizes_block_and_ignore(self) -> None:
for behavior, action in (("block", "block"), ("continue", "ignore")):
with self.subTest(behavior=behavior), tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
watched = root / "watched"
watched.mkdir()
(watched / "residual.txt").write_text("residual", encoding="utf-8")
campaign_file = root / "campaign.json"
campaign_file.write_text("{}", encoding="utf-8")
config = CampaignConfig.model_validate({
"version": "1.0",
"campaign": {"id": f"residual-{behavior}", "name": "Residual", "mode": "test"},
"fields": [],
"global_values": {},
"server": {
"mail_profile_id": "profile-1",
"profile_capabilities": {"smtp_available": True},
},
"recipients": {
"from": {"email": "sender@example.org", "type": "to"},
"allow_individual_to": True,
},
"template": {"subject": "Normal", "text": "Body"},
"attachments": {
"base_paths": [{
"id": "watched",
"name": "Watched folder",
"path": "watched",
"unsent_warning": True,
}],
},
"entries": {"inline": [{
"id": "recipient-1",
"to": [{"email": "recipient@example.org", "type": "to"}],
}]},
"validation_policy": {"unsent_attachment_files": behavior},
"delivery": {"imap_append_sent": {"enabled": False}},
})
result = build_campaign_messages(
config,
campaign_file=campaign_file,
output_dir=root / "out",
write_eml=False,
)
self.assertEqual(action, result.report.residual_file_disposition["action"])
self.assertEqual(1, result.report.residual_file_disposition["residual_file_count"])
issue_codes = {
issue.code
for message in result.report.messages
for issue in message.issues
}
self.assertEqual(behavior == "block", "unsent_attachment_files" in issue_codes)
if __name__ == "__main__":
unittest.main()