Skip to content

#1113: opt-in live tests against a real mail server in Docker - #1142

Closed
nextxch wants to merge 5 commits into
UCSLabs:mainfrom
nextxch:pr/1113-live-tests
Closed

nextxch wants to merge 5 commits into
UCSLabs:mainfrom
nextxch:pr/1113-live-tests

Conversation

@nextxch

@nextxch nextxch commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

A proposal for #1113, in the shape the issue calls 2 (in the repository, server-neutral, with a default image) and without a workflow. It builds on #1015 (the desktop app reads JMAP accounts), #1123 (#1068, contacts come down) and #1124 (#1072, calendars and events are shown), none of which is on main yet: the branch is main with #1015 merged in, the commits of those two, and the one commit of this pull request on top. It is a draft until those are on main and until you have said which shape you want, if any; a no, or another shape, is as good an answer, and I will change or close it accordingly.

Closes #1113.

What it is

cargo xtask live runs the desktop app's JMAP code against a real mail server in a throwaway Docker container on the computer of whoever asks for it, and removes everything afterwards. It is opt-in: for somebody who changes that code and wants to see it work against a server before proposing the change. Nobody has to run it and nothing depends on it.

Why

The unit tests script the server (scripted exchanges, the stand-in). That proves the client does what we think the protocol asks. It cannot show whether a server answers that way, because the script and the client were written by the same people.

The live run has already found one such case: a server that answers Email/set destroy for an id it does not know with neither destroyed nor notDestroyed. A client that keeps to RFC 8620 then has no answer and asks again at every run, for ever. The client now looks such ids up once (#1110); no scripted test would have found it.

What it starts and removes

  • A Docker network of its own (mailcraft-live).
  • A mail catcher (mailcraft-live-catcher, axllent/mailpit, MIT), which is the server's smart host, so that mail the server sends goes to the catcher and nowhere else. Its web page is on 127.0.0.1:58125.
  • The server (mailcraft-live-jmap) on 127.0.0.1:58180, which on first start makes one mailbox, ada@example.org, with a password made up for the run.
  • Then cargo test --locked -p mailcraft --bin mailcraft live_ -- --ignored --test-threads=1, with the server's address, the mailbox's address and the password in the environment of that one process.
  • Afterwards both containers and the network are removed, whatever came of the tests (--keep leaves them for a look; the next run removes them first).

What it never does

  • Nothing of it runs in cargo test or in cargo xtask ci: every test is #[ignore]d. There is no workflow, and CI never pulls either image.
  • Nothing is added to the build or to Cargo.lock: the harness is on the standard library alone, and the tests use what the desktop app has already (Cargo.lock and every Cargo.toml are unchanged).
  • Both ports are published on loopback only.
  • No test touches a real mailbox. The tests refuse a server that is not on this computer (localhost, 127.0.0.1, ::1) before a byte is sent, since they write to the mailbox they are given. Without the harness's environment a test fails and says so, rather than pass having tested nothing.
  • The run's password is never printed: not by the harness, not in what Docker said when a start failed, not by a test.

The tests in it now, and the ones that follow

Each test puts something into the test mailbox the way another client would (a JMAP set call) and reads it back through the functions the window's jobs run (jmap_runner::run_*_with). Three are here, for what this base can do:

A server has to offer mail. Where its session names no account for contacts or for calendars, that test prints live: skipped, ... and ends there (the test run then counts it as passed; the doc says to read the lines).

The others that the issue lists exist on my fork and each comes with the pull request of its feature, since the code it calls is not on this base: sending through the catcher (#1074), contacts made, changed and deleted (#1076), events made, changed and deleted, series, to-dos and notes over CalDAV (#1090, #1073, #1100), Add Account's sign-in check and the Autoconfig document. The one for marks going up and the lookup of unknown ids exists there too: its code is on main now (#1110), and the test is not part of this pull request. The catcher is started already, as the server's only smart host, although no test here sends mail yet.

Another server

The image, its start recipe (the container's environment, with {email}, {password} and {catcher} filled in by the harness), the port it speaks HTTP on, and the loopback ports come from the environment: MAILCRAFT_LIVE_IMAGE, MAILCRAFT_LIVE_ENV, MAILCRAFT_LIVE_SERVER_PORT, MAILCRAFT_LIVE_PORT, MAILCRAFT_LIVE_CATCHER_IMAGE, MAILCRAFT_LIVE_CATCHER_PORT. docs/live-tests.md says what an image has to offer: one mailbox made on first start from environment variables, HTTP on one port with the JMAP session at /.well-known/jmap, and an outbound smart host. If you would like it to pass against an open-source JMAP server of your choice, name it and I will add its recipe; if you would rather have no default image in the tree (shape 1), that is DEFAULT_IMAGE and DEFAULT_RECIPE in xtask/src/live.rs taken out and one paragraph of the doc.

What you should know about the default image

The image a run starts when none is named is nextxch/server from Docker Hub. It is the mail server I work on. It is commercial software under its own licence, free to pull and to run for a few mailboxes, and not open source. It is the default because it offers JMAP for mail, contacts and calendars on one origin and because I can fix it when a test finds a fault on its side. Nothing of it is in the repository or in a build; Docker pulls it on the computer of whoever runs cargo xtask live, and nothing else does. The one place in the code that names it (DEFAULT_IMAGE) says what it is, and so does docs/live-tests.md. Naming a commercial image in the repository is your call, which is why this is a proposal.

What goes where

  • xtask/src/live.rs (new) and four lines of xtask/src/main.rs (the module, the usage text, the command).
  • apps/mailcraft/src/live_tests.rs (new), brought in by #[cfg(test)] mod live_tests; in main.rs. No other code changes.
  • docs/live-tests.md (new), one sentence each in CONTRIBUTING.md (beside "Tests never touch a real mailbox") and in docs/jmap.md (Trying it), each with its revision-history fragment under docs/log.d/. No release note: nothing changes for a person using MailCraft.

How it was checked

  • cargo xtask live on Windows with Docker Desktop: 3 passed; 0 failed; 0 ignored against the default image nextxch/server:1.3.3, and the same again against the image as Docker Hub has it under that tag (named by its digest through MAILCRAFT_LIVE_IMAGE, with the recipe given through MAILCRAFT_LIVE_ENV and another inner port through MAILCRAFT_LIVE_SERVER_PORT, which is the path another server takes). After each run no container and no network of the harness was left. A recipe entry that is not NAME=value and an image that cannot be pulled each end with an error and leave nothing behind.
  • cargo xtask ci: all 12 steps pass (fmt, test, assets, spdx, test-files, workflows, layers, wasm, deny, i18n, release-notes, docs-log; cargo-deny is not installed here and its step says skipped), and cargo clippy --locked --workspace --all-targets --exclude mailcraft -- -D warnings and cargo clippy --locked -p mailcraft --bin mailcraft -- -D warnings beside it. 7,564 tests pass, 0 fail, 24 ignored; the three live tests are among the ignored (ignored, needs a mail server on this computer: cargo xtask live), so ci runs none of them.
  • Cargo.lock and every Cargo.toml are the same as on #1072: a JMAP account's calendars and events are shown #1124's branch.

What a reviewer should look at first

  1. docs/live-tests.md: "What it never does" and "The default image". They are the promises, and the disclosure.
  2. xtask/src/live.rs: run and start_all (what is started, that both ports are published on 127.0.0.1 only, that remove runs on every way out) and start (the password is taken out of what Docker said before it is shown); DEFAULT_IMAGE and DEFAULT_RECIPE.
  3. apps/mailcraft/src/live_tests.rs: Live::get (the refusal of a server that is not on this computer, before anything is sent) and Live::offers (the skip).
  4. CONTRIBUTING.md: the sentence added to "Tests never touch a real mailbox". Say if you would rather word it yourselves or not have it there.
  • cargo xtask ci passes
  • "Allow edits by maintainers" is ticked (the box beside Create pull request)
  • I have signed the CLA, or will by commenting on this pull request

Human-reviewed, AI-assisted, nobody's mailbox harmed.

The desktop app gets the host the browser build has for a JMAP account:
apps/mailcraft/src/jmap_runner.rs runs mailcraft-jmap's Send/Receive and
its whole-message fetch over mailcraft_net::https, each job on a thread of
its own, the pieces streamed to the window. main.rs sets Services::jmap and
Services::jmap_fetch; the window already takes JMAP accounts into
Send/Receive once its host runs them.

- mailcraft-net: an answer's Content-Type is kept (a JMAP answer must be
  JSON; one too long to be a media type is none); https::send_with gives an
  exchange a time limit of the caller's (at most 10 min); is_too_slow and
  is_too_long are public.
- Each request kind has its own time limit (session 30 s, API 2 min,
  download 5 min). Stop is heard before each request and latched per job; a
  job never sets the window's shared flag. A Retry-After date is handed to
  the client as seconds, and ignored while the clock is plainly not set.
- The credential stays in memory: the read of the credential store leaves
  JMAP accounts out, so a password kept under an install's old name is no
  longer moved to a JMAP account with that address (it was written to the
  store, though never used to send).
- docs/jmap.md, the architecture table, README, gap 5, M6's row; fragments
  for the logs and the release notes.

Tests: jmap_runner_tests.rs runs the real transport over loopback sockets
against the JMAP stand-in (a whole run, Basic and Bearer, refusals, no
secret and Stop sending nothing, an unreachable server, plain http refused,
messages fetched whole, time limits, the stop latch, Retry-After); a net
test for Content-Type; the_old_name_never_moves_to_a_jmap_account fails
without its fix. cargo xtask ci passes (all 13 steps, deny included).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

… until it is on main

README.md: both sides changed the Servers and Files lines. Kept main's
lines (nothing is sent yet; a .pst file's calendar, tasks, notes and
journal come in) and UCSLabs#1015's word that JMAP is on the desktop too.

ROADMAP.md: both sides changed the M6 row. Kept main's row (the marks,
moves and deletions go up, UCSLabs#1074 part 1) and UCSLabs#1015's word that JMAP
reads mail in the desktop app too.

docs/architecture.md, docs/gaps.md, docs/jmap.md: both sides changed the
sentences that say where a JMAP account is read. Kept main's word that
what is changed in its mail goes up and UCSLabs#1015's that the desktop app is
a host too; the desktop app runs the same `sync_mail`, so the changes go
up from there as well.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Comment thread xtask/src/live.rs Fixed
Builds on UCSLabs#1015, the desktop app's JMAP runner. Read only: nothing of
a contact goes up (that is UCSLabs#1076).

- mailcraft-jmap: sync_contacts reads the account's contacts (JMAP for
  Contacts, RFC 9610; cards in JSContact, RFC 9553) where the server
  offers them: ContactCard/query a page at a time, ContactCard/get 200
  to a request, a call that fails halved until the card that breaks it
  is found, 20,000 contacts at the most, every map, list and text of a
  card bounded. A card's picture is not read, and nothing in a card is
  fetched. reader.rs holds what the readers of one kind of data share:
  whose data is read, a request of one call, and the reading itself
  (Calls::read_all: the list page by page, the get in chunks and its
  halving), with tests of its own; contacts.rs says what is asked for
  contacts and what a card becomes.
- mailcraft-model: JmapContactsRequest and JmapContactsResult; a JMAP
  account keeps contacts.
- mailcraft-engine: a JMAP account's download is merged as a Microsoft
  account's is (a test; no change to the code).
- mailcraft-ui-egui: the contacts are a job of their own, after the
  account's Send/Receive and every quarter of an hour, one at a time,
  with the credential the Send/Receive went with. jmap_side_job.rs
  holds what such a job is whatever it reads (when one is due, the wait
  after one that came to nothing, whose an answer is); jmap_contacts.rs
  what is asked for contacts and how they are taken in.
- mailcraft (desktop): run_contacts on top of UCSLabs#1015's runner, through
  on_thread and signed_in, which any such job goes through.
- PRIVACY.md, README.md, ROADMAP.md, docs/jmap.md, docs/gaps.md,
  docs/architecture.md with their fragments, and the release note.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Builds on UCSLabs#1015 and on UCSLabs#1068. Read only: nothing of a calendar or an
event goes up, and a repeating event comes as its occurrences in the
stretch; the series as one repeating event, and writing, are UCSLabs#1090.

- mailcraft-jmap: sync_calendar reads the calendars the account
  subscribes to and may read (JMAP for Calendars; events in
  JSCalendar, RFC 8984) where the server offers them, and for each the
  events of the stretch: CalendarEvent/query a page at a time with what
  repeats expanded by the server, CalendarEvent/get 200 to a request
  for the properties that are read and no others, a call that fails
  halved until the event that breaks it is found, every map, list and
  text of an event bounded. The list and the halving are reader.rs's,
  as for the contacts (Calls::read_all); it learns of an object that
  can not be read (an event whose time can not be told), which counts
  as not answered for.
- mailcraft-model: JmapCalendarRequest and JmapCalendarResult.
- mailcraft-engine: a JMAP account's calendar is never where an event
  made without saying where goes, and a change to one is refused with
  the reason.
- mailcraft-ui-egui: the calendars are a job of their own, on
  jmap_side_job.rs as the contacts' is, after the contacts' and when
  the calendar comes to the front, a month back and a year ahead.
- mailcraft (desktop): run_calendar beside run_contacts on UCSLabs#1015's
  runner, through the same on_thread and signed_in.
- PRIVACY.md, README.md, ROADMAP.md, docs/jmap.md, docs/gaps.md,
  docs/architecture.md with their fragments, and the release note.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
`cargo xtask live` starts a mail server and a mail catcher in throwaway
containers on loopback ports, runs the `#[ignore]`d `live_` tests of the
desktop app against the server, and removes both containers and their
network, whatever came of the tests.

The scripted tests prove that the client does what we think the protocol
asks; a real server shows whether servers answer that way. Nothing of this
runs in `cargo test` or `cargo xtask ci`, no workflow runs it, and nothing
is added to the build or to `Cargo.lock`.

- `xtask/src/live.rs`: the harness, on the standard library alone. One
  mailbox (`ada@example.org`) with a password made up for the run and never
  printed. The server image, its start recipe, its port and the catcher's
  are taken from the environment (`MAILCRAFT_LIVE_IMAGE`,
  `MAILCRAFT_LIVE_ENV`, `MAILCRAFT_LIVE_SERVER_PORT`, `MAILCRAFT_LIVE_PORT`,
  `MAILCRAFT_LIVE_CATCHER_IMAGE`, `MAILCRAFT_LIVE_CATCHER_PORT`).
- `apps/mailcraft/src/live_tests.rs`: three tests through the functions the
  window's jobs run: mail is listed and a message fetched whole, contacts
  come down, calendars and their events come down. They refuse a server
  that is not on this computer. A server that offers no contacts or no
  calendars has that test say so and end there.
- `docs/live-tests.md`: what it is, how to run it, what it starts and
  removes, another server and what its image must offer. Linked from
  `CONTRIBUTING.md` and `docs/jmap.md`.

The default image, `nextxch/server`, is the mail server the author of this
change works on: commercial software under its own licence, free to pull
and to run for a few mailboxes, not open source. The harness and the doc
say so. CI never pulls it.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@sonarqubecloud

Copy link
Copy Markdown

@benandez

benandez commented Dec 1, 2026

Copy link
Copy Markdown
Member

@nextxch, thank you for the thought and work in this, and sorry for the wait. We've decided to keep tests on the in-process fake servers (crates/net/src/fake.rs) and not to add live-server tests in the repository, even opt-in ones, so I'm closing this and #1113. This is a question of scope, not of the quality of the work.

Human-reviewed, AI-assisted, nobody's mailbox harmed.

@benandez benandez closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: opt-in live tests of the JMAP and CalDAV hosts against a real server in Docker (with a mail catcher)

4 participants