From b5beb8cbb4269964f9b78fec52a13cbae19c73de Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Mon, 16 Nov 2026 21:20:40 -0700 Subject: [PATCH] Send an HTML reply when a transformer returns message_html A transformer may now add an optional message_html to result.json: an email-safe HTML fragment of the same report. When a succeeded job has one, the reply goes out as both text and HTML (Mailgun's html field beside text); a reply whose jobs sent none is byte-for-byte as before. The first user is check_temple_schedule, whose report of sections and a per-block count table is hard to read as plain text on a phone. - contract: Result.MessageHTML (json message_html, omitempty). Additive; contract_version stays "1". - store: jobs.message_html TEXT NOT NULL DEFAULT '', added by migration on existing databases. The default keeps the rollback binary, which inserts jobs without naming the column, working. The files_deleted_at migration is generalized into addJobsColumn. Complete takes the HTML; PendingEmails and Get read it. - app: only a succeeded job's HTML is stored. finish now logs only the first line of a job's message: a report runs to 50+ lines, which %q turned into one long escaped log line per job. - mailgun: deliver builds an HTML document from each job's fragment under an escaped caption naming the file and report, then the sheet links as anchors and the support line as a mailto link. The link and support wording each live in one helper shared with the text reply. Everything FileMill inserts is escaped; the fragment goes in verbatim, as transformers are trusted code. Alerts stay plain text. - README documents result.json, including message_html's rules, and the uppercase example sets a one-line message_html. doc/HTML-REPLY-PLAN.md is the plan, revised after review. Co-Authored-By: Claude Opus 5.5 --- README.md | 67 +++++++ doc/HTML-REPLY-PLAN.md | 221 ++++++++++++++++++++++++ examples/transformers/uppercase/main.go | 2 +- internal/app/app.go | 33 +++- internal/app/fake_test.go | 21 ++- internal/app/message_html_test.go | 81 +++++++++ internal/app/retention_test.go | 6 +- internal/app/sweep_alert_test.go | 2 +- internal/contract/contract.go | 1 + internal/contract/contract_test.go | 27 +++ internal/mailgun/delivery_test.go | 17 +- internal/mailgun/htmlreply.go | 78 +++++++++ internal/mailgun/htmlreply_test.go | 176 +++++++++++++++++++ internal/mailgun/outbound.go | 64 +++++-- internal/mailgun/outbound_test.go | 6 +- internal/store/interrupt_test.go | 2 +- internal/store/message_html_test.go | 98 +++++++++++ internal/store/store.go | 51 +++--- internal/store/store_test.go | 10 +- 19 files changed, 893 insertions(+), 70 deletions(-) create mode 100644 doc/HTML-REPLY-PLAN.md create mode 100644 internal/app/message_html_test.go create mode 100644 internal/contract/contract_test.go create mode 100644 internal/mailgun/htmlreply.go create mode 100644 internal/mailgun/htmlreply_test.go create mode 100644 internal/store/message_html_test.go diff --git a/README.md b/README.md index e9758a6..5f52251 100644 --- a/README.md +++ b/README.md @@ -438,3 +438,70 @@ workspace before the transformer is even started: When the transformer exits, FileMill looks for `result.json` in the same workspace — `examples/transformers/uppercase/main.go` shows the matching write side of that contract. + +### The result.json contract + +`uppercase`, after a successful run, writes: + +```json +{ + "contract_version": "1", + "success": true, + "message": "File uppercased", + "message_html": "

File uppercased

", + "output_files": [ + { + "name": "uppercase-example.txt", + "path": "output/uppercase-example.txt" + } + ], + "details": {} +} +``` + +- **`contract_version`** — must be `"1"`. Any other value fails the job. +- **`success`** — `true` if the job did what was asked. `false` is how a + transformer turns its input down ("not a worker list"): the job fails, the + sender gets the message, and the operator is *not* alerted. A crash, a + missing `result.json`, or `success: true` with a non-zero exit code is + FileMill's problem instead, and alerts. +- **`message`** — required. One line for the sender, or a whole report: it is + the body of the reply (plain text). Only its first line goes into + `filemill.log`. +- **`message_html`** — optional; see below. Used only when `success` is + `true`. +- **`error_code`** — optional, a short code for a failure, for logs. +- **`output_files`** — every artifact in `output/`, by workspace-relative + path. They are attached to the reply, or published as Google Sheets on a + `sheets-link` address. A job may produce none: a report delivered entirely + in the message needs no file. +- **`details`** — free-form data for logs and debugging. + +#### HTML replies (`message_html`) + +When a successful job's `message_html` is set, the reply is sent as both +plain text and HTML: `message` is the text part, which a text-only mail client +shows, and `message_html` goes into the HTML part. FileMill wraps it in the +page, puts a small caption naming the input file and report above it, and +adds the sheet links (on a `sheets-link` address) and the support line below. +A transformer that doesn't set `message_html` gets exactly a plain-text reply, +as before. The field is additive, so a transformer may send it to an older +FileMill, which ignores it. + +The fragment must be: + +- **A fragment**, placed inside the reply's ``: no ``, + ``, `` or ``. Don't repeat the input file's name; FileMill's + caption already shows it. +- **Email-safe:** inline `style` attributes only, tables for layout, no + `