console: approved claim-journey pages (ticket, cards, progress, tada)
Paul's approved claim UX, item 1. The app ticket from the first screen; Keymail explained before leaving; account cards with used slots and reasons; real stages from /demo/claim/status, each shown at least 650 ms with no blank gap; working buttons; the tada (address moves home, clock to tick, one burst, big Open your app), settled on reload; calm motion; expired and kept states. CSP unchanged. Same-page retry not built: it needs new bounded authority (asked platform-f6). Luna copy verbatim. Opus review approve with nits, applied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from claim-ux-pages into main. Co-Authored-By: claude <claude~paul@keymail.dev>
11 files changed,
+740
−120
internal/console/demo_claim_choice_test.go+11 −9internal/console/demo_claim_copy.go+51 −10internal/console/demo_claim_csp_test.go+6 −6internal/console/demo_claim_page.go+40 −1internal/console/demo_claim_review_test.go+1 −1internal/console/demo_claim_ux_test.go+222 −0internal/console/static/demo_claim.js+132 −49internal/console/templates/demo_claim.html+132 −30internal/console/testdata/demo_claim_browser.mjs+113 −4internal/console/testdata/demo_claim_layout.mjs+21 −1internal/console/testdata/demo_claim_resume_browser.mjs+11 −9
CI passed — run details
diff --git a/internal/console/demo_claim_choice_test.go b/internal/console/demo_claim_choice_test.go| index 2e64d73aa..6e94cb44b 100644 |
| --- a/internal/console/demo_claim_choice_test.go |
| +++ b/internal/console/demo_claim_choice_test.go |
| @@ -36,7 +36,7 @@ func TestDemoClaimChoiceRendering(t *testing.T) { |
| t.Fatal(err) |
| } |
| body := b.request("GET", "/demo/claim", nil).Body.String() |
| - for _, want := range []string{d.Name, d.Host, "Its saved data comes with it", "a permanent address on apps.example.com"} { |
| + for _, want := range []string{d.Name, d.Host, `class="claim-ticket`, `class="claim-clock"`} { |
| if !strings.Contains(body, want) { |
| t.Errorf("missing %q", want) |
| } |
| @@ -110,7 +110,7 @@ func TestDemoClaimStatusDoor(t *testing.T) { |
| t.Errorf("%s lost polling", tc.phase) |
| } |
| } |
| - if tc.state == "stopping" && !strings.Contains(page, "The claim did not finish. The demo is not serving its pages while we undo the claim.") { |
| + if tc.state == "stopping" && !strings.Contains(page, demoClaimStopping) { |
| t.Error("missing stopping explanation") |
| } |
| want := 2 |
| @@ -239,7 +239,7 @@ func TestDemoClaimChoiceRoom(t *testing.T) { |
| t.Error("plans off or role-disabled account read store") |
| } |
| if tc.plans && !tc.fail && tc.role != "viewer" { |
| - if !strings.Contains(body, ">Free<") { |
| + if !strings.Contains(body, ">Free plan<") { |
| t.Error("missing plan") |
| } |
| if isPlanCap(s.checkRunningThings(t.Context(), a, 2)) != (tc.instances >= 1) { |
| @@ -384,7 +384,9 @@ func TestDemoClaimProgressAndOutcome(t *testing.T) { |
| t.Run(state, func(t *testing.T) { |
| var rendered bytes.Buffer |
| address := "https://a-long-permanent-app-name.account.apps.example.com" |
| - if err := demoClaimPageTemplate.ExecuteTemplate(&rendered, "demo_claim.html", demoClaimPageData{Copy: demoClaimBrowserCopy(), State: state, Step: 2, URL: address}); err != nil { |
| + copy := demoClaimBrowserCopy() |
| + copy["completeHeading"] = "example is yours" |
| + if err := demoClaimPageTemplate.ExecuteTemplate(&rendered, "demo_claim.html", demoClaimPageData{Copy: copy, State: state, Step: 2, URL: address}); err != nil { |
| t.Fatal(err) |
| } |
| body := rendered.String() |
| @@ -392,15 +394,15 @@ func TestDemoClaimProgressAndOutcome(t *testing.T) { |
| if !strings.Contains(body, `id="claim-status" class="claim-sr-only" role="status" aria-live="polite"`) || !strings.Contains(body, "#claim .claim-sr-only") { |
| t.Error("live status must use the scoped screen-reader-only class") |
| } |
| - if !strings.Contains(body, `data-step="2" aria-current="step">Starting your app</li>`) { |
| + if !strings.Contains(body, `data-step="2" aria-current="step">`) || !strings.Contains(body, `<strong>Starting your app</strong>`) { |
| t.Error("current step is not marked") |
| } |
| } else { |
| - if !strings.Contains(body, "<h1>"+demoClaimComplete+"</h1>") || strings.Count(body, demoClaimComplete) != 1 { |
| + if !strings.Contains(body, `<h1 id="claim-heading">example is yours</h1>`) || strings.Contains(body, demoClaimComplete) { |
| t.Error("outcome must appear once, as the heading") |
| } |
| - link := regexp.MustCompile(`<a class="btn" href="([^"]+)" rel="noreferrer">([^<]+)</a>`).FindStringSubmatch(body) |
| - if len(link) != 3 || link[1] != address || strings.TrimPrefix(link[2], "https://") != strings.TrimPrefix(address, "https://") { |
| + link := regexp.MustCompile(`<a class="btn claim-open" href="([^"]+)" rel="noreferrer">([^<]+)</a>`).FindStringSubmatch(body) |
| + if len(link) != 3 || link[1] != address || link[2] != demoClaimUX45 || !strings.Contains(body, `<p class="claim-result-address">`+address+`</p>`) { |
| t.Error("result link must display the permanent address") |
| } |
| } |
| @@ -503,7 +505,7 @@ func TestDemoClaimChoiceAdmissionAndExemption(t *testing.T) { |
| if spy.calls.Load() != 0 { |
| t.Error("counted unavailable or exempt account") |
| } |
| - if strings.Contains(body, ">Free<") { |
| + if strings.Contains(body, ">Free plan<") { |
| t.Error("false plan label") |
| } |
| if !exempt && (!strings.Contains(body, "<p>unavailable</p>") || strings.Contains(body, demoClaimNoEligibleAccount)) { |
diff --git a/internal/console/demo_claim_copy.go b/internal/console/demo_claim_copy.go| index af9b54c53..9abaf010f 100644 |
| --- a/internal/console/demo_claim_copy.go |
| +++ b/internal/console/demo_claim_copy.go |
| @@ -42,17 +42,17 @@ const ( |
| // CLAIM-PROOF: identity confirmation. |
| demoClaimIdentityLabel = "You are signed in as" |
| // CLAIM-EMAIL-INTRO: signed-out email explanation. |
| - demoClaimEmailIntro = "To keep this demo, enter your email. We’ll send a six-digit code, or send you to Keymail to sign in." |
| + demoClaimEmailIntro = "It moves to a permanent address, and everything saved in it comes along." |
| // CLAIM-EMAIL: email field label. |
| - demoClaimEmailLabel = "Email address" |
| + demoClaimEmailLabel = "Your email address" |
| // CLAIM-EMAIL: discovery action. |
| demoClaimEmailContinue = "Continue" |
| // CLAIM-CODE-INTRO: pending code explanation. |
| demoClaimCodeIntro = "Enter the six-digit code from your email." |
| // CLAIM-EMAIL: code field label. |
| - demoClaimCodeLabel = "Email code" |
| + demoClaimCodeLabel = "Code" |
| // CLAIM-EMAIL: code action. |
| - demoClaimCodeConfirm = "Confirm email" |
| + demoClaimCodeConfirm = "Confirm" |
| // CLAIM-EMAIL: browser email body; code and nonce-confirmed link. |
| demoClaimBrowserEmailBody = "To keep your demo, enter this code where you started: %s\n\nOr confirm your email here: %s\n\nThis proof expires within 15 minutes. It signs you in so you can choose where to keep your demo.\n" |
| // CLAIM-EMAIL: awaiting proof. |
| @@ -60,7 +60,7 @@ const ( |
| // CLAIM-KEYMAIL: ordinary sign-in action. |
| demoClaimSignin = "Sign in" |
| // CLAIM-SIGNIN-PROMPT: secondary console sign-in. |
| - demoClaimSigninPrompt = "Already have a console account?" |
| + demoClaimSigninPrompt = "Already have an account?" |
| // CLAIM-ACCOUNT: empty picker choice. |
| demoClaimChooseAccount = "Choose an account" |
| // CLAIM-ACCOUNT-NEW: zero membership confirmation. |
| @@ -72,9 +72,9 @@ const ( |
| // CLAIM-RESULT: completed claim. |
| demoClaimComplete = "Your demo is now a permanent app." |
| // CLAIM-RESULT: result URL label. |
| - demoClaimURLLabel = "Open app" |
| + demoClaimURLLabel = "Open your app" |
| // CLAIM-CLI-LABEL: next workflow. |
| - demoClaimCLICommandLabel = "To deploy changes, sign in with the CLI:" |
| + demoClaimCLICommandLabel = "Sign in once, then send changes with carlos deploy." |
| // CLAIM-RESULT: command format consumed by the existing page renderer. |
| demoClaimCLINext = "carlos auth login --console %s" |
| // CLAIM-COPY: command clipboard action. |
| @@ -115,15 +115,15 @@ const ( |
| // CLAIM-ROOM-INSUFFICIENT: one slot remains, but the claim needs two. |
| demoClaimNoRoom = "Not enough room: %d of %d apps and instances in use. This demo needs room for one app and its instance." |
| // CLAIM-ROLE-DENIED: membership cannot create apps. |
| - demoClaimRoleDenied = "Your role cannot create apps in this account." |
| + demoClaimRoleDenied = "You can view this account but not add apps. Ask one of its owners." |
| // CLAIM-STEP-COPYING: first progress step. |
| demoClaimCopying = "Copying your data" |
| // CLAIM-STEP-STARTING: second progress step. |
| demoClaimStarting = "Starting your app" |
| // CLAIM-STEP-DONE: final progress step. |
| - demoClaimDone = "Done" |
| + demoClaimDone = "Ready" |
| // CLAIM-STOPPING: undoing an unfinished claim. |
| - demoClaimStopping = "The claim did not finish. The demo is not serving its pages while we undo the claim. When this finishes, the demo resumes if its 24 hours have not ended." |
| + demoClaimStopping = "Nothing is lost. We’re putting your demo back the way it was. While we do, it’s paused for a moment." |
| // CLAIM-POLL-FAILED: repeated status failures, with a reload link. |
| demoClaimPollFailed = "Progress could not be checked. Reload to try again." |
| // CLAIM-OLD-ADDRESS: notice lifetime, without a redirect promise. |
| @@ -140,3 +140,44 @@ const ( |
| // CLAIM-LINK-BROKEN |
| demoClaimLinkBroken = "This link is wrong or incomplete. Copy the whole link again from where your agent gave it to you." |
| ) |
| + |
| +// Approved claim journey deck; placeholders are replaced by the renderer. |
| +const ( |
| + demoClaimUX02 = "Keep this app" |
| + demoClaimUX05 = "We’ll send a code, or take you to Keymail if you use it." |
| + demoClaimUX07 = "Checking your email address…" |
| + demoClaimUX10 = "Finish with Keymail" |
| + demoClaimUX11 = "Your address uses Keymail, so you’ll confirm it there." |
| + demoClaimUX12 = "One sign-in, then straight back. Keymail confirms it’s you and signs you in to the console at the same time. You won’t be asked again." |
| + demoClaimUX13 = "Continue with Keymail" |
| + demoClaimUX14 = "Opening Keymail" |
| + demoClaimUX15 = "Use a different email" |
| + demoClaimUX16 = "Check your email" |
| + demoClaimUX17 = "We sent a six-digit code to {address}. It works for 15 minutes." |
| + demoClaimUX20 = "Checking the code…" |
| + demoClaimUX21 = "No email? Check your spam folder, or" |
| + demoClaimUX22 = "use a different address" |
| + demoClaimUX24 = "Where should it go?" |
| + demoClaimUX25 = "You have {used} accounts. Choose one with room for it." |
| + demoClaimUX26 = "Accounts" |
| + demoClaimUX34 = "Starting" |
| + demoClaimUX38 = "Everything saved in your demo comes with it." |
| + demoClaimUX40 = "Getting it ready at its permanent address." |
| + demoClaimUX43 = "{app} is yours" |
| + demoClaimUX44 = "It has a permanent address now, and everything saved in it came along." |
| + demoClaimUX45 = "Open your app" |
| + demoClaimUX47 = "Keep going" |
| + demoClaimUX48 = "Keep building with your agent" |
| + demoClaimUX49 = "Paste this into your agent to keep changing the app the proper way." |
| + demoClaimUX50 = "Help me keep working on {app}. Follow the directions on https://carlosframework.com/start" |
| + demoClaimUX52 = "Prefer the command line?" |
| + demoClaimUX61 = "That didn’t finish" |
| + demoClaimUX65 = "Your demo is back" |
| + demoClaimUX72 = "This demo has ended" |
| + demoClaimUX74 = "You can make a new one any time. Paste this into your coding agent:" |
| + demoClaimUX75 = "Follow the directions on https://carlosframework.com/start" |
| + demoClaimUX77 = "This app has already been kept" |
| + demoClaimUX80 = "Sign in to the console" |
| + demoClaimPlan = "%s plan" |
| + demoClaimOpening = "Opening your demo…" |
| +) |
diff --git a/internal/console/demo_claim_csp_test.go b/internal/console/demo_claim_csp_test.go| index e56f4db9d..9c45a6b09 100644 |
| --- a/internal/console/demo_claim_csp_test.go |
| +++ b/internal/console/demo_claim_csp_test.go |
| @@ -88,7 +88,7 @@ func TestDemoClaimMobileMarkup(t *testing.T) { |
| t.Helper() |
| for _, want := range []string{ |
| demoClaimEmailIntro, demoClaimSigninPrompt, |
| - `<label for="email">Email address</label>`, |
| + `<label for="email">Your email address</label>`, |
| `id="email" name="email" type="email" autocomplete="email" autocapitalize="off" spellcheck="false" inputmode="email" required`, |
| `<a href="/?next=%2Fdemo%2Fclaim">Sign in</a>`, |
| } { |
| @@ -108,11 +108,11 @@ func TestDemoClaimMobileMarkup(t *testing.T) { |
| body := w.Body.String() |
| check(body) |
| for _, want := range []string{ |
| - demoClaimCodeIntro, |
| - `<label for="code">Email code</label>`, |
| + "We sent a six-digit code to reader@example.com. It works for 15 minutes.", |
| + `<label for="code">Code</label>`, |
| `id="code" name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" required`, |
| - `<details class="claim-email-change"><summary>Email address</summary>`, |
| - `<button type="submit" class="btn-secondary">Continue</button>`, |
| + `<details class="claim-email-change"><summary>use a different address</summary>`, |
| + `<button type="submit" data-working="Checking your email address…" class="btn-secondary">Continue</button>`, |
| } { |
| if !strings.Contains(body, want) { |
| t.Errorf("pending code missing %q", want) |
| @@ -137,7 +137,7 @@ func TestDemoClaimCommandMarkup(t *testing.T) { |
| t.Fatal(err) |
| } |
| for _, want := range []string{ |
| - `<p>To deploy changes, sign in with the CLI:</p>`, |
| + `<p>Sign in once, then send changes with carlos deploy.</p>`, |
| `<pre><code id="claim-cli-command">` + p.Copy["next"] + `</code></pre>`, |
| `data-copy="Copy" data-copied="Copied" aria-live="polite" hidden>Copy</button>`, |
| } { |
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go| index 1ae9a883e..f70fe3ad9 100644 |
| --- a/internal/console/demo_claim_page.go |
| +++ b/internal/console/demo_claim_page.go |
| @@ -43,6 +43,8 @@ type demoClaimPageData struct { |
| Single *demoClaimAccountChoice |
| Eligible int |
| DemoName, DemoHost, Permanent string |
| + ExpiresAt int64 |
| + TimeLeft, EndTime string |
| Step int |
| CanClaim, HasIntent, EmailPending bool |
| } |
| @@ -130,6 +132,11 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| if op, opErr := s.store.demoClaimOpForFlow(r.Context(), hash); opErr == nil { |
| setDemoClaimCookie(w, cookie, demoClaimResultExpiry(op)) |
| p.State, p.Step = demoClaimProgressStep(op.Phase) |
| + p.ExpiresAt = op.SourceExpiresAt |
| + p.App = op.Target.App |
| + if d, err := s.store.demoByID(r.Context(), op.DemoID); err == nil { |
| + p.DemoName, p.DemoHost = d.Name, d.Host |
| + } |
| if op.Phase == "done" { |
| p.State = "claimed" |
| p.App = op.Target.App |
| @@ -148,6 +155,10 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| p.DemoName, p.DemoHost = d.Name, d.Host |
| + if life, err := s.store.AppLife(d.AccountID, d.App); err == nil && life != nil { |
| + p.ExpiresAt = life.ExpiresAt |
| + } |
| + p.Copy["codeIntro"] = strings.ReplaceAll(demoClaimUX17, "{address}", f.Address) |
| p.Permanent = fmt.Sprintf(demoClaimPermanent, s.cfg.AppsDomain) |
| p.HasIntent = true |
| p.State = "proof" |
| @@ -202,6 +213,14 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| } |
| + if p.ExpiresAt > 0 { |
| + remaining := max(0, p.ExpiresAt-time.Now().Unix()) |
| + p.TimeLeft = fmt.Sprintf("%02d:%02d:%02d", remaining/3600, remaining/60%60, remaining%60) |
| + p.EndTime = time.Unix(p.ExpiresAt, 0).UTC().Format(time.RFC3339) |
| + } |
| + p.Copy["completeHeading"] = strings.ReplaceAll(demoClaimUX43, "{app}", p.App) |
| + p.Copy["agentLine"] = strings.ReplaceAll(demoClaimUX50, "{app}", p.App) |
| + p.Copy["accountsIntro"] = strings.ReplaceAll(demoClaimUX25, "{used}", fmt.Sprint(len(p.Accounts))) |
| w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| if err = demoClaimPageTemplate.ExecuteTemplate(w, "demo_claim.html", p); err != nil { |
| return |
| @@ -530,6 +549,17 @@ func (s *Server) demoClaimSessionIdentity(raw, person string) (string, string, b |
| func demoClaimBrowserCopy() map[string]string { |
| return map[string]string{ |
| + "heading": demoClaimUX02, "emailHint": demoClaimUX05, "emailWorking": demoClaimUX07, |
| + "keymailHeading": demoClaimUX10, "keymailIntro": demoClaimUX11, "keymailDetail": demoClaimUX12, |
| + "keymailContinue": demoClaimUX13, "keymailWorking": demoClaimUX14, "changeEmail": demoClaimUX15, |
| + "codeHeading": demoClaimUX16, "codeWorking": demoClaimUX20, "codeRecovery": demoClaimUX21, "changeAddress": demoClaimUX22, |
| + "accountsHeading": demoClaimUX24, "accountsLabel": demoClaimUX26, "selectWorking": demoClaimUX34, |
| + "copyingDetail": demoClaimUX38, "startingDetail": demoClaimUX40, |
| + "completeDetail": demoClaimUX44, "open": demoClaimUX45, |
| + "keepGoing": demoClaimUX47, "agentHeading": demoClaimUX48, "agentDetail": demoClaimUX49, |
| + "cliHeading": demoClaimUX52, "failureHeading": demoClaimUX61, |
| + "expiredHeading": demoClaimUX72, "newDemo": demoClaimUX74, "newDemoLine": demoClaimUX75, |
| + "keptHeading": demoClaimUX77, "consoleSignin": demoClaimUX80, "opening": demoClaimOpening, |
| "expired": demoClaimExpired, |
| "kept": demoClaimAlreadyKept, |
| "takenDown": demoClaimTakenDown, |
| @@ -612,6 +642,8 @@ func (s *Server) continueDemoClaimKeymail(w http.ResponseWriter, r *http.Request |
| // Room is a GET-only hint. Reservation still checks under its account lock. |
| type demoClaimAccountChoice struct { |
| Sqid, Name, Plan, Room, Reason, Button string |
| + Slots []bool |
| + Used, Limit int |
| } |
| func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool) demoClaimAccountChoice { |
| @@ -626,7 +658,7 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool |
| if row != nil { |
| name = row.Plan |
| } |
| - c.Plan = planLabel(name) |
| + c.Plan = fmt.Sprintf(demoClaimPlan, planLabel(name)) |
| } |
| } |
| if !count || c.Reason != "" || ctx.Err() != nil { |
| @@ -640,6 +672,13 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool |
| if err != nil || ctx.Err() != nil { |
| return c |
| } |
| + c.Used, c.Limit = n, limits.RunningThings |
| + // Keep the drawing bounded for large plans; the numeric ratio stays exact. |
| + if c.Limit <= 100 { |
| + for i := 0; i < c.Limit; i++ { |
| + c.Slots = append(c.Slots, i < n) |
| + } |
| + } |
| switch { |
| case n >= limits.RunningThings: |
| c.Reason = fmt.Sprintf(demoClaimFull, n, limits.RunningThings) |
diff --git a/internal/console/demo_claim_review_test.go b/internal/console/demo_claim_review_test.go| index 7d77f0a6a..28a20aee8 100644 |
| --- a/internal/console/demo_claim_review_test.go |
| +++ b/internal/console/demo_claim_review_test.go |
| @@ -303,7 +303,7 @@ func TestDemoClaimBrowserCorrectionLimits(t *testing.T) { |
| t.Fatal("send limit preserved old proof after correction") |
| } |
| // A withheld challenge must not be distinguishable from a sent one on the page. |
| - if w := b.request("GET", "/demo/claim", nil); !strings.Contains(w.Body.String(), demoClaimCodeIntro) || !strings.Contains(w.Body.String(), `id="code"`) { |
| + if w := b.request("GET", "/demo/claim", nil); !strings.Contains(w.Body.String(), "We sent a six-digit code to ") || !strings.Contains(w.Body.String(), `id="code"`) { |
| t.Fatal("withheld challenge missing") |
| } |
| } |
diff --git a/internal/console/demo_claim_ux_test.go b/internal/console/demo_claim_ux_test.go| new file mode 100644 |
| index 000000000..86dc45dd9 |
| --- /dev/null |
| +++ b/internal/console/demo_claim_ux_test.go |
| @@ -0,0 +1,222 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/json" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "os" |
| + "os/exec" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestDemoClaimUXProductionPages(t *testing.T) { |
| + s, _, b := claimSigninFixture(t) |
| + body := b.request("GET", "/demo/claim", nil).Body.String() |
| + for _, want := range []string{`class="claim-ticket`, `class="claim-clock"`, "Keep this app", "One sign-in, then straight back.", `data-working="Checking your email address…"`} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("email missing %q", want) |
| + } |
| + } |
| + b.login("shop@example.com", MethodEmail, true) |
| + a := claimAccount(t, s, 801, "shop@example.com", RoleOwner) |
| + s.cfg.PlanCatalog = examplePlanCatalog(t) |
| + body = b.request("GET", "/demo/claim", nil).Body.String() |
| + if !strings.Contains(body, `class="claim-slots"`) { |
| + t.Error("no capacity drawing") |
| + } |
| + if w := b.post("/demo/claim/select", url.Values{"accountId": {a.Sqid}}); w.Code != 303 { |
| + t.Fatalf("select: %d %s", w.Code, w.Body) |
| + } |
| + for _, phase := range []string{"reserved", "copying", "verifying", "committed", "aborting", "aborted", "done"} { |
| + t.Run(phase, func(t *testing.T) { |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase=?`, phase); err != nil { |
| + t.Fatal(err) |
| + } |
| + body := b.request("GET", "/demo/claim", nil).Body.String() |
| + if !strings.Contains(body, `class="claim-ticket`) { |
| + t.Error("ticket lost after selection") |
| + } |
| + if phase == "done" { |
| + for _, want := range []string{"Open your app", "Keep building with your agent", `<details class="claim-command">`, `data-state="claimed"`} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("result missing %q", want) |
| + } |
| + } |
| + } |
| + if phase == "aborting" && (!strings.Contains(body, "Nothing is lost.") || strings.Index(body, `<p id="claim-status"`) > strings.Index(body, `<div class="claim-transit"`)) { |
| + t.Error("missing recovery explanation") |
| + } |
| + if phase == "aborted" && (!strings.Contains(body, demoClaimAborted) || strings.Contains(body, `action="/demo/claim/retry"`)) { |
| + t.Error("status capability must not offer retry") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Reservation irreversibly narrows this cookie to one-operation status. Even |
| +// an aborted op cannot reuse select; retry has no route or authority to grant. |
| +func TestDemoClaimUXRetryRemainsClosed(t *testing.T) { |
| + for _, condition := range []string{"aborted", "no flow", "other session", "expired", "spent token", "not aborted", "stale step-up", "CSRF", "concurrent op", "admission", "membership"} { |
| + t.Run(condition, func(t *testing.T) { |
| + s, _, b := claimSigninFixture(t) |
| + b.login("shop@example.com", MethodEmail, true) |
| + a := claimAccount(t, s, 801, "shop@example.com", RoleOwner) |
| + if w := b.post("/demo/claim/select", url.Values{"accountId": {a.Sqid}}); w.Code != 303 { |
| + t.Fatal(w.Code) |
| + } |
| + query := `UPDATE demo_claim_ops SET phase='aborted'` |
| + if condition == "not aborted" || condition == "concurrent op" { |
| + query = `UPDATE demo_claim_ops SET phase='copying'` |
| + } |
| + if _, err := s.store.db.Exec(query); err != nil { |
| + t.Fatal(err) |
| + } |
| + switch condition { |
| + case "no flow": |
| + b.cookie = "" |
| + case "other session": |
| + b.login("other@example.com", MethodEmail, true) |
| + case "expired": |
| + _, _ = s.store.db.Exec(`UPDATE demo_claim_flows SET expires_at=1`) |
| + case "spent token": |
| + _, _ = s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=NULL`) |
| + case "stale step-up": |
| + b.login("shop@example.com", MethodEmail, false) |
| + case "CSRF": |
| + b.nonce = "wrong" |
| + case "admission": |
| + s.demoClaimTestEnabled = false |
| + s.cfg.Demo.ClaimEnabled = false |
| + case "membership": |
| + _, _ = s.store.db.Exec(`DELETE FROM memberships WHERE account_id=?`, a.ID) |
| + } |
| + for _, path := range []string{"/demo/claim/select", "/demo/claim/retry"} { |
| + w := b.post(path, url.Values{"accountId": {a.Sqid}}) |
| + if w.Code < 400 { |
| + t.Fatalf("%s accepted status capability: %d", path, w.Code) |
| + } |
| + } |
| + if claimBrowserCount(t, s, "demo_claim_ops") != 1 { |
| + t.Fatal("second operation created") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestDemoClaimUXHeadless(t *testing.T) { |
| + chromium, err := exec.LookPath("chromium") |
| + if err != nil { |
| + t.Skip("no Chromium") |
| + } |
| + node, err := exec.LookPath("node") |
| + if err != nil { |
| + t.Skip("no node") |
| + } |
| + type scene struct{ Name, URL, Cookie, Session, State, Text string } |
| + var scenes []scene |
| + for _, name := range []string{"email", "code", "one", "many", "no-accounts", "new-account", "missing", "missing-link", "disabled", "copying", "starting", "unknown", "stopping", "aborted", "done", "fast", "expired", "kept", "taken-down", "invalid"} { |
| + s, _, b := claimSigninFixture(t) |
| + s.consoleMail = &fakeConsoleMail{ready: true} |
| + state := "proof" |
| + if name == "code" { |
| + if w := b.post("/demo/claim/prove", url.Values{"email": {"reader@example.com"}}); w.Code != 303 { |
| + t.Fatal(w.Code) |
| + } |
| + } |
| + phase := map[string]string{"copying": "copying", "starting": "verifying", "unknown": "future-phase", "stopping": "aborting", "aborted": "aborted", "done": "done", "fast": "copying"}[name] |
| + if phase != "" || name == "one" || name == "many" || name == "no-accounts" { |
| + b.login("shop@example.com", MethodEmail, true) |
| + role := RoleOwner |
| + if name == "no-accounts" { |
| + role = "viewer" |
| + state = "no_accounts" |
| + } |
| + a := claimChoiceAccount(t, s, 801, "shop@example.com", role) |
| + if name == "many" { |
| + claimAccount(t, s, 802, "shop@example.com", RoleOwner) |
| + claimChoiceAccount(t, s, 803, "shop@example.com", "viewer") |
| + } |
| + s.cfg.PlanCatalog = examplePlanCatalog(t) |
| + if phase != "" { |
| + if w := b.post("/demo/claim/select", url.Values{"accountId": {a.Sqid}}); w.Code != 303 { |
| + t.Fatal(w.Code) |
| + } |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase=?`, phase); err != nil { |
| + t.Fatal(err) |
| + } |
| + state, _ = demoClaimProgressStep(phase) |
| + } |
| + } |
| + if name == "new-account" { |
| + b.login("shop@example.com", MethodEmail, true) |
| + } |
| + if name == "missing" || name == "missing-link" { |
| + b.cookie = "" |
| + state = "missing" |
| + } |
| + if name == "disabled" { |
| + s.demoClaimTestEnabled = false |
| + s.cfg.Demo.ClaimEnabled = false |
| + state = "disabled" |
| + } |
| + suffix, message := "", "" |
| + reasons := map[string]string{"expired": demoClaimExpired, "kept": demoClaimAlreadyKept, "taken-down": demoClaimTakenDown, "invalid": demoClaimLinkBroken} |
| + if text, ok := reasons[name]; ok { |
| + raw, err := randomToken() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if name != "invalid" { |
| + decoded, _ := base64.RawURLEncoding.DecodeString(raw) |
| + hash := sha256.Sum256(decoded) |
| + reason := name |
| + if reason == "taken-down" { |
| + reason = "operator" |
| + } |
| + if _, err = s.store.db.Exec(`INSERT INTO demo_spent_tokens(hash,reason,spent_at) VALUES(?,?,?)`, hash[:], reason, time.Now().Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // Keep an existing unrelated flow: a refused new fragment must clear its UI. |
| + b.session = "" |
| + suffix = "#" + raw |
| + message = text |
| + state = "missing" |
| + } |
| + fast := name == "fast" |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if fast && r.URL.Path == "/demo/claim" && r.URL.Query().Has("replay") { |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase='copying'`); err != nil { |
| + t.Error(err) |
| + } |
| + } |
| + if fast && r.URL.Path == "/demo/claim/status" { |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase='done'`); err != nil { |
| + t.Error(err) |
| + } |
| + } |
| + s.mux.ServeHTTP(w, r) |
| + })) |
| + t.Cleanup(ts.Close) |
| + s.cfg.Origin = ts.URL |
| + scenes = append(scenes, scene{name, ts.URL + "/demo/claim" + suffix, b.cookie, b.session, state, message}) |
| + } |
| + encoded, err := json.Marshal(scenes) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx, cancel := context.WithTimeout(t.Context(), 4*time.Minute) |
| + defer cancel() |
| + cmd := exec.CommandContext(ctx, node, "testdata/demo_claim_browser.mjs", chromium, t.TempDir(), string(encoded), os.Getenv("CARLOS_DEMO_CLAIM_SCREENSHOTS")) |
| + output, err := cmd.CombinedOutput() |
| + if err != nil { |
| + t.Fatalf("UX browser: %v\n%s", err, output) |
| + } |
| + t.Log(string(output)) |
| +} |
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js| index 349a657c4..465e589da 100644 |
| --- a/internal/console/static/demo_claim.js |
| +++ b/internal/console/static/demo_claim.js |
| @@ -2,16 +2,60 @@ |
| "use strict"; |
| let token = location.hash.slice(1); |
| history.replaceState(null, "", "/demo/claim"); |
| - for (const form of document.querySelectorAll("form")) { |
| - form.addEventListener("submit", () => { |
| + const claim = document.getElementById("claim"); |
| + const minimum = 650; |
| + const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); |
| + const paint = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); |
| + const opening = document.getElementById("claim-opening"); |
| + const missing = document.getElementById("claim-missing"); |
| + const heading = document.getElementById("claim-heading"); |
| + |
| + if (token) { |
| + // A fragment may name a different demo from the existing cookie. Keep |
| + // only the exchange shell, so a refusal cannot display the previous app. |
| + const shell = new Set(["claim-heading", "claim-error", "claim-opening", "claim-expired-next", "claim-kept-next"]); |
| + for (const child of [...claim.children]) { |
| + if (!shell.has(child.id) && child.tagName !== "INPUT") child.remove(); |
| + } |
| + heading.textContent = claim.dataset.title; |
| + claim.dataset.state = "missing"; |
| + opening.hidden = false; |
| + } |
| + // One guard for the page: two forms (the code and a different address) |
| + // must not both go inside the working window. |
| + let submitted = false; |
| + const working = []; |
| + addEventListener("pageshow", event => { |
| + if (!event.persisted) return; |
| + submitted = false; |
| + for (const [button, label] of working) { |
| + button.disabled = false; |
| + button.classList.remove("is-working"); |
| + button.removeAttribute("aria-busy"); |
| + button.textContent = label; |
| + } |
| + working.length = 0; |
| + }); |
| + for (const form of document.querySelectorAll("#claim form")) { |
| + form.addEventListener("submit", async event => { |
| + event.preventDefault(); |
| + if (submitted) return; |
| + submitted = true; |
| for (const button of form.querySelectorAll('button[type="submit"]')) { |
| + working.push([button, button.textContent]); |
| button.disabled = true; |
| + button.classList.add("is-working"); |
| + button.setAttribute("aria-busy", "true"); |
| + button.textContent = button.dataset.working; |
| } |
| + await paint(); |
| + await wait(minimum); |
| + HTMLFormElement.prototype.submit.call(form); |
| }); |
| } |
| - const copy = document.getElementById("claim-copy"); |
| - const command = document.getElementById("claim-cli-command"); |
| - if (copy && command && typeof navigator.clipboard?.writeText === "function") { |
| + for (const copy of document.querySelectorAll("[data-copy-target]")) { |
| + const command = document.getElementById(copy.dataset.copyTarget); |
| + if (!command || typeof navigator.clipboard?.writeText !== "function") continue; |
| copy.hidden = false; |
| let reset; |
| copy.addEventListener("click", async () => { |
| @@ -20,37 +64,73 @@ |
| copy.textContent = copy.dataset.copied; |
| clearTimeout(reset); |
| reset = setTimeout(() => { copy.textContent = copy.dataset.copy; }, 2000); |
| - } catch (_) { |
| - copy.hidden = true; |
| - } |
| + } catch (_) { copy.hidden = true; } |
| }); |
| } |
| const choice = document.querySelector('form[action="/demo/claim/select"]'); |
| if (choice) { |
| const radios = choice.querySelectorAll('input[type="radio"]:not(:disabled)'); |
| const button = choice.querySelector('button[type="submit"]'); |
| - let submitted = false; |
| - choice.addEventListener("submit", () => { submitted = true; }); |
| const update = () => { |
| - if (submitted) return; |
| + if (button.classList.contains("is-working")) return; |
| const selected = choice.querySelector('input[type="radio"]:checked:not(:disabled)'); |
| button.disabled = !selected; |
| button.textContent = selected ? selected.dataset.button : button.dataset.neutral; |
| }; |
| - if (radios.length) { |
| - choice.addEventListener("change", update); |
| - update(); |
| - } |
| + if (radios.length) { choice.addEventListener("change", update); update(); } |
| + } |
| + const clock = claim.querySelector("time[datetime]"); |
| + if (clock) { |
| + const expiry = Date.parse(clock.dateTime); |
| + const timer = setInterval(() => { |
| + if (claim.dataset.state === "claimed") { clearInterval(timer); return; } |
| + const seconds = Math.max(0, Math.floor((expiry - Date.now()) / 1000)); |
| + if (Number.isFinite(seconds)) clock.textContent = [Math.floor(seconds / 3600), Math.floor(seconds / 60) % 60, seconds % 60].map(n => String(n).padStart(2, "0")).join(":"); |
| + }, 1000); |
| } |
| const progress = document.getElementById("claim-progress"); |
| if (progress && !token) { |
| const status = document.getElementById("claim-status"); |
| const reload = document.getElementById("claim-reload"); |
| const labels = [progress.dataset.neutral, progress.dataset.copying, progress.dataset.starting, progress.dataset.done]; |
| - const setStatus = text => { |
| - if (status.textContent !== text) status.textContent = text; |
| + let stage = Number(progress.dataset.stage), since = performance.now(), failures = 0; |
| + const setStatus = text => { if (status.textContent !== text) status.textContent = text; }; |
| + const hold = async () => { await wait(Math.max(0, minimum - (performance.now() - since))); }; |
| + const setStage = async n => { |
| + stage = n; |
| + progress.dataset.stage = String(n); |
| + for (const step of progress.querySelectorAll("[data-step]")) { |
| + const k = Number(step.dataset.step); |
| + step.classList.toggle("is-done", k < n); |
| + if (k === n) step.setAttribute("aria-current", "step"); |
| + else step.removeAttribute("aria-current"); |
| + } |
| + status.classList.toggle("claim-sr-only", n > 0); |
| + setStatus(labels[n]); |
| + await paint(); |
| + since = performance.now(); |
| + }; |
| + const advance = async target => { |
| + // A successful later phase proves these preceding phases completed. |
| + // Never advance beyond the server's last reported stage. |
| + while (stage < target) { await hold(); await setStage(stage + 1); } |
| + }; |
| + const finish = result => { |
| + const url = new URL(result.url); |
| + if (url.protocol !== "https:" || url.username || url.password) throw new Error(); |
| + const finished = document.getElementById("claim-finished"); |
| + for (const link of claim.querySelectorAll("a.claim-new, .claim-open")) link.href = url.href; |
| + const address = claim.querySelector(".claim-address .claim-new"); |
| + if (address) address.textContent = url.host; |
| + claim.querySelector(".claim-result-address").textContent = url.href; |
| + heading.textContent = claim.dataset.completeHeading; |
| + claim.dataset.state = "claimed"; |
| + claim.querySelector(".claim-ticket")?.classList.add("is-settled"); |
| + claim.classList.add("is-celebrating"); |
| + finished.hidden = false; |
| + progress.hidden = true; |
| + setTimeout(() => claim.classList.remove("is-celebrating"), 1500); |
| }; |
| - let failures = 0; |
| reload.hidden = true; |
| const poll = async () => { |
| try { |
| @@ -60,24 +140,21 @@ |
| }); |
| if (!response.ok) throw new Error(); |
| const result = await response.json(); |
| - if (result.state === "aborted" && result.step === 0) { |
| - for (const step of progress.querySelectorAll("[data-step]")) step.removeAttribute("aria-current"); |
| - status.classList.remove("claim-sr-only"); |
| - setStatus(progress.dataset.aborted); |
| - return; |
| - } |
| if (!((result.state === "claiming" && [0, 1, 2].includes(result.step)) || |
| - (result.state === "stopping" && result.step === 0) || |
| + (["stopping", "aborted"].includes(result.state) && result.step === 0) || |
| (result.state === "claimed" && result.step === 3))) throw new Error(); |
| - for (const step of progress.querySelectorAll("[data-step]")) { |
| - if (Number(step.dataset.step) === result.step) step.setAttribute("aria-current", "step"); |
| - else step.removeAttribute("aria-current"); |
| - } |
| - status.classList.toggle("claim-sr-only", result.step > 0); |
| - setStatus(result.state === "stopping" ? progress.dataset.stopping : labels[result.step]); |
| - if (result.state === "claimed") { |
| - location.replace("/demo/claim"); |
| - return; |
| + if (result.state === "stopping" || result.state === "aborted") { |
| + await hold(); |
| + const failed = progress.querySelector('[aria-current="step"]'); |
| + if (failed) { failed.classList.add("is-failed"); failed.removeAttribute("aria-current"); } |
| + progress.dataset.stage = "0"; |
| + status.classList.remove("claim-sr-only"); |
| + setStatus(result.state === "stopping" ? progress.dataset.stopping : progress.dataset.aborted); |
| + heading.textContent = progress.dataset.failureHeading; |
| + if (result.state === "aborted") return; |
| + } else { |
| + await advance(result.step); |
| + if (result.state === "claimed") { await hold(); finish(result); return; } |
| } |
| failures = 0; |
| } catch (_) { |
| @@ -90,21 +167,19 @@ |
| } |
| setTimeout(poll, 3000); |
| }; |
| - setTimeout(poll, 3000); |
| + // The initial stage is already painted by the server. |
| + paint().then(() => { since = performance.now(); setTimeout(poll, minimum); }); |
| } |
| if (!token) { |
| + if (opening) opening.hidden = true; |
| + if (missing) missing.hidden = false; |
| const selection = document.querySelector("form[data-auto-submit]"); |
| if (selection) { |
| selection.removeAttribute("data-auto-submit"); |
| const status = document.getElementById("claim-resuming"); |
| try { |
| - if (selection.checkValidity()) { |
| - status.hidden = false; |
| - selection.requestSubmit(); |
| - } |
| - } catch (_) { |
| - status.hidden = true; |
| - } |
| + if (selection.checkValidity()) { status.hidden = false; selection.requestSubmit(); } |
| + } catch (_) { status.hidden = true; } |
| } |
| return; |
| } |
| @@ -115,32 +190,40 @@ |
| }); |
| token = ""; |
| const showError = reason => { |
| - const copy = document.getElementById("claim").dataset; |
| + const copy = claim.dataset; |
| const messages = new Map([ |
| ["expired", copy.expired], ["kept", copy.kept], |
| ["taken-down", copy.takenDown], ["invalid", copy.invalid] |
| ]); |
| + if (opening) opening.hidden = true; |
| + if (missing) missing.hidden = true; |
| + if (reason === "expired") { |
| + heading.textContent = copy.expiredHeading; |
| + document.getElementById("claim-expired-next").hidden = false; |
| + } else if (reason === "kept") { |
| + heading.textContent = copy.keptHeading; |
| + document.getElementById("claim-kept-next").hidden = false; |
| + } |
| const error = document.getElementById("claim-error"); |
| error.textContent = messages.get(reason) || copy.failed; |
| error.hidden = false; |
| error.focus(); |
| }; |
| + const visible = paint().then(() => wait(minimum)); |
| fetch("/demo/claim/intent", { |
| - method: "POST", |
| - credentials: "same-origin", |
| - mode: "same-origin", |
| - cache: "no-store", |
| - body: form |
| + method: "POST", credentials: "same-origin", mode: "same-origin", cache: "no-store", body: form |
| }).then(async response => { |
| form.delete("claimToken"); |
| + await visible; |
| if (!response.ok) { |
| const result = await response.json(); |
| showError(result && typeof result === "object" ? result.reason : undefined); |
| return; |
| } |
| location.replace("/demo/claim"); |
| - }).catch(() => { |
| + }).catch(async () => { |
| form.delete("claimToken"); |
| + await visible; |
| showError(); |
| }); |
| })(); |
diff --git a/internal/console/templates/demo_claim.html b/internal/console/templates/demo_claim.html| index eb5da8d26..9bd379816 100644 |
| --- a/internal/console/templates/demo_claim.html |
| +++ b/internal/console/templates/demo_claim.html |
| @@ -17,7 +17,7 @@ |
| #claim .claim-card:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; } |
| #claim .claim-card:has(:disabled) { color: var(--muted); background: var(--rst-surface-2); cursor: not-allowed; } |
| #claim .claim-card input { flex: none; width: 1.1rem; height: 1.1rem; margin-top: 0.25rem; accent-color: var(--accent); } |
| -#claim .claim-card strong, #claim .claim-card span span { display: block; } |
| +#claim .claim-card strong, #claim .claim-card .claim-detail { display: block; } |
| #claim .claim-detail { color: var(--muted); font-size: 0.9rem; } |
| #claim .claim-single { margin: 1.5rem 0; } |
| #claim .claim-single p { margin-bottom: 0.35rem; } |
| @@ -43,43 +43,142 @@ |
| #claim .claim-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; } |
| #claim .claim-result { margin: 1.5rem 0; } |
| #claim .claim-result .btn { display: inline-block; max-width: 100%; white-space: normal; overflow-wrap: anywhere; padding: 0.65rem 1.25rem; } |
| +#claim { max-width: 38rem; padding-top: 2.5rem; --claim-good: light-dark(#1f7a4d,#6fd3a0); --claim-warn: light-dark(#8a5a12,#f0b34a); } |
| +#claim [hidden] { display: none !important; } |
| +#claim h1 { font-size: clamp(1.75rem,5vw,2.25rem); line-height: 1.15; } |
| +#claim .claim-ticket { position: relative; display: grid; grid-template-columns: auto minmax(0,1fr); gap: .9rem; align-items: center; padding: 1rem; margin: 0 0 1.75rem; border: 1px solid var(--rack-edge); border-radius: 14px; background: var(--panel-cool); box-shadow: var(--shadow-module); } |
| +#claim .claim-tile { display: grid; place-items: center; width: 3.25rem; height: 3.25rem; border-radius: 12px; background: var(--rst-accent-fill); color: white; } |
| +#claim .claim-tile svg { width: 26px; height: 26px; } |
| +#claim .claim-ticket-body { min-width: 0; display: grid; gap: .2rem; } |
| +#claim .claim-address { display: grid; font: .84rem/1.5 ui-monospace,monospace; } |
| +#claim .claim-address a { grid-area: 1/1; color: var(--muted); text-decoration: none; } |
| +#claim .claim-life { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); } |
| +#claim .claim-clock { width: 16px; height: 16px; fill: none; stroke: var(--accent); stroke-width: 1.8; } |
| +#claim .claim-tick, #claim .claim-new { display: none; } |
| +#claim .is-settled .claim-new { display: block; color: var(--claim-good); } |
| +#claim .is-settled .claim-old, #claim .is-settled .claim-clock circle, #claim .is-settled .claim-hands { display: none; } |
| +#claim .is-settled .claim-tick { display: block; stroke: var(--claim-good); } |
| +#claim .claim-proof input:not([type=hidden]) { border-radius: 10px; min-height: 50px; } |
| +#claim #code { font-size: 1.6rem; letter-spacing: .3em; text-align: center; } |
| +#claim .claim-keymail { margin: 1rem 0; padding: 1rem 0; border-block: 1px solid var(--rule); font-size: .9rem; } |
| +#claim .claim-keymail p { color: var(--muted); margin: .4rem 0 0; } |
| +#claim .claim-single { display: block; } |
| +#claim .claim-slots { display: flex; gap: 3px; flex-wrap: wrap; margin: .5rem 0; } |
| +#claim .claim-slots i { width: 18px; height: 5px; border-radius: 3px; background: var(--rule); } |
| +#claim .claim-slots i.used { background: var(--accent); } |
| +#claim .claim-card:has(:disabled) .used { background: var(--claim-warn); } |
| +#claim button[type=submit] { min-height: 50px; border-radius: 10px; } |
| +#claim button.is-working { color: var(--rst-on-accent-fill); opacity: 1; } |
| +#claim button.btn-secondary.is-working { color: var(--accent); } |
| +#claim button.is-working::after { display: none; } |
| +#claim .claim-spinner, #claim button.is-working::before { content: ""; display: inline-block; width: 1rem; height: 1rem; margin-right: .6rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -.15em; animation: claim-spin .7s linear infinite; } |
| +#claim .claim-transit { display: grid; grid-template-columns: 3.25rem 1fr 3.25rem; align-items: center; gap: .75rem; margin: 2rem 0; } |
| +#claim .claim-transit > span:not(.claim-track) { display: grid; place-items: center; height: 3.25rem; border: 1px dashed var(--muted); border-radius: 12px; } |
| +#claim .claim-transit svg { width: 24px; height: 24px; } |
| +#claim .claim-transit .claim-home { color: white; background: var(--rst-accent-fill); border-style: solid; } |
| +#claim .claim-track { position: relative; height: 2px; border-top: 2px dashed var(--rule); } |
| +#claim .claim-track i { position: absolute; top: -5px; left: 0; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); opacity: 0; } |
| +#claim [data-stage="1"] .claim-track i { animation: claim-travel 1.8s ease-in-out infinite; } |
| +#claim .claim-track i:nth-child(2) { animation-delay: .25s; } |
| +#claim .claim-track i:nth-child(3) { animation-delay: .5s; } |
| +#claim [data-stage="2"] .claim-home { animation: claim-breathe 1.6s ease-in-out infinite; } |
| +#claim .claim-steps { list-style: none; padding: 0; } |
| +#claim .claim-steps li { position: relative; min-height: 3rem; padding: 0 0 1.5rem 2.5rem; } |
| +#claim .claim-step-detail { display: block; font-weight: 400; font-size: .95rem; margin-top: .25rem; } |
| +#claim .claim-node { position: absolute; left: 0; top: 0; width: 26px; height: 26px; border: 2px solid var(--muted); border-radius: 50%; display: grid; place-items: center; } |
| +#claim .claim-node svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; opacity: 0; } |
| +#claim [aria-current=step] .claim-node { border-color: var(--accent); } |
| +#claim [aria-current=step] .claim-node::before { content: ""; position: absolute; inset: -2px; border: 2px solid transparent; border-top-color: var(--accent); border-radius: 50%; animation: claim-spin .7s linear infinite; } |
| +#claim [aria-current=step] .claim-node::after { content: ""; position: absolute; inset: 7px; background: var(--accent); border-radius: 50%; } |
| +#claim .claim-steps .is-done .claim-node { color: var(--claim-good); border-color: var(--claim-good); } |
| +#claim .claim-steps .is-done svg { opacity: 1; } |
| +#claim .claim-steps .is-failed { color: var(--claim-warn); } |
| +#claim .claim-steps .is-failed .claim-node { border-color: var(--claim-warn); } |
| +#claim .claim-result .claim-open { display: block; width: 100%; text-align: center; font-size: 2rem; font-weight: 700; padding: 1.25rem; border-radius: 12px; } |
| +#claim .claim-result-address { text-align: center; font: .85rem/1.5 ui-monospace,monospace; color: var(--muted); } |
| +#claim .claim-next { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); } |
| +#claim .claim-next h2 { font-size: 1.15rem; } |
| +#claim .claim-next h3 { font-size: 1rem; margin-bottom: .3rem; } |
| +#claim .claim-next p { color: var(--muted); } |
| +#claim .claim-paste { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: .75rem; border: 1px solid var(--rule); padding: .6rem; border-radius: 10px; background: var(--rst-surface-2); } |
| +#claim .claim-paste code { background: transparent; padding: 0; white-space: normal; overflow-wrap: anywhere; font-size: .84rem; } |
| +#claim .claim-paste button { min-height: 44px; } |
| +#claim .claim-command { border-top: 1px solid var(--rule); padding-top: 1rem; } |
| +#claim .claim-command summary { cursor: pointer; min-height: 44px; font-weight: 600; } |
| +#claim .claim-burst { position: absolute; left: 2.6rem; top: 2.6rem; pointer-events: none; } |
| +#claim .claim-burst i { position: absolute; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); opacity: 0; } |
| +#claim .claim-burst i:nth-child(1) { --a: -110deg; --d: 70px; } |
| +#claim .claim-burst i:nth-child(2) { --a: -70deg; --d: 105px; background: light-dark(#067a68,#2fd4ac); } |
| +#claim .claim-burst i:nth-child(3) { --a: -40deg; --d: 90px; } |
| +#claim .claim-burst i:nth-child(4) { --a: -10deg; --d: 140px; background: #e7a7d9; } |
| +#claim .claim-burst i:nth-child(5) { --a: 20deg; --d: 120px; } |
| +#claim .claim-burst i:nth-child(6) { --a: 50deg; --d: 90px; background: #e7a7d9; } |
| +#claim .claim-burst i:nth-child(7) { --a: 90deg; --d: 65px; } |
| +#claim .claim-burst i:nth-child(8) { --a: -150deg; --d: 45px; } |
| +#claim.is-celebrating .claim-burst i { animation: claim-burst 1.1s ease-out .3s both; } |
| +#claim.is-celebrating .claim-address .claim-new { animation: claim-wipe-in .7s ease-out .3s both; } |
| +#claim.is-celebrating .claim-address .claim-old { display: block; animation: claim-wipe-out .45s ease-out both; } |
| +#claim.is-celebrating .claim-tick { stroke-dasharray: 20; animation: claim-tick .45s ease-out .55s both; } |
| +#claim.is-celebrating #claim-finished { animation: claim-fade .5s ease .8s both; } |
| +@keyframes claim-spin { to { transform: rotate(1turn); } } |
| +@keyframes claim-travel { 0% { left: 0; opacity: 0; } 20%,80% { opacity: 1; } 100% { left: 100%; opacity: 0; } } |
| +@keyframes claim-breathe { 50% { box-shadow: 0 0 0 6px var(--accent-soft); } } |
| +@keyframes claim-wipe-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } } |
| +@keyframes claim-wipe-out { to { clip-path: inset(0 0 0 100%); opacity: 0; } } |
| +@keyframes claim-tick { from { stroke-dashoffset: 20; } to { stroke-dashoffset: 0; } } |
| +@keyframes claim-fade { from { opacity: .15; } to { opacity: 1; } } |
| +@keyframes claim-burst { 0% { opacity: 1; transform: rotate(var(--a)) translateX(6px) scale(.4); } 70% { opacity: 1; } 100% { opacity: 0; transform: rotate(var(--a)) translateX(var(--d)) rotate(90deg); } } |
| +@media (prefers-reduced-motion: reduce) { |
| + #claim *, #claim *::before, #claim *::after { animation: none !important; transition: none !important; } |
| + #claim .claim-track i, #claim .claim-burst, #claim.is-celebrating .claim-address .claim-old { display: none; } |
| + #claim.is-celebrating #claim-finished { animation: claim-fade .2s ease both !important; } |
| +} |
| </style> |
| </head> |
| <body> |
| {{template "console_header" .Chrome}} |
| -<main id="claim" data-failed="{{.Copy.failed}}" data-expired="{{.Copy.expired}}" data-kept="{{.Copy.kept}}" data-taken-down="{{.Copy.takenDown}}" data-invalid="{{.Copy.invalid}}"> |
| -<h1>{{if eq .State "claimed"}}{{.Copy.complete}}{{else}}{{.Copy.title}}{{end}}</h1> |
| -{{if .DemoName}}<div class="claim-summary"> |
| -<strong>{{.DemoName}}</strong><a href="https://{{.DemoHost}}" rel="noreferrer">{{.DemoHost}}</a> |
| -<p>{{.Copy.saved}} {{.Permanent}}</p> |
| +<main id="claim" data-title="{{.Copy.title}}" data-state="{{.State}}" data-complete-heading="{{.Copy.completeHeading}}" data-expired-heading="{{.Copy.expiredHeading}}" data-kept-heading="{{.Copy.keptHeading}}" data-failed="{{.Copy.failed}}" data-expired="{{.Copy.expired}}" data-kept="{{.Copy.kept}}" data-taken-down="{{.Copy.takenDown}}" data-invalid="{{.Copy.invalid}}"> |
| +{{if .DemoName}}<div class="claim-ticket{{if eq .State "claimed"}} is-settled{{end}}"> |
| +<span class="claim-tile" aria-hidden="true">{{icon "layers"}}</span> |
| +<div class="claim-ticket-body"><strong>{{.DemoName}}</strong> |
| +<span class="claim-address"><a class="claim-old" href="https://{{.DemoHost}}" rel="noreferrer">{{.DemoHost}}</a><a class="claim-new" href="{{.URL}}" rel="noreferrer">{{.URL}}</a></span> |
| +<span class="claim-life"><svg class="claim-clock" viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="6"/><path class="claim-hands" d="M8 4v4l3 2"/><path class="claim-tick" d="M4 8l3 3 5-6"/></svg><time class="claim-old" datetime="{{.EndTime}}" title="{{.EndTime}}">{{.TimeLeft}}</time><span class="claim-new">{{.Copy.done}}</span></span></div> |
| +<span class="claim-burst" aria-hidden="true"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></span> |
| </div>{{end}} |
| +<h1 id="claim-heading">{{if eq .State "claimed"}}{{.Copy.completeHeading}}{{else if or (eq .State "stopping") (eq .State "aborted")}}{{.Copy.failureHeading}}{{else if .EmailPending}}{{.Copy.codeHeading}}{{else if and .Address (gt .Eligible 1)}}{{.Copy.accountsHeading}}{{else if eq .State "proof"}}{{.Copy.heading}}{{else}}{{.Copy.title}}{{end}}</h1> |
| {{if .Error}}<p role="alert">{{.Error}}</p><p><a href="/demo/claim">{{.Copy.back}}</a></p>{{end}} |
| {{if eq .State "no_accounts"}}<p>{{.Copy.identity}} <strong>{{.Address}}</strong></p><p>{{.Copy.noAccounts}}</p> |
| -<fieldset class="claim-unavailable"><legend>{{.Copy.unavailableAccounts}}</legend>{{range .Accounts}}{{template "claim_card" .}}{{end}}</fieldset>{{end}} |
| +<fieldset class="claim-unavailable"><legend>{{.Copy.accountsLabel}}</legend>{{range .Accounts}}{{template "claim_card" .}}{{end}}</fieldset>{{end}} |
| <input type="hidden" name="nonce" value="{{.Nonce}}"> |
| <input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <p id="claim-error" role="alert" tabindex="-1" hidden></p> |
| -{{if eq .State "missing"}}<p>{{.Copy.missing}}</p>{{end}} |
| +<p id="claim-opening" role="status"{{if ne .State "missing"}} hidden{{end}}><span class="claim-spinner" aria-hidden="true"></span>{{.Copy.opening}}</p>{{if eq .State "missing"}}<p id="claim-missing" hidden>{{.Copy.missing}}</p>{{end}} |
| +<div id="claim-expired-next" hidden><p>{{.Copy.newDemo}}</p><div class="claim-paste"><code id="claim-new-demo">{{.Copy.newDemoLine}}</code><button class="btn-sm btn-secondary" type="button" data-copy-target="claim-new-demo" data-copy="{{.Copy.copy}}" data-copied="{{.Copy.copied}}" hidden>{{.Copy.copy}}</button></div></div> |
| +<p id="claim-kept-next" hidden><a href="/?next=%2Fdemo%2Fclaim">{{.Copy.consoleSignin}}</a></p> |
| {{if eq .State "disabled"}}<p>{{.Copy.disabled}}</p>{{end}} |
| {{if or (eq .State "claiming") (eq .State "stopping")}} |
| -<div id="claim-progress" data-neutral="{{.Copy.title}}" data-stopping="{{.Copy.stopping}}" data-copying="{{.Copy.copying}}" data-starting="{{.Copy.starting}}" data-done="{{.Copy.done}}" data-aborted="{{.Copy.aborted}}" data-poll-failed="{{.Copy.pollFailed}}"> |
| +<div id="claim-progress" data-stage="{{.Step}}" data-failure-heading="{{.Copy.failureHeading}}" data-neutral="{{.Copy.resuming}}" data-stopping="{{.Copy.stopping}}" data-copying="{{.Copy.copying}}" data-starting="{{.Copy.starting}}" data-done="{{.Copy.done}}" data-aborted="{{.Copy.aborted}}" data-poll-failed="{{.Copy.pollFailed}}"> |
| +<p id="claim-status"{{if gt .Step 0}} class="claim-sr-only"{{end}} role="status" aria-live="polite">{{if eq .State "stopping"}}{{.Copy.stopping}}{{else if eq .Step 2}}{{.Copy.starting}}{{else if eq .Step 1}}{{.Copy.copying}}{{else}}<span class="claim-spinner" aria-hidden="true"></span>{{.Copy.resuming}}{{end}}</p> |
| +<div class="claim-transit" aria-hidden="true"><span>{{icon "layers"}}</span><span class="claim-track"><i></i><i></i><i></i></span><span class="claim-home">{{icon "server"}}</span></div> |
| <ol class="claim-steps"> |
| -<li data-step="1"{{if eq .Step 1}} aria-current="step"{{end}}>{{.Copy.copying}}</li> |
| -<li data-step="2"{{if eq .Step 2}} aria-current="step"{{end}}>{{.Copy.starting}}</li> |
| -<li data-step="3"{{if eq .Step 3}} aria-current="step"{{end}}>{{.Copy.done}}</li> |
| +<li data-step="1"{{if gt .Step 1}} class="is-done"{{end}}{{if eq .Step 1}} aria-current="step"{{end}}><span class="claim-node" aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3 8l3 3 7-7"/></svg></span><strong>{{.Copy.copying}}</strong><span class="claim-step-detail">{{.Copy.copyingDetail}}</span></li> |
| +<li data-step="2"{{if gt .Step 2}} class="is-done"{{end}}{{if eq .Step 2}} aria-current="step"{{end}}><span class="claim-node" aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3 8l3 3 7-7"/></svg></span><strong>{{.Copy.starting}}</strong><span class="claim-step-detail">{{.Copy.startingDetail}}</span></li> |
| +<li data-step="3"{{if eq .Step 3}} aria-current="step"{{end}}><span class="claim-node" aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3 8l3 3 7-7"/></svg></span><strong>{{.Copy.done}}</strong></li> |
| </ol> |
| -<p id="claim-status"{{if gt .Step 0}} class="claim-sr-only"{{end}} role="status" aria-live="polite">{{if eq .State "stopping"}}{{.Copy.stopping}}{{else if eq .Step 2}}{{.Copy.starting}}{{else if eq .Step 1}}{{.Copy.copying}}{{else}}{{.Copy.title}}{{end}}</p> |
| + |
| <a id="claim-reload" href="/demo/claim">{{.Copy.reload}}</a> |
| </div>{{end}} |
| {{if eq .State "aborted"}}<p>{{.Copy.aborted}}</p>{{end}} |
| -{{if eq .State "claimed"}} |
| -<p class="claim-result"><a class="btn" href="{{.URL}}" rel="noreferrer">{{.URL}}</a></p> |
| -<p><strong>{{.App}}</strong></p><p>{{.Copy.oldAddress}}</p> |
| -<div class="claim-command"> |
| -<p>{{.Copy.cliCommandLabel}}</p> |
| -<pre><code id="claim-cli-command">{{.Copy.next}}</code></pre> |
| -<button id="claim-copy" class="btn-sm btn-secondary" type="button" data-copy="{{.Copy.copy}}" data-copied="{{.Copy.copied}}" aria-live="polite" hidden>{{.Copy.copy}}</button> |
| -</div> |
| +{{if or (eq .State "claimed") (eq .State "claiming") (eq .State "stopping")}} |
| +<div id="claim-finished"{{if ne .State "claimed"}} hidden{{end}}> |
| +<p>{{.Copy.completeDetail}}</p> |
| +<p class="claim-result"><a class="btn claim-open" href="{{.URL}}" rel="noreferrer">{{.Copy.open}}</a></p><p class="claim-result-address">{{.URL}}</p> |
| +<section class="claim-next"><h2>{{.Copy.keepGoing}}</h2><h3>{{.Copy.agentHeading}}</h3><p>{{.Copy.agentDetail}}</p> |
| +<div class="claim-paste"><code id="claim-agent-command">{{.Copy.agentLine}}</code><button class="btn-sm btn-secondary" type="button" data-copy-target="claim-agent-command" data-copy="{{.Copy.copy}}" data-copied="{{.Copy.copied}}" hidden>{{.Copy.copy}}</button></div> |
| +<details class="claim-command"><summary>{{.Copy.cliHeading}}</summary> |
| +<p>{{.Copy.cliCommandLabel}}</p><pre><code id="claim-cli-command">{{.Copy.next}}</code></pre> |
| +<button id="claim-copy" data-copy-target="claim-cli-command" class="btn-sm btn-secondary" type="button" data-copy="{{.Copy.copy}}" data-copied="{{.Copy.copied}}" aria-live="polite" hidden>{{.Copy.copy}}</button> |
| +</details><p class="claim-detail">{{.Copy.oldAddress}}</p></section></div> |
| {{end}} |
| {{if and .HasIntent .CanClaim}} |
| {{if .Address}} |
| @@ -87,18 +186,18 @@ |
| <form method="post" action="/demo/claim/select"{{if .AutoSubmit}} data-auto-submit{{end}}> |
| <input type="hidden" name="nonce" value="{{.Nonce}}"><input type="hidden" name="csrf" value="{{.CSRF}}"> |
| {{if .Single}} |
| -<div class="claim-single"><p><strong>{{.Copy.destination}}</strong></p>{{with .Single.Plan}}<p class="claim-detail">{{.}}</p>{{end}}{{with .Single.Room}}<p class="claim-detail">{{.}}</p>{{end}}</div> |
| +<fieldset><legend>{{.Copy.accountsLabel}}</legend><div class="claim-single claim-card"><p><strong>{{.Copy.destination}}</strong></p>{{with .Single.Plan}}<p class="claim-detail">{{.}}</p>{{end}}{{template "claim_slots" .Single}}{{with .Single.Room}}<p class="claim-detail">{{.}}</p>{{end}}</div> |
| <input type="hidden" name="accountId" value="{{.Single.Sqid}}"> |
| -{{if gt (len .Accounts) 1}}<fieldset class="claim-unavailable"><legend>{{.Copy.unavailableAccounts}}</legend>{{range .Accounts}}{{if .Reason}}{{template "claim_card" .}}{{end}}{{end}}</fieldset>{{end}} |
| +{{range .Accounts}}{{if .Reason}}{{template "claim_card" .}}{{end}}{{end}}</fieldset> |
| {{else if .Accounts}} |
| -<fieldset><legend>{{.Copy.choose}}</legend> |
| +<p>{{.Copy.accountsIntro}}</p><fieldset><legend>{{.Copy.accountsLabel}}</legend> |
| {{range .Accounts}} |
| <label class="claim-card"><input type="radio" name="accountId" value="{{.Sqid}}"{{if eq .Sqid $.SelectedAccount}} checked{{end}}{{if .Reason}} disabled{{else}} required{{end}} data-button="{{.Button}}"> |
| -<span><strong>{{.Name}}</strong>{{with .Plan}}<span class="claim-detail">{{.}}</span>{{end}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}{{with .Reason}}<span class="claim-detail">{{.}}</span>{{end}}</span></label> |
| +<span><strong>{{.Name}}</strong>{{with .Plan}}<span class="claim-detail">{{.}}</span>{{end}}{{template "claim_slots" .}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}{{with .Reason}}<span class="claim-detail">{{.}}</span>{{end}}</span></label> |
| {{end}}</fieldset> |
| {{else}}<p>{{.Copy.new}}</p><input type="hidden" name="create" value="1">{{end}} |
| <p id="claim-resuming" role="status" hidden>{{.Copy.resuming}}</p> |
| -<button type="submit" data-neutral="{{.Copy.confirm}}">{{.Copy.confirm}}</button> |
| +<button type="submit" data-working="{{.Copy.selectWorking}}" data-neutral="{{.Copy.choose}}">{{.Copy.confirm}}</button> |
| </form> |
| {{else}} |
| {{if .EmailPending}} |
| @@ -106,15 +205,16 @@ |
| <form class="claim-proof" method="post" action="/demo/claim/prove"> |
| <input type="hidden" name="nonce" value="{{.Nonce}}"><input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <label for="code">{{.Copy.code}}</label><input type="text" id="code" name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" required> |
| -<button type="submit">{{.Copy.prove}}</button> |
| +<button type="submit" data-working="{{.Copy.codeWorking}}">{{.Copy.prove}}</button> |
| </form> |
| -<details class="claim-email-change"><summary>{{.Copy.email}}</summary> |
| +<p>{{.Copy.codeRecovery}}</p><details class="claim-email-change"><summary>{{.Copy.changeAddress}}</summary> |
| {{end}} |
| <p class="claim-intro">{{.Copy.emailIntro}}</p> |
| <form class="claim-proof" method="post" action="/demo/claim/prove"> |
| <input type="hidden" name="nonce" value="{{.Nonce}}"><input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <label for="email">{{.Copy.email}}</label><input id="email" name="email" type="email" autocomplete="email" autocapitalize="off" spellcheck="false" inputmode="email" required> |
| -<button type="submit"{{if .EmailPending}} class="btn-secondary"{{end}}>{{.Copy.continue}}</button> |
| +<p class="claim-detail">{{.Copy.emailHint}}</p><div class="claim-keymail"><strong>{{.Copy.keymailHeading}}</strong><p>{{.Copy.keymailDetail}}</p></div> |
| +<button type="submit" data-working="{{.Copy.emailWorking}}"{{if .EmailPending}} class="btn-secondary"{{end}}>{{.Copy.continue}}</button> |
| </form> |
| {{if .EmailPending}}</details>{{end}} |
| <p class="claim-signin">{{.Copy.signinPrompt}} <a href="/?next=%2Fdemo%2Fclaim">{{.Copy.signin}}</a></p> |
| @@ -128,5 +228,7 @@ |
| {{define "claim_card"}} |
| <label class="claim-card"><input type="radio" name="accountId" value="{{.Sqid}}" disabled> |
| -<span><strong>{{.Name}}</strong>{{with .Plan}}<span class="claim-detail">{{.}}</span>{{end}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}<span class="claim-detail">{{.Reason}}</span></span></label> |
| +<span><strong>{{.Name}}</strong>{{with .Plan}}<span class="claim-detail">{{.}}</span>{{end}}{{template "claim_slots" .}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}<span class="claim-detail">{{.Reason}}</span></span></label> |
| {{end}} |
| + |
| +{{define "claim_slots"}}{{if gt .Limit 0}}{{if .Slots}}<span class="claim-slots" aria-hidden="true">{{range .Slots}}<i{{if .}} class="used"{{end}}></i>{{end}}</span>{{else}}<meter min="0" max="{{.Limit}}" value="{{.Used}}" aria-label="{{.Room}}">{{.Used}} / {{.Limit}}</meter>{{end}}<span class="claim-detail">{{.Used}} / {{.Limit}}</span>{{end}}{{end}} |
diff --git a/internal/console/testdata/demo_claim_browser.mjs b/internal/console/testdata/demo_claim_browser.mjs| index 8e19f87b2..c22c0c43f 100644 |
| --- a/internal/console/testdata/demo_claim_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_browser.mjs |
| @@ -1,5 +1,6 @@ |
| import {spawn} from 'node:child_process'; |
| import assert from 'node:assert/strict'; |
| +import {writeFile} from 'node:fs/promises'; |
| import {captureClaim, watchClaimCSP} from './demo_claim_layout.mjs'; |
| const [binary, profile, target, screenshots, expectedError] = process.argv.slice(2); |
| @@ -44,12 +45,15 @@ async function key(key, code, number) { |
| await call('Input.dispatchKeyEvent', {type:key === 'Enter' ? 'keyDown' : 'rawKeyDown', key, code, windowsVirtualKeyCode:number, ...(key === 'Enter' ? {text:'\r', unmodifiedText:'\r'} : {})}); |
| await call('Input.dispatchKeyEvent', {type:'keyUp', key, code, windowsVirtualKeyCode:number}); |
| } |
| -const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 25000); |
| +const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, target.startsWith("[") ? 230000 : 40000); |
| try { |
| const created = await call('Target.createTarget', {url:'about:blank'}, false); |
| session = (await call('Target.attachToTarget', {targetId:created.targetId, flatten:true}, false)).sessionId; |
| await call('Page.enable'); |
| await call('Page.addScriptToEvaluateOnNewDocument', {source:watchClaimCSP}); |
| + if (target.startsWith('[')) { |
| + await runUX(JSON.parse(target)); |
| + } else { |
| await call('Page.navigate', {url:target}); |
| if (expectedError) { |
| await until('location.hash === "" && document.getElementById("claim-error")?.hidden === false'); |
| @@ -61,7 +65,7 @@ try { |
| process.stdout.write('expired message, fragment cleared, zero CSP violations passed\n'); |
| } else { |
| await until('location.hash === "" && !!document.getElementById("email")'); |
| - await captureClaim(call, evaluate, screenshots, 'email', [360, 390, 1100]); |
| + await captureClaim(call, evaluate, screenshots, 'email', [390, 1280]); |
| const history = await call('Page.getNavigationHistory'); |
| assert(history.entries.every(entry => !entry.url.includes('#') && !entry.url.includes('claimToken'))); |
| assert(!String(await evaluate('document.referrer')).includes('#')); |
| @@ -75,7 +79,7 @@ try { |
| await key('Enter','Enter',13); |
| await until('!!document.getElementById("code")'); |
| assert.equal(await evaluate('document.querySelector("label[for=code]") !== null'), true); |
| - await captureClaim(call, evaluate, screenshots, 'code', [360, 390, 1100]); |
| + await captureClaim(call, evaluate, screenshots, 'code', [390, 1280]); |
| assert.equal(await evaluate('document.querySelectorAll("#claim button[type=submit]:not(.btn-secondary)").length'), 1); |
| assert.equal(await evaluate('document.querySelector(".claim-email-change").open'), false); |
| await evaluate('document.querySelector(".claim-email-change summary").click(); document.getElementById("email").focus()'); |
| @@ -88,7 +92,7 @@ try { |
| await call('Input.insertText', {text:'123456'}); |
| assert.equal(await evaluate('document.getElementById("code").form.checkValidity()'), true); |
| await key('Tab','Tab',9); |
| - assert.equal(await evaluate('document.activeElement.textContent'), 'Confirm email'); |
| + assert.equal(await evaluate('document.activeElement.textContent'), 'Confirm'); |
| await evaluate(`document.getElementById('code').form.addEventListener('submit', event => { |
| event.preventDefault(); |
| const form = event.target; |
| @@ -110,9 +114,114 @@ try { |
| process.stdout.write('email/code mobile layouts, secondary email and code submissions, CSP passed\n'); |
| process.stdout.write('fragment_cleared post_exchange keyboard_email_submit passed\n'); |
| } |
| + } |
| } finally { |
| clearTimeout(timer); |
| const closed = new Promise(resolve => chrome.once('exit', resolve)); |
| chrome.kill('SIGTERM'); |
| await closed; |
| } |
| + |
| +async function runUX(scenes) { |
| + await call('Network.enable'); |
| + for (const scene of scenes) { |
| + await call('Network.clearBrowserCookies'); |
| + const origin = new URL(scene.URL).origin; |
| + const cookies = []; |
| + if (scene.Cookie) cookies.push({name:'carlos_demo_claim_flow',value:scene.Cookie,url:origin,path:'/demo/claim',secure:true,httpOnly:true}); |
| + if (scene.Session) cookies.push({name:'carlos_console_session',value:scene.Session,url:origin,path:'/',httpOnly:true}); |
| + await call('Network.setCookies',{cookies}); |
| + if (scene.Name === 'missing') await call('Network.setBlockedURLs',{urls:['*demo_claim.js*']}); |
| + await call('Page.navigate',{url:scene.URL}); |
| + await until('document.readyState === "complete" && !!document.getElementById("claim")'); |
| + assert.equal(await evaluate('document.getElementById("claim").dataset.state'),scene.State,scene.Name); |
| + if (scene.Text) { |
| + await until('document.getElementById("claim-error").hidden === false'); |
| + assert.equal(await evaluate('document.getElementById("claim-error").textContent'),scene.Text); |
| + assert.equal(await evaluate('!document.getElementById("claim-missing") || document.getElementById("claim-missing").hidden'),true); |
| + assert.equal(await evaluate('document.querySelector(".claim-ticket")'),null,'spent token disclosed a ticket'); |
| + if (scene.Name === 'expired') { |
| + assert.equal(await evaluate('document.getElementById("claim-heading").textContent'),'This demo has ended'); |
| + assert.equal(await evaluate('document.getElementById("claim-expired-next").hidden'),false); |
| + } |
| + if (scene.Name === 'kept') { |
| + assert.equal(await evaluate('document.getElementById("claim-heading").textContent'),'This app has already been kept'); |
| + assert.equal(await evaluate('document.getElementById("claim-kept-next").hidden'),false); |
| + } |
| + } |
| + if (scene.Name === 'missing') { |
| + assert.equal(await evaluate('document.getElementById("claim-opening").getBoundingClientRect().height > 0'),true,'loader depends on script'); |
| + } |
| + if (scene.Name === 'fast') { |
| + await until('document.getElementById("claim").dataset.state === "claimed"'); |
| + const stages = await evaluate('window.claimStageTimes'); |
| + for (const stage of [1,2,3]) { |
| + const a = stages.find(row => row.stage === stage); |
| + const b = stages.find(row => row.stage === stage+1); |
| + assert(a && b,JSON.stringify(stages)); |
| + assert(b.time-a.time >= 650,JSON.stringify(stages)); |
| + } |
| + assert.equal(await evaluate('window.claimBlankFrames'),0,'blank progress frame'); |
| + await captureClaim(call,evaluate,screenshots,'live-done',[390,1280]); |
| + await call('Page.reload'); |
| + await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| + assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),false); |
| + assert.equal(await evaluate('document.querySelector(".claim-command").open'),false); |
| + } |
| + await captureClaim(call,evaluate,screenshots,scene.Name,[390,1280]); |
| + if (scene.Name === 'fast') await liveMotion(scene); |
| + assert.equal(await evaluate(`Array.from(document.getAnimations()).some(a => a.playState === 'running' && a.animationName !== 'claim-fade')`),false,'reduced motion travels'); |
| + if (['email','code','one','many'].includes(scene.Name)) { |
| + await evaluate(`(() => { |
| + const form = document.querySelector('#claim form'); |
| + if (document.getElementById('email') && !document.getElementById('code')) document.getElementById('email').value='reader@example.com'; |
| + if (document.getElementById('code')) document.getElementById('code').value='123456'; |
| + const radio = form.querySelector('input[type=radio]:not(:disabled)'); |
| + if (radio) radio.click(); |
| + HTMLFormElement.prototype.submit = function() { window.claimSubmitEnd=performance.now(); }; |
| + window.claimSubmitStart=performance.now(); form.requestSubmit(); |
| + })()`); |
| + assert.equal(await evaluate('!!document.querySelector("button.is-working[aria-busy=true]")'),true); |
| + assert.notEqual(await evaluate('getComputedStyle(document.querySelector("button.is-working")).color'),'rgba(0, 0, 0, 0)','working label is transparent'); |
| + assert.equal(await evaluate('getComputedStyle(document.querySelector("button.is-working"),"::after").display'),'none','shared spinner covers the working label'); |
| + assert.equal(await evaluate('document.querySelector("button.is-working").textContent === document.querySelector("button.is-working").dataset.working'),true); |
| + await new Promise(resolve=>setTimeout(resolve,500)); |
| + assert.equal(await evaluate('window.claimSubmitEnd === undefined'),true,'button submitted before 650ms'); |
| + await until('window.claimSubmitEnd !== undefined'); |
| + assert(await evaluate('window.claimSubmitEnd-window.claimSubmitStart >= 650')); |
| + await captureClaim(call,evaluate,screenshots,scene.Name+'-working',[390,1280]); |
| + } |
| + await call('Network.setBlockedURLs',{urls:[]}); |
| + process.stdout.write(scene.Name+' screenshots and CSP passed\n'); |
| + } |
| +} |
| + |
| +async function liveMotion(scene) { |
| + for (const width of [390,1280]) for (const theme of ['light','dark']) for (const motion of ['no-preference','reduce']) { |
| + await call('Emulation.setDeviceMetricsOverride',{width,height:900,deviceScaleFactor:1,mobile:false}); |
| + await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:theme},{name:'prefers-reduced-motion',value:motion}]}); |
| + await call('Page.navigate',{url:scene.URL+'?replay=1'}); |
| + await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claiming"'); |
| + await until('document.getElementById("claim")?.dataset.state === "claimed"'); |
| + assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),true); |
| + if (motion === 'reduce') { |
| + assert.equal(await evaluate('getComputedStyle(document.querySelector(".claim-burst")).display'),'none'); |
| + assert.equal(await evaluate(`document.getAnimations().some(a=>a.animationName==='claim-burst'||a.animationName==='claim-wipe-in')`),false); |
| + } else { |
| + assert.equal(await evaluate(`document.getAnimations().some(a=>a.animationName==='claim-burst')`),true); |
| + } |
| + const stages = await evaluate('window.claimStageTimes'); |
| + for (const n of [1,2,3]) assert(stages.find(s=>s.stage===n+1).time-stages.find(s=>s.stage===n).time>=650,JSON.stringify(stages)); |
| + assert.equal(await evaluate('window.claimBlankFrames'),0); |
| + await new Promise(resolve=>setTimeout(resolve,450)); |
| + if (screenshots) { |
| + const shot=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:true}); |
| + await writeFile(screenshots+'/reveal-'+motion+'-'+theme+'-'+width+'.png',Buffer.from(shot.data,'base64')); |
| + } |
| + assert.deepEqual(await evaluate('window.claimCSPViolations'),[]); |
| + await call('Page.reload'); |
| + await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| + assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),false); |
| + assert.equal(await evaluate('document.getAnimations().length'),0); |
| + } |
| +} |
diff --git a/internal/console/testdata/demo_claim_layout.mjs b/internal/console/testdata/demo_claim_layout.mjs| index a56208ef7..9fd2ec562 100644 |
| --- a/internal/console/testdata/demo_claim_layout.mjs |
| +++ b/internal/console/testdata/demo_claim_layout.mjs |
| @@ -1,7 +1,7 @@ |
| import assert from 'node:assert/strict'; |
| import {writeFile} from 'node:fs/promises'; |
| -export async function captureClaim(call, evaluate, screenshots, state, widths = [360, 390]) { |
| +export async function captureClaim(call, evaluate, screenshots, state, widths = [390, 1280]) { |
| for (const width of widths) { |
| await call('Emulation.setDeviceMetricsOverride', {width, height:900, deviceScaleFactor:1, mobile:false}); |
| for (const theme of ['light', 'dark']) { |
| @@ -58,6 +58,26 @@ export async function captureClaim(call, evaluate, screenshots, state, widths = |
| export const watchClaimCSP = ` |
| window.claimCSPViolations = []; |
| + window.claimStageTimes = []; |
| + window.claimBlankFrames = 0; |
| + document.addEventListener('DOMContentLoaded', () => { |
| + const claim = document.getElementById('claim'); |
| + const progress = document.getElementById('claim-progress'); |
| + if (!progress) return; |
| + let last; |
| + const record = () => { |
| + const stage = claim.dataset.state === 'claimed' ? 4 : Number(progress.dataset.stage); |
| + if (stage !== last) { window.claimStageTimes.push({stage,time:performance.now()}); last=stage; } |
| + }; |
| + record(); |
| + new MutationObserver(record).observe(claim,{attributes:true,subtree:true,attributeFilter:['data-stage','data-state']}); |
| + const frame = () => { |
| + const finished = document.getElementById('claim-finished'); |
| + if (progress.getBoundingClientRect().height === 0 && (!finished || finished.getBoundingClientRect().height === 0)) window.claimBlankFrames++; |
| + if (claim.dataset.state !== 'claimed') requestAnimationFrame(frame); |
| + }; |
| + requestAnimationFrame(frame); |
| + }); |
| document.addEventListener('securitypolicyviolation', event => { |
| window.claimCSPViolations.push(event.violatedDirective); |
| }); |
diff --git a/internal/console/testdata/demo_claim_resume_browser.mjs b/internal/console/testdata/demo_claim_resume_browser.mjs| index 6b06e9ccb..016410fb3 100644 |
| --- a/internal/console/testdata/demo_claim_resume_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_resume_browser.mjs |
| @@ -97,7 +97,7 @@ try { |
| await call('Page.navigate',{url:single.target+'/demo/claim?long=1'}); |
| await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 2'); |
| assert.equal(await evaluate('document.querySelector(".claim-card strong").textContent.length > 100'), true); |
| - assert.equal(await evaluate('document.querySelector(".claim-summary a").textContent.length > 100'), true); |
| + assert.equal(await evaluate('document.querySelector(".claim-address .claim-old").textContent.length > 100'), true); |
| await evaluate('document.querySelector(".claim-card input").click()'); |
| await capture('long-name'); |
| await call('Network.setCookies', {cookies:[ |
| @@ -134,7 +134,7 @@ try { |
| await call('Page.navigate', {url:target+'/demo/claim'}); |
| await until('document.readyState === "complete" && !!document.querySelector("input[type=radio][name=accountId]")'); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").disabled'),true); |
| - assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'),'Keep this demo'); |
| + assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'),'Choose an account'); |
| await evaluate('document.querySelector("#claim input[type=radio]:not(:disabled)").focus()'); |
| await key(' ', 'Space', 32); |
| await until('!!document.querySelector("#claim input[type=radio]:checked")'); |
| @@ -148,7 +148,7 @@ try { |
| assert.equal(await evaluate('document.querySelectorAll("script").length'),1); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'), 'Keep in Personal projects'); |
| assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:not(:disabled))")).every(card => card.innerText.includes("Has room") && !card.innerText.includes("apps and instances"))'),true); |
| - assert.deepEqual(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:disabled) .claim-detail")).map(el => el.textContent)'),['Free', 'Your role cannot create apps in this account.']); |
| + assert.deepEqual(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:disabled) .claim-detail")).map(el => el.textContent)'),['Free plan', 'You can view this account but not add apps. Ask one of its owners.']); |
| await capture('many'); |
| await evaluate(`const form = document.querySelector('form[action="/demo/claim/select"]'); form.addEventListener('submit', event => event.preventDefault(), {once:true}); form.requestSubmit(); document.querySelector('#claim input[type=radio]:not(:disabled)').click()`); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").disabled'),true,'radio change re-enabled submitted button'); |
| @@ -178,11 +178,12 @@ try { |
| for (let i=0; i<40 && statusRequests === repeatedPoll; i++) await new Promise(r=>setTimeout(r,100)); |
| await new Promise(r=>setTimeout(r,200)); |
| assert.equal(await evaluate('window.liveWrites'),0,'unchanged poll rewrote live region'); |
| - await until('!!document.querySelector(".claim-result a")'); |
| + await until('document.getElementById("claim").dataset.state === "claimed"'); |
| await capture('done'); |
| - assert.equal(await evaluate('document.querySelector(".claim-result a").textContent.replace(/^https:\\/\\//, "")'),await evaluate('document.querySelector(".claim-result a").getAttribute("href").replace(/^https:\\/\\//, "")')); |
| - assert.equal(await evaluate('document.querySelector("#claim h1").textContent'),'Your demo is now a permanent app.'); |
| - assert.equal(await evaluate('document.querySelector("#claim").innerText.split("Your demo is now a permanent app.").length-1'),1); |
| + assert.equal(await evaluate('document.querySelector(".claim-result a").textContent'),'Open your app'); |
| + assert.equal(await evaluate('document.querySelector("#claim h1").textContent.endsWith(" is yours")'),true); |
| + assert.equal(await evaluate('document.querySelector(".claim-command").open'),false); |
| + await evaluate('document.querySelector(".claim-command").open = true'); |
| assert.equal(security.length,0,JSON.stringify(security)); |
| process.stdout.write('progress: polled to step 2 and done automatically; no CSP violations\n'); |
| assert.equal(await evaluate('document.getElementById("claim-copy").hidden'), false); |
| @@ -238,14 +239,15 @@ try { |
| await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.stopping'); |
| assert.equal(await evaluate('document.querySelectorAll("[aria-current=step]").length'),0); |
| assert.equal(await evaluate('getComputedStyle(document.getElementById("claim-status")).clipPath'),'none'); |
| - await capture('stopping'); |
| + assert.equal(await evaluate('!!document.querySelector(".claim-steps .is-failed")'),true); |
| + await capture('stopping-live'); |
| await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.aborted'); |
| await call('Page.navigate',{url:target+'/demo/claim?testProgress=unknown'}); |
| await until('!!document.getElementById("claim-progress") && document.querySelectorAll("[aria-current=step]").length === 0'); |
| const unknownPolls = statusRequests; |
| await new Promise(r=>setTimeout(r,6500)); |
| assert(statusRequests >= unknownPolls + 2, 'neutral progress stopped polling'); |
| - assert.equal(await evaluate('document.getElementById("claim-status").textContent'),'Keep your demo'); |
| + assert.equal(await evaluate('document.getElementById("claim-status").textContent'),'Keeping your demo in the account you chose…'); |
| assert.equal(await evaluate('document.querySelectorAll("[aria-current=step]").length'),0); |
| process.stdout.write('fallback: stopped after three failures, retained no-script reload, stopped on abort; no CSP violations\n'); |
| } finally { |