oficina / calendar Public

Calendar: mail through rastrillo's FromCarlos (rastrillo v0.27.1)

CARLOS platform mail submission, Task 9. rastrillo moves to the
v0.27.1 patch tag, which adds only mail/ (FromCarlos, Submit) on top of
the old fb806a2 pin; go.mod's rastrillo line is the only dependency
change, and the credits are regenerated for it.

newMailer (cmd/calendar) builds the sender for sign-in links and
reminders through mail.FromCarlos: CARLOS mail submission when the
agent sets CARLOS_MAIL=submit, From CARLOS_MAIL_FROM exactly as the
platform delivers it for the declared CARLOS_SMTP prefix (no CALENDAR_
override), else the SMTP prefix smtpPrefix picks, unchanged. With
neither it is nil and calendar.New refuses outside development, its
refusal now naming submission too. A half-set submission refuses at
boot. Built on the serving path only (calendar-contract never builds
one). Deploy notes: ship with --mail submit, then promote, until carlos
deploy takes --mail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 0e5140002dc9f15077fe8aa91b8199b1a9966a26 parent 800406a
10 files changed, +229 −14
  • AGENTS.md +4 −1
  • Makefile +3 −1
  • README.md +15 −2
  • cmd/calendar/mail_test.go +139 −0
  • cmd/calendar/main.go +36 −5
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/calendar/auth.go +1 −1
  • internal/calendar/credits/notices.json +1 −1
  • internal/calendar/mail_refusal_test.go +27 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/calendartest/
=== fmt ===
=== test ===
go test ./...
ok  	amadan.net/oficina/calendar/cmd/calendar	0.090s
?   	amadan.net/oficina/calendar/cmd/calendar-contract	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendar	26.066s
?   	amadan.net/oficina/calendar/internal/calendar/icons	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/keymailtest	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/seal	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/teamstate	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendartest	3.894s
ok  	amadan.net/oficina/calendar/internal/guardstest	0.084s
?   	amadan.net/oficina/calendar/scripts/writeestilo	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/AGENTS.md b/AGENTS.md
index db91587..0f016c0 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -275,7 +275,10 @@ relying on remembering one, make it a test instead.
**Deploys**
- One binary, `CGO_ENABLED=0`, cgo-free SQLite.
- **`carlos deploy`, never `carlos ship` alone.** `ship` leaves the
- release unpromoted and nothing serving it.
+ release unpromoted and nothing serving it. **Until `carlos deploy`
+ takes `--mail`, the exception is mail submission:** ship with `--mail
+ submit`, then promote (README, Deploying), because every instance of a
+ switched app must run a build shipped with the flag.
- **`make release`, never a bare `go build`** — it stamps
`rastrillo.BuildVersion` and refuses a dirty tree.
- **A 200 is not verification, and neither is `X-Carlos-Version`.** That
diff --git a/Makefile b/Makefile
index 261b53b..01abd2f 100644
--- a/Makefile
+++ b/Makefile
@@ -51,7 +51,9 @@ release: version-check
@echo
@echo "built $(RELEASE_BIN) reporting version $(VERSION)"
@echo "ship it with:"
- @echo " carlos ship -app $(APP) -target $(RELEASE_GOOS)-$(RELEASE_GOARCH) $(RELEASE_BIN)"
+ @echo " carlos ship -app $(APP) -mail submit -target $(RELEASE_GOOS)-$(RELEASE_GOARCH) $(RELEASE_BIN)"
+ @echo "then promote it (carlos deploy has no -mail flag yet; see README):"
+ @echo " carlos promote -app $(APP) <version>"
# version-check refuses rather than letting release ship a binary whose
# version is untrue. Both refusals are about the same thing: /api/version
diff --git a/README.md b/README.md
index 6165f78..605caca 100644
--- a/README.md
+++ b/README.md
@@ -131,10 +131,23 @@ instance is down rather than quietly wrong.
```sh
make release
-carlos deploy --account oficina --app calendar --channel edge \
- --timeout 5m releases/calendar-linux-arm64
+carlos ship --account oficina --app calendar --mail submit \
+ --version "$(git describe --tags --always)" releases/calendar-linux-arm64
+carlos promote --account oficina --app calendar <version> edge
```
+**Mail submission.** Ship every build with `--mail submit`: it declares
+that the build sends through CARLOS mail submission (`mail.FromCarlos`,
+`newMailer` in `cmd/calendar`, From `$CARLOS_MAIL_FROM`). Until `carlos
+email submission on --app calendar` runs, Calendar keeps sending over
+SMTP (`CALENDAR_SMTP_*` when set, else `CARLOS_SMTP_*`); after it the
+agent sets `CARLOS_MAIL=submit`, Calendar holds no mail credential, and
+every instance must run a build shipped with the flag. `carlos deploy`
+has no `--mail` flag yet (carlos main 9eec0236), so ship and promote as
+above; once it has, `carlos deploy --account oficina --app calendar
+--channel edge --mail submit --timeout 5m releases/calendar-linux-arm64`
+does both.
+
Then check the **process**, not the edge:
```sh
diff --git a/cmd/calendar/mail_test.go b/cmd/calendar/mail_test.go
new file mode 100644
index 0000000..8b81eb3
--- /dev/null
+++ b/cmd/calendar/mail_test.go
@@ -0,0 +1,139 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "log/slog"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/mail"
+)
+
+// The three boots CARLOS platform mail submission needs (carlos plan
+// Task 9): on submission with the agent's socket, on SMTP alone, and
+// with neither, where newMailer returns nil and calendar.New refuses
+// outside development (TestNoMailRefusesOutsideDevelopment, in
+// internal/calendar).
+
+var mailVars = []string{"CARLOS_MAIL", "CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM", "CALENDAR_MAIL_FROM"}
+
+func mailerWith(t *testing.T, env map[string]string) (mail.Sender, error) {
+ t.Helper()
+ for _, k := range mailVars {
+ t.Setenv(k, "")
+ }
+ for _, p := range []string{"CALENDAR_SMTP_", "CARLOS_SMTP_"} {
+ for _, s := range []string{"HOST", "PORT", "USER", "PASS", "FROM"} {
+ t.Setenv(p+s, "")
+ }
+ }
+ for k, v := range env {
+ t.Setenv(k, v)
+ }
+ return newMailer(slog.New(slog.DiscardHandler))
+}
+
+// controlSocket stands in for the agent's socket: it answers POST
+// /v1/mail and reports each request's path and From.
+func controlSocket(t *testing.T) (string, chan string) {
+ t.Helper()
+ dir, err := os.MkdirTemp("/tmp", "calendar-mail") // unix paths are short
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ socket := filepath.Join(dir, "control.sock")
+ ln, err := net.Listen("unix", socket)
+ if err != nil {
+ t.Fatal(err)
+ }
+ seen := make(chan string, 1)
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ var body struct {
+ From string `json:"from"`
+ }
+ raw, _ := io.ReadAll(r.Body)
+ _ = json.Unmarshal(raw, &body)
+ seen <- r.Method + " " + r.URL.Path + " " + body.From
+ w.Write([]byte(`{"message_id":"m-1"}`))
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ return socket, seen
+}
+
+// The From is the one the platform delivers, CARLOS_MAIL_FROM
+// (Calendar is declared CARLOS_SMTP), and nothing of Calendar's own
+// overrides it.
+func TestNewMailerSubmits(t *testing.T) {
+ socket, seen := controlSocket(t)
+ sender, err := mailerWith(t, map[string]string{
+ "CARLOS_MAIL": "submit", "CARLOS_CONTROL_SOCKET": socket,
+ "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@calendar.oficina.works",
+ // Not delivered by the platform, so not read.
+ "CALENDAR_MAIL_FROM": "reminders@calendar.oficina.works",
+ // SMTP left over beside it is not used.
+ "CALENDAR_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ "CALENDAR_SMTP_FROM": "old@calendar.oficina.works"})
+ if err != nil || sender == nil {
+ t.Fatalf("sender %v, err %v", sender, err)
+ }
+ if err := sender.Send(context.Background(), "ana@example.com", "Reminder", "body"); err != nil {
+ t.Fatal(err)
+ }
+ if got, want := <-seen, "POST /v1/mail noreply@calendar.oficina.works"; got != want {
+ t.Fatalf("got %q, want %q", got, want)
+ }
+}
+
+// SMTP alone is what Calendar has always booted on, CALENDAR_ first.
+func TestNewMailerUsesSMTPAlone(t *testing.T) {
+ for _, prefix := range []string{"CARLOS", "CALENDAR"} {
+ t.Run(prefix, func(t *testing.T) {
+ sender, err := mailerWith(t, map[string]string{
+ prefix + "_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ prefix + "_SMTP_FROM": "noreply@calendar.oficina.works"})
+ if err != nil || sender == nil || !mail.IsConfigured(sender) {
+ t.Fatalf("sender %v, err %v", sender, err)
+ }
+ })
+ }
+}
+
+func TestNewMailerWithNeitherLeavesItToNew(t *testing.T) {
+ sender, err := mailerWith(t, nil)
+ if err != nil || sender != nil {
+ t.Fatalf("sender %v, err %v: with no channel calendar.New must decide", sender, err)
+ }
+}
+
+// A submission missing anything the agent or platform delivers is a
+// boot refusal, never SMTP or logged mail in its place: not even with
+// SMTP still configured beside it.
+func TestNewMailerRefusesHalfASubmission(t *testing.T) {
+ socket, _ := controlSocket(t)
+ for _, missing := range []string{"CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM"} {
+ t.Run(missing, func(t *testing.T) {
+ env := map[string]string{"CARLOS_MAIL": "submit",
+ "CARLOS_CONTROL_SOCKET": socket, "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@calendar.oficina.works",
+ "CALENDAR_MAIL_FROM": "reminders@calendar.oficina.works",
+ "CARLOS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ "CARLOS_SMTP_FROM": "old@calendar.oficina.works"}
+ delete(env, missing)
+ _, err := mailerWith(t, env)
+ if err == nil || !strings.Contains(err.Error(), missing) {
+ t.Fatalf("submission with no %s: %v", missing, err)
+ }
+ })
+ }
+}
diff --git a/cmd/calendar/main.go b/cmd/calendar/main.go
index 9704ed8..1d80800 100644
--- a/cmd/calendar/main.go
+++ b/cmd/calendar/main.go
@@ -49,13 +49,14 @@ func main() {
origin = "http://" + opts.Addr
}
- // A mailer only when both halves of some prefix are configured.
- // calendar.New's own fail-closed rule turns "none were" into a
+ // A mailer only when a channel is configured (newMailer below).
+ // calendar.New's own fail-closed rule turns "none was" into a
// startup refusal outside development rather than a silent
// no-mail instance.
- var mailer mail.Sender
- if prefix, ok := smtpPrefix(); ok {
- mailer = mail.FromEnv(prefix, logger)
+ mailer, err := newMailer(logger)
+ if err != nil {
+ logger.Error("configure mail", "err", err)
+ os.Exit(1)
}
app, err := calendar.New(calendar.Config{
@@ -90,6 +91,36 @@ func main() {
}
}
+// newMailer builds the sender for sign-in links and reminders through
+// rastrillo's mail.FromCarlos, from one of two channels.
+//
+// CARLOS mail submission: the agent sets $CARLOS_MAIL=submit beside its
+// control socket, and the instance holds no mail credential. The From
+// is $CARLOS_MAIL_FROM, exactly what the platform delivers: it names
+// the variable from the app's declared prefix (CARLOS_SMTP for
+// Calendar, so stem CARLOS). There is deliberately no CALENDAR_
+// override here, unlike SMTP below: the platform never delivers one,
+// and the mail verb sends only as the app's own sender. A submission
+// missing its socket, token or From is an error, so Calendar refuses to
+// start rather than failing the first sign-in or reminder.
+//
+// SMTP: the prefix smtpPrefix picks, exactly as before.
+//
+// With neither it returns nil, and calendar.New decides: a refusal
+// outside development. main calls this only where Calendar serves (a
+// scheduled reminder wake is the same serving process): a CARLOS seed
+// or one-shot has no control socket and the agent strips $CARLOS_MAIL
+// from it, and calendar-contract never builds a sender.
+func newMailer(logger *slog.Logger) (mail.Sender, error) {
+ if os.Getenv("CARLOS_MAIL") == "submit" {
+ return mail.FromCarlos("CARLOS", logger)
+ }
+ if prefix, ok := smtpPrefix(); ok {
+ return mail.FromCarlos(prefix, logger)
+ }
+ return nil, nil
+}
+
// smtpPrefix picks which <PREFIX>_SMTP_* set to build the mailer from,
// preferring the app's own over the platform's.
//
diff --git a/go.mod b/go.mod
index c2efbdd..710732d 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ toolchain go1.26.5
require (
amadan.net/oficina/home/connect v0.0.0-20261110233753-14c83d71b992
amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d
- amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060
+ amadan.net/rastrillo/rastrillo v0.27.1
github.com/carlosframework/rastrillo v0.23.0
github.com/chromedp/chromedp v0.14.2
github.com/go-chi/chi/v5 v5.3.2
diff --git a/go.sum b/go.sum
index 1f174d1..77dc882 100644
--- a/go.sum
+++ b/go.sum
@@ -14,8 +14,8 @@ amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 h1:0PQiRUkC+
amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2/go.mod h1:dXBZeB2ic33SIZiGUCzafmviUT8TYWgzSYZvo2rM6zA=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3/go.mod h1:ZaaxeE278dJltdrLwmwpxUjQ5wuKzqDAVSNRet+WupY=
-amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE=
-amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060/go.mod h1:WmC8TAIfqjAkSwmD+FCTqr7VuqAO5FaX03HlV49K608=
+amadan.net/rastrillo/rastrillo v0.27.1 h1:cVG2ll1BZxlyyuNINRKblKO/6hvk/ucCFXz6HNoCo58=
+amadan.net/rastrillo/rastrillo v0.27.1/go.mod h1:WmC8TAIfqjAkSwmD+FCTqr7VuqAO5FaX03HlV49K608=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
diff --git a/internal/calendar/auth.go b/internal/calendar/auth.go
index 92bf346..a848f12 100644
--- a/internal/calendar/auth.go
+++ b/internal/calendar/auth.go
@@ -66,7 +66,7 @@ func buildMailer(cfg Config, logger *slog.Logger) (mail.Sender, *recordingMailer
// enable` writes, and naming only the app's prefix sent
// the first deploy of this app into a wake loop against
// an instance whose mail was configured correctly.
- return nil, nil, fmt.Errorf("calendar: mail is not configured (set $CARLOS_SMTP_HOST and $CARLOS_SMTP_FROM with `carlos email enable`, or $CALENDAR_SMTP_HOST and $CALENDAR_SMTP_FROM to override) and Env is %q, not %q — refusing to start: a sign-in that cannot send its link is not sign-in, and a reminder that cannot be delivered is not a reminder", cfg.Env, "development")
+ return nil, nil, fmt.Errorf("calendar: mail is not configured (CARLOS mail submission sets $CARLOS_MAIL=submit; otherwise set $CARLOS_SMTP_HOST and $CARLOS_SMTP_FROM with `carlos email enable`, or $CALENDAR_SMTP_HOST and $CALENDAR_SMTP_FROM to override) and Env is %q, not %q — refusing to start: a sign-in that cannot send its link is not sign-in, and a reminder that cannot be delivered is not a reminder", cfg.Env, "development")
}
sender = mail.Logged(logger)
}
diff --git a/internal/calendar/credits/notices.json b/internal/calendar/credits/notices.json
index b237262..5a8d191 100644
--- a/internal/calendar/credits/notices.json
+++ b/internal/calendar/credits/notices.json
@@ -35,7 +35,7 @@
},
{
"Name": "amadan.net/rastrillo/rastrillo",
- "Version": "v0.27.1-0.20261006204347-fb806a287060",
+ "Version": "v0.27.1",
"SourceURL": "https://amadan.net/rastrillo/rastrillo",
"Notices": [
{
diff --git a/internal/calendar/mail_refusal_test.go b/internal/calendar/mail_refusal_test.go
new file mode 100644
index 0000000..dcc9eed
--- /dev/null
+++ b/internal/calendar/mail_refusal_test.go
@@ -0,0 +1,27 @@
+package calendar
+
+import (
+ "log/slog"
+ "strings"
+ "testing"
+)
+
+// TestNoMailRefusesOutsideDevelopment is the third boot of CARLOS mail
+// submission (cmd/calendar mail_test.go has the other two): with
+// neither channel, cmd/calendar leaves Mailer nil, and that is a
+// refusal anywhere but development, naming both ways to fix it.
+func TestNoMailRefusesOutsideDevelopment(t *testing.T) {
+ logger := slog.New(slog.DiscardHandler)
+ _, _, err := buildMailer(Config{Env: "production"}, logger)
+ if err == nil {
+ t.Fatal("started with no mail in production")
+ }
+ for _, want := range []string{"CARLOS_MAIL=submit", "CARLOS_SMTP_HOST"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("refusal %q does not name %s", err, want)
+ }
+ }
+ if sender, _, err := buildMailer(Config{Env: "development"}, logger); err != nil || sender == nil {
+ t.Fatalf("development: sender %v, err %v", sender, err)
+ }
+}