Mail relay: state block without an import-map entry, e2e on the reference site, sharper failure reports

- the state block is rendered by IntegrationStatusBanner (no new admin component: generate:importmap gives no diff)
- reference site: e2e/mail-relay.spec.ts with a fixture and setup script; e2e:built runs it with both bundlers
- a failed enrolment is reported as what it was; the service's own refusal after a fresh enrolment
- a message keeps its key after any failure that is not final
- a local site is shown as refused in the panel before any e-mail

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 21:14:47 +01:00
co-authored by Claude Fable 5.2
parent dd3792cbc7
commit 2cceceffd0
29 changed files with 1461 additions and 65 deletions
+11 -5
View File
@@ -48,9 +48,11 @@ type SendBody = { id?: string; messageId?: string; replayed?: boolean; senderNam
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
/**
* Messages whose outcome the service never confirmed, by the hash of their bytes: sent again within
* 24 hours they go out under the SAME key, so the service answers with what happened to the first
* attempt instead of sending a second mail. Per process; a message of a new content always gets a new key.
* Messages the service gave no final answer for (no answer at all, a retryable failure, an error page
* of the network in front), by the hash of their bytes: sent again within 24 hours they go out under
* the SAME key, so the service answers with what happened to the first attempt instead of sending a
* second mail. Per process (there is no stored outbox): after a restart, or from another instance of
* the site, the same message gets a new key. A message of a new content always gets a new key.
*/
const unconfirmed = new Map<string, { at: number; key: string }>()
const DAY = 24 * 60 * 60_000
@@ -180,6 +182,8 @@ export async function sendThroughRelay(payload: BasePayload, options: ResolvedRe
use,
)
if (answer.ok || !answer.retryable || attempts >= RELAY_DEFAULTS.attempts) {break}
// The site could not enrol: the message was never handed over, and asking again would not change that.
if (use.enrolment && !use.enrolment.ok) {break}
const wait = answer.retryAfter !== undefined ? answer.retryAfter * 1000 : attempts * (options.retryBackoffMs ?? 1000)
// The ten seconds win over retryAfter: stop at once and report.
if (waited + wait > budget) {break}
@@ -228,8 +232,10 @@ export async function sendThroughRelay(payload: BasePayload, options: ResolvedRe
}
const result = describeRefusal(answer)
// Not confirmed, or failed in a way the back end does not explain: the same key if this message is tried again.
if (!result.confirmed || result.detail.startsWith('Probably not sent')) {unconfirmed.set(hash, { at: Date.now(), key: idempotencyKey })}
// Whenever the service did not give a final "no" (no answer, a failure it calls retryable, an answer that was
// not its own): the same key if this message is tried again. Reusing a key is always safe — the service either
// answers with what happened to the first attempt or sends the message now; a new key could send it twice.
if (answer.noAnswer || answer.retryable) {unconfirmed.set(hash, { at: Date.now(), key: idempotencyKey })}
else {unconfirmed.delete(hash)}
if (answer.code === 'site-pending' || answer.code === 'site-suspended') {
const state = answer.code === 'site-pending' ? 'pending' : 'suspended'