truvek-comply 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: truvek-comply
3
+ Version: 0.1.0
4
+ Summary: Pre-send compliance checks for email and SMS — Spam Act (AU), CAN-SPAM (US), CASL (CA), GDPR (EU)
5
+ Author: Truckling
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Truckling/truvek-comply
8
+ Project-URL: Repository, https://github.com/Truckling/truvek-comply
9
+ Project-URL: Issues, https://github.com/Truckling/truvek-comply/issues
10
+ Keywords: mcp,email,compliance,spam-act,australia,can-spam,casl,gdpr,marketing,truvek
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Communications :: Email
15
+ Classifier: Topic :: Office/Business
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: mcp>=2.0.0
19
+ Requires-Dist: uvicorn>=0.30.0
20
+
21
+ # Truvek Comply
22
+
23
+ Pre-send compliance checker for email and SMS. Checks messages against four major laws before you send them — returns a verdict, findings, and fixes.
24
+
25
+ Works as an MCP server. Add it to Claude and ask it to check your emails in plain English.
26
+
27
+ ## Laws covered
28
+
29
+ | Law | Region | Channel |
30
+ |-----|--------|---------|
31
+ | Spam Act 2003 | Australia | Email + SMS |
32
+ | CAN-SPAM Act | United States | Email |
33
+ | CASL | Canada | Email + SMS |
34
+ | GDPR / ePrivacy Directive | European Union | Email + SMS |
35
+ | TCPA | United States | SMS |
36
+
37
+ ## What it checks
38
+
39
+ | Rule | Laws | Severity |
40
+ |------|------|----------|
41
+ | Consent missing (opt-in required) | Spam Act, CASL, GDPR | Block |
42
+ | Opt-out not confirmed | CAN-SPAM | Review |
43
+ | Inferred/implied consent risk | Spam Act, CASL | Review |
44
+ | Sender not identified | All four laws | Block |
45
+ | No unsubscribe mechanism | All four laws | Block |
46
+ | Unsubscribe requires login | Spam Act, CASL, GDPR | Review |
47
+ | Physical mailing address missing | CAN-SPAM, CASL | Block |
48
+ | Transactional email with promotional content | Spam Act, CAN-SPAM, CASL | Review |
49
+ | SMS alphanumeric sender ID unregistered | ACMA (AU, from Jul 2026) | Info |
50
+ | SMS prior written consent missing | TCPA (US) | Block |
51
+ | SMS opt-in consent missing | ePrivacy (EU) | Block |
52
+
53
+ ## Add to Claude
54
+
55
+ **Claude Desktop** — add this to your `claude_desktop_config.json`:
56
+
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "truvek-comply": {
61
+ "command": "truvek-comply"
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ **Claude Code** — run:
68
+
69
+ ```bash
70
+ claude mcp add truvek-comply truvek-comply
71
+ ```
72
+
73
+ ## Install
74
+
75
+ ```bash
76
+ pip install truvek-comply
77
+ ```
78
+
79
+ Requires Python 3.10+.
80
+
81
+ ## Usage
82
+
83
+ Once added, ask Claude to check an email:
84
+
85
+ > "Check this email for compliance. We have express consent from subscribers who opted in via our website."
86
+
87
+ Specify a jurisdiction if you know your audience:
88
+
89
+ > "Check this email against Australian law only."
90
+
91
+ Or check all jurisdictions at once (the default):
92
+
93
+ > "Check this email — our list includes US, Canadian, and Australian subscribers."
94
+
95
+ Claude will call Truvek Comply and return a verdict — **pass**, **review**, or **block** — with findings tagged to the specific law they come from.
96
+
97
+ ## Tools
98
+
99
+ | Tool | What it does |
100
+ |------|-------------|
101
+ | `check_message` | Full compliance check — verdict, findings tagged by law, check ID |
102
+ | `classify_message` | Classify as marketing / transactional / transactional_with_promotion / unclear |
103
+ | `explain_rule` | Look up a specific rule by ID |
104
+ | `list_rules` | Return all rules with severity, jurisdiction, and fix guidance |
105
+ | `get_evidence` | Retrieve past check records from the local evidence log |
106
+
107
+ ## Parameters
108
+
109
+ **`check_message` accepts:**
110
+
111
+ | Parameter | Values | Default |
112
+ |-----------|--------|---------|
113
+ | `channel` | `email`, `sms` | `email` |
114
+ | `consent` | `express`, `inferred`, `none`, `unknown` | `unknown` |
115
+ | `sender_identified` | `true`, `false` | `false` |
116
+ | `jurisdiction` | `au`, `us`, `ca`, `eu`, `all` | `all` |
117
+
118
+ **Consent by jurisdiction:**
119
+ - AU / CA / EU: opt-in required — `none` or `unknown` blocks the send
120
+ - US CAN-SPAM: opt-out model — prior consent not required, but opt-outs must be honoured
121
+
122
+ ## Background
123
+
124
+ Email and SMS marketing is regulated everywhere. ACMA (Australia) has issued fines over 7 million AUD for consent failures and 700K AUD for transactional emails containing promotional content. The FTC enforces CAN-SPAM with fines up to 51,744 USD per email. CRTC enforces CASL with penalties up to 10 million CAD per violation.
125
+
126
+ Truvek Comply is a pre-send compliance tool, not legal advice.
127
+
128
+ ## License
129
+
130
+ MIT
@@ -0,0 +1,110 @@
1
+ # Truvek Comply
2
+
3
+ Pre-send compliance checker for email and SMS. Checks messages against four major laws before you send them — returns a verdict, findings, and fixes.
4
+
5
+ Works as an MCP server. Add it to Claude and ask it to check your emails in plain English.
6
+
7
+ ## Laws covered
8
+
9
+ | Law | Region | Channel |
10
+ |-----|--------|---------|
11
+ | Spam Act 2003 | Australia | Email + SMS |
12
+ | CAN-SPAM Act | United States | Email |
13
+ | CASL | Canada | Email + SMS |
14
+ | GDPR / ePrivacy Directive | European Union | Email + SMS |
15
+ | TCPA | United States | SMS |
16
+
17
+ ## What it checks
18
+
19
+ | Rule | Laws | Severity |
20
+ |------|------|----------|
21
+ | Consent missing (opt-in required) | Spam Act, CASL, GDPR | Block |
22
+ | Opt-out not confirmed | CAN-SPAM | Review |
23
+ | Inferred/implied consent risk | Spam Act, CASL | Review |
24
+ | Sender not identified | All four laws | Block |
25
+ | No unsubscribe mechanism | All four laws | Block |
26
+ | Unsubscribe requires login | Spam Act, CASL, GDPR | Review |
27
+ | Physical mailing address missing | CAN-SPAM, CASL | Block |
28
+ | Transactional email with promotional content | Spam Act, CAN-SPAM, CASL | Review |
29
+ | SMS alphanumeric sender ID unregistered | ACMA (AU, from Jul 2026) | Info |
30
+ | SMS prior written consent missing | TCPA (US) | Block |
31
+ | SMS opt-in consent missing | ePrivacy (EU) | Block |
32
+
33
+ ## Add to Claude
34
+
35
+ **Claude Desktop** — add this to your `claude_desktop_config.json`:
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "truvek-comply": {
41
+ "command": "truvek-comply"
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ **Claude Code** — run:
48
+
49
+ ```bash
50
+ claude mcp add truvek-comply truvek-comply
51
+ ```
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ pip install truvek-comply
57
+ ```
58
+
59
+ Requires Python 3.10+.
60
+
61
+ ## Usage
62
+
63
+ Once added, ask Claude to check an email:
64
+
65
+ > "Check this email for compliance. We have express consent from subscribers who opted in via our website."
66
+
67
+ Specify a jurisdiction if you know your audience:
68
+
69
+ > "Check this email against Australian law only."
70
+
71
+ Or check all jurisdictions at once (the default):
72
+
73
+ > "Check this email — our list includes US, Canadian, and Australian subscribers."
74
+
75
+ Claude will call Truvek Comply and return a verdict — **pass**, **review**, or **block** — with findings tagged to the specific law they come from.
76
+
77
+ ## Tools
78
+
79
+ | Tool | What it does |
80
+ |------|-------------|
81
+ | `check_message` | Full compliance check — verdict, findings tagged by law, check ID |
82
+ | `classify_message` | Classify as marketing / transactional / transactional_with_promotion / unclear |
83
+ | `explain_rule` | Look up a specific rule by ID |
84
+ | `list_rules` | Return all rules with severity, jurisdiction, and fix guidance |
85
+ | `get_evidence` | Retrieve past check records from the local evidence log |
86
+
87
+ ## Parameters
88
+
89
+ **`check_message` accepts:**
90
+
91
+ | Parameter | Values | Default |
92
+ |-----------|--------|---------|
93
+ | `channel` | `email`, `sms` | `email` |
94
+ | `consent` | `express`, `inferred`, `none`, `unknown` | `unknown` |
95
+ | `sender_identified` | `true`, `false` | `false` |
96
+ | `jurisdiction` | `au`, `us`, `ca`, `eu`, `all` | `all` |
97
+
98
+ **Consent by jurisdiction:**
99
+ - AU / CA / EU: opt-in required — `none` or `unknown` blocks the send
100
+ - US CAN-SPAM: opt-out model — prior consent not required, but opt-outs must be honoured
101
+
102
+ ## Background
103
+
104
+ Email and SMS marketing is regulated everywhere. ACMA (Australia) has issued fines over 7 million AUD for consent failures and 700K AUD for transactional emails containing promotional content. The FTC enforces CAN-SPAM with fines up to 51,744 USD per email. CRTC enforces CASL with penalties up to 10 million CAD per violation.
105
+
106
+ Truvek Comply is a pre-send compliance tool, not legal advice.
107
+
108
+ ## License
109
+
110
+ MIT
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "truvek-comply"
7
+ version = "0.1.0"
8
+ description = "Pre-send compliance checks for email and SMS — Spam Act (AU), CAN-SPAM (US), CASL (CA), GDPR (EU)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Truckling"}
14
+ ]
15
+ keywords = ["mcp", "email", "compliance", "spam-act", "australia", "can-spam", "casl", "gdpr", "marketing", "truvek"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Topic :: Communications :: Email",
21
+ "Topic :: Office/Business",
22
+ ]
23
+ dependencies = [
24
+ "mcp>=2.0.0",
25
+ "uvicorn>=0.30.0",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/Truckling/truvek-comply"
30
+ Repository = "https://github.com/Truckling/truvek-comply"
31
+ Issues = "https://github.com/Truckling/truvek-comply/issues"
32
+
33
+ [project.scripts]
34
+ truvek-comply = "truvek_comply.server:main"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["."]
38
+ include = ["truvek_comply*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,205 @@
1
+ # test_checker.py — Tests for message classification and compliance checking
2
+
3
+ import pytest
4
+ from sendcheck.checker import classify_message, check_message
5
+
6
+
7
+ # ---------------------------------------------------------------------------
8
+ # classify_message tests
9
+ # ---------------------------------------------------------------------------
10
+
11
+ class TestClassifyMessage:
12
+
13
+ def test_marketing_email(self):
14
+ """Body with 'sale' should be classified as marketing."""
15
+ result = classify_message(
16
+ subject="Weekend deals",
17
+ body="Big sale on now! Save up to 50% on all items.",
18
+ )
19
+ assert result["type"] == "marketing"
20
+ assert len(result["reasons"]) > 0
21
+
22
+ def test_transactional_email(self):
23
+ """Body with 'order confirmation' should be classified as transactional."""
24
+ result = classify_message(
25
+ subject="Your order confirmation",
26
+ body="Thank you for your order. Your order confirmation number is 12345.",
27
+ )
28
+ assert result["type"] == "transactional"
29
+
30
+ def test_transactional_with_promotion(self):
31
+ """Body with both 'order' and 'sale' should be transactional_with_promotion."""
32
+ result = classify_message(
33
+ subject="Your order is on the way",
34
+ body="Your order has shipped! Also, check out our flash sale — 30% off everything.",
35
+ )
36
+ assert result["type"] == "transactional_with_promotion"
37
+
38
+ def test_unclear_generic_body(self):
39
+ """A generic message with no signals should be classified as unclear."""
40
+ result = classify_message(
41
+ subject="Hello",
42
+ body="Just checking in. Hope you are well.",
43
+ )
44
+ assert result["type"] == "unclear"
45
+
46
+ def test_sms_channel_accepted(self):
47
+ """channel parameter should be accepted without errors."""
48
+ result = classify_message(
49
+ subject="",
50
+ body="Flash sale on now!",
51
+ channel="sms",
52
+ )
53
+ assert result["type"] == "marketing"
54
+
55
+
56
+ # ---------------------------------------------------------------------------
57
+ # check_message tests
58
+ # ---------------------------------------------------------------------------
59
+
60
+ class TestCheckMessage:
61
+
62
+ def test_block_when_consent_none(self):
63
+ """consent='none' on a commercial message must produce a block verdict."""
64
+ result = check_message(
65
+ subject="Big sale",
66
+ body="Sale on now! Unsubscribe: https://example.com/unsub",
67
+ consent="none",
68
+ sender_identified=True,
69
+ )
70
+ assert result["verdict"] == "block"
71
+ rule_ids = [f["rule_id"] for f in result["findings"]]
72
+ assert "consent_missing" in rule_ids
73
+
74
+ def test_block_when_consent_unknown(self):
75
+ """consent='unknown' (the default) must also block a commercial message."""
76
+ result = check_message(
77
+ subject="Exclusive offer",
78
+ body="Members only deal! Unsubscribe: https://example.com/unsub",
79
+ consent="unknown",
80
+ sender_identified=True,
81
+ )
82
+ assert result["verdict"] == "block"
83
+ rule_ids = [f["rule_id"] for f in result["findings"]]
84
+ assert "consent_missing" in rule_ids
85
+
86
+ def test_block_when_no_unsubscribe(self):
87
+ """Missing unsubscribe link must block even with express consent and sender ID."""
88
+ result = check_message(
89
+ subject="Weekend sale",
90
+ body="Huge discounts available now. Sent by Acme Pty Ltd.",
91
+ consent="express",
92
+ sender_identified=True,
93
+ )
94
+ assert result["verdict"] == "block"
95
+ rule_ids = [f["rule_id"] for f in result["findings"]]
96
+ assert "unsubscribe_missing" in rule_ids
97
+
98
+ def test_block_when_sender_not_identified(self):
99
+ """sender_identified=False must add a sender_missing finding (block)."""
100
+ result = check_message(
101
+ subject="Sale now on",
102
+ body="Big sale! Unsubscribe: https://example.com/unsub",
103
+ consent="express",
104
+ sender_identified=False,
105
+ )
106
+ assert result["verdict"] == "block"
107
+ rule_ids = [f["rule_id"] for f in result["findings"]]
108
+ assert "sender_missing" in rule_ids
109
+
110
+ def test_pass_fully_compliant_marketing_email(self):
111
+ """
112
+ A marketing email with express consent, sender identified, and an
113
+ unsubscribe link should pass.
114
+ """
115
+ result = check_message(
116
+ subject="Your 20% off sale",
117
+ body=(
118
+ "Your 20% off sale is here! "
119
+ "Unsubscribe: https://example.com/unsub. "
120
+ "Sent by Acme Pty Ltd, 123 Main St Sydney."
121
+ ),
122
+ channel="email",
123
+ consent="express",
124
+ sender_identified=True,
125
+ )
126
+ assert result["verdict"] == "pass"
127
+ assert result["findings"] == []
128
+
129
+ def test_review_for_inferred_consent(self):
130
+ """consent='inferred' should produce a review (not block) finding."""
131
+ result = check_message(
132
+ subject="Sale on now",
133
+ body=(
134
+ "Save 20% today! "
135
+ "Unsubscribe: https://example.com/unsub. "
136
+ "Sent by Acme Pty Ltd."
137
+ ),
138
+ consent="inferred",
139
+ sender_identified=True,
140
+ )
141
+ assert result["verdict"] == "review"
142
+ rule_ids = [f["rule_id"] for f in result["findings"]]
143
+ assert "consent_inferred_risk" in rule_ids
144
+
145
+ def test_transactional_with_promotion_triggers_review(self):
146
+ """A transactional message with promotional content must trigger a review finding."""
147
+ result = check_message(
148
+ subject="Your order has shipped",
149
+ body=(
150
+ "Your order has shipped! "
151
+ "Also, our flash sale is on — save 30%! "
152
+ "Unsubscribe: https://example.com/unsub. "
153
+ "Sent by Acme Pty Ltd."
154
+ ),
155
+ consent="express",
156
+ sender_identified=True,
157
+ )
158
+ rule_ids = [f["rule_id"] for f in result["findings"]]
159
+ assert "transactional_with_promotion" in rule_ids
160
+ # Overall verdict must be at least review
161
+ assert result["verdict"] in ("review", "block")
162
+
163
+ def test_transactional_pure_no_unsubscribe_needed(self):
164
+ """
165
+ A pure transactional message with sender identified should not require
166
+ an unsubscribe link (it is not commercial).
167
+ """
168
+ result = check_message(
169
+ subject="Your invoice #9001",
170
+ body="Please find your invoice attached. Contact us at support@acme.com.",
171
+ consent="express",
172
+ sender_identified=True,
173
+ )
174
+ rule_ids = [f["rule_id"] for f in result["findings"]]
175
+ assert "unsubscribe_missing" not in rule_ids
176
+
177
+ def test_sms_always_adds_sender_id_finding(self):
178
+ """SMS channel must always add the sms_sender_id_unregistered finding."""
179
+ result = check_message(
180
+ subject="",
181
+ body="Flash sale! Unsubscribe reply STOP. Sent by Acme.",
182
+ channel="sms",
183
+ consent="express",
184
+ sender_identified=True,
185
+ )
186
+ rule_ids = [f["rule_id"] for f in result["findings"]]
187
+ assert "sms_sender_id_unregistered" in rule_ids
188
+
189
+ def test_findings_contain_required_keys(self):
190
+ """Each finding must contain the expected keys."""
191
+ result = check_message(
192
+ subject="Sale",
193
+ body="Big sale!",
194
+ consent="none",
195
+ sender_identified=False,
196
+ )
197
+ for finding in result["findings"]:
198
+ for key in ("rule_id", "severity", "section", "act", "trigger", "fix"):
199
+ assert key in finding, f"Missing key '{key}' in finding: {finding}"
200
+
201
+ def test_ruleset_version_present(self):
202
+ """Result must include ruleset_version."""
203
+ result = check_message(subject="Hi", body="Hello", consent="express", sender_identified=True)
204
+ assert "ruleset_version" in result
205
+ assert isinstance(result["ruleset_version"], str)
@@ -0,0 +1,141 @@
1
+ # test_evidence.py — Tests for the evidence logging module
2
+
3
+ import json
4
+ import pytest
5
+ from sendcheck.evidence import record_check, get_evidence
6
+ from sendcheck.checker import check_message
7
+
8
+
9
+ # A minimal passing result to use across tests
10
+ def _make_result():
11
+ return check_message(
12
+ subject="Your 20% off sale",
13
+ body=(
14
+ "Your 20% off sale is here! "
15
+ "Unsubscribe: https://example.com/unsub. "
16
+ "Sent by Acme Pty Ltd, 123 Main St Sydney."
17
+ ),
18
+ consent="express",
19
+ sender_identified=True,
20
+ )
21
+
22
+
23
+ class TestRecordCheck:
24
+
25
+ def test_writes_one_line(self, tmp_path, monkeypatch):
26
+ """record_check should write exactly one JSON line to the log file."""
27
+ log_file = tmp_path / "evidence.jsonl"
28
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
29
+
30
+ result = _make_result()
31
+ record_check("Subject", "Body", "test@example.com", result)
32
+
33
+ lines = log_file.read_text(encoding="utf-8").strip().splitlines()
34
+ assert len(lines) == 1
35
+
36
+ def test_line_is_valid_json(self, tmp_path, monkeypatch):
37
+ """The written line must be valid JSON."""
38
+ log_file = tmp_path / "evidence.jsonl"
39
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
40
+
41
+ result = _make_result()
42
+ record_check("Subject", "Body", "test@example.com", result)
43
+
44
+ line = log_file.read_text(encoding="utf-8").strip()
45
+ entry = json.loads(line) # will raise if not valid JSON
46
+ assert isinstance(entry, dict)
47
+
48
+ def test_returns_check_id(self, tmp_path, monkeypatch):
49
+ """record_check should return a non-empty string check_id."""
50
+ log_file = tmp_path / "evidence.jsonl"
51
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
52
+
53
+ result = _make_result()
54
+ check_id = record_check("Subject", "Body", "test@example.com", result)
55
+
56
+ assert isinstance(check_id, str)
57
+ assert len(check_id) > 0
58
+
59
+ def test_original_text_not_in_log(self, tmp_path, monkeypatch):
60
+ """Subject, body, and recipient text must NOT appear in the log — only the hash."""
61
+ log_file = tmp_path / "evidence.jsonl"
62
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
63
+
64
+ subject = "Super secret subject line"
65
+ body = "Super secret body content that should never appear"
66
+ recipient = "private@example.com"
67
+
68
+ result = _make_result()
69
+ record_check(subject, body, recipient, result)
70
+
71
+ raw = log_file.read_text(encoding="utf-8")
72
+ assert subject not in raw
73
+ assert body not in raw
74
+ assert recipient not in raw
75
+ # The hash should be there instead
76
+ assert "content_hash" in raw
77
+
78
+
79
+ class TestGetEvidence:
80
+
81
+ def test_get_by_check_id(self, tmp_path, monkeypatch):
82
+ """get_evidence with a check_id should return only the matching entry."""
83
+ log_file = tmp_path / "evidence.jsonl"
84
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
85
+
86
+ result = _make_result()
87
+ check_id = record_check("Sub1", "Body1", "a@example.com", result)
88
+ record_check("Sub2", "Body2", "b@example.com", result) # second entry
89
+
90
+ entries = get_evidence(check_id=check_id)
91
+ assert len(entries) == 1
92
+ assert entries[0]["check_id"] == check_id
93
+
94
+ def test_get_by_campaign_id(self, tmp_path, monkeypatch):
95
+ """get_evidence with a campaign_id should return all entries for that campaign."""
96
+ log_file = tmp_path / "evidence.jsonl"
97
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
98
+
99
+ result = _make_result()
100
+ record_check("Sub1", "Body1", "a@example.com", result, campaign_id="camp-123")
101
+ record_check("Sub2", "Body2", "b@example.com", result, campaign_id="camp-123")
102
+ record_check("Sub3", "Body3", "c@example.com", result, campaign_id="camp-999")
103
+
104
+ entries = get_evidence(campaign_id="camp-123")
105
+ assert len(entries) == 2
106
+ for e in entries:
107
+ assert e["campaign_id"] == "camp-123"
108
+
109
+ def test_get_all_recent_when_no_filter(self, tmp_path, monkeypatch):
110
+ """get_evidence with no filters should return recent entries up to limit."""
111
+ log_file = tmp_path / "evidence.jsonl"
112
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
113
+
114
+ result = _make_result()
115
+ for i in range(5):
116
+ record_check(f"Subject {i}", f"Body {i}", f"{i}@example.com", result)
117
+
118
+ entries = get_evidence(limit=3)
119
+ assert len(entries) == 3 # limited to 3
120
+
121
+ def test_returns_empty_list_for_missing_log(self, tmp_path, monkeypatch):
122
+ """get_evidence should return an empty list if the log file does not exist yet."""
123
+ log_file = tmp_path / "nonexistent.jsonl"
124
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
125
+
126
+ entries = get_evidence()
127
+ assert entries == []
128
+
129
+ def test_entry_has_expected_keys(self, tmp_path, monkeypatch):
130
+ """Each log entry should contain the required fields."""
131
+ log_file = tmp_path / "evidence.jsonl"
132
+ monkeypatch.setenv("SENDCHECK_LOG", str(log_file))
133
+
134
+ result = _make_result()
135
+ check_id = record_check("Sub", "Body", "x@example.com", result)
136
+
137
+ entries = get_evidence(check_id=check_id)
138
+ assert len(entries) == 1
139
+ entry = entries[0]
140
+ for key in ("check_id", "ts", "content_hash", "verdict", "rule_ids", "ruleset_version"):
141
+ assert key in entry, f"Missing key '{key}' in log entry"
File without changes