Build the approved console claim journey
Add app tickets, capacity cards, timed progress, a live completion reveal, and the approved claim copy. Keep the existing CSP and authentication paths. Keep aborted claims read-only: reservation narrows the browser credential to status access and does not retain the original session for safe retry. Validate with the scoped console tests, record-read audit and Chromium checks for timing, CSP, reduced motion, reload and responsive layouts.
13 files changed,
+834
−120
docs/superpowers/specs/LUNA-COPY-BRIEF-CLAIM-UX.md+9 −0docs/superpowers/specs/LUNA-COPY-RESULT-CLAIM-UX.md+100 −0internal/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+117 −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
Intent
diff --git a/docs/superpowers/specs/LUNA-COPY-BRIEF-CLAIM-UX.md b/docs/superpowers/specs/LUNA-COPY-BRIEF-CLAIM-UX.md| new file mode 100644 |
| index 000000000..6f523126a |
| --- /dev/null |
| +++ b/docs/superpowers/specs/LUNA-COPY-BRIEF-CLAIM-UX.md |
| @@ -0,0 +1,9 @@ |
| +You are the copy-review gate itself for a build. Do NOT run the copy-review skill or start any server. Read only; write nothing except your final answer. |
| + |
| +Inputs (read them): the approved UX mockups in /home/paulca/.cache/agent-start-demo-ux/site/ (s1-newcomer.html, s2-developer.html, s3-keymail.html, s4-email-code.html, s5-failures.html, s6-tada.html, s7-moved.html, notes.html) and the current shipped strings in /home/paulca/amadan.net/carlos/platform/internal/console/demo_claim_copy.go, internal/edge/demo_banner.go, internal/edge/demo_moved.go (and any copy file they reference). Also the approved Plan 2 banner text wherever demo_banner.go takes it from. |
| + |
| +Scope: ONLY text a person reads on surfaces served by the console and the edge: the console claim pages (/demo/claim and its states: ticket, account cards, progress stages, buttons and working labels, tada/kept page, next steps, expired / already kept / failure / "Your demo is back" retry states, Keymail explanation such as "One sign-in, then straight back."), the edge demo banner (one line with time left, plus the no-script details content including Report abuse), and the edge moved page. EXCLUDE the website homepage, /start, the hero and its paste box, the agent chat/terminal sketches, Keymail's own page and emails. |
| + |
| +Rules: plain, calm, direct; no em dashes (use a full stop and a new sentence); no exclamation marks; British spelling is not required, keep the repo's existing spelling; never name a tenant; keep values as placeholders like {app}, {address}, {hours}, {account}, {used}, {limit}. Where a mockup string already matches an approved shipped constant, keep the shipped constant verbatim and say so. The four shipped spent-link constants (demoClaimExpired, demoClaimAlreadyKept, demoClaimTakenDown, demoClaimLinkBroken) and the loader lines approved earlier ("Opening your demo…", "Checking your email address…", "Checking the code…", "Keeping your demo in the account you chose…") are approved; reuse them unless the mockup's state needs different words, and then say why. Check the banner line against the Plan 2 banner text: every warning it carries must survive (in the line or the details). |
| + |
| +Output: a copy deck as a Markdown table with columns ID | surface/state | approved text | source (mockup file or shipped constant) | note. IDs like CLAIM-UX-01, BANNER-UX-01, MOVED-UX-01. One row per distinct string, including button labels, working labels, aria labels and alt text a screen reader speaks. Then a short list of strings you changed from the mockup and why. No other prose. |
diff --git a/docs/superpowers/specs/LUNA-COPY-RESULT-CLAIM-UX.md b/docs/superpowers/specs/LUNA-COPY-RESULT-CLAIM-UX.md| new file mode 100644 |
| index 000000000..9d98d399b |
| --- /dev/null |
| +++ b/docs/superpowers/specs/LUNA-COPY-RESULT-CLAIM-UX.md |
| @@ -0,0 +1,100 @@ |
| +| ID | surface/state | approved text | source (mockup file or shipped constant) | note | |
| +|---|---|---|---|---| |
| +| CLAIM-UX-01 | Claim page title | Keep your demo | Shipped `demoClaimPageTitle` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-02 | Claim page, email entry heading | Keep this app | `s3-keymail.html` | Mockup wording. | |
| +| CLAIM-UX-03 | Claim page, email entry explanation | It moves to a permanent address, and everything saved in it comes along. | `s3-keymail.html` | | |
| +| CLAIM-UX-04 | Email field label | Your email address | `s3-keymail.html` | | |
| +| CLAIM-UX-05 | Email entry hint | We’ll send a code, or take you to Keymail if you use it. | `s3-keymail.html` | | |
| +| CLAIM-UX-06 | Email entry button | Continue | Shipped `demoClaimEmailContinue` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-07 | Email entry working label | Checking your email address… | Approved loader line | Reuse approved line. | |
| +| CLAIM-UX-08 | Sign-in prompt | Already have an account? | `s3-keymail.html` | | |
| +| CLAIM-UX-09 | Sign-in link | Sign in | Shipped `demoClaimSignin` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-10 | Keymail step heading | Finish with Keymail | `s3-keymail.html` | | |
| +| CLAIM-UX-11 | Keymail explanation | Your address uses Keymail, so you’ll confirm it there. | `s3-keymail.html` | | |
| +| CLAIM-UX-12 | Keymail explanation detail | 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. | `s3-keymail.html`; `notes.html` | Mockup includes this approved one-sign-in promise. | |
| +| CLAIM-UX-13 | Keymail button | Continue with Keymail | `s3-keymail.html` | | |
| +| CLAIM-UX-14 | Keymail working label | Opening Keymail | `s3-keymail.html` | | |
| +| CLAIM-UX-15 | Alternate email action | Use a different email | `s3-keymail.html` | | |
| +| CLAIM-UX-16 | Email code heading | Check your email | `s4-email-code.html` | | |
| +| CLAIM-UX-17 | Email code explanation | We sent a six-digit code to {address}. It works for 15 minutes. | `s4-email-code.html` | Use `{address}`; spelling out six avoids mixed number styles. | |
| +| CLAIM-UX-18 | Code field label | Code | `s4-email-code.html` | | |
| +| CLAIM-UX-19 | Code button | Confirm | `s4-email-code.html` | | |
| +| CLAIM-UX-20 | Code working label | Checking the code… | Approved loader line | Reuse approved line. | |
| +| CLAIM-UX-21 | Code recovery prompt | No email? Check your spam folder, or | `s4-email-code.html` | | |
| +| CLAIM-UX-22 | Alternate email action | use a different address | `s4-email-code.html` | | |
| +| CLAIM-UX-23 | Resend-code timing | You can ask for a new code in {time}. | `s4-email-code.html` | Use dynamic `{time}`. | |
| +| CLAIM-UX-24 | Account picker heading | Where should it go? | `s4-email-code.html` | | |
| +| CLAIM-UX-25 | Account picker explanation | You have {used} accounts. Choose one with room for it. | `s4-email-code.html` | Use `{used}`. | |
| +| CLAIM-UX-26 | Account list accessible label | Accounts | `s4-email-code.html` | | |
| +| CLAIM-UX-27 | Account card name | {account} | `s4-email-code.html` | Dynamic account name. | |
| +| CLAIM-UX-28 | Account plan label | {plan} plan | `s4-email-code.html` | Dynamic plan value. | |
| +| CLAIM-UX-29 | Account capacity, available | Room for it | `s4-email-code.html` | | |
| +| CLAIM-UX-30 | Account capacity, full | Full: {used} of {limit} apps. Remove one, or see plans. | `s4-email-code.html` | Use placeholders; mockup’s app count omits instance capacity in current shipped copy. | |
| +| CLAIM-UX-31 | Account capacity, no permission | You can view this account but not add apps. Ask one of its owners. | `s4-email-code.html` | | |
| +| CLAIM-UX-32 | Account picker disabled button | Choose an account | `s4-email-code.html` | | |
| +| CLAIM-UX-33 | Account picker selected button | Keep in {account} | `s3-keymail.html` | | |
| +| CLAIM-UX-34 | Account selection working label | Starting | `s3-keymail.html` | | |
| +| CLAIM-UX-35 | Claim submission working label | Keeping your demo in the account you chose… | Shipped `demoClaimResuming` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-36 | Claim submission working label | Keeping your demo in the account you chose… | Approved loader line | Reuse approved line. | |
| +| CLAIM-UX-37 | Progress: data stage | Copying your data | Shipped `demoClaimCopying` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-38 | Progress: data stage detail | Everything saved in your demo comes with it. | `s3-keymail.html` | | |
| +| CLAIM-UX-39 | Progress: app stage | Starting your app | Shipped `demoClaimStarting` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-40 | Progress: app stage detail | Getting it ready at its permanent address. | `s3-keymail.html` | | |
| +| CLAIM-UX-41 | Progress: final stage | Ready | `s3-keymail.html` | | |
| +| CLAIM-UX-42 | Progress live status | {status} | `s3-keymail.html` | Status region speaks its current progress text. | |
| +| CLAIM-UX-43 | Completion heading | {app} is yours | `s3-keymail.html` | Replace example app name with `{app}`. | |
| +| CLAIM-UX-44 | Completion explanation | It has a permanent address now, and everything saved in it came along. | `s3-keymail.html` | | |
| +| CLAIM-UX-45 | Completion button | Open your app | `s3-keymail.html` | | |
| +| CLAIM-UX-46 | Completion app address | {app} | `s3-keymail.html` | Display and link to the assigned address. | |
| +| CLAIM-UX-47 | Next steps heading | Keep going | `s3-keymail.html` | | |
| +| CLAIM-UX-48 | Agent next-step heading | Keep building with your agent | `s3-keymail.html` | | |
| +| CLAIM-UX-49 | Agent next-step explanation | Paste this into your agent to keep changing the app the proper way. | `s3-keymail.html` | | |
| +| CLAIM-UX-50 | Agent instruction | Help me keep working on {app}. Follow the directions on https://carlosframework.com/start | `s3-keymail.html` | Substitute `{app}` for the mockup example. | |
| +| CLAIM-UX-51 | Clipboard button | Copy | Shipped `demoClaimCopy` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-52 | Command-line disclosure | Prefer the command line? | `s3-keymail.html` | | |
| +| CLAIM-UX-53 | Command-line explanation | Sign in once, then send changes with `carlos deploy`. | `s3-keymail.html` | | |
| +| CLAIM-UX-54 | Command-line instruction | `carlos auth login --console {console}` | `s3-keymail.html` | Substitute `{console}` for the mockup address. | |
| +| CLAIM-UX-55 | Old address notice | The old address now sends visitors here until {date}. | `s3-keymail.html` | Use `{date}`. | |
| +| CLAIM-UX-56 | Console link | See it in your console | `s3-keymail.html` | | |
| +| CLAIM-UX-57 | Expired claim heading | This demo has expired and been deleted. Nothing can be recovered. Ask your agent to build it again. The new demo will have a new link. | Shipped `demoClaimExpired` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-58 | Already kept claim heading | Someone has already kept this demo as a permanent app. If that was you, you can find it in your console account. This link can no longer be used. | Shipped `demoClaimAlreadyKept` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-59 | Taken-down claim message | The platform operator took down this demo. Nothing can be recovered. | Shipped `demoClaimTakenDown` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-60 | Broken claim link message | This link is wrong or incomplete. Copy the whole link again from where your agent gave it to you. | Shipped `demoClaimLinkBroken` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-61 | Claim failure heading | That didn’t finish | `s5-failures.html` | | |
| +| CLAIM-UX-62 | Claim failure explanation | Nothing is lost. We’re putting your demo back the way it was. While we do, it’s paused for a moment. | `s5-failures.html` | | |
| +| CLAIM-UX-63 | Failure recovery action | See what happens next | `s5-failures.html` | | |
| +| CLAIM-UX-64 | Failure recovery working label | Undoing | `s5-failures.html` | | |
| +| CLAIM-UX-65 | Retry state heading | Your demo is back | `s5-failures.html` | | |
| +| CLAIM-UX-66 | Retry state explanation | It’s running at its old address with all its data, until {date}. You can try keeping it again. | `s5-failures.html` | Use `{date}`. | |
| +| CLAIM-UX-67 | Retry action | Try again | `s5-failures.html` | | |
| +| CLAIM-UX-68 | Retry working label | Starting again | `s5-failures.html` | | |
| +| CLAIM-UX-69 | Open demo action | Open the demo | `s5-failures.html` | | |
| +| CLAIM-UX-70 | Retry fallback | If it fails again, try later. Your demo keeps running either way. | `s5-failures.html` | | |
| +| CLAIM-UX-71 | Aborted claim message | This claim did not finish. Open the original demo link to try again if the demo has not expired. | Shipped `demoClaimAborted` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-72 | Expired page heading | This demo has ended | `s5-failures.html` | | |
| +| CLAIM-UX-73 | Expired page explanation | Demos last 24 hours. This one ended on {date}, and its data was removed, so it can’t be kept now. | `s5-failures.html` | Use `{date}`. | |
| +| CLAIM-UX-74 | New demo instruction | You can make a new one any time. Paste this into your coding agent: | `s5-failures.html` | | |
| +| CLAIM-UX-75 | New demo instruction | Follow the directions on https://carlosframework.com/start | `s5-failures.html` | | |
| +| CLAIM-UX-76 | Expired page clipboard button | Copy | Shipped `demoClaimCopy` | Keep shipped constant verbatim. | |
| +| CLAIM-UX-77 | Already kept page heading | This app has already been kept | `s5-failures.html` | | |
| +| CLAIM-UX-78 | Already kept page explanation | It was kept on {date} and now has a permanent address. If that was you, you’ll find it in your console. | `s5-failures.html` | Use `{date}`. | |
| +| CLAIM-UX-79 | Already kept page app action | Open the app | `s5-failures.html` | | |
| +| CLAIM-UX-80 | Already kept page sign-in action | Sign in to the console | `s5-failures.html` | | |
| +| BANNER-UX-01 | Edge banner summary | Made by an AI. Temporary. Don’t enter real passwords. {hours} h left | `s1-newcomer.html` | Shortened wording retains AI origin, temporary status and password warning; details retain sensitive information warning. | |
| +| BANNER-UX-02 | Edge banner details | This is a demo that someone made with their coding agent. It ends {date} unless they keep it, and nothing in it is backed up. | `s1-newcomer.html` | | |
| +| BANNER-UX-03 | Edge banner details | Don’t enter real passwords or personal details. | `s1-newcomer.html` | Preserves the shipped warning about sensitive information. | |
| +| BANNER-UX-04 | Edge banner report link | Report abuse | Shipped `DEMO-REPORT-LINK` | Keep shipped constant verbatim. | |
| +| BANNER-UX-05 | Edge banner warning | This app was built by an AI. It is temporary. Do not enter real passwords or sensitive information. | Shipped `DEMO-BANNER` | Approved Plan 2 text, verbatim. | |
| +| BANNER-UX-06 | Edge banner details disclosure accessible label | Made by an AI. Temporary. Don’t enter real passwords. {hours} h left | `s1-newcomer.html` | Summary is the disclosure’s accessible name; warning remains present when details are collapsed. | |
| +| MOVED-UX-01 | Moved page title | This app has moved | `s7-moved.html` | | |
| +| MOVED-UX-02 | Moved page old address | {old address} | `s7-moved.html` | Displayed as the crossed-out prior address. | |
| +| MOVED-UX-03 | Moved page new address | {new address} | `s7-moved.html` | | |
| +| MOVED-UX-04 | Moved page notice expiry | This notice stays here until {date}. After that, this address stops working. | `s7-moved.html` | Use `{date}`. | |
| +| MOVED-UX-05 | Moved page action | Visit your app | `s7-moved.html` | Mockup CTA adapted to avoid tenant name. | |
| +| MOVED-UX-06 | Moved page refusal for non-browser method | This demo has moved. Open this address in your browser to visit its new home. | Shipped `MovedMethodRefusal` | Keep shipped constant verbatim. | |
| + |
| +Strings changed from the mockup: |
| + |
| +- The banner keeps the AI origin, temporary status, and warning against real passwords in its collapsed line. The expanded details retain the warning against personal or sensitive information, matching the approved Plan 2 text. |
| +- Replaced example account, app, address, time, and date values with the requested placeholders. |
| +- Changed “This app has moved” to the shipped “This demo has moved” in the non-browser refusal to preserve existing behavior. |
| \ No newline at end of file |
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..5a2392cb1 100644 |
| --- a/internal/console/static/demo_claim.js |
| +++ b/internal/console/static/demo_claim.js |
| @@ -2,16 +2,45 @@ |
| "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; |
| + } |
| + for (const form of document.querySelectorAll("#claim form")) { |
| + let submitted = false; |
| + form.addEventListener("submit", async event => { |
| + event.preventDefault(); |
| + if (submitted) return; |
| + submitted = true; |
| for (const button of form.querySelectorAll('button[type="submit"]')) { |
| 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 +49,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 +125,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 +152,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 +175,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..8e29def90 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 eq .State "stopping"}}{{.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 { |