oficina / mapa Public

Mapa: mail through rastrillo's FromCarlos, ready for CARLOS platform mail submission (SMTP unchanged until switched)

CARLOS platform mail submission, Task 9. Fable APPROVED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from mail/from-carlos into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 6eaee96d6f1f1da851548bb2961443dc65d3bee0 parent 2cf0c44
8 files changed, +195 −12
  • README.md +17 −0
  • cmd/mapa/main.go +5 −2
  • go.mod +1 −1
  • go.sum +2 −0
  • internal/mapa/config.go +15 −8
  • internal/mapa/credits/notices.json +1 −1
  • internal/mapa/mailer.go +23 −0
  • internal/mapa/mailer_test.go +131 −0

CI passed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 307ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.fd68828f6fa8343e.js (317138 bytes, 99.0KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (45.911824ms)
ℹ 760 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (59.89178ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (92.239078ms)
ℹ 748 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (100.544077ms)
ℹ 755 inserts, 715 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (3054.506786ms)
ℹ 18240 edits over 760 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (935.833536ms)
ℹ 4124 links over 760 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":610,"A page link can’t show [ or ]]. Select words without them.":370,"Select some words to link them to a page.":163,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":17}
✔ linear: trailing spaces (28.753802ms)
✔ linear: trailing whitespace (12.72303ms)
✔ linear: unclosed web links (12.271475ms)
✔ linear: web links with no address (18.219691ms)
✔ linear: unclosed wiki links (17.411597ms)
✔ linear: unclosed embeds (17.643913ms)
✔ linear: closes only (11.928923ms)
✔ the selected words become the chip's shown text (11.440038ms)
✔ words that are the title make a plain [[Title]] (3.20499ms)
✔ spaces at the selection's edges stay outside the chip (1.235162ms)
✔ a date makes a date link, in a heading, an item and a quote (5.721792ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.012045ms)
✔ only the linked block's bytes change, and undo gives the body back (1.994444ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (1.021031ms)
✔ a target the words cannot be linked to as typed is refused (0.213851ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.224204ms)
✔ web-linked words are refused: the address would be lost (review M4) (0.92393ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.644128ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.380141ms)
✔ linkCheck says why it refuses (review low 2) (0.664484ms)
✔ golden file has bodies (0.915123ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (17.359169ms)
✔ markup.mjs strips and spans every block as Go does (26.346685ms)
✔ the schema's toDOM draws every body as Go renders it (43.713129ms)
✔ emphasis draws the four pinned outputs (12.841082ms)
✔ a body ends in the editor's empty paragraph (0.222747ms)
✔ a POST that never answers is aborted after the timeout (21.137354ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (0.949457ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (9.066774ms)
✔ an offered draft never commits by itself; Save commits it (1.289143ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.661639ms)
✔ closing carries text not yet sent, and the cap leaves it out (23.155711ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (3.347356ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (2.299155ms)
✔ typing mid-flight: the merge is not applied and the base does not move (0.957663ms)
✔ a merge the editor cannot represent stops after three tries (3.008973ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.150123ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.560642ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (0.968143ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.67263ms)
✔ noBase and gone lead to the existing choices (0.679452ms)
✔ a commit that merged is applied when nothing was typed since (0.920193ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (6.743194ms)
✔ an own draft committed meanwhile goes on as a new draft (1.195839ms)
✔ a reload keeps a stored draft; unsent text still commits (0.417792ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (0.879296ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.117785ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (0.965317ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (3.202285ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (0.898993ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.264385ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.802422ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.471883ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.566861ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.468908ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.525434ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.961571ms)
✔ marks close before code, links and atoms, and reopen after (0.998549ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (7.100133ms)
✔ empty blocks are written as nothing (2.230045ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.421942ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.962114ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (3.66945ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (2.460136ms)
✔ a trailing hard break stays on screen and is written as nothing (0.581559ms)
✔ the reparse waits while an IME is composing (0.797994ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.645685ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.858056ms)
✔ rebuild changes origins only, outside undo history (1.576882ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.393699ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (1.647545ms)
✔ a duplicate ^id typed above its holder never takes the id from it (1.320402ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (0.759372ms)
✔ a history command that throws is refused, never thrown (2.282363ms)
✔ one rename at a time, from either field (2.041702ms)
✔ an empty or unchanged title sends nothing (0.217116ms)
✔ a refusal keeps what was typed, and the title (0.272189ms)
✔ the pending state holds for the busy rule (5.312506ms)
✔ a failed POST says so and keeps the title (0.49182ms)
✔ Update links posts the confirm page's POST (0.263503ms)
✔ clean is CleanTitle's whitespace rule (0.136796ms)
✔ the saver's base follows a rename made over it, and only that (0.317354ms)
✔ closing sends the rename as one keepalive POST (1.702627ms)
ℹ tests 89
ℹ suites 0
ℹ pass 89
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4411.049931
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
?   	amadan.net/oficina/mapa/cmd/mapa	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa	0.547s
?   	amadan.net/oficina/mapa/internal/mapa/icons	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa/markup	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/seal	(cached)
ok  	amadan.net/oficina/mapa/internal/mapatest	9.121s
?   	amadan.net/oficina/mapa/scripts/mutate	[no test files]
?   	amadan.net/oficina/mapa/scripts/preview	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
credits: checked
diff --git a/README.md b/README.md
index f63bbcc..4b538c6 100644
--- a/README.md
+++ b/README.md
@@ -67,6 +67,23 @@ the memoria hookup. What it will stand on is already built and tested:
- What remains is the suite contract module, `conformance.CheckProducer`
with §8's pinned expectations, and the routes, as Fichas has them.
+## Deploying
+
+`make release` builds `releases/mapa-linux-arm64`. Ship it declaring that
+the build sends through CARLOS mail submission, then promote it:
+
+ carlos ship --app mapa --account bds --mail submit \
+ --version "$(git describe --tags --always)" releases/mapa-linux-arm64
+ carlos promote --app mapa --account bds <version>
+
+`--mail submit` is what lets `carlos email submission on --app mapa`
+switch Mapa's mail to the platform: every instance must run a build
+shipped with it. Until then Mapa keeps sending over `CARLOS_SMTP_*`, and
+after it the agent sets `CARLOS_MAIL=submit` and Mapa holds no mail
+credential (`mail.FromCarlos`, `internal/mapa/mailer.go`). `carlos
+deploy` has no `--mail` flag yet (carlos main 9eec0236), so ship and
+promote instead of deploying in one step.
+
## Working on it
`AGENTS.md` is the source of truth for the code. `make ci` is the gate;
diff --git a/cmd/mapa/main.go b/cmd/mapa/main.go
index e46c7c2..4a69d4e 100644
--- a/cmd/mapa/main.go
+++ b/cmd/mapa/main.go
@@ -8,7 +8,6 @@ import (
"amadan.net/rastrillo/rastrillo"
"amadan.net/rastrillo/rastrillo/db"
- "amadan.net/rastrillo/rastrillo/mail"
"amadan.net/oficina/mapa/internal/mapa"
)
@@ -50,9 +49,13 @@ func run(logger *slog.Logger) error {
// The mailer before auth: without a real sender rastrillo writes the
// magic link, a live credential, to the log. LoadConfig refuses that
// unless MAPA_ALLOW_LOGGED_MAIL says so on loopback.
+ mailer, err := mapa.Mailer(config, logger)
+ if err != nil {
+ return err
+ }
signins, err := mapa.NewAuth(database.Writer(), mapa.AuthEnv{
Origin: config.Origin, InstanceKey: config.InstanceKey,
- Mailer: mail.FromEnv("CARLOS", logger)}, logger, built.Admit)
+ Mailer: mailer}, logger, built.Admit)
if err != nil {
return err
}
diff --git a/go.mod b/go.mod
index 0826137..f779bcf 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ toolchain go1.26.11
require (
amadan.net/oficina/estilo.git v0.0.0-20261114124532-4d5b9357d49e
- amadan.net/rastrillo/rastrillo v0.35.1-0.20261111230602-f908c5fa31f1
+ amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc
github.com/chromedp/cdproto v0.158.6
github.com/chromedp/chromedp v0.21.0
github.com/go-chi/chi/v5 v5.3.2
diff --git a/go.sum b/go.sum
index a56a189..b807b3e 100644
--- a/go.sum
+++ b/go.sum
@@ -4,6 +4,8 @@ amadan.net/rastrillo/fiesta v1.3.0 h1:7SsHw4aeWPLStR3RHFEEtX4CwqKu+Ig3PgNX8FvD8W
amadan.net/rastrillo/fiesta v1.3.0/go.mod h1:LpO391W1dIRUxOIKklHm+bGyWXtlFyBRRPQCysb9LjY=
amadan.net/rastrillo/rastrillo v0.35.1-0.20261111230602-f908c5fa31f1 h1:tAGrlcgRBwpuJOvowtu7JKZ/QKjwDZIEtQs+EX9ggMI=
amadan.net/rastrillo/rastrillo v0.35.1-0.20261111230602-f908c5fa31f1/go.mod h1:y45ucMD+Al4tN47mmnm7h6pGDw7N20k0CMg6IwB9vfc=
+amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc h1:QakboVkj9nqA6ZaKXeDVXWLPobQSVvd80ic521aA8/U=
+amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc/go.mod h1:y45ucMD+Al4tN47mmnm7h6pGDw7N20k0CMg6IwB9vfc=
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/mapa/config.go b/internal/mapa/config.go
index 25c0dad..6b439e7 100644
--- a/internal/mapa/config.go
+++ b/internal/mapa/config.go
@@ -28,9 +28,12 @@ type Config struct {
InstanceKey string
// Owners is the lone shape's whole admission list (ruling 5).
Owners []string
- // AllowLoggedMail permits booting with no SMTP, so magic links are
+ // AllowLoggedMail permits booting with no mail, so magic links are
// written to the log: loopback origins only.
AllowLoggedMail bool
+ // MailConfigured is true when the platform gave Mapa a way to send:
+ // CARLOS mail submission or SMTP. Mailer builds the sender.
+ MailConfigured bool
// Directory is the hub directory's origin, the menu's "All apps".
Directory string
// TimeZone is the team's default time zone, an instance setting
@@ -97,7 +100,9 @@ func loadSealer(raw string) (*seal.Sealer, error) {
}
// loadMail refuses to boot where every magic link, a live credential,
-// would be written to platform logs we cannot retract.
+// would be written to platform logs we cannot retract. Mail is either
+// channel mail.FromCarlos takes: CARLOS mail submission, which the
+// agent turns on with CARLOS_MAIL=submit, or CARLOS_SMTP_*.
func (config *Config) loadMail(getenv func(string) string) error {
config.AllowLoggedMail = getenv("MAPA_ALLOW_LOGGED_MAIL") == "1"
if config.AllowLoggedMail && !isLocal(config.Origin) {
@@ -105,13 +110,15 @@ func (config *Config) loadMail(getenv func(string) string) error {
"sign-in links to the log and is loopback only, but "+
"MAPA_ORIGIN is %s", config.Origin)
}
- configured := getenv("CARLOS_SMTP_HOST") != "" &&
+ submit := getenv("CARLOS_MAIL") == "submit"
+ smtp := getenv("CARLOS_SMTP_HOST") != "" &&
getenv("CARLOS_SMTP_FROM") != ""
- if !configured && !config.AllowLoggedMail {
- return fmt.Errorf("%w: CARLOS_SMTP_HOST and CARLOS_SMTP_FROM; "+
- "without them every sign-in link goes to the log. Set "+
- "MAPA_ALLOW_LOGGED_MAIL=1 to accept that on loopback",
- ErrMissing)
+ config.MailConfigured = submit || smtp
+ if !config.MailConfigured && !config.AllowLoggedMail {
+ return fmt.Errorf("%w: CARLOS_MAIL=submit, or CARLOS_SMTP_HOST "+
+ "and CARLOS_SMTP_FROM; without one every sign-in link "+
+ "goes to the log. Set MAPA_ALLOW_LOGGED_MAIL=1 to accept "+
+ "that on loopback", ErrMissing)
}
return nil
}
diff --git a/internal/mapa/credits/notices.json b/internal/mapa/credits/notices.json
index d11d56c..e563686 100644
--- a/internal/mapa/credits/notices.json
+++ b/internal/mapa/credits/notices.json
@@ -35,7 +35,7 @@
},
{
"Name": "amadan.net/rastrillo/rastrillo",
- "Version": "v0.35.1-0.20261111230602-f908c5fa31f1",
+ "Version": "v0.35.1-0.20261116213651-96812beacacc",
"SourceURL": "https://amadan.net/rastrillo/rastrillo",
"Notices": [
{
diff --git a/internal/mapa/mailer.go b/internal/mapa/mailer.go
new file mode 100644
index 0000000..9fb229c
--- /dev/null
+++ b/internal/mapa/mailer.go
@@ -0,0 +1,23 @@
+package mapa
+
+import (
+ "log/slog"
+
+ "amadan.net/rastrillo/rastrillo/mail"
+)
+
+// Mailer builds the sign-in sender. Call it only where Mapa serves:
+// a CARLOS seed or one-shot runs with no control socket, and the agent
+// strips CARLOS_MAIL from it, so mail.FromCarlos there would refuse
+// once the app is switched to submission.
+//
+// mail.FromCarlos picks submission when CARLOS_MAIL=submit, else SMTP,
+// and refuses with neither, or with submission half set up. Logged mail
+// is only what LoadConfig admitted: MAPA_ALLOW_LOGGED_MAIL on loopback
+// with no channel at all.
+func Mailer(config Config, logger *slog.Logger) (mail.Sender, error) {
+ if !config.MailConfigured {
+ return mail.FromEnv("CARLOS", logger), nil
+ }
+ return mail.FromCarlos("CARLOS", logger)
+}
diff --git a/internal/mapa/mailer_test.go b/internal/mapa/mailer_test.go
new file mode 100644
index 0000000..1ab6a22
--- /dev/null
+++ b/internal/mapa/mailer_test.go
@@ -0,0 +1,131 @@
+package mapa
+
+import (
+ "context"
+ "errors"
+ "log/slog"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/mail"
+)
+
+// mailEnv is every variable the boot's mail choice reads, so each case
+// starts from none of them whatever the test process inherited.
+var mailEnv = []string{"CARLOS_MAIL", "CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM", "CARLOS_SMTP_HOST",
+ "CARLOS_SMTP_PORT", "CARLOS_SMTP_FROM", "CARLOS_SMTP_USER",
+ "CARLOS_SMTP_PASS"}
+
+// boot is main's mail path: LoadConfig, then Mailer, against the
+// process environment, which is what mail.FromCarlos reads.
+func boot(t *testing.T, env map[string]string) (mail.Sender, error) {
+ t.Helper()
+ for _, key := range mailEnv {
+ t.Setenv(key, "")
+ }
+ for key, value := range env {
+ t.Setenv(key, value)
+ }
+ config, err := LoadConfig(os.Getenv)
+ if err != nil {
+ return nil, err
+ }
+ return Mailer(config, slog.New(slog.DiscardHandler))
+}
+
+// public is a deployed instance: no logged mail, a public origin.
+func public(env map[string]string) map[string]string {
+ full := goodEnv()
+ delete(full, "MAPA_ALLOW_LOGGED_MAIL")
+ full["MAPA_ORIGIN"] = "https://paulca.mapa.oficina.works"
+ for key, value := range env {
+ full[key] = value
+ }
+ return full
+}
+
+// mailVerb is the agent's control socket, answering POST /v1/mail.
+func mailVerb(t *testing.T) (string, chan string) {
+ t.Helper()
+ // A short directory: a unix socket path has a 104-byte limit.
+ dir, err := os.MkdirTemp("/tmp", "mapa-mail")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ socket := filepath.Join(dir, "control.sock")
+ listener, err := net.Listen("unix", socket)
+ if err != nil {
+ t.Fatal(err)
+ }
+ paths := make(chan string, 1)
+ server := &http.Server{Handler: http.HandlerFunc(
+ func(writer http.ResponseWriter, request *http.Request) {
+ paths <- request.Method + " " + request.URL.Path
+ writer.Write([]byte(`{"message_id":"m-1"}`))
+ })}
+ go server.Serve(listener)
+ t.Cleanup(func() { server.Close() })
+ return socket, paths
+}
+
+func TestBootsOnMailSubmission(t *testing.T) {
+ socket, paths := mailVerb(t)
+ sender, err := boot(t, public(map[string]string{
+ "CARLOS_MAIL": "submit", "CARLOS_CONTROL_SOCKET": socket,
+ "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@mapa.oficina.works"}))
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = sender.Send(context.Background(), "ana@example.com",
+ "Sign in", "link")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got := <-paths; got != "POST /v1/mail" {
+ t.Fatalf("the sign-in went to %s, not the mail verb", got)
+ }
+}
+
+func TestBootsOnSMTPAlone(t *testing.T) {
+ sender, err := boot(t, public(map[string]string{
+ "CARLOS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ "CARLOS_SMTP_FROM": "noreply@mapa.oficina.works"}))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !mail.IsConfigured(sender) {
+ t.Fatal("SMTP is configured but the sender only logs")
+ }
+}
+
+func TestRefusesWithNeitherChannel(t *testing.T) {
+ _, err := boot(t, public(nil))
+ if !errors.Is(err, ErrMissing) {
+ t.Fatalf("booted with no mail: %v", err)
+ }
+}
+
+func TestRefusesHalfASubmission(t *testing.T) {
+ // CARLOS_MAIL=submit with no socket: mail.FromCarlos says why.
+ _, err := boot(t, public(map[string]string{"CARLOS_MAIL": "submit",
+ "CARLOS_MAIL_FROM": "noreply@mapa.oficina.works"}))
+ if err == nil {
+ t.Fatal("booted with submission and no control socket")
+ }
+}
+
+func TestLoggedMailStaysLoopbackOnly(t *testing.T) {
+ sender, err := boot(t, goodEnv())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if mail.IsConfigured(sender) {
+ t.Fatal("logged mail on loopback built a real sender")
+ }
+}