oficina / docs Public

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.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 330d6a4ddfc8e603ada30a9804573a206086a22f parent b45b7b2
10 files changed, +189 −24
  • AGENTS.md +10 −0
  • Makefile +3 −0
  • cmd/docs/mail_test.go +107 −0
  • cmd/docs/main.go +33 −15
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/docs/app.go +4 −4
  • internal/docs/auth.go +1 −1
  • internal/docs/colophon.json +1 −1
  • internal/docs/mail_refusal_test.go +27 −0

CI passed — run details

diff --git a/AGENTS.md b/AGENTS.md
index 1cfdbef..061248b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -394,6 +394,16 @@ time in a single afternoon:
"serving it" from "pointed at it".
*(Recorded from the live-sync deploy; not re-verified since, so the
timer's exact behaviour is one observation rather than a measurement.)*
+- **Ship with `--mail submit`.** It declares that the build sends through
+ CARLOS mail submission (`mail.FromCarlos`, `platformMailer` in
+ `cmd/docs`, From `$DOCS_MAIL_FROM`). Until `carlos email submission on
+ --app docs` runs Docs keeps sending over `DOCS_SMTP_*`; after it the
+ agent sets `CARLOS_MAIL=submit`, Docs 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 use
+ `carlos ship --app docs --mail submit <binary>`, then `carlos promote`
+ (or `carlos deploy --mail submit` once that ships), and check
+ `x-carlos-version` on the real host as above.
- **A library function that ignores its own "dry run" argument.**
`y-prosemirror`'s exported `undo` is `state => ...undoManager?.undo()`
diff --git a/Makefile b/Makefile
index 2e12f11..51ab751 100644
--- a/Makefile
+++ b/Makefile
@@ -21,3 +21,6 @@ release:
GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) ./scripts/build-release.sh $(RELEASE_BIN) $(REVISION)
@echo "publish it with:"
@echo " amadan release create -repo oficina/$(APP) -notes-file NOTES.md <tag> $(RELEASE_BIN)"
+ @echo "ship it declaring CARLOS mail submission, then promote it (AGENTS.md):"
+ @echo " carlos ship -app $(APP) -mail submit -target $(RELEASE_GOOS)-$(RELEASE_GOARCH) $(RELEASE_BIN)"
+ @echo " carlos promote -app $(APP) <version>"
diff --git a/cmd/docs/mail_test.go b/cmd/docs/mail_test.go
new file mode 100644
index 0000000..107ca16
--- /dev/null
+++ b/cmd/docs/mail_test.go
@@ -0,0 +1,107 @@
+package main
+
+import (
+ "context"
+ "log/slog"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "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, which leaves Mailer nil for docs.New to refuse outside
+// development (TestNoMailRefusesOutsideDevelopment, internal/docs).
+
+// mailVars is every variable platformMailer and mail.FromCarlos read,
+// so each case starts from none of them.
+var mailVars = []string{"CARLOS_MAIL", "CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "DOCS_MAIL_FROM", "DOCS_SMTP_HOST",
+ "DOCS_SMTP_PORT", "DOCS_SMTP_FROM", "DOCS_SMTP_USER", "DOCS_SMTP_PASS"}
+
+func mailerWith(t *testing.T, env map[string]string) (mail.Sender, error) {
+ t.Helper()
+ for _, k := range mailVars {
+ t.Setenv(k, "")
+ }
+ for k, v := range env {
+ t.Setenv(k, v)
+ }
+ return platformMailer(slog.New(slog.DiscardHandler))
+}
+
+// controlSocket stands in for the agent's socket: it answers POST
+// /v1/mail and reports each request's method and path.
+func controlSocket(t *testing.T) (string, chan string) {
+ t.Helper()
+ dir, err := os.MkdirTemp("/tmp", "docs-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) {
+ seen <- r.Method + " " + r.URL.Path
+ w.Write([]byte(`{"message_id":"m-1"}`))
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ return socket, seen
+}
+
+func TestPlatformMailerSubmits(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", "DOCS_MAIL_FROM": "noreply@docs.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 := <-seen; got != "POST /v1/mail" {
+ t.Fatalf("the link went to %s, not the platform's mail verb", got)
+ }
+}
+
+func TestPlatformMailerUsesSMTPAlone(t *testing.T) {
+ sender, err := mailerWith(t, map[string]string{
+ "DOCS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ "DOCS_SMTP_FROM": "noreply@docs.oficina.works"})
+ if err != nil || sender == nil || !mail.IsConfigured(sender) {
+ t.Fatalf("sender %v, err %v", sender, err)
+ }
+}
+
+func TestPlatformMailerWithNeitherLeavesItToNew(t *testing.T) {
+ sender, err := mailerWith(t, nil)
+ if err != nil || sender != nil {
+ t.Fatalf("sender %v, err %v: with no channel docs.New must decide", sender, err)
+ }
+}
+
+func TestPlatformMailerRefusesHalfASubmission(t *testing.T) {
+ // No socket: only the agent sets CARLOS_MAIL, and it sets both.
+ if _, err := mailerWith(t, map[string]string{"CARLOS_MAIL": "submit",
+ "DOCS_MAIL_FROM": "noreply@docs.oficina.works"}); err == nil {
+ t.Fatal("built a submit sender with no control socket")
+ }
+ // The From is DOCS_MAIL_FROM, not CARLOS_MAIL_FROM: the platform
+ // names it from Docs' DOCS_SMTP declaration.
+ socket, _ := controlSocket(t)
+ if _, err := mailerWith(t, map[string]string{"CARLOS_MAIL": "submit",
+ "CARLOS_CONTROL_SOCKET": socket, "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@docs.oficina.works"}); err == nil {
+ t.Fatal("built a submit sender with no DOCS_MAIL_FROM")
+ }
+}
diff --git a/cmd/docs/main.go b/cmd/docs/main.go
index 3d2805b..770fc92 100644
--- a/cmd/docs/main.go
+++ b/cmd/docs/main.go
@@ -138,6 +138,32 @@ func checkSeedGate(seed bool, env string) error {
return fmt.Errorf("-seed requires -env development; refusing to seed a database that might not be a throwaway one (env=%q)", env)
}
+// platformMailer builds the magic-link sender from what the platform
+// configured, through rastrillo's mail.FromCarlos: CARLOS mail
+// submission when the agent set $CARLOS_MAIL=submit (the From is
+// $DOCS_MAIL_FROM, the control socket the agent's), else SMTP from
+// $DOCS_SMTP_HOST/$DOCS_SMTP_FROM and their siblings. A half-configured
+// channel is an error, so the process refuses to start rather than
+// failing the first sign-in.
+//
+// With neither channel it returns nil, and the decision is docs.New's
+// (Config.Mailer's own doc comment): rastrillo's logging sender in
+// development, a startup refusal anywhere else. mail.FromEnv would
+// instead fall back to logging a live credential silently.
+//
+// main calls it only on the serving path, never for docs-seal: a
+// CARLOS seed or one-shot has no control socket and the agent strips
+// $CARLOS_MAIL from it, so FromCarlos there would refuse a switched
+// app.
+func platformMailer(logger *slog.Logger) (mail.Sender, error) {
+ smtp := strings.TrimSpace(os.Getenv("DOCS_SMTP_HOST")) != "" &&
+ strings.TrimSpace(os.Getenv("DOCS_SMTP_FROM")) != ""
+ if os.Getenv("CARLOS_MAIL") != "submit" && !smtp {
+ return nil, nil
+ }
+ return mail.FromCarlos("DOCS", logger)
+}
+
func main() {
logger := slog.Default()
if len(os.Args) > 1 && os.Args[1] == "docs-seal" {
@@ -213,21 +239,13 @@ func main() {
// development, the same fail-closed shape as an empty Origin.
instanceKey := os.Getenv("DOCS_INSTANCE_KEY")
- // $DOCS_SMTP_HOST/$DOCS_SMTP_FROM (and the sibling
- // $DOCS_SMTP_PORT/$DOCS_SMTP_USER/$DOCS_SMTP_PASS
- // rastrillo/mail.FromEnv also reads) configure real magic-link
- // delivery. Only built when both of the two values with no sane
- // default are actually set — mail.FromEnv itself falls back to a
- // silent warning-and-log Sender when they're missing, which is
- // the wrong answer outside development, so that decision is left
- // to docs.New (Config.Mailer's own doc comment): a nil Mailer
- // here is what lets it refuse to start rather than silently
- // logging a live credential in a real deployment's log.
- var mailer mail.Sender
- if host := strings.TrimSpace(os.Getenv("DOCS_SMTP_HOST")); host != "" {
- if from := strings.TrimSpace(os.Getenv("DOCS_SMTP_FROM")); from != "" {
- mailer = mail.FromEnv("DOCS", logger)
- }
+ // The sign-in sender (platformMailer below): CARLOS mail submission
+ // or $DOCS_SMTP_*, and nil with neither, which docs.New turns into
+ // a refusal outside development.
+ mailer, err := platformMailer(logger)
+ if err != nil {
+ logger.Error("docs: mail", "err", err)
+ os.Exit(1)
}
// $DOCS_ALLOWED_ADDRESSES is the comma-separated allowlist
diff --git a/go.mod b/go.mod
index 5c00a2c..45ac1f1 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
amadan.net/oficina/home/teammode v0.0.0-20261030153823-602f5136f9af
amadan.net/oficina/suite v0.0.0-20261102002704-91affa14eae4
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3
- amadan.net/rastrillo/rastrillo v0.29.1-0.20261027164201-054787952dd2
+ amadan.net/rastrillo/rastrillo v0.29.2
github.com/carlosframework/rastrillo v0.23.0
github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327
github.com/chromedp/chromedp v0.14.2
diff --git a/go.sum b/go.sum
index 32f9010..9c618ce 100644
--- a/go.sum
+++ b/go.sum
@@ -16,8 +16,8 @@ amadan.net/oficina/suite v0.0.0-20261102002704-91affa14eae4 h1:BP+KHZTSgL7HDCz9I
amadan.net/oficina/suite v0.0.0-20261102002704-91affa14eae4/go.mod h1:Xgw0N+DBiDzkhQHm/nIhgumfaiMElDg/KIFD1OxTm5w=
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.29.1-0.20261027164201-054787952dd2 h1:ybFov1+wRduFtkxTn44QnzCKTDhyjfFWxWsW+cKaAyk=
-amadan.net/rastrillo/rastrillo v0.29.1-0.20261027164201-054787952dd2/go.mod h1:jSSeydqEvlm/fU3hhWoXFnyEaDgroR8LPRZSo9ZhhIM=
+amadan.net/rastrillo/rastrillo v0.29.2 h1:oYKj+Ae8SsOc9ej9+VqLrwsoGb+4PqCDlOCcTbB/A3c=
+amadan.net/rastrillo/rastrillo v0.29.2/go.mod h1:jSSeydqEvlm/fU3hhWoXFnyEaDgroR8LPRZSo9ZhhIM=
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/docs/app.go b/internal/docs/app.go
index a700867..2a5c8d4 100644
--- a/internal/docs/app.go
+++ b/internal/docs/app.go
@@ -153,10 +153,10 @@ type Config struct {
// startup refusal: a sign-in that cannot send its link is not
// sign-in, and silently falling back to logging a live credential
// in a real deployment's log is exactly the mistake that fallback
- // exists to flag, not absorb. cmd/docs/main.go builds this from
- // $DOCS_SMTP_HOST/$DOCS_SMTP_FROM (and the other
- // $DOCS_SMTP_* vars rastrillo/mail.FromEnv reads) when both are
- // set, and leaves it nil otherwise — New.buildMailer (auth.go) is
+ // exists to flag, not absorb. cmd/docs/main.go builds this with
+ // rastrillo/mail.FromCarlos (platformMailer) when CARLOS mail
+ // submission is on ($CARLOS_MAIL=submit) or $DOCS_SMTP_HOST and
+ // $DOCS_SMTP_FROM are both set, and leaves it nil otherwise — New.buildMailer (auth.go) is
// what turns "nil outside development" into the refusal, the same
// split Origin/InstanceKey use.
Mailer mail.Sender
diff --git a/internal/docs/auth.go b/internal/docs/auth.go
index e6d31f5..11989b6 100644
--- a/internal/docs/auth.go
+++ b/internal/docs/auth.go
@@ -75,7 +75,7 @@ func buildMailer(cfg Config, logger *slog.Logger) (mail.Sender, *recordingMailer
sender := cfg.Mailer
if sender == nil {
if cfg.Env != "development" {
- return nil, nil, fmt.Errorf("docs: mail is not configured (set $DOCS_SMTP_HOST and $DOCS_SMTP_FROM) and Env is %q, not %q — refusing to start: a sign-in that cannot send its link is not sign-in", cfg.Env, "development")
+ return nil, nil, fmt.Errorf("docs: mail is not configured (CARLOS mail submission sets $CARLOS_MAIL=submit; otherwise set $DOCS_SMTP_HOST and $DOCS_SMTP_FROM) and Env is %q, not %q — refusing to start: a sign-in that cannot send its link is not sign-in", cfg.Env, "development")
}
// Loudly labelled by mail.Logged itself on every send — see
// its own doc comment; this is the dev/test-only fallback,
diff --git a/internal/docs/colophon.json b/internal/docs/colophon.json
index ff00b57..cce7bf3 100644
--- a/internal/docs/colophon.json
+++ b/internal/docs/colophon.json
@@ -14,7 +14,7 @@
{
"ecosystem": "go",
"name": "amadan.net/rastrillo/rastrillo",
- "version": "v0.29.1-0.20261027164201-054787952dd2",
+ "version": "v0.29.2",
"notices": [
{
"Name": "LICENSE",
diff --git a/internal/docs/mail_refusal_test.go b/internal/docs/mail_refusal_test.go
new file mode 100644
index 0000000..ccb5d10
--- /dev/null
+++ b/internal/docs/mail_refusal_test.go
@@ -0,0 +1,27 @@
+package docs
+
+import (
+ "log/slog"
+ "strings"
+ "testing"
+)
+
+// TestNoMailRefusesOutsideDevelopment is the third boot of CARLOS mail
+// submission (cmd/docs mail_test.go has the other two): with neither
+// channel, cmd/docs 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", "DOCS_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)
+ }
+}