{ "description": "Scripted flows (CONTRACT.md section 7). Each runs against a fresh email side with the callback stub and, for 'slave', a stub outside master that assigns EXT-100, EXT-101, ... The statute is statute.json. Placeholders: {case_id}, {message_ref}, {handoff_id} come from the latest response that carried them; {callback} is the stub's handoff URL. Peers: email, callback-1 (the stub), cms-1 (the stub master); every request is signed (CONTRACT.md section 7). Master role config: ticket, modes {callback}, fields phone/time, timeout 3600 s. Slave role config: case, defaults autonomous_send false, transfers block, overridden by 'config'.", "flows": [ { "id": "m-001", "role": "master", "title": "callback completes", "scenario": "completed", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" }, "expect": { "response_status": "created" } }, { "mode": "run", "expect": { "statuses": [ "scheduled", "running", "completed" ], "last_mail_contains": "has taken place" } } ] }, { "id": "m-002", "role": "master", "title": "negotiation over email", "scenario": "negotiate", "steps": [ { "mail": { "to": "ticket!callback", "text": "Please call me." }, "expect": { "response_status": "created" } }, { "mode": "run", "expect": { "statuses": [ "negotiating" ], "last_mail_contains": "Phone: ..." } }, { "mail": { "to": "ticket={case_id}", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" }, "expect": { "response_status": "correlated" } }, { "mode": "run", "expect": { "statuses": [ "negotiating", "scheduled", "running", "completed" ], "last_mail_contains": "has taken place" } } ] }, { "id": "m-003", "role": "master", "title": "no answer, retried, completed", "scenario": "no-answer-retry", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "mode": "run", "expect": { "statuses": [ "scheduled", "attempted", "scheduled", "running", "completed" ] } } ] }, { "id": "m-004", "role": "master", "title": "no answer twice, failed", "scenario": "no-answer-fail", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "mode": "run", "expect": { "statuses": [ "scheduled", "attempted", "scheduled", "attempted", "failed" ], "last_mail_contains": "did not succeed" } } ] }, { "id": "m-005", "role": "master", "title": "refused out of hours", "scenario": "out-of-hours", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "mode": "run", "expect": { "statuses": [ "refused" ], "last_mail_contains": "out-of-hours" } } ] }, { "id": "m-006", "role": "master", "title": "email owns the timeout", "scenario": "silent", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "mode": "run", "expect": { "statuses": [] } }, { "advance": 3599, "expect": { "timed_out": 0 } }, { "advance": 2, "expect": { "timed_out": 1, "mode_received_last": "handoff.cancel", "last_mail_contains": "could not arrange" } } ] }, { "id": "m-007", "role": "master", "title": "mode not enabled by the statute", "scenario": "completed", "steps": [ { "mail": { "to": "ticket!chat", "text": "hi" }, "expect": { "response_status": "created", "mode_received": 0, "outbox_count": 1 } } ] }, { "id": "m-008", "role": "master", "title": "unauthenticated sender gets no mail", "scenario": "negotiate", "steps": [ { "mail": { "to": "ticket!callback", "text": "call me", "dmarc": "fail" }, "expect": { "response_status": "created" } }, { "mode": "run", "expect": { "statuses": [ "negotiating" ], "outbox_count": 0 } } ] }, { "id": "s-001", "role": "slave", "title": "master issues the id; email sends only on instruction", "steps": [ { "mail": { "to": "case", "text": "My order is late" }, "expect": { "response_status": "intake-reported", "master_received": { "case.intake": 1 }, "outbox_count": 0 } }, { "pump": true, "expect": { "case_address": "case=EXT-100@modes.example" } }, { "mail": { "to": "case={case_id}", "text": "more" }, "expect": { "response_status": "reported", "master_received": { "case.message": 1 }, "outbox_count": 0 } }, { "master": { "command": "send", "in_reply_to": "{message_ref}", "body": "We are on it." }, "expect": { "command_ok": true, "outbox_count": 1 } } ] }, { "id": "s-002", "role": "slave", "title": "principle 10 refuses a master send", "steps": [ { "mail": { "to": "case", "text": "hi", "dmarc": "fail" } }, { "pump": true }, { "master": { "command": "send", "in_reply_to": "{message_ref}", "body": "x" }, "expect": { "command_ok": false, "command_reason": "unauthenticated-sender", "outbox_count": 0 } } ] }, { "id": "s-003", "role": "slave", "title": "transfer blocked", "steps": [ { "mail": { "to": "case!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "pump": true, "expect": { "master_received": { "handoff.requested": 1, "handoff.status": 1 }, "mode_received": 0 } } ] }, { "id": "s-004", "role": "slave", "title": "transfer to the primed webhook; statuses relayed", "config": { "transfers": { "webhook": "{callback}", "peer": "callback-1" } }, "scenario": "completed", "steps": [ { "mail": { "to": "case!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "pump": true, "expect": { "mode_received": 1 } }, { "mode": "run", "expect": { "relayed": [ "scheduled", "running", "completed" ], "outbox_count": 0 } }, { "advance": 1000000, "expect": { "timed_out": 0 } } ] }, { "id": "s-005", "role": "slave", "title": "the master owns the timeout", "config": { "transfers": { "webhook": "{callback}", "peer": "callback-1" } }, "scenario": "silent", "steps": [ { "mail": { "to": "case!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" } }, { "pump": true }, { "mode": "run", "expect": { "relayed": [] } }, { "master": { "command": "cancel", "handoff_id": "{handoff_id}" }, "expect": { "command_ok": true, "mode_received_last": "handoff.cancel" } }, { "mode": "run", "expect": { "relayed": [ "cancelled" ] } } ] }, { "id": "a-001", "role": "slave", "title": "unsigned master command refused", "steps": [ { "mail": { "to": "case", "text": "hi" } }, { "pump": true }, { "inject": { "endpoint": "master", "sign": "none", "message": { "type": "mail.send", "case": "current", "in_reply_to": "{message_ref}", "body": "hello" } }, "expect": { "http_status": 401, "error": "unauthenticated-peer", "outbox_count": 0 } } ] }, { "id": "a-002", "role": "slave", "title": "a mode cannot assign case ids", "steps": [ { "mail": { "to": "case", "text": "hi" }, "expect": { "response_status": "intake-reported" } }, { "inject": { "endpoint": "master", "as": "callback-1", "message": { "type": "case.assign", "intake_ref": "{intake_ref}", "resource_id": "EVIL-1" } }, "expect": { "http_status": 403, "error": "wrong-peer" } }, { "pump": true, "expect": { "case_address": "case=EXT-100@modes.example" } } ] }, { "id": "a-003", "role": "slave", "title": "webhook to a peer email has no key for", "steps": [ { "mail": { "to": "case", "text": "hi" } }, { "pump": true }, { "inject": { "endpoint": "master", "as": "cms-1", "message": { "type": "case.policy", "case": "current", "transfers": { "webhook": "http://attacker.example/h", "peer": "mallory" } } }, "expect": { "http_status": 400, "error": "unknown-peer" } } ] }, { "id": "a-004", "role": "slave", "title": "replayed master command", "steps": [ { "mail": { "to": "case", "text": "hi" } }, { "pump": true }, { "inject": { "endpoint": "master", "as": "cms-1", "sign": "stale", "message": { "type": "mail.send", "case": "current", "in_reply_to": "{message_ref}", "body": "hello" } }, "expect": { "http_status": 401, "error": "replayed", "outbox_count": 0 } } ] }, { "id": "a-005", "role": "slave", "title": "master command signed with the wrong key", "steps": [ { "mail": { "to": "case", "text": "hi" } }, { "pump": true }, { "inject": { "endpoint": "master", "as": "cms-1", "sign": "wrong-key", "message": { "type": "mail.send", "case": "current", "in_reply_to": "{message_ref}", "body": "hello" } }, "expect": { "http_status": 401, "error": "unauthenticated-peer", "outbox_count": 0 } }, { "inject": { "endpoint": "master", "as": "cms-1", "message": { "type": "mail.send", "case": "current", "in_reply_to": "{message_ref}", "body": "hello" } }, "expect": { "http_status": 200, "outbox_count": 1 } } ] }, { "id": "a-006", "role": "master", "title": "statuses only from the handoff's peer, at its URL", "scenario": "silent", "steps": [ { "mail": { "to": "ticket!callback", "text": "Phone: +49 30 1234567\nTime: tomorrow 10:00" }, "expect": { "outbox_count": 1 } }, { "inject": { "endpoint": "status", "as": "cms-1", "message": { "type": "handoff.status", "case": "current", "seq": 1, "status": "completed" } }, "expect": { "http_status": 403, "error": "wrong-peer" } }, { "inject": { "endpoint": "status", "as": "callback-1", "token": "bogus", "message": { "type": "handoff.status", "case": "current", "seq": 1, "status": "completed" } }, "expect": { "http_status": 404, "error": "unknown-handoff", "outbox_count": 1 } }, { "inject": { "endpoint": "status", "as": "callback-1", "message": { "type": "handoff.status", "case": "current", "seq": 1, "status": "scheduled", "at": "x" } }, "expect": { "http_status": 200 } } ] }, { "id": "a-007", "role": "master", "title": "only the gateway posts events", "steps": [ { "inject": { "endpoint": "events", "as": "callback-1", "message": { "type": "x" } }, "expect": { "http_status": 403, "error": "wrong-peer" } } ] } ] }