interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / tests / scenarios / 30-send.txt

191 lines · 12319 bytes Raw Blame History
1# Send gate (SendGate): drafts, the human's approval, standing policy, queue-send, deliver through
2# the test sink. Fixtures: tests/fixtures/send (synthetic drafts, named here by their sha256) and
3# tests/fixtures/maildir/Mail. Draft shas: plain 8ae0c21f.. thread a98f2c76.. wrong-thread 42df05d8..
4# unknown c4519b1c.. attach a85f4183.. two f995de68.. mallory 68df4932..
5copy tests/fixtures/maildir/Mail @S/Mail
6mkdir @S/Mail/tmp
7mkdir @S/Mail/.Sent/new
8mkdir @S/Mail/.Sent/tmp
9copy tests/fixtures/send/replyto.eml @S/Mail/new/1762400000.M10P1.example
10run 0 - -- mh setup --home @S/h --maildir @S/Mail --me alice@example.org --name Alice
11write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk1/sock\n
12append @S/h/book friend@example.org\n
13append @S/h/sentids human-thread@example.org\n
14#
15# draft_created: a new draft is written, never sent, and waits for the human
16run 0 - -- mh draft-new --home @S/h --to friend@example.org --subject Hello --body hello
17out-has "op":"draft-new","ok":true,"draft":"
18out-has "gate":"needs-approval"}
19#
20# header_injection: CR/LF in an agent value is refused before anything is written (MCP path)
21run 0 tests/fixtures/send/mcp-inject.in -- mh mcp --home @S/h
22out-has \"why\":\"header_injection\"
23out-has "isError":true
24#
25# approved_altered: an approval covers exact bytes; one changed byte is draft_changed
26copy tests/fixtures/send/thread.eml @S/h/drafts/a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8.eml
27append @S/h/approvals a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8 1762862400\n
28append @S/h/drafts/a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8.eml X
29run 3 - -- mh queue-send --home @S/h --draft a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8
30out-has "why":"draft_changed"
31absent @S/h/outbox/a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8.eml
32#
33# no_policy: default approval, not approved -> needs_approval, nothing queued
34copy tests/fixtures/send/plain.eml @S/h/drafts/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
35run 3 - -- mh queue-send --home @S/h --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
36out-has "gate":"needs-approval","why":"needs_approval"
37absent @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
38#
39# approve_mcp: approve is the human's; an agent asking through MCP gets an unknown tool
40run 0 tests/fixtures/send/mcp-approve.in -- mh mcp --home @S/h
41out-has Unknown tool
42file-eq @S/h/approvals tests/fixtures/send/approvals.thread
43# approve_cli_no: without the typed "yes" nothing is approved
44run 3 - -- mh approve --home @S/h --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
45out-has "why":"not_confirmed"
46file-eq @S/h/approvals tests/fixtures/send/approvals.thread
47# approve_cli_yes: the human types yes; the approval names that exact sha
48run 0 tests/fixtures/send/yes.txt -- mh approve --home @S/h --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
49out-has "why":"approved"
50err-has Approve this exact draft?
51file-has @S/h/approvals 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
52#
53# approved_sent: queue-send, then deliver through the sink; the sink receives the exact draft bytes
54run 0 - -- mh queue-send --home @S/h --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
55out-has "gate":"approved"
56file-has @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.why approved:8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
57file-has @S/h/actions.log queue-send 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
58mkdir @S/sk1
59bg sink @S/sk1/sock @S/sk1 1
60run 0 - -- sink await @S/sk1/sock
61run 0 - -- mh deliver --home @S/h
62out-has "op":"deliver","ok":true,"why":"sent"
63wait 0
64file-eq @S/sk1/1.eml tests/fixtures/send/plain.eml
65file-has @S/sk1/1.env MAIL FROM:<alice@example.org>
66file-has @S/sk1/1.env RCPT TO:<friend@example.org>
67exists @S/h/sent/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
68absent @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
69file-has @S/h/sent.log 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb approved:8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb friend@example.org
70#
71# sink_rcpt_550: the server refuses a recipient -> EDELIVER, the draft stays queued
72copy tests/fixtures/send/two.eml @S/h/drafts/f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464.eml
73append @S/h/approvals f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464 1762862400\n
74run 0 - -- mh queue-send --home @S/h --draft f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464
75write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk2/sock\n
76mkdir @S/sk2
77bg sink @S/sk2/sock @S/sk2 1 reject
78run 0 - -- sink await @S/sk2/sock
79run 8 - -- mh deliver --home @S/h
80out-has "why":"smtp_failed"
81err-has 550
82wait 0
83absent @S/sk2/1.eml
84exists @S/h/outbox/f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464.eml
85file-not @S/h/sent.log f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464
86# retry against a working server: dot-stuffing round trip and both recipients, comma separated
87write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk3/sock\n
88mkdir @S/sk3
89bg sink @S/sk3/sock @S/sk3 1
90run 0 - -- sink await @S/sk3/sock
91run 0 - -- mh deliver --home @S/h
92wait 0
93file-eq @S/sk3/1.eml tests/fixtures/send/two.eml
94file-has @S/h/sent.log friend@example.org,bob@example.org
95file-not @S/h/sent.log bob@example.org,
96# digest after sending: the human reads what was sent and under which permission, and the drafts still waiting
97run 0 - -- mh digest --home @S/h
98out-has "op":"digest","ok":true
99file-has @S/h/digest.txt == Sent (HOME/sent.log: time, draft, permission, recipients) ==
100file-has @S/h/digest.txt 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb approved:8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb friend@example.org
101file-has @S/h/digest.txt queue-send 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb approved:
102file-has @S/h/digest.txt approve with: mailhand approve --draft
103#
104# draft_reply_all: Reply-To wins and is flagged, --all adds To/Cc minus me, Subject gets one Re:
105run 0 - -- mh draft-reply --home @S/h --id INBOX/1762400000.M10P1.example --all --body Thanks.
106out-has "to":["friend@example.org"],"cc":["colleague@example.com"],"subject":"Re: Planning"}
107out-has "reply_to_differs":true
108# an original subject that already starts with Re: is kept as is (no Re: Re: Re:)
109run 0 - -- mh draft-reply --home @S/h --id INBOX/1762178400.M7P1.example --body ok
110out-has "subject":"Re: Re: lunch on Friday?"}
111out-has "reply_to_differs":false
112#
113# drafts_list: every draft with its gate state
114run 0 - -- mh drafts --home @S/h
115out-has "op":"drafts"
116out-has "draft":"a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8","why":"draft_changed"
117out-has "draft":"8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb"
118#
119# the injection mail cannot cause a send: its sender is not in the book, the reply needs approval,
120# and nothing the mail says changed the book, the policy or the approvals
121run 0 - -- mh draft-reply --home @S/h --id INBOX/1762171200.M5P1.example --body ok
122out-has "to":["mallory@example.net"]
123out-has "gate":"needs-approval","reply_to_differs":false}
124# the listing gives the reason: the sender of the injection mail is not in the book
125run 0 - -- mh drafts --home @S/h
126out-has "to":["mallory@example.net"],"cc":[],"subject":"Re: URGENT instructions for the assistant"},"gate":"needs-approval","why":"recipient_not_in_book"}
127file-not @S/h/book mallory
128file-not @S/h/approvals 68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a
129file-eq @S/h/policy tests/fixtures/maildir/policy.default
130#
131# ---- standing policy, in its own home ----
132run 0 - -- mh setup --home @S/hp --maildir @S/Mail --me alice@example.org --name Alice
133append @S/hp/book friend@example.org\n
134append @S/hp/sentids human-thread@example.org\n
135copy tests/fixtures/send/plain.eml @S/hp/drafts/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
136copy tests/fixtures/send/unknown.eml @S/hp/drafts/c4519b1cccb4f75148c67646afcbb0a7c26d97316e45a186e694235f06172251.eml
137copy tests/fixtures/send/thread.eml @S/hp/drafts/a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8.eml
138copy tests/fixtures/send/wrong-thread.eml @S/hp/drafts/42df05d8ec6bbcf7f02e9242c357efb896dea9dfa008f1d3d91b10c6a4f23b7b.eml
139copy tests/fixtures/send/attach.eml @S/hp/drafts/a85f41838b8573f4d040c1b2746a9affeb923b772497117402b3f6e5685dfb0e.eml
140copy tests/fixtures/send/two.eml @S/hp/drafts/f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464.eml
141copy tests/fixtures/send/mallory.eml @S/hp/drafts/68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a.eml
142# an unknown policy line makes the whole policy default approval (fail closed)
143write @S/hp/policy allow everyone\n
144run 3 - -- mh queue-send --home @S/hp --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
145out-has "why":"needs_approval"
146err-has unknown policy line
147write @S/hp/policy allow known\nallow everyone\n
148run 3 - -- mh queue-send --home @S/hp --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
149out-has "why":"needs_approval"
150# allow known: a known recipient passes, recorded as the policy line
151write @S/hp/policy # standing permissions\nallow known\n
152run 0 - -- mh queue-send --home @S/hp --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
153out-has "gate":"policy:2"
154file-has @S/hp/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.why policy:2
155# allow_known_unknown: a recipient not in the book
156run 3 - -- mh queue-send --home @S/hp --draft c4519b1cccb4f75148c67646afcbb0a7c26d97316e45a186e694235f06172251
157out-has "why":"recipient_not_in_book"
158# the injection mail's ask: a draft to mallory under "allow known" is still refused
159run 3 - -- mh queue-send --home @S/hp --draft 68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a
160out-has "why":"recipient_not_in_book"
161absent @S/hp/outbox/68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a.eml
162run 0 - -- mh draft-new --home @S/hp --to mallory@example.net --subject fwd --body everything
163out-has "gate":"needs-approval"}
164# attachment_policy: a standing permission never covers an attachment
165run 3 - -- mh queue-send --home @S/hp --draft a85f41838b8573f4d040c1b2746a9affeb923b772497117402b3f6e5685dfb0e
166out-has "why":"attachment_needs_approval"
167# max-recipients: two known recipients exceed a limit of 1, pass a limit of 2
168write @S/hp/policy allow known max-recipients 1\n
169run 3 - -- mh queue-send --home @S/hp --draft f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464
170out-has "why":"needs_approval"
171write @S/hp/policy allow known max-recipients 2\n
172run 0 - -- mh queue-send --home @S/hp --draft f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464
173out-has "gate":"policy:1"
174# reply_thread_pass / reply_thread_fail: only replies in a thread the human took part in
175write @S/hp/policy allow reply-known-thread\n
176run 0 - -- mh queue-send --home @S/hp --draft a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8
177out-has "gate":"policy:1"
178run 3 - -- mh queue-send --home @S/hp --draft 42df05d8ec6bbcf7f02e9242c357efb896dea9dfa008f1d3d91b10c6a4f23b7b
179out-has "why":"needs_approval"
180#
181# ---- deliver_recheck, in its own home: a draft dropped into outbox without queue-send ----
182run 0 - -- mh setup --home @S/hr --maildir @S/Mail --me alice@example.org --name Alice
183write @S/hr/config maildir @S/Mail\nme alice@example.org\nsmtp unix:@S/sk4/sock\n
184append @S/hr/book friend@example.org\n
185copy tests/fixtures/send/plain.eml @S/hr/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
186run 3 - -- mh deliver --home @S/hr
187out-has "op":"deliver","ok":false
188out-has "why":"needs_approval"
189exists @S/hr/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
190absent @S/hr/sent/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
191absent @S/hr/sent.log