carlos / platform Public

console: approved sign-in copy, CARLOS_CONSOLE_NAME, mailer readiness

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 9fcccb93456d8e0e94eac40fba709f6cafbde963 parent 618518c
8 files changed, +243 −11
  • cmd/console/main.go +4 −0
  • internal/console/consolemail.go +17 −0
  • internal/console/consolemail_test.go +52 −0
  • internal/console/delivery_test.go +14 −1
  • internal/console/invite_delivery_test.go +15 −10
  • internal/console/server.go +14 −0
  • internal/console/signincopy.go +66 −0
  • internal/console/signincopy_test.go +61 −0
diff --git a/cmd/console/main.go b/cmd/console/main.go
index bdee22837..b2964f92e 100644
--- a/cmd/console/main.go
+++ b/cmd/console/main.go
@@ -80,6 +80,8 @@
// until a _carlos-mail.<domain> TXT proof is published (#216). There is no
// console email while CARLOS_HOST_CLAIM is on, because the console mailer
// does not yet go through the claim mail gate (#250).
+// CARLOS_CONSOLE_NAME is how the console's emails name it ("Your sign-in link
+// for <name>"); unset, they say "the CARLOS platform".
//
// grant/revoke/owners need only CONSOLE_DB.
package main
@@ -443,6 +445,8 @@ func serve() {
// deployment with no From address or no mail Provisioner — invites
// then fall through to the hand-off link.
ConsoleMail: consoleMail,
+ // ConsoleName is how the console's emails name it (CARLOS_CONSOLE_NAME).
+ ConsoleName: os.Getenv("CARLOS_CONSOLE_NAME"),
// The STUN/TURN relay (relay spec §5). The region list is the whole
// switch: unset is every deployment until an operator arms one, and
// it leaves the relay doors refusing and no background loop running.
diff --git a/internal/console/consolemail.go b/internal/console/consolemail.go
index b0a1a3cc3..6e6152589 100644
--- a/internal/console/consolemail.go
+++ b/internal/console/consolemail.go
@@ -32,6 +32,9 @@ var ErrConsoleMailNotReady = errors.New("console mail: sending identity not veri
type ConsoleMailer interface {
Send(ctx context.Context, to, subject, body string) error
+ // Ready reports whether a Send would go out now: the sending identity is
+ // verified. It makes no SES call, and gives up after two seconds.
+ Ready(ctx context.Context) bool
}
// ConsoleMailFrom resolves the From address: the operator's explicit choice,
@@ -163,6 +166,20 @@ func (m *sesConsoleMailer) ready(ctx context.Context) (string, error) {
return m.configSet, nil
}
+// Ready is the check a page runs before it promises an email: it shares
+// ready's cache and its pending-recheck window, and returns false rather
+// than waiting on a stalled ensure.
+func (m *sesConsoleMailer) Ready(ctx context.Context) bool {
+ if ctx.Err() != nil {
+ // acquire picks at random when the lock is free and ctx is over.
+ return false
+ }
+ ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
+ defer cancel()
+ _, err := m.ready(ctx)
+ return err == nil
+}
+
func (m *sesConsoleMailer) Send(ctx context.Context, to, subject, body string) error {
configSet, err := m.ready(ctx)
if err != nil {
diff --git a/internal/console/consolemail_test.go b/internal/console/consolemail_test.go
index 3130f63bb..b4d447d54 100644
--- a/internal/console/consolemail_test.go
+++ b/internal/console/consolemail_test.go
@@ -90,6 +90,58 @@ func TestConsoleMailerRefusesUntilVerified(t *testing.T) {
}
}
+func TestConsoleMailerReady(t *testing.T) {
+ ctx := context.Background()
+ deployment := testMailDeployment()
+ from := "noreply@console-mail.bab.oncarlos.test"
+
+ // Unverified: false, and nothing goes out through SES.
+ p := mail.NewMemProvisioner("1") // identities stay PENDING
+ ses := &fakeSES{}
+ m := newSESConsoleMailer(from, release.NewDirStore(t.TempDir()), p, dnsrec.NewMemWriter(), deployment, ses)
+ if m.Ready(ctx) {
+ t.Fatal("Ready = true for an unverified identity")
+ }
+ if len(ses.sent) != 0 {
+ t.Fatal("Ready sent mail")
+ }
+
+ // Verified: true, and still nothing sent.
+ p = mail.NewMemProvisioner("1")
+ p.StatusOnEnsure = verifiedStatus
+ ses = &fakeSES{}
+ m = newSESConsoleMailer(from, release.NewDirStore(t.TempDir()), p, dnsrec.NewMemWriter(), deployment, ses)
+ if !m.Ready(ctx) {
+ t.Fatal("Ready = false for a verified identity")
+ }
+ if len(ses.sent) != 0 {
+ t.Fatal("Ready sent mail")
+ }
+
+ // A context that has already ended: false, even though the identity is
+ // verified and cached.
+ ended, cancel := context.WithCancel(ctx)
+ cancel()
+ for i := 0; i < 20; i++ {
+ if m.Ready(ended) {
+ t.Fatal("Ready = true on an ended context")
+ }
+ }
+}
+
+func TestServerConsoleName(t *testing.T) {
+ for _, c := range []struct{ set, want string }{
+ {"", "the CARLOS platform"},
+ {" ", "the CARLOS platform"},
+ {" Acme Console ", "Acme Console"},
+ } {
+ s := &Server{consoleNameCfg: c.set}
+ if got := s.consoleName(); got != c.want {
+ t.Errorf("consoleName() with %q = %q, want %q", c.set, got, c.want)
+ }
+ }
+}
+
func TestConsoleMailerCachesAVerifiedIdentity(t *testing.T) {
ctx := context.Background()
s := release.NewDirStore(t.TempDir())
diff --git a/internal/console/delivery_test.go b/internal/console/delivery_test.go
index a55e3db60..9a9ded897 100644
--- a/internal/console/delivery_test.go
+++ b/internal/console/delivery_test.go
@@ -87,7 +87,7 @@ func TestSendFederatedClassifiesLookupErrors(t *testing.T) {
func deliverFixture(t *testing.T) (*consoleFixture, *fakeConsoleMail) {
t.Helper()
fx := newConsoleFixture(t)
- mailer := &fakeConsoleMail{}
+ mailer := &fakeConsoleMail{ready: true}
fx.srv.consoleMail = mailer
return fx, mailer
}
@@ -129,6 +129,19 @@ func TestDeliverChain(t *testing.T) {
to: func(*consoleFixture) string { return "sam@keymail.dev" },
setup: func(fx *consoleFixture, _ string) { fx.fk.powBits = maxFederationPowBits + 1 },
wantErr: func(err error) bool { return errors.Is(err, ErrFederationPriceTooHigh) }},
+ // The lookup said the mailbox exists, then the delivery itself failed
+ // (neither blocked nor price): still a Keymail address, never SES.
+ {name: "delivery 500 after a good lookup stops",
+ to: func(*consoleFixture) string { return "sam@keymail.dev" },
+ setup: func(fx *consoleFixture, _ string) { fx.fk.deliverStatus = 500 },
+ wantErr: func(err error) bool { var ke *keymailError; return errors.As(err, &ke) && ke.Status == 500 }},
+ {name: "delivery 500 for a custom domain with a mailbox stops",
+ to: func(*consoleFixture) string { return "x@example.com" },
+ setup: func(fx *consoleFixture, to string) {
+ fx.fk.lookupStatus[to] = 200
+ fx.fk.deliverStatus = 500
+ },
+ wantErr: func(err error) bool { var ke *keymailError; return errors.As(err, &ke) && ke.Status == 500 }},
{name: "lookup 500 for the keymail host stops",
to: func(fx *consoleFixture) string { return "x@" + kmHost(fx) },
setup: func(fx *consoleFixture, to string) { fx.fk.lookupStatus[to] = 500 },
diff --git a/internal/console/invite_delivery_test.go b/internal/console/invite_delivery_test.go
index 2e34e097b..fbffe785d 100644
--- a/internal/console/invite_delivery_test.go
+++ b/internal/console/invite_delivery_test.go
@@ -18,8 +18,13 @@ type fakeConsoleMail struct {
mu sync.Mutex
err error
sent []string // to|body
+ // ready is what Ready reports. Construct with ready: true wherever the
+ // test expects the console to be able to send.
+ ready bool
}
+func (f *fakeConsoleMail) Ready(context.Context) bool { return f.ready }
+
func (f *fakeConsoleMail) Send(_ context.Context, to, _, body string) error {
f.mu.Lock()
defer f.mu.Unlock()
@@ -62,28 +67,28 @@ func TestInviteDelivery(t *testing.T) {
wantFed bool
wantMail bool
}{
- {name: "keymail delivers", to: "sam@keymail.dev", mail: &fakeConsoleMail{},
+ {name: "keymail delivers", to: "sam@keymail.dev", mail: &fakeConsoleMail{ready: true},
wantKind: "ok", wantInMsg: "Keymail", wantFed: true},
- {name: "no mailbox, email delivers", to: "sam@gmail.com", mail: &fakeConsoleMail{},
+ {name: "no mailbox, email delivers", to: "sam@gmail.com", mail: &fakeConsoleMail{ready: true},
wantKind: "ok", wantInMsg: "emailed", wantMail: true},
// The address is a Keymail mailbox (the lookup said so); a price above
// the cap is not a reason to email it (spec 4.3).
- {name: "price too high is final", to: "sam@keymail.dev", mail: &fakeConsoleMail{},
+ {name: "price too high is final", to: "sam@keymail.dev", mail: &fakeConsoleMail{ready: true},
keymail: func(fx *consoleFixture) { fx.fk.powBits = maxFederationPowBits + 1 },
wantKind: "err", wantInMsg: "/invite/"},
// A Keymail outage for the Keymail host's own address sends nothing.
- {name: "keymail host lookup 5xx is final", to: "sam@127.0.0.1", mail: &fakeConsoleMail{},
+ {name: "keymail host lookup 5xx is final", to: "sam@127.0.0.1", mail: &fakeConsoleMail{ready: true},
keymail: func(fx *consoleFixture) { fx.fk.lookupStatus["sam@127.0.0.1"] = 500 },
wantKind: "err", wantInMsg: "/invite/"},
- {name: "other domain lookup 5xx falls to email", to: "sam@example.com", mail: &fakeConsoleMail{},
+ {name: "other domain lookup 5xx falls to email", to: "sam@example.com", mail: &fakeConsoleMail{ready: true},
keymail: func(fx *consoleFixture) { fx.fk.lookupStatus["sam@example.com"] = 500 },
wantKind: "ok", wantInMsg: "emailed", wantMail: true},
// A recipient who blocked the console said no; email to the same
// address would go round them. Straight to the hand-off.
- {name: "blocked is final", to: "sam@keymail.dev", mail: &fakeConsoleMail{},
+ {name: "blocked is final", to: "sam@keymail.dev", mail: &fakeConsoleMail{ready: true},
keymail: func(fx *consoleFixture) { fx.fk.blocked["console@"+OriginHost(fx.ts.URL)] = true },
wantKind: "err", wantInMsg: "/invite/"},
- {name: "both fail", to: "sam@gmail.com", mail: &fakeConsoleMail{err: ErrConsoleMailNotReady},
+ {name: "both fail", to: "sam@gmail.com", mail: &fakeConsoleMail{ready: true, err: ErrConsoleMailNotReady},
wantKind: "err", wantInMsg: "/invite/"},
{name: "no email configured", to: "sam@gmail.com",
wantKind: "err", wantInMsg: "/invite/"},
@@ -151,7 +156,7 @@ func TestInviteDeliversWithoutTheInvitersGrant(t *testing.T) {
// Review Focus 3: a Keymail that never answers must not swallow the email leg.
func TestInviteFallsBackWhenKeymailHangs(t *testing.T) {
fx := newConsoleFixture(t)
- mailer := &fakeConsoleMail{}
+ mailer := &fakeConsoleMail{ready: true}
fx.srv.consoleMail = mailer
fx.srv.inviteTimeout = 300 * time.Millisecond
fx.srv.inviteKeymailShare = 150 * time.Millisecond
@@ -218,7 +223,7 @@ func inviteAttempts(fx *consoleFixture) (fed *int, mailer *fakeConsoleMail) {
n++
return "id", nil
}
- mailer = &fakeConsoleMail{}
+ mailer = &fakeConsoleMail{ready: true}
fx.srv.consoleMail = mailer
return &n, mailer
}
@@ -363,7 +368,7 @@ func TestInviteRefusesAnythingButOneBareAddress(t *testing.T) {
// as such.
func TestInviteLogsNoMailboxQuietly(t *testing.T) {
fx := newConsoleFixture(t)
- fx.srv.consoleMail = &fakeConsoleMail{}
+ fx.srv.consoleMail = &fakeConsoleMail{ready: true}
owner := newBrowser(t)
signUp(t, fx, owner, "code-owner")
csrf := sessionToken(t, fx, owner)
diff --git a/internal/console/server.go b/internal/console/server.go
index 2009ee332..ae055b028 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -794,6 +794,9 @@ type Config struct {
// ConsoleMail is the console's own email sender (consolemail.go), the
// invite fallback when Keymail cannot deliver. nil: no email fallback.
ConsoleMail ConsoleMailer
+ // ConsoleName is how this console names itself in the emails it sends
+ // (CARLOS_CONSOLE_NAME). Empty reads "the CARLOS platform".
+ ConsoleName string
// RelayRegions are the AWS regions this deployment runs a STUN/TURN
// relay in (CARLOS_RELAY_REGIONS, comma-separated), IN THE ORDER an
// enabled app's CARLOS_RELAY lists them — the order every browser will
@@ -953,6 +956,7 @@ type Server struct {
// console's own email. Fields so tests can substitute and shrink them.
sendFederated func(ctx context.Context, to, subject, body string) (string, error)
consoleMail ConsoleMailer
+ consoleNameCfg string
inviteTimeout time.Duration
inviteKeymailShare time.Duration
// inviteRate is each account's invites created in the last hour
@@ -1172,6 +1176,15 @@ type edgeFoldCache struct {
// its steering hostname, read from ONE place so the app page, the Settings
// page and the /domains API can never disagree about where a member should
// point DNS.
+// consoleName is what the console's emails call it: the operator's
+// CARLOS_CONSOLE_NAME, else today's wording.
+func (s *Server) consoleName() string {
+ if n := strings.TrimSpace(s.consoleNameCfg); n != "" {
+ return n
+ }
+ return "the CARLOS platform"
+}
+
func (s *Server) dnsTargets() DNSTargets {
return DNSTargets{EdgeIPs: s.edgeIPs(), SteeringHost: s.steeringHost}
}
@@ -1339,6 +1352,7 @@ func NewServer(cfg Config, st *Store) (*Server, error) {
lookupTXT: cfg.LookupTXT,
storeWalks: newStoreWalkLocks(),
consoleMail: cfg.ConsoleMail,
+ consoleNameCfg: cfg.ConsoleName,
inviteTimeout: 20 * time.Second,
inviteKeymailShare: 12 * time.Second,
// This process's identity in the relay writer lease. Random rather
diff --git a/internal/console/signincopy.go b/internal/console/signincopy.go
new file mode 100644
index 000000000..9f1a848d5
--- /dev/null
+++ b/internal/console/signincopy.go
@@ -0,0 +1,66 @@
+// The approved copy for email sign-in, by review id. The strings are the
+// reviewed text byte for byte; TestSigninCopyMatchesApproved pins this map to
+// docs/superpowers/specs/2026-10-21-console-email-signin-copy-approved.json.
+package console
+
+import "strings"
+
+// signinCopy holds every approved string by its review id.
+var signinCopy = map[string]string{
+ "home.email_label": "Your email address",
+ "home.email_placeholder": "you@example.com",
+ "home.email_button": "Continue",
+ "home.small": "New here or coming back, it's the same form. Keymail addresses sign in with Keymail. Any other address gets a link and a code by email, and your first sign-in sets up your account. No passwords.",
+ "home.invite_prompt": "Sign in as {address} to accept your invitation.",
+ "home.cli_prompt": "Sign in to approve your terminal.",
+ "home.bad_address": "That doesn't look like an email address.",
+ "home.no_mail": "This console can't send email yet, so it can only sign in Keymail addresses for now.",
+ "check.title": "Check your email",
+ "check.sent": "A sign-in link and code are on their way to {address}. Both work once, for 15 minutes.",
+ "check.code_label": "Or type the code from the email",
+ "check.code_button": "Sign in",
+ "check.code_wrong": "That code doesn't match. Check the email and try again.",
+ "check.code_used_up": "That code has expired or had too many wrong tries. Ask for a new link below.",
+ "check.code_throttled": "Too many wrong codes for this address. Use the link in the email, or try again later.",
+ "check.nothing": "Nothing arriving? Check your spam folder, or ask for a new link. You can ask once a minute.",
+ "check.again_button": "Send a new link",
+ "link.title": "Sign in as {address}?",
+ "link.button": "Sign in",
+ "link.expired": "That sign-in link has expired or was already used. Ask for a new one from the front page.",
+ "link.wrong_site": "That sign-in didn't come from this page, so we stopped it. Open the link from your email again.",
+ "stepup.title": "Confirm it's you",
+ "stepup.sent": "To finish this, we've sent a link and a code to {address}. They work for 10 minutes, and only in this browser. Nothing has changed yet.",
+ "stepup.code_label": "Type the code from the email",
+ "stepup.code_button": "Confirm",
+ "stepup.link_title": "Confirm it's you",
+ "stepup.link_button": "Confirm and continue",
+ "stepup.wrong_browser": "Open this link in the browser where you started, or type the code there. Nothing has changed.",
+ "stepup.expired": "That confirmation has expired or was already used. Nothing has changed. Try the action again.",
+ "email.signin.subject": "Your sign-in link for {console}",
+ "email.signin.body": "Someone, hopefully you, asked to sign in to {console} as {address}.\n\nOpen this link to sign in:\n\n{link}\n\nOr type this code on the page that's waiting: {code}\n\nThe link and the code work once, for 15 minutes. If this wasn't you, ignore this email. Nothing happens without the link or the code.",
+ "email.stepup.subject": "Confirm it's you on {console}",
+ "email.stepup.body": "Someone signed in to {console} as {address} started an action that needs you to confirm it's you.\n\nOpen this link in the same browser to confirm:\n\n{link}\n\nOr type this code there: {code}\n\nThey work once, for 10 minutes. If this wasn't you, don't confirm. Sign in again and check your account's members and command line logins.",
+ "email.invite.body": "{inviter} invited you to the account \"{account}\" on {console}.\n\nOpen this link to accept. You'll sign in as {to} first if you aren't already:\n\n{link}\n\nIt works once and expires in 7 days. If you weren't expecting this, ignore it. Nothing happens without the link.",
+ "team.confirm_note": "Removing a member, handing over ownership and deleting the account each ask you to confirm it's you. A signed-in browser on its own isn't enough.",
+ "team.invite_placeholder": "them@example.com",
+ "team.invite_note": "We send the invitation by email, or to Keymail for Keymail addresses. It works once and expires in 7 days.",
+ "team.bad_address": "That doesn't look like an email address.",
+}
+
+// copyText returns the approved string for id with each {key} placeholder
+// replaced by its value (kv is key, value, key, value, ...). An unknown id is
+// a programming error and panics, so a typo cannot ship blank copy.
+func copyText(id string, kv ...string) string {
+ text, ok := signinCopy[id]
+ if !ok {
+ panic("console: unknown copy id " + id)
+ }
+ if len(kv)%2 != 0 {
+ panic("console: copyText " + id + ": odd number of placeholder arguments")
+ }
+ pairs := make([]string, 0, len(kv))
+ for i := 0; i < len(kv); i += 2 {
+ pairs = append(pairs, "{"+kv[i]+"}", kv[i+1])
+ }
+ return strings.NewReplacer(pairs...).Replace(text)
+}
diff --git a/internal/console/signincopy_test.go b/internal/console/signincopy_test.go
new file mode 100644
index 000000000..3b9884af7
--- /dev/null
+++ b/internal/console/signincopy_test.go
@@ -0,0 +1,61 @@
+package console
+
+import (
+ "encoding/json"
+ "os"
+ "testing"
+)
+
+func TestSigninCopyMatchesApproved(t *testing.T) {
+ raw, err := os.ReadFile("../../docs/superpowers/specs/2026-10-21-console-email-signin-copy-approved.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var approved struct {
+ Action string `json:"action"`
+ Strings []struct {
+ ID string `json:"id"`
+ Text string `json:"text"`
+ } `json:"strings"`
+ }
+ if err := json.Unmarshal(raw, &approved); err != nil {
+ t.Fatal(err)
+ }
+ if approved.Action != "approve" {
+ t.Fatalf("action = %q, want approve", approved.Action)
+ }
+ seen := map[string]bool{}
+ for _, s := range approved.Strings {
+ seen[s.ID] = true
+ got, ok := signinCopy[s.ID]
+ if !ok {
+ t.Errorf("approved id %q missing from signinCopy", s.ID)
+ continue
+ }
+ if got != s.Text {
+ t.Errorf("%s = %q, approved %q", s.ID, got, s.Text)
+ }
+ }
+ for id := range signinCopy {
+ if !seen[id] {
+ t.Errorf("signinCopy has %q, which is not in the approved copy", id)
+ }
+ }
+ if len(signinCopy) != len(approved.Strings) {
+ t.Errorf("signinCopy has %d strings, approved copy has %d", len(signinCopy), len(approved.Strings))
+ }
+}
+
+func TestCopyTextFillsPlaceholders(t *testing.T) {
+ for id, text := range signinCopy {
+ if got := copyText(id); got != text {
+ t.Errorf("copyText(%q) with no arguments changed the text", id)
+ }
+ }
+ defer func() {
+ if recover() == nil {
+ t.Error("copyText of an unknown id did not panic")
+ }
+ }()
+ copyText("no.such.id")
+}