demo claims: ready without a mailer when Keymail can finish
Claim readiness keeps the Keymail OAuth requirement but no longer needs a mailer; email-code starts on a mailer-less console stay 503 before any send budget. The claim result page names carlos auth login --console. Squashed from demo-claim-keymail-ready into main. Co-Authored-By: codex <codex~paul@keymail.dev>
7 files changed,
+108
−23
README.md+2 −2internal/console/demo_claim_browser_test.go+1 −1internal/console/demo_claim_copy.go+1 −1internal/console/demo_claim_no_mailer_test.go+70 −0internal/console/demo_claim_page.go+2 −1internal/console/demo_claim_ready.go+3 −3internal/console/demo_claim_ready_test.go+29 −15
CI passed — run details
diff --git a/README.md b/README.md| index 5fcd5804a..420933e9e 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -694,7 +694,7 @@ For an agent, use these JSON endpoints on the console: |
| | `POST /api/demo/claims/select` with `flowToken` and `accountId` | Reserves a claim in that exact account if membership and plan limits allow it. Use its sqid, not its name. | |
| | `GET /api/demo/claims/status` with `Authorization: Bearer <flowToken>` | `202` with `state:claiming`, `phase` and `retryAfter:2`, or `200` with `state:claimed`, `accountId`, `app`, `url` and `next:cli_login`. | |
| -Keep both tokens private. All responses are `no-store`. Proof lasts at most 15 minutes and never beyond the original demo expiry. Resending does not extend it. After reservation, the flow token can only read that operation's status, until the original expiry plus 24 hours. Successful commitment consumes the demo token. It does not issue a CLI or account credential. Use `carlos login` and the ordinary account workflow to deploy subsequent changes. |
| +Keep both tokens private. All responses are `no-store`. Proof lasts at most 15 minutes and never beyond the original demo expiry. Resending does not extend it. After reservation, the flow token can only read that operation's status, until the original expiry plus 24 hours. Successful commitment consumes the demo token. It does not issue a CLI or account credential. Use `carlos auth login --console <console URL>` and the ordinary account workflow to deploy subsequent changes. |
| A claim counts as an app plus an instance against the chosen account's limits. It briefly stops the source to copy committed SQLite data, including WAL contents. The destination stays gated until verification and commitment. DB plus WAL and the final snapshot each have a 256 MiB limit. Unsupported placement, a full plan or a failed copy cannot create a permanent serving app. Before commitment, recovery must confirm that the destination stopped before releasing the source. If that confirmation is missing, the source stays held. No retry extends the demo's original 24 hours. |
| @@ -702,7 +702,7 @@ After success, the old URL displays a link to the permanent app until the origin |
| #### Claim activation and recovery |
| -The controller activates dev after the branch lands and the gated acceptance checks pass. Keep the production switch unset pending its separately scoped rollout. Set `CARLOS_DEMO_CLAIM=1` in the console's drop-in alongside the existing demo settings. Claims require a ready mailer and configured Keymail path, a connected export-capable demo worker, ordinary nested arm64 placement in the console's data region, no HA or host claims, a policy writer, streaming seed storage and change delivery. Enable the existing shared watch with `CARLOS_CHANGE_INDEX=read`. Every serving edge must report the moved-page and claim-seed capabilities. A failed readiness check gives the uniform `503 unavailable`; `claimAvailable` stays false. Readiness successes and failures are cached for 45 seconds, with a separate 10-second check deadline. |
| +The controller activates dev after the branch lands and the gated acceptance checks pass. Keep the production switch unset pending its separately scoped rollout. Set `CARLOS_DEMO_CLAIM=1` in the console's drop-in alongside the existing demo settings. Claims require a configured Keymail path, a connected export-capable demo worker, ordinary nested arm64 placement in the console's data region, no HA or host claims, a policy writer, streaming seed storage and change delivery. Enable the existing shared watch with `CARLOS_CHANGE_INDEX=read`. Every serving edge must report the moved-page and claim-seed capabilities. Without a ready mailer, only Keymail addresses can claim, in the browser; other addresses get `503 unavailable` when they start, so `claimAvailable` can be true while email codes are not. A failed readiness check gives the uniform `503 unavailable`; `claimAvailable` stays false. Readiness successes and failures are cached for 45 seconds, with a separate 10-second check deadline. |
| Before activation, publish the signed seeds floor with minimum protocol **2** and confirm acceptance on every reader, including rollback binaries. The existing `carlos system seeds-floor publish` door now republishes minimum 2. An old minimum-1 publication is insufficient even when all running binaries are new. Use the existing demo wildcard and housekeeper certificate path. New DNS, IAM or provisioning work requires its own scoped approval. |
diff --git a/internal/console/demo_claim_browser_test.go b/internal/console/demo_claim_browser_test.go| index 751156b68..10fd67854 100644 |
| --- a/internal/console/demo_claim_browser_test.go |
| +++ b/internal/console/demo_claim_browser_test.go |
| @@ -321,7 +321,7 @@ func TestDemoClaimBrowserStatus(t *testing.T) { |
| if w.Code != 200 { |
| t.Fatalf("%s status: %d", phase, w.Code) |
| } |
| - if phase == "done" && (!strings.Contains(w.Body.String(), op.Target.Host) || !strings.Contains(w.Body.String(), op.Target.App) || !strings.Contains(w.Body.String(), op.Target.Sqid) || !strings.Contains(w.Body.String(), "carlos login")) { |
| + if phase == "done" && (!strings.Contains(w.Body.String(), op.Target.Host) || !strings.Contains(w.Body.String(), op.Target.App) || !strings.Contains(w.Body.String(), op.Target.Sqid) || !strings.Contains(w.Body.String(), "carlos auth login --console "+s.cfg.Origin)) { |
| t.Fatalf("result missing: %s", w.Body.String()) |
| } |
| } |
diff --git a/internal/console/demo_claim_copy.go b/internal/console/demo_claim_copy.go| index 5a648e948..2ea655557 100644 |
| --- a/internal/console/demo_claim_copy.go |
| +++ b/internal/console/demo_claim_copy.go |
| @@ -74,7 +74,7 @@ const ( |
| // CLAIM-RESULT: result URL label. |
| demoClaimURLLabel = "Open app" |
| // CLAIM-RESULT: next workflow. |
| - demoClaimCLINext = "To deploy changes, sign in with the CLI: carlos login" |
| + demoClaimCLINext = "To deploy changes, sign in with the CLI: carlos auth login --console %s" |
| // CLAIM-RETIRED: unsuccessful operation. |
| demoClaimAborted = "This claim did not finish. Open the original demo link to try again if the demo has not expired." |
| ) |
diff --git a/internal/console/demo_claim_no_mailer_test.go b/internal/console/demo_claim_no_mailer_test.go| new file mode 100644 |
| index 000000000..ca5926913 |
| --- /dev/null |
| +++ b/internal/console/demo_claim_no_mailer_test.go |
| @@ -0,0 +1,70 @@ |
| +package console |
| + |
| +import ( |
| + "encoding/json" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func claimNoMailerServer(t *testing.T) (*Server, string) { |
| + t.Helper() |
| + s, _, token := claimTestServer(t) |
| + claimActivationFixture(t, s) |
| + s.consoleMail = nil |
| + fk := newFakeKeymail(t, "shop@example.com") |
| + fk.mu.Lock() |
| + fk.lookupStatus["shop@example.com"] = 404 |
| + fk.mu.Unlock() |
| + s.km = NewKeymail(fk.srv.URL, s.cfg.Origin) |
| + return s, token |
| +} |
| + |
| +func claimNoSendBudget(t *testing.T, s *Server) { |
| + t.Helper() |
| + s.limits.mu.Lock() |
| + defer s.limits.mu.Unlock() |
| + if len(s.limits.addrSends.hits) != 0 || len(s.limits.ipSends.hits) != 0 || len(s.limits.globalSend) != 0 { |
| + t.Fatal("claim start changed shared send-limit state") |
| + } |
| +} |
| + |
| +func TestDemoClaimEmailNoMailer(t *testing.T) { |
| + s, token := claimNoMailerServer(t) |
| + claimNoSendBudget(t, s) |
| + for range 31 { |
| + _, w := claimStart(t, s, token, "shop@example.com", "") |
| + var reply struct{ Error string } |
| + if w.Code != 503 || json.Unmarshal(w.Body.Bytes(), &reply) != nil || reply.Error != demoClaimUnavailable { |
| + t.Fatalf("no mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| + } |
| + if claimBrowserCount(t, s, "demo_claim_flows") != 0 { |
| + t.Fatal("unavailable email start created a flow") |
| + } |
| + _, w := claimStart(t, s, token, "shop@"+s.km.Host(), "") |
| + var reply struct{ State, ClaimURL string } |
| + if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &reply) != nil || reply.State != "browser_required" || reply.ClaimURL != s.cfg.Origin+"/demo/claim#"+token { |
| + t.Fatalf("Keymail without mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| +} |
| + |
| +func TestDemoClaimBrowserNoMailer(t *testing.T) { |
| + s, token := claimNoMailerServer(t) |
| + b := newClaimBrowser(t, s, token) |
| + claimNoSendBudget(t, s) |
| + for range 31 { |
| + w := b.post("/demo/claim/prove", url.Values{"email": {"shop@example.com"}}) |
| + if w.Code != 503 || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/html") || !strings.Contains(w.Body.String(), `<p role="alert">`+demoClaimUnavailable+`</p>`) { |
| + t.Fatalf("no mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| + } |
| + w := b.post("/demo/claim/prove", url.Values{"email": {"shop@" + s.km.Host()}}) |
| + if w.Code != 303 || w.Header().Get("Location") != "/auth/signin?next=%2Fdemo%2Fclaim" { |
| + t.Fatalf("Keymail without mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| +} |
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go| index 1ad62d695..2b0a89493 100644 |
| --- a/internal/console/demo_claim_page.go |
| +++ b/internal/console/demo_claim_page.go |
| @@ -94,6 +94,7 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| } |
| address, session, _ := s.session(r) |
| p := demoClaimPageData{Copy: demoClaimBrowserCopy(), Nonce: demoClaimNonce(cookie, session), CSRF: session, Address: address, State: "missing"} |
| + p.Copy["next"] = fmt.Sprintf(demoClaimCLINext, s.cfg.Origin) |
| hash, err := s.store.demoClaimBrowserHash(r.Context(), cookie, time.Now()) |
| if err == nil { |
| if op, opErr := s.store.demoClaimOpForFlow(r.Context(), hash); opErr == nil { |
| @@ -466,7 +467,7 @@ func (s *Server) demoClaimSessionIdentity(raw, person string) (string, string, b |
| } |
| func demoClaimBrowserCopy() map[string]string { |
| - return map[string]string{"back": demoClaimBack, "noAccounts": demoClaimNoEligibleAccount, "title": demoClaimPageTitle, "missing": demoClaimIntentExpired, "failed": demoClaimExchangeFailed, "noscript": demoClaimNeedsScript, "identity": demoClaimIdentityLabel, "email": demoClaimEmailLabel, "continue": demoClaimEmailContinue, "code": demoClaimCodeLabel, "prove": demoClaimCodeConfirm, "sent": demoClaimEmailSent, "signin": demoClaimSignin, "account": demoClaimAccountLabel, "choose": demoClaimChooseAccount, "new": demoClaimNewAccount, "confirm": demoClaimConfirm, "working": demoClaimWorking, "reload": demoClaimReload, "complete": demoClaimComplete, "app": demoClaimAppLabel, "url": demoClaimURLLabel, "next": demoClaimCLINext, "aborted": demoClaimAborted, "disabled": demoClaimUnavailable} |
| + return map[string]string{"back": demoClaimBack, "noAccounts": demoClaimNoEligibleAccount, "title": demoClaimPageTitle, "missing": demoClaimIntentExpired, "failed": demoClaimExchangeFailed, "noscript": demoClaimNeedsScript, "identity": demoClaimIdentityLabel, "email": demoClaimEmailLabel, "continue": demoClaimEmailContinue, "code": demoClaimCodeLabel, "prove": demoClaimCodeConfirm, "sent": demoClaimEmailSent, "signin": demoClaimSignin, "account": demoClaimAccountLabel, "choose": demoClaimChooseAccount, "new": demoClaimNewAccount, "confirm": demoClaimConfirm, "working": demoClaimWorking, "reload": demoClaimReload, "complete": demoClaimComplete, "app": demoClaimAppLabel, "url": demoClaimURLLabel, "aborted": demoClaimAborted, "disabled": demoClaimUnavailable} |
| } |
| func demoClaimCanCreate(a Account) bool { return a.Role == RoleOwner || a.Role == RoleMember } |
diff --git a/internal/console/demo_claim_ready.go b/internal/console/demo_claim_ready.go| index 2dfd66f5a..0115f0fb4 100644 |
| --- a/internal/console/demo_claim_ready.go |
| +++ b/internal/console/demo_claim_ready.go |
| @@ -33,9 +33,9 @@ func (s *Server) demoClaimReady(ctx context.Context) error { |
| func (s *Server) checkDemoClaimReady(ctx context.Context) error { |
| refuse := func() error { return errors.New(demoClaimUnavailable) } |
| - // Keymail discovery has its existing email fallback. Do not probe a person's |
| - // identity or add provider polling: require the OAuth path and ready mailer. |
| - if !s.mailReady(ctx) || s.km == nil || s.km.Host() == "" || s.cfg.AppsDomain == "" || |
| + // Readiness means the browser Keymail path can complete. Email-code starts |
| + // are refused per request when no mailer is ready. |
| + if s.km == nil || s.km.Host() == "" || s.cfg.AppsDomain == "" || |
| len(s.cfg.Key) != ed25519.PrivateKeySize || len(s.cfg.ReleasePub) != ed25519.PublicKeySize || |
| s.cfg.Releases == nil || s.cfg.SeedData == nil || !s.leftoverCheckApplies(s.cfg.Region, "") { |
| return refuse() |
diff --git a/internal/console/demo_claim_ready_test.go b/internal/console/demo_claim_ready_test.go| index d789b65ff..aa5bfda7f 100644 |
| --- a/internal/console/demo_claim_ready_test.go |
| +++ b/internal/console/demo_claim_ready_test.go |
| @@ -34,7 +34,7 @@ func claimActivationFixture(t *testing.T, s *Server) { |
| } |
| func TestDemoClaimReadiness(t *testing.T) { |
| - for _, missing := range []string{"", "mail", "keymail", "worker", "seed", "moved", "policy", "delivery", "data", "placement"} { |
| + for _, missing := range []string{"", "mail", "keymail", "mailAndKeymail", "keymailHost", "worker", "seed", "moved", "policy", "delivery", "data", "placement"} { |
| t.Run(missing, func(t *testing.T) { |
| s, _, _ := claimTestServer(t) |
| claimActivationFixture(t, s) |
| @@ -43,6 +43,11 @@ func TestDemoClaimReadiness(t *testing.T) { |
| s.consoleMail = nil |
| case "keymail": |
| s.km = nil |
| + case "mailAndKeymail": |
| + s.consoleMail = nil |
| + s.km = nil |
| + case "keymailHost": |
| + s.km = NewKeymail("", s.cfg.Origin) |
| case "worker": |
| s.demoJobs.peers["box"].ready.ClaimCapability = "" |
| case "seed": |
| @@ -62,10 +67,11 @@ func TestDemoClaimReadiness(t *testing.T) { |
| ctx, cancel := context.WithCancel(t.Context()) |
| cancel() |
| err := s.demoClaimReady(ctx) |
| - if (err != nil) != (missing != "") { |
| + ready := missing == "" || missing == "mail" |
| + if (err == nil) != ready { |
| t.Fatalf("readiness %q: %v", missing, err) |
| } |
| - if s.demoClaimEnabled() != (missing == "") { |
| + if s.demoClaimEnabled() != ready { |
| t.Fatal("enabled ignores readiness") |
| } |
| }) |
| @@ -81,7 +87,8 @@ func TestDemoClaimReadinessCache(t *testing.T) { |
| t.Fatal(err) |
| } |
| gets, lists := counted.gets.Load(), counted.lists.Load() |
| - s.consoleMail = nil |
| + km := s.km |
| + s.km = nil |
| for range 3 { |
| if err := s.demoClaimReady(t.Context()); err != nil { |
| t.Fatal(err) |
| @@ -97,7 +104,7 @@ func TestDemoClaimReadinessCache(t *testing.T) { |
| if s.demoClaimReady(t.Context()) == nil { |
| t.Fatal("stale success") |
| } |
| - s.consoleMail = &fakeConsoleMail{ready: true} |
| + s.km = km |
| if s.demoClaimReady(t.Context()) == nil { |
| t.Fatal("failure not cached") |
| } |
| @@ -124,13 +131,14 @@ func TestDemoClaimRecoveryRoutes(t *testing.T) { |
| } |
| } |
| -func TestDemoClaimAvailabilityResponse(t *testing.T) { |
| +func TestDemoClaimReadinessAvailabilityResponse(t *testing.T) { |
| for _, ready := range []bool{false, true} { |
| t.Run(map[bool]string{false: "notReady", true: "ready"}[ready], func(t *testing.T) { |
| s, _ := demoJobServer(t) |
| claimActivationFixture(t, s) |
| + s.consoleMail = nil |
| if !ready { |
| - s.consoleMail = nil |
| + s.km = nil |
| } |
| r := httptest.NewRequest("POST", "/api/demo/apps", bytes.NewReader(demoHTTPSource(t))) |
| r.RemoteAddr = "192.0.2.1:1" |
| @@ -148,28 +156,34 @@ func TestDemoClaimAvailabilityResponse(t *testing.T) { |
| } |
| } |
| -type claimDeadlineMail struct { |
| - *fakeConsoleMail |
| - t *testing.T |
| +type claimDeadlineStore struct { |
| + release.Store |
| + t *testing.T |
| + checked bool |
| } |
| -func (m claimDeadlineMail) Ready(ctx context.Context) bool { |
| - m.t.Helper() |
| +func (s *claimDeadlineStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + s.t.Helper() |
| deadline, ok := ctx.Deadline() |
| if !ok || time.Until(deadline) > 10*time.Second || time.Until(deadline) < 9*time.Second || ctx.Err() != nil { |
| - m.t.Fatal("readiness did not receive its own ten-second context") |
| + s.t.Fatal("readiness did not receive its own ten-second context") |
| } |
| - return true |
| + s.checked = true |
| + return s.Store.Get(ctx, key) |
| } |
| func TestDemoClaimReadinessDeadline(t *testing.T) { |
| s, _, _ := claimTestServer(t) |
| claimActivationFixture(t, s) |
| - s.consoleMail = claimDeadlineMail{fakeConsoleMail: &fakeConsoleMail{ready: true}, t: t} |
| + store := &claimDeadlineStore{Store: s.cfg.Releases, t: t} |
| + s.cfg.Releases = store |
| ctx, cancel := context.WithCancel(t.Context()) |
| cancel() |
| if err := s.demoClaimReady(ctx); err != nil { |
| t.Fatal(err) |
| } |
| + if !store.checked { |
| + t.Fatal("readiness did not check the deployment store") |
| + } |
| } |
| func TestDemoClaimReadinessWithPurgedStrays(t *testing.T) { |