Mail through rastrillo's FromCarlos, ready for CARLOS platform mail submission (SMTP unchanged until switched)
Re-pinned to the rastrillo patch tag, which adds only mail/. Boots with CARLOS_MAIL=submit and a socket, or on SMTP as before; refuses with neither. Fable APPROVED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from mail/from-carlos-patch into main.
9 files changed,
+211
−11
Makefile+3 −1README.md+14 −0cmd/calls/mail_test.go+133 −0cmd/calls/main.go+28 −5go.mod+1 −1go.sum+2 −2internal/calls/config.go+1 −1internal/calls/credits/notices.json+1 −1internal/calls/mail_refusal_test.go+28 −0
CI passed — run details
CI log
=== vet === go vet ./... go: downloading amadan.net/rastrillo/rastrillo v0.27.1 === fmt === === test === go test ./... ok amadan.net/oficina/calls/callscore (cached) ok amadan.net/oficina/calls/cmd/calls 13.221s ? amadan.net/oficina/calls/cmd/calls-contract [no test files] ok amadan.net/oficina/calls/cmd/quality-summary (cached) ok amadan.net/oficina/calls/internal/calls 12.999s ok amadan.net/oficina/calls/internal/calls/apns (cached) ok amadan.net/oficina/calls/internal/calls/hub (cached) ? amadan.net/oficina/calls/internal/calls/icons [no test files] ? amadan.net/oficina/calls/internal/calls/keymailtest [no test files] ok amadan.net/oficina/calls/internal/calls/relay (cached) ok amadan.net/oficina/calls/internal/calls/seal (cached) ? amadan.net/oficina/calls/internal/calls/teamstate [no test files] ok amadan.net/oficina/calls/internal/callstest 12.480s ok amadan.net/oficina/calls/protocol (cached) ? amadan.net/oficina/calls/scripts/writeestilo [no test files] === migration-check === go run amadan.net/rastrillo/rastrillo/cmd/rastrillo migration check rastrillo migration check: models and migrations agree === race === CGO_ENABLED=1 go test -race ./internal/... ok amadan.net/oficina/calls/internal/calls 90.070s ok amadan.net/oficina/calls/internal/calls/apns (cached) ok amadan.net/oficina/calls/internal/calls/hub (cached) ? amadan.net/oficina/calls/internal/calls/icons [no test files] ? amadan.net/oficina/calls/internal/calls/keymailtest [no test files] ok amadan.net/oficina/calls/internal/calls/relay (cached) ok amadan.net/oficina/calls/internal/calls/seal (cached) ? amadan.net/oficina/calls/internal/calls/teamstate [no test files] ok amadan.net/oficina/calls/internal/callstest 48.643s
diff --git a/Makefile b/Makefile| index 795a27f..6e72c4b 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -53,7 +53,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/AGENTS):" |
| + @echo " carlos promote -app $(APP) <version>" |
| version-check: |
| @if [ -z "$(VERSION)" ]; then \ |
diff --git a/README.md b/README.md| index 97d76f8..0f18933 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -124,6 +124,20 @@ promote and wait (its own help text). Building for your own |
| architecture and shipping that uploads fine and fails to exec on the |
| instance. |
| +**Mail submission.** Ship every Calls build with `--mail submit`, which |
| +declares that it can send through CARLOS mail submission |
| +(`mail.FromCarlos`, `newMailer` in `cmd/calls`). Until `carlos email |
| +submission on --app calls` runs, Calls keeps sending over SMTP; after |
| +it the agent sets `CARLOS_MAIL=submit` and Calls holds no SMTP |
| +credential, and every instance must run a build shipped with the flag. |
| +`carlos deploy` has no `--mail` flag yet (carlos main 9eec0236), so |
| +until it does, ship and promote: `carlos ship --app calls --account |
| +oficina --mail submit --version <sha> --target linux-arm64 |
| +releases/calls-linux-arm64`, then `carlos promote --app calls --account |
| +oficina <sha> edge` (or `carlos deploy --mail submit` once that ships). |
| +The From on submission is `$CARLOS_MAIL_FROM`, the one the platform |
| +delivers; `CALLS_SMTP_*` still win over `CARLOS_SMTP_*` on SMTP. |
| + |
| These are the settings a deploy needs (`config.go`, `standing.go`). |
| Five refuse startup when empty outside `-env development`: |
| `CALLS_ORIGIN` (the external origin, scheme included); |
diff --git a/cmd/calls/mail_test.go b/cmd/calls/mail_test.go| new file mode 100644 |
| index 0000000..c0b0ad4 |
| --- /dev/null |
| +++ b/cmd/calls/mail_test.go |
| @@ -0,0 +1,133 @@ |
| +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 calls.App refuses |
| +// outside development (the mail case of resolve, |
| +// in internal/calls config.go). |
| + |
| +var mailVars = []string{"CARLOS_MAIL", "CARLOS_CONTROL_SOCKET", |
| + "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM", "CALLS_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{"CALLS_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", "calls-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 (Calls |
| +// is declared CARLOS_SMTP), and nothing of Calls' 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@calls.oficina.works", |
| + // Not delivered by the platform, so not read. |
| + "CALLS_MAIL_FROM": "calls@calls.oficina.works", |
| + // SMTP left over beside it is not used. |
| + "CARLOS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com", |
| + "CARLOS_SMTP_FROM": "old@calls.oficina.works"}) |
| + if err != nil || sender == nil { |
| + t.Fatalf("sender %v, err %v", sender, err) |
| + } |
| + if err := sender.Send(context.Background(), "ana@example.com", "Sign in", "link"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got, want := <-seen, "POST /v1/mail noreply@calls.oficina.works"; got != want { |
| + t.Fatalf("got %q, want %q", got, want) |
| + } |
| +} |
| + |
| +func TestNewMailerUsesSMTPAlone(t *testing.T) { |
| + sender, err := mailerWith(t, map[string]string{ |
| + "CARLOS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com", |
| + "CARLOS_SMTP_FROM": "noreply@calls.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 calls.App 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@calls.oficina.works", |
| + "CALLS_MAIL_FROM": "calls@calls.oficina.works", |
| + "CALLS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com", |
| + "CALLS_SMTP_FROM": "old@calls.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/calls/main.go b/cmd/calls/main.go| index 76e82ab..5fb8284 100644 |
| --- a/cmd/calls/main.go |
| +++ b/cmd/calls/main.go |
| @@ -71,7 +71,10 @@ func run(logger, reportLogger *slog.Logger) error { |
| // Raw: calls.resolve wraps every mailer in RedactMailErrors, so the |
| // invariant holds for whatever a caller passes, not only for what |
| // this main happens to build (review C1-2). |
| - mailer := newMailer(logger) |
| + mailer, err := newMailer(logger) |
| + if err != nil { |
| + return fmt.Errorf("configure mail: %w", err) |
| + } |
| cfg := calls.Config{ |
| Home: connect.CredentialsFromEnv("CALLS"), |
| @@ -156,17 +159,37 @@ func smtpSecret(name string) string { |
| return os.Getenv("CARLOS_SMTP_" + name) |
| } |
| -// newMailer builds the magic-link sender. HOST and FROM have no sane |
| +// newMailer builds the magic-link sender: CARLOS mail submission when |
| +// the agent turned it on, else SMTP from the settings above. |
| +// |
| +// Submission ($CARLOS_MAIL=submit, which only the CARLOS agent sets, |
| +// beside its control socket) goes through rastrillo's mail.FromCarlos, |
| +// 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 Calls, so |
| +// stem CARLOS). There is deliberately no CALLS_ override here, unlike |
| +// the SMTP settings: 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 Calls refuses to start rather than fail |
| +// the first sign-in. run calls this only on the serving path: a CARLOS |
| +// seed or one-shot has no control socket, and the agent strips |
| +// $CARLOS_MAIL from it. |
| +// |
| +// SMTP is mail.SMTP directly, because FromCarlos reads one prefix and |
| +// this needs the per-variable fallback. HOST and FROM have no sane |
| // default, so either missing means no relay, and a nil return is what |
| // lets calls.App refuse to start outside development rather than log |
| // live links. |
| -func newMailer(logger *slog.Logger) mail.Sender { |
| +func newMailer(logger *slog.Logger) (mail.Sender, error) { |
| + if os.Getenv("CARLOS_MAIL") == "submit" { |
| + return mail.FromCarlos("CARLOS", logger) |
| + } |
| host, from := smtpSetting("HOST"), smtpSetting("FROM") |
| if host == "" || from == "" { |
| - return nil |
| + return nil, nil |
| } |
| logger.Info("calls: SMTP configured", "host", host, "from", from) |
| - return mail.SMTP(host, smtpSetting("PORT"), from, smtpSecret("USER"), smtpSecret("PASS")) |
| + return mail.SMTP(host, smtpSetting("PORT"), from, smtpSecret("USER"), smtpSecret("PASS")), nil |
| } |
| // extractEnvFlag pulls -env (in its four spellings) out of argv and |
diff --git a/go.mod b/go.mod| index 48abede..05dc651 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -9,7 +9,7 @@ require ( |
| amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d |
| amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2 |
| amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 |
| - amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| + amadan.net/rastrillo/rastrillo v0.27.1 |
| github.com/go-chi/chi/v5 v5.3.2 |
| github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 |
| github.com/google/uuid v1.6.0 |
diff --git a/go.sum b/go.sum| index 8c46365..aa6eb41 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -10,8 +10,8 @@ amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2 h1:yKUTS0nOiVw |
| amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2/go.mod h1:gqshuXyDtFZUCYbhuZyV3Epc51pUcsLbpqAqiA5UiXg= |
| amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 h1:0PQiRUkC+9cbTHE67Y4/SmW1sPH1NNWNwTceNFyMjTY= |
| amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2/go.mod h1:dXBZeB2ic33SIZiGUCzafmviUT8TYWgzSYZvo2rM6zA= |
| -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/calls/config.go b/internal/calls/config.go| index c7f8e0e..84d8a5b 100644 |
| --- a/internal/calls/config.go |
| +++ b/internal/calls/config.go |
| @@ -190,7 +190,7 @@ func resolve(cfg Config) (resolved, error) { |
| case cfg.development(): |
| out.mailer = RedactMailErrors(mail.Logged(cfg.Logger), cfg.Logger) |
| default: |
| - return out, fmt.Errorf("calls: mail is not configured (set $CALLS_SMTP_HOST and $CALLS_SMTP_FROM) and Env is %q, not %q; a sign-in that cannot send its link is not sign-in", cfg.Env, EnvDevelopment) |
| + return out, fmt.Errorf("calls: mail is not configured (CARLOS mail submission sets $CARLOS_MAIL=submit; otherwise set $CALLS_SMTP_HOST and $CALLS_SMTP_FROM, or $CARLOS_SMTP_*) and Env is %q, not %q; a sign-in that cannot send its link is not sign-in", cfg.Env, EnvDevelopment) |
| } |
| list, err := resolveAllowlist(cfg) |
diff --git a/internal/calls/credits/notices.json b/internal/calls/credits/notices.json| index 6ea672c..4b6462e 100644 |
| --- a/internal/calls/credits/notices.json |
| +++ b/internal/calls/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/calls/mail_refusal_test.go b/internal/calls/mail_refusal_test.go| new file mode 100644 |
| index 0000000..8c5aeaa |
| --- /dev/null |
| +++ b/internal/calls/mail_refusal_test.go |
| @@ -0,0 +1,28 @@ |
| +package calls |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// TestNoMailRefusesOutsideDevelopment is the third boot of CARLOS mail |
| +// submission (cmd/calls mail_test.go has the other two): with neither |
| +// channel, cmd/calls passes a nil Mailer, and resolve refuses anywhere |
| +// but development, naming both ways to fix it. |
| +func TestNoMailRefusesOutsideDevelopment(t *testing.T) { |
| + cfg := minimalConfig(t) |
| + cfg.Mailer = nil |
| + _, err := resolve(cfg) |
| + if err == nil { |
| + t.Fatal("started with no mail in production") |
| + } |
| + for _, want := range []string{"CARLOS_MAIL=submit", "CALLS_SMTP_HOST"} { |
| + if !strings.Contains(err.Error(), want) { |
| + t.Errorf("refusal %q does not name %s", err, want) |
| + } |
| + } |
| + cfg.Env = EnvDevelopment |
| + if _, err := resolve(cfg); err != nil { |
| + t.Fatalf("development with no mail: %v", err) |
| + } |
| +} |