console: one-line claim picker, honest progress, two-link done page
Account picker: each account is one row (radio, name, plan chip, usage, status chip), with a short muted note only under rows that cannot take the demo. Sponsored accounts' "unlimited" sentinel (sponsorMost) shows as "17 running"; no meter, no raw number. Rows that can take the demo sort first, each group in its original order. Past six accounts a search box (revealed by the existing external script) filters rows by name; Enter does not submit and a filtered-out choice stays chosen. Resumed choice (after Keymail step-up): the first paint is the progress view, not the list. GET still mutates nothing: the script posts the hidden choice; a noscript button keeps the no-JS path. Progress: a bar that eases inside each stage's band and never goes back, rotating reassurance lines under the active step (no animation under reduced motion), an elapsed line after 30 s, and a stuck state once the server reports progress 90 s past the operation's own 5-minute deadline (relative to render, so the browser clock does not matter). Done page: "Open in the console" (the app's console page) plus the live address as a link with an external-link icon, new tab; the duplicate grey address line is gone and the ticket shows the address as text. UX pass in the mockup kit first; type steps widened on the changed screens. New and changed strings are placeholders in demo_claim_copy.go awaiting Paul's copy review. Footer golden digests retaken for the new page bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+598
−120
internal/console/demo_claim_choice_test.go+119 −18internal/console/demo_claim_copy.go+44 −8internal/console/demo_claim_footer_test.go+11 −10internal/console/demo_claim_page.go+77 −13internal/console/demo_claim_resume_browser_test.go+62 −3internal/console/demo_claim_resume_test.go+12 −1internal/console/demo_claim_ux_test.go+3 −3internal/console/static/demo_claim.js+114 −10internal/console/templates/demo_claim.html+71 −40internal/console/testdata/demo_claim_resume_browser.mjs+85 −14
diff --git a/internal/console/demo_claim_choice_test.go b/internal/console/demo_claim_choice_test.go| index 4b3a8842a..d4714777c 100644 |
| --- a/internal/console/demo_claim_choice_test.go |
| +++ b/internal/console/demo_claim_choice_test.go |
| @@ -180,9 +180,9 @@ func TestDemoClaimChoiceRoom(t *testing.T) { |
| reason, room string |
| }{ |
| {"fits exactly", RoleOwner, 0, true, false, "", "Has room"}, |
| - {"needs two slots", RoleMember, 1, true, false, "Not enough room: 2 of 3 apps and instances in use. This demo needs room for one app and its instance.", ""}, |
| - {"full", RoleOwner, 2, true, false, "Full: 3 of 3 apps and instances in use", ""}, |
| - {"over limit", RoleOwner, 3, true, false, "Full: 4 of 3 apps and instances in use", ""}, |
| + {"needs two slots", RoleMember, 1, true, false, demoClaimNoRoom, ""}, |
| + {"full", RoleOwner, 2, true, false, demoClaimFull, ""}, |
| + {"over limit", RoleOwner, 3, true, false, demoClaimFull, ""}, |
| {"role", "viewer", 0, true, false, demoClaimRoleDenied, ""}, |
| {"role at limit", "viewer", 2, true, false, demoClaimRoleDenied, ""}, |
| {"plans off", RoleOwner, 1, false, false, "", ""}, |
| @@ -215,8 +215,12 @@ func TestDemoClaimChoiceRoom(t *testing.T) { |
| if !strings.Contains(body, tc.reason) || !strings.Contains(body, `value="`+a.Sqid+`" disabled`) || strings.Contains(body, `action="/demo/claim/select"`) { |
| t.Error("ineligible account not disabled with its reason") |
| } |
| - if !strings.Contains(body, "You are signed in as") || !strings.Contains(body, `<span class="claim-detail">`+tc.reason+"</span>") { |
| - t.Error("no_accounts missing identity or muted reason") |
| + if !strings.Contains(body, "You are signed in as") || !regexp.MustCompile(`<span class="chip chip-(stale|env)">`+regexp.QuoteMeta(tc.reason)+`</span>`).MatchString(body) { |
| + t.Error("no_accounts missing identity or status chip") |
| + } |
| + note := map[string]string{demoClaimNoRoom: demoClaimNoRoomNote, demoClaimRoleDenied: demoClaimRoleDeniedNote}[tc.reason] |
| + if note != "" && !strings.Contains(body, `<span class="claim-row-note">`+note+"</span>") { |
| + t.Errorf("ineligible row missing its note %q", note) |
| } |
| } else if !strings.Contains(body, `type="hidden" name="accountId" value="`+a.Sqid+`"`) { |
| t.Error("eligible account lost") |
| @@ -228,18 +232,21 @@ func TestDemoClaimChoiceRoom(t *testing.T) { |
| if tc.room != "" && strings.Count(body, ">"+tc.room+"<") != 1 { |
| t.Errorf("single account must show exactly one %q line", tc.room) |
| } |
| - if tc.reason == "" || tc.role == "viewer" { |
| - if strings.Contains(body, "apps and instances") { |
| - t.Error("eligible or role-disabled account shows counts") |
| - } |
| - } else if strings.Count(body, tc.reason) != 1 { |
| - t.Error("capacity reason must appear once") |
| + counted := tc.plans && !tc.fail && tc.role != "viewer" |
| + if usage := fmt.Sprintf(demoClaimUsageOf, tc.instances+1, 3); counted != strings.Contains(body, `<span class="claim-usage">`+usage+"</span>") { |
| + t.Errorf("usage %q shown = %v, want %v", usage, !counted, counted) |
| + } |
| + if !counted && strings.Contains(body, `class="claim-usage"`) { |
| + t.Error("uncounted account shows a usage figure") |
| + } |
| + if tc.reason != "" && strings.Count(body, ">"+tc.reason+"<") != 1 { |
| + t.Error("status chip must appear once") |
| } |
| if (!tc.plans || tc.role == "viewer") && spy.calls.Load() != 0 { |
| t.Error("plans off or role-disabled account read store") |
| } |
| if tc.plans && !tc.fail && tc.role != "viewer" { |
| - if !strings.Contains(body, ">Free plan<") { |
| + if !strings.Contains(body, `<span class="chip chip-env">Free</span>`) { |
| t.Error("missing plan") |
| } |
| if isPlanCap(s.checkRunningThings(t.Context(), a, 2)) != (tc.instances >= 1) { |
| @@ -386,7 +393,7 @@ func TestDemoClaimProgressAndOutcome(t *testing.T) { |
| address := "https://a-long-permanent-app-name.account.apps.example.com" |
| 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 { |
| + if err := demoClaimPageTemplate.ExecuteTemplate(&rendered, "demo_claim.html", demoClaimPageData{Copy: copy, State: state, Step: 2, URL: address, ConsoleURL: "/a/k3x9/apps/example", DeadlineIn: "240", DemoName: "example", DemoHost: "example-demo.example.com"}); err != nil { |
| t.Fatal(err) |
| } |
| body := rendered.String() |
| @@ -394,16 +401,29 @@ 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">`) || !strings.Contains(body, `<strong>Starting your app</strong>`) { |
| + if !strings.Contains(body, `aria-current="step">`) || !strings.Contains(body, `<strong>Starting your app</strong>`) || !regexp.MustCompile(`data-step="2" data-hints="[^"]+" aria-current="step"`).MatchString(body) { |
| t.Error("current step is not marked") |
| } |
| + for _, want := range []string{`data-deadline-in="240"`, `role="progressbar"`, `id="claim-stuck"`, `id="claim-elapsed"`, demoClaimStuckHeading} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("progress view missing %q", want) |
| + } |
| + } |
| } else { |
| if !strings.Contains(body, `<h1 id="claim-heading" tabindex="-1">example is yours</h1>`) || strings.Contains(body, demoClaimComplete) { |
| t.Error("outcome must appear once, as the heading") |
| } |
| - 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") |
| + // Two actions: the app in the console, and the live address as |
| + // its own link opening a new tab, shown once. |
| + if !strings.Contains(body, `<a class="btn claim-console" href="/a/k3x9/apps/example">`+demoClaimOpenConsole+`</a>`) { |
| + t.Error("missing the console action") |
| + } |
| + link := regexp.MustCompile(`<a class="claim-open" href="([^"]+)" target="_blank" rel="noopener noreferrer"><span class="claim-open-address">([^<]+)</span><svg[^>]*aria-hidden="true"`).FindStringSubmatch(body) |
| + if len(link) != 3 || link[1] != address || link[2] != address || !strings.Contains(body, demoClaimOpensNewTab) { |
| + t.Error("result link must display the permanent address with an external-link icon") |
| + } |
| + if strings.Count(body, ">"+address+"<") != 2 || strings.Contains(body, "claim-result-address") { |
| + t.Error("permanent address must show in the ticket and the action row only") |
| } |
| } |
| }) |
| @@ -505,7 +525,7 @@ func TestDemoClaimChoiceAdmissionAndExemption(t *testing.T) { |
| if spy.calls.Load() != 0 { |
| t.Error("counted unavailable or exempt account") |
| } |
| - if strings.Contains(body, ">Free plan<") { |
| + if strings.Contains(body, `<span class="chip chip-env">Free</span>`) { |
| t.Error("false plan label") |
| } |
| if !exempt && (!strings.Contains(body, "<p>unavailable</p>") || strings.Contains(body, demoClaimNoEligibleAccount)) { |
| @@ -537,3 +557,84 @@ func TestDemoClaimChoicePrivacy(t *testing.T) { |
| t.Error("another person's proved flow revealed summary or accounts") |
| } |
| } |
| + |
| +// A sponsored account's "unlimited" limit is a sentinel (sponsorMost). The |
| +// picker shows how many things run, never the sentinel and never a meter |
| +// that would sit empty against it. |
| +func TestDemoClaimChoiceUnlimitedUsage(t *testing.T) { |
| + s, _, token := claimTestServer(t) |
| + b := newClaimBrowser(t, s, token) |
| + b.login("shop@example.com", MethodEmail, true) |
| + a := claimAccount(t, s, 501, "shop@example.com", RoleOwner) |
| + claimAccount(t, s, 502, "shop@example.com", RoleOwner) |
| + s.cfg.PlanCatalog = examplePlanCatalog(t) |
| + unlimited := sponsorUnlimited() |
| + if _, err := s.store.SetAccountPlan(a.ID, "personal", nil, 0, PlanSourceSponsored, &unlimited, "test", "ops@example.com", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := s.store.CreateAppIn(a.ID, "shop", "shop@example.com", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if choice := s.demoClaimAccountView(t.Context(), *a, true); choice.Limit != sponsorMost || choice.Usage != fmt.Sprintf(demoClaimUsage, 1) || choice.Status != demoClaimHasRoom { |
| + t.Fatalf("sponsored choice = %+v", choice) |
| + } |
| + body := b.request("GET", "/demo/claim", nil).Body.String() |
| + for _, banned := range []string{fmt.Sprint(int64(sponsorMost)), "<meter", "claim-slots"} { |
| + if strings.Contains(body, banned) { |
| + t.Errorf("sponsored account renders %q", banned) |
| + } |
| + } |
| + if !strings.Contains(body, `<span class="claim-usage">1 running</span>`) || !strings.Contains(body, `<span class="claim-usage">0 of 3 running</span>`) { |
| + t.Error("rows lack their usage figures") |
| + } |
| + for _, c := range []struct { |
| + used, limit int |
| + want string |
| + }{{17, sponsorMost, "17 running"}, {3, 5, "3 of 5 running"}, {0, 0, ""}} { |
| + if got := demoClaimUsageText(c.used, c.limit); got != c.want { |
| + t.Errorf("usage(%d, %d) = %q, want %q", c.used, c.limit, got, c.want) |
| + } |
| + } |
| +} |
| + |
| +// Past demoClaimSearchFrom accounts the list gets a search box (hidden until |
| +// the script shows it); rows that can take the demo come first, each group |
| +// in its original order. |
| +func TestDemoClaimChoiceSearchAndOrder(t *testing.T) { |
| + for _, n := range []int{demoClaimSearchFrom, demoClaimSearchFrom + 1} { |
| + t.Run(fmt.Sprint(n), func(t *testing.T) { |
| + s, _, token := claimTestServer(t) |
| + b := newClaimBrowser(t, s, token) |
| + b.login("shop@example.com", MethodEmail, true) |
| + var want, viewers []string |
| + for i := 0; i < n; i++ { |
| + role := RoleOwner |
| + if i%3 == 0 { |
| + role = "viewer" |
| + } |
| + a := claimChoiceAccount(t, s, int64(501+i), "shop@example.com", role) |
| + if role == "viewer" { |
| + viewers = append(viewers, a.Sqid) |
| + } else { |
| + want = append(want, a.Sqid) |
| + } |
| + } |
| + want = append(want, viewers...) |
| + body := b.request("GET", "/demo/claim", nil).Body.String() |
| + var got []string |
| + for _, m := range regexp.MustCompile(`type="radio" name="accountId" value="([^"]+)"`).FindAllStringSubmatch(body, -1) { |
| + got = append(got, m[1]) |
| + } |
| + if strings.Join(got, ",") != strings.Join(want, ",") { |
| + t.Errorf("row order %v, want %v", got, want) |
| + } |
| + searchable := n > demoClaimSearchFrom |
| + if strings.Contains(body, `<p class="claim-search" hidden><input type="search" id="claim-search"`) != searchable || strings.Contains(body, `id="claim-search-empty"`) != searchable { |
| + t.Errorf("search box shown = %v, want %v", !searchable, searchable) |
| + } |
| + if searchable && regexp.MustCompile(`id="claim-search"[^>]* name=`).MatchString(body) { |
| + t.Error("search field would be posted with the choice") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/demo_claim_copy.go b/internal/console/demo_claim_copy.go| index 23086c70c..bfa2542c6 100644 |
| --- a/internal/console/demo_claim_copy.go |
| +++ b/internal/console/demo_claim_copy.go |
| @@ -117,14 +117,26 @@ const ( |
| demoClaimDestination = "This goes into %s." |
| // CLAIM-KEEP-IN: action after choosing an account. |
| demoClaimKeepIn = "Keep in %s" |
| - // CLAIM-ROOM-AVAILABLE: the account has room for the app and its instance. |
| + // CLAIM-ROOM-AVAILABLE: status chip; the account has room for the app and its instance. |
| demoClaimHasRoom = "Has room" |
| - // CLAIM-ROOM-FULL: current use is at or above the catalog cap. |
| - demoClaimFull = "Full: %d of %d apps and instances in use" |
| - // 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 = "You can view this account but not add apps. Ask one of its owners." |
| + // CLAIM-ROOM-FULL: status chip; current use is at or above the catalog cap. |
| + demoClaimFull = "Full" |
| + // CLAIM-ROOM-INSUFFICIENT: status chip; one slot remains, but the claim needs two. |
| + demoClaimNoRoom = "No room" |
| + // CLAIM-ROOM-INSUFFICIENT-NOTE: muted line under a no-room row. |
| + demoClaimNoRoomNote = "Needs room for an app and its instance." |
| + // CLAIM-ROLE-DENIED: status chip; membership cannot create apps. |
| + demoClaimRoleDenied = "View only" |
| + // CLAIM-ROLE-DENIED-NOTE: muted line under a view-only row. |
| + demoClaimRoleDeniedNote = "Ask an owner to add apps." |
| + // CLAIM-USAGE-CAPPED: row usage figure against a plan cap; used, limit. |
| + demoClaimUsageOf = "%d of %d running" |
| + // CLAIM-USAGE-UNLIMITED: row usage figure when the plan has no cap; used. |
| + demoClaimUsage = "%d running" |
| + // CLAIM-SEARCH-LABEL: search box label and placeholder above a long account list. |
| + demoClaimSearchLabel = "Find an account" |
| + // CLAIM-SEARCH-EMPTY: no account name matches the search. |
| + demoClaimSearchEmpty = "No accounts match." |
| // CLAIM-STEP-COPYING: first progress step. |
| demoClaimCopying = "Copying your data" |
| // CLAIM-STEP-STARTING: second progress step. |
| @@ -187,10 +199,34 @@ const ( |
| 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…" |
| ) |
| +// Progress reassurance, the stuck state and the result actions. |
| +const ( |
| + // CLAIM-PROGRESS-LABEL: accessible name of the progress bar. |
| + demoClaimProgressLabel = "Progress" |
| + // CLAIM-ELAPSED: shown after 30 s of progress; {elapsed} is "45 s" or "1 min 10 s". |
| + demoClaimElapsed = "{elapsed} so far. This can take a few minutes." |
| + // CLAIM-STUCK-HEADING: past the server's own deadline and the claim still reports running. |
| + demoClaimStuckHeading = "This is taking longer than it should." |
| + // CLAIM-STUCK-DETAIL: what is true while stuck, and what to do. |
| + demoClaimStuckDetail = "Nothing is lost. A move that does not finish is undone, and your demo goes back to how it was." |
| + // CLAIM-STUCK-ACTION: reloads the page to read the claim's state again. |
| + demoClaimStuckAction = "Check again" |
| + // CLAIM-OPEN-CONSOLE: done page primary action, the app's page in the console. |
| + demoClaimOpenConsole = "Open in the console" |
| + // CLAIM-OPENS-NEW-TAB: screen-reader suffix on the live address link. |
| + demoClaimOpensNewTab = "(opens in a new tab)" |
| +) |
| + |
| +// CLAIM-HINTS-*: reassurance lines that rotate under the active step, one at |
| +// a time, after the step's own detail line. |
| +var ( |
| + demoClaimHintsCopying = []string{"Pausing the demo so nothing changes mid-copy", "Packing up its saved data", "Checking everything arrived"} |
| + demoClaimHintsStarting = []string{"Placing it on a server", "Restoring its saved data", "Waiting for its secure address", "Checking it answers", "Still working. A first start can take a minute or two."} |
| +) |
| + |
| // COUNTDOWN-01..14, with the controller's singular-unit ruling. |
| func demoClaimCountdown(seconds int64) (visible, accessible string) { |
| unit := func(n int64, name string) string { |
diff --git a/internal/console/demo_claim_footer_test.go b/internal/console/demo_claim_footer_test.go| index 5c4754a95..9b3185ca9 100644 |
| --- a/internal/console/demo_claim_footer_test.go |
| +++ b/internal/console/demo_claim_footer_test.go |
| @@ -11,19 +11,20 @@ import ( |
| "testing" |
| ) |
| -// The digests were taken from the claim page before the footer existed. With |
| +// The digests are the claim page with no footer, retaken when the page itself |
| +// changes (last: the one-line account picker, claim-picker-rows). With |
| // neither item configured (or both invalid) the page is these exact bytes. |
| -const demoClaimFooterBaseStyleHash = "'sha256-0/eCVx0ZVcjLY0c+mSbXxujrLi96B+0QEsMyCIBaADI='" |
| +const demoClaimFooterBaseStyleHash = "'sha256-jbEMQSC7VKnO3PowM9lc1xx5+TuvoIMmes/XPpn9IEM='" |
| var demoClaimFooterBaseDigests = map[string]string{ |
| - "template-zero": "48b65f39722b9f26dfd9e1cc74e99b8d25859993e4af6681e886e8a9b09c923f", |
| - "template-missing": "2c793c646d7199bba6a84e4c552992dfc8fd7d17111a108232b93e4fa92ec5a0", |
| - "template-error": "1e8177ca639ff61406cfc0bc9db173b6668ac924bf53b875da7a5ef0dd1961ae", |
| - "template-claimed": "ab4542a9b912449bbc637595e9f51f653b417940eee103e7970eadb710fd667e", |
| - "template-proof": "9ca3d70d40f86bffa5081768630b3524b60548f2e8ffcb26eaf10e0a0c9e6458", |
| - "error-page": "f6cd7ee22473fb614b2f247599a1dfe3eac1ce870268ad6332ebafc37fd49a09", |
| - "get-claim": "c67a7aa13e23edb1a78fec563c17d74f173fa5153dc4fea3c8a10d128c18395d", |
| - "get-kept": "6050a0a0f5516f8209baf8dcf4a6549986f4f97d1f0026889cc8ad5e1b4c5d93", |
| + "template-zero": "b2a2585b5085df3f78941ea2a4459d849ef13715b9f51df83fdc3b42fd185454", |
| + "template-missing": "6e2aef84f98c10cbc49349b49f6865274e8fca54ff56c17846a1595746fe5eec", |
| + "template-error": "64e38dc116cdeae9cfb91b305aabc081f77a3d2fb4a3c0dfdba2963dc3bafa41", |
| + "template-claimed": "e4c9b4a267c8d58dbbf5514de16a6d40320f7992ea498aad799cb593eb3c4a20", |
| + "template-proof": "3bbd6532e51a6a6b40a853f8ccf0af1aa067f424af700a7b09d2f1ea7101c582", |
| + "error-page": "30011bb94cb643d51206c04502fbbf39ea49c714b8e117948cfbf505b6d154be", |
| + "get-claim": "41f8abb5d62650d39dff65d15fde9da6b52ace3926a886956c56c3af5081e8c2", |
| + "get-kept": "4698b2a67ebb90206df4dd855876ea7de458494ec651641605107fa89191cc69", |
| } |
| const ( |
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go| index 77b4e04d9..53f570981 100644 |
| --- a/internal/console/demo_claim_page.go |
| +++ b/internal/console/demo_claim_page.go |
| @@ -13,6 +13,7 @@ import ( |
| "io" |
| "net/http" |
| "net/url" |
| + "sort" |
| "strings" |
| "time" |
| ) |
| @@ -59,7 +60,18 @@ type demoClaimPageData struct { |
| TimeLeft, TimeLeftAccessible, EndTime string |
| Step int |
| CanClaim, HasIntent, EmailPending bool |
| - Footer demoClaimFooter |
| + // Searchable shows the account filter above a long list. |
| + Searchable bool |
| + // ConsoleURL is the claimed app's page in the console, for a reader who |
| + // can open it; empty otherwise. |
| + ConsoleURL string |
| + // DeadlineIn is the seconds from render to the operation's server |
| + // deadline (negative once past; empty with no operation). Past it the |
| + // coordinator undoes an unfinished claim, so a claim that still reports |
| + // progress well after it is stuck. Relative, so the browser's clock |
| + // does not matter. |
| + DeadlineIn string |
| + Footer demoClaimFooter |
| } |
| func (s *Server) demoClaimPageHeaders(w http.ResponseWriter, keymailOrigin string) { |
| @@ -169,6 +181,7 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| setDemoClaimCookie(w, cookie, expiry) |
| p.State, p.Step = demoClaimProgressStep(op.Phase) |
| p.ExpiresAt = op.SourceExpiresAt |
| + p.DeadlineIn = fmt.Sprint(op.Deadline.Unix() - time.Now().Unix()) |
| 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 |
| @@ -185,6 +198,7 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| if canContinue { |
| if acct, err := s.store.AccountByID(op.Target.AccountID); err == nil && acct != nil && acct.Sqid == op.Target.Sqid { |
| p.AccountName, p.AccountSqid = acct.Name, acct.Sqid |
| + p.ConsoleURL = "/a/" + url.PathEscape(acct.Sqid) + "/apps/" + url.PathEscape(p.App) |
| p.Copy["sameChat"] = "Still in the chat where you built it?" |
| p.Copy["sameChatLine"] = fmt.Sprintf("Tell your agent: “I kept %s. It now lives at %s in my account %s.”", p.App, p.URL, acct.Name) |
| p.Copy["agentHeading"] = "Starting fresh, in a new chat or with another agent?" |
| @@ -252,6 +266,9 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| } |
| + // Accounts that can take the demo come first, each group in |
| + // its original order. Sort before Single points into the slice. |
| + sort.SliceStable(p.Accounts, func(i, j int) bool { return p.Accounts[i].Reason == "" && p.Accounts[j].Reason != "" }) |
| if p.Eligible == 1 { |
| for i := range p.Accounts { |
| if p.Accounts[i].Reason == "" { |
| @@ -264,6 +281,7 @@ func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) { |
| if resume && selection.Create && len(accounts) == 0 { |
| p.AutoSubmit = p.CanClaim |
| } |
| + p.Searchable = p.Single == nil && len(p.Accounts) > demoClaimSearchFrom |
| if len(accounts) > 0 && p.Eligible == 0 { |
| p.State, p.CanClaim = "no_accounts", false |
| } |
| @@ -617,8 +635,7 @@ func demoClaimBrowserCopy() map[string]string { |
| "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, |
| + "completeDetail": demoClaimUX44, "keepGoing": demoClaimUX47, "agentHeading": demoClaimUX48, "agentDetail": demoClaimUX49, |
| "cliHeading": demoClaimUX52, "failureHeading": demoClaimUX61, |
| "expiredHeading": demoClaimUX72, "newDemo": demoClaimUX74, "newDemoLine": demoClaimUX75, |
| "keptHeading": demoClaimUX77, "consoleSignin": demoClaimUX80, "opening": demoClaimOpening, |
| @@ -663,6 +680,18 @@ func demoClaimBrowserCopy() map[string]string { |
| "disabled": demoClaimUnavailable, |
| "footerTerms": demoClaimFooterTerms, |
| "footerAbuse": demoClaimFooterAbuse, |
| + "searchLabel": demoClaimSearchLabel, |
| + "searchEmpty": demoClaimSearchEmpty, |
| + "progressLabel": demoClaimProgressLabel, |
| + "elapsed": demoClaimElapsed, |
| + "stuckHeading": demoClaimStuckHeading, |
| + "stuckDetail": demoClaimStuckDetail, |
| + "stuckAction": demoClaimStuckAction, |
| + "openConsole": demoClaimOpenConsole, |
| + "opensNewTab": demoClaimOpensNewTab, |
| + // Rotating lines travel as one attribute each, a line per hint. |
| + "hintsCopying": strings.Join(demoClaimHintsCopying, "\n"), |
| + "hintsStarting": strings.Join(demoClaimHintsStarting, "\n"), |
| } |
| } |
| @@ -703,14 +732,55 @@ func (s *Server) continueDemoClaimKeymail(w http.ResponseWriter, r *http.Request |
| s.continueKeymailSignin(w, r, flow, "/demo/claim") |
| } |
| +// demoClaimSearchFrom is the list length above which the picker offers a |
| +// search box: past it the list no longer fits a phone screen. |
| +const demoClaimSearchFrom = 6 |
| + |
| // Room is a GET-only hint. Reservation still checks under its account lock. |
| +// Reason is the status chip of an account that cannot take the demo (empty |
| +// when it can); Room is the chip of one that can, when it was counted. |
| +// Status and StatusClass are the chip the row shows, Note a short muted line |
| +// for an ineligible row, and Usage the running count, never the "unlimited" |
| +// sentinel. |
| type demoClaimAccountChoice struct { |
| Sqid, Name, Plan, Room, Reason, Button string |
| - Slots []bool |
| + Status, StatusClass, Note, Usage string |
| Used, Limit int |
| } |
| +// demoClaimUsageText is the row's running figure: "3 of 5 running" under a |
| +// cap, "17 running" when the plan has none (sponsorMost, as the billing page |
| +// treats it). A zero limit (not counted) shows nothing. |
| +func demoClaimUsageText(used, limit int) string { |
| + switch { |
| + case limit <= 0: |
| + return "" |
| + case int64(limit) >= sponsorMost: |
| + return fmt.Sprintf(demoClaimUsage, used) |
| + default: |
| + return fmt.Sprintf(demoClaimUsageOf, used, limit) |
| + } |
| +} |
| + |
| func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool) demoClaimAccountChoice { |
| + c := s.demoClaimAccountCount(ctx, a, count) |
| + c.Usage = demoClaimUsageText(c.Used, c.Limit) |
| + switch { |
| + case c.Reason == demoClaimRoleDenied: |
| + // The plan does not matter to someone who cannot add apps. |
| + c.Plan = "" |
| + c.Status, c.StatusClass, c.Note = c.Reason, "chip-env", demoClaimRoleDeniedNote |
| + case c.Reason == demoClaimNoRoom: |
| + c.Status, c.StatusClass, c.Note = c.Reason, "chip-stale", demoClaimNoRoomNote |
| + case c.Reason != "": |
| + c.Status, c.StatusClass = c.Reason, "chip-stale" |
| + case c.Room != "": |
| + c.Status, c.StatusClass = c.Room, "chip-health-ok" |
| + } |
| + return c |
| +} |
| + |
| +func (s *Server) demoClaimAccountCount(ctx context.Context, a Account, count bool) demoClaimAccountChoice { |
| c := demoClaimAccountChoice{Sqid: a.Sqid, Name: a.Name, Button: fmt.Sprintf(demoClaimKeepIn, a.Name)} |
| if !demoClaimCanCreate(a) { |
| c.Reason = demoClaimRoleDenied |
| @@ -722,7 +792,7 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool |
| if row != nil { |
| name = row.Plan |
| } |
| - c.Plan = fmt.Sprintf(demoClaimPlan, planLabel(name)) |
| + c.Plan = planLabel(name) |
| } |
| } |
| if !count || c.Reason != "" || ctx.Err() != nil { |
| @@ -737,17 +807,11 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool |
| 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) |
| + c.Reason = demoClaimFull |
| case n+2 > limits.RunningThings: |
| - c.Reason = fmt.Sprintf(demoClaimNoRoom, n, limits.RunningThings) |
| + c.Reason = demoClaimNoRoom |
| default: |
| c.Room = demoClaimHasRoom |
| } |
diff --git a/internal/console/demo_claim_resume_browser_test.go b/internal/console/demo_claim_resume_browser_test.go| index 29ecc78cc..482b9f205 100644 |
| --- a/internal/console/demo_claim_resume_browser_test.go |
| +++ b/internal/console/demo_claim_resume_browser_test.go |
| @@ -45,7 +45,19 @@ func TestDemoClaimSelectStepUpHeadless(t *testing.T) { |
| mode.Store(4) |
| phase = "future-phase" |
| } |
| - if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase=?`, phase); err != nil { |
| + // Past the server's deadline by more than the page's grace, and |
| + // still reporting progress: the page must call it stuck. |
| + deadline := time.Now().Add(5 * time.Minute).Unix() |
| + if r.URL.Query().Get("testProgress") == "stuck" { |
| + mode.Store(5) |
| + phase = "verifying" |
| + deadline = time.Now().Add(-100 * time.Second).Unix() |
| + } |
| + if r.URL.Query().Get("testProgress") == "starting" { |
| + mode.Store(5) |
| + phase = "verifying" |
| + } |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET phase=?,deadline=?`, phase, deadline); err != nil { |
| t.Error(err) |
| } |
| } |
| @@ -72,6 +84,9 @@ func TestDemoClaimSelectStepUpHeadless(t *testing.T) { |
| if mode.Load() == 4 { |
| phase = "future-phase" |
| } |
| + if mode.Load() == 5 { |
| + phase = "verifying" |
| + } |
| if mode.Load() == 2 { |
| phase = "aborted" |
| } |
| @@ -164,9 +179,53 @@ func TestDemoClaimSelectStepUpHeadless(t *testing.T) { |
| } |
| } |
| } |
| + // Thirty accounts, as one person had on production: sponsored (no cap), |
| + // capped with room, full, short of room and view-only rows. |
| + picker, _, pickerToken := claimTestServer(t) |
| + picker.registerRoute(routeDecl{Pattern: "GET /static/{hash}/{file...}"}, picker.handleStatic) |
| + pickerServer := httptest.NewServer(picker.mux) |
| + defer pickerServer.Close() |
| + picker.cfg.Origin = pickerServer.URL |
| + picker.cfg.PlanCatalog = examplePlanCatalog(t) |
| + many := newClaimBrowser(t, picker, pickerToken) |
| + many.login("shop@example.com", MethodEmail, true) |
| + unlimited := sponsorUnlimited() |
| + for i := 1; i <= 30; i++ { |
| + role := RoleOwner |
| + if i%7 == 0 { |
| + role = "viewer" |
| + } |
| + a := claimChoiceAccount(t, picker, int64(800+i), "shop@example.com", role) |
| + if _, err := picker.store.db.Exec(`UPDATE accounts SET name=? WHERE id=?`, fmt.Sprintf("team-%02d", i), a.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + apps, instances := i%2, 0 |
| + switch i { |
| + case 1, 4, 12: |
| + if _, err := picker.store.SetAccountPlan(a.ID, "personal", nil, 0, PlanSourceSponsored, &unlimited, "test", "ops@example.com", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + apps = 17 |
| + case 3, 10: |
| + apps, instances = 1, 2 |
| + case 6: |
| + apps, instances = 1, 1 |
| + } |
| + for j := 0; j < apps; j++ { |
| + if _, err := picker.store.CreateAppIn(a.ID, fmt.Sprintf("app%d", j), "shop@example.com", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + for j := 0; j < instances; j++ { |
| + if _, err := picker.cfg.Releases.Put(t.Context(), provision.RecordKey(a.Sqid, "app0", fmt.Sprintf("app0-%d.example.com", j)), []byte(`{}`), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + } |
| singleArgs, _ := json.Marshal(map[string]string{"target": singleServer.URL, "session": one.session, "cookie": one.cookie, |
| - "capacityTarget": capacityServer.URL, "capacitySession": room.session, "capacityCookie": room.cookie}) |
| - ctx, cancel := context.WithTimeout(t.Context(), 120*time.Second) |
| + "capacityTarget": capacityServer.URL, "capacitySession": room.session, "capacityCookie": room.cookie, |
| + "pickerTarget": pickerServer.URL, "pickerSession": many.session, "pickerCookie": many.cookie}) |
| + ctx, cancel := context.WithTimeout(t.Context(), 180*time.Second) |
| defer cancel() |
| cmd := exec.CommandContext(ctx, node, "testdata/demo_claim_resume_browser.mjs", chromium, t.TempDir(), ts.URL, b.session, b.cookie, a.Sqid, os.Getenv("CARLOS_DEMO_CLAIM_SCREENSHOTS"), string(singleArgs)) |
| output, err := cmd.CombinedOutput() |
diff --git a/internal/console/demo_claim_resume_test.go b/internal/console/demo_claim_resume_test.go| index c0a347595..019cb134f 100644 |
| --- a/internal/console/demo_claim_resume_test.go |
| +++ b/internal/console/demo_claim_resume_test.go |
| @@ -83,9 +83,20 @@ func TestDemoClaimSelectStepUpRoundTrip(t *testing.T) { |
| t.Fatal("resume must consume stash without claiming") |
| } |
| w = b.request("GET", "/demo/claim", nil) |
| - if !strings.Contains(w.Body.String(), `data-auto-submit`) || !strings.Contains(w.Body.String(), `value="`+a.Sqid+`" checked`) { |
| + if !strings.Contains(w.Body.String(), `data-auto-submit`) || !strings.Contains(w.Body.String(), `<input type="hidden" name="accountId" value="`+a.Sqid+`">`) { |
| t.Fatalf("selected account was not resumed: %s", w.Body) |
| } |
| + // The first paint of a resumed choice is the progress view: no |
| + // account list flashes up before the script posts the choice. |
| + body := w.Body.String() |
| + for _, banned := range []string{`type="radio"`, `class="claim-card"`, demoClaimUX24, `id="claim-accounts"`, demoClaimIdentityLabel} { |
| + if strings.Contains(body, banned) { |
| + t.Errorf("auto-submit first paint shows the account list (%q)", banned) |
| + } |
| + } |
| + if !strings.Contains(body, `<div id="claim-progress" data-stage="0" data-pending`) || !strings.Contains(body, `<h1 id="claim-heading" tabindex="-1">`+demoClaimPageTitle+`</h1>`) || !strings.Contains(body, "<noscript><button type=\"submit\">") { |
| + t.Errorf("auto-submit first paint is not the progress view with a no-script button: %s", body) |
| + } |
| if claimBrowserCount(t, s, "demo_claim_ops") != 0 { |
| t.Fatal("GET claimed") |
| } |
diff --git a/internal/console/demo_claim_ux_test.go b/internal/console/demo_claim_ux_test.go| index d161b94b2..9763241cb 100644 |
| --- a/internal/console/demo_claim_ux_test.go |
| +++ b/internal/console/demo_claim_ux_test.go |
| @@ -27,8 +27,8 @@ func TestDemoClaimUXProductionPages(t *testing.T) { |
| 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 !strings.Contains(body, `<span class="claim-usage">0 of 3 running</span>`) || !strings.Contains(body, `<span class="chip chip-health-ok">Has room</span>`) { |
| + t.Error("no capacity figure or status chip") |
| } |
| if w := b.post("/demo/claim/select", url.Values{"accountId": {a.Sqid}}); w.Code != 303 { |
| t.Fatalf("select: %d %s", w.Code, w.Body) |
| @@ -43,7 +43,7 @@ func TestDemoClaimUXProductionPages(t *testing.T) { |
| t.Error("ticket lost after selection") |
| } |
| if phase == "done" { |
| - for _, want := range []string{"Open your app", "Still in the chat where you built it?", "No saved source for this app.", `data-state="claimed"`} { |
| + for _, want := range []string{demoClaimOpenConsole, `class="claim-open"`, "Still in the chat where you built it?", "No saved source for this app.", `data-state="claimed"`} { |
| if !strings.Contains(body, want) { |
| t.Errorf("result missing %q", want) |
| } |
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js| index a2edb27cb..3e20de7b9 100644 |
| --- a/internal/console/static/demo_claim.js |
| +++ b/internal/console/static/demo_claim.js |
| @@ -83,6 +83,25 @@ |
| button.textContent = selected ? selected.dataset.button : button.dataset.neutral; |
| }; |
| if (radios.length) { choice.addEventListener("change", update); update(); } |
| + // The filter only hides rows: a checked radio stays checked out of view, |
| + // and the search field has no name, so it is never posted. |
| + const search = document.getElementById("claim-search"); |
| + if (search) { |
| + const rows = [...choice.querySelectorAll("#claim-accounts .claim-card")]; |
| + const empty = document.getElementById("claim-search-empty"); |
| + search.parentElement.hidden = false; |
| + search.addEventListener("keydown", event => { if (event.key === "Enter") event.preventDefault(); }); |
| + search.addEventListener("input", () => { |
| + const query = search.value.trim().toLocaleLowerCase(); |
| + let shown = 0; |
| + for (const row of rows) { |
| + const name = row.querySelector(".claim-row-name").textContent.toLocaleLowerCase(); |
| + row.hidden = query !== "" && !name.includes(query); |
| + if (!row.hidden) shown++; |
| + } |
| + empty.hidden = shown > 0; |
| + }); |
| + } |
| } |
| const clock = claim.querySelector("time[datetime]"); |
| if (clock) { |
| @@ -130,8 +149,81 @@ |
| 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))); }; |
| + |
| + // Reassurance while the server works. The bar is honest: each stage owns |
| + // a band ending at the next stage's mark, and within it the bar eases |
| + // toward that mark over the stage's usual time without reaching it. It |
| + // never moves back. The server's stage is the only thing that crosses a mark. |
| + const opened = performance.now(); |
| + const fill = progress.querySelector(".claim-bar i"); |
| + const elapsed = document.getElementById("claim-elapsed"); |
| + const stuck = document.getElementById("claim-stuck"); |
| + const calm = matchMedia("(prefers-reduced-motion: reduce)"); |
| + const marks = [0, 0.1, 0.55, 1]; |
| + const pace = [5000, 15000, 30000]; |
| + let entered = opened, shown = marks[Math.min(stage, 3)], rotation = 0, claimingPolls = 0, timers = []; |
| + // Stuck: the server undoes an unfinished claim at its deadline (5 minutes |
| + // after the account was chosen) and then reports "stopping". A claim |
| + // that, on two polls, still reports progress 90 s after that deadline is |
| + // stuck. With no deadline to read, 6.5 minutes without a stage change is |
| + // (the 5-minute deadline plus the same 90 s). |
| + const deadline = progress.dataset.deadlineIn === undefined ? NaN : opened + Number(progress.dataset.deadlineIn) * 1000; |
| + const isStuck = () => Number.isFinite(deadline) |
| + ? claimingPolls >= 2 && performance.now() > deadline + 90000 |
| + : performance.now() - entered > 390000; |
| + const draw = () => { |
| + if (fill) { |
| + let value = 1; |
| + if (stage < 3) { |
| + const from = marks[stage], to = marks[stage + 1]; |
| + value = from + (to - from) * 0.97 * (1 - Math.exp(-(performance.now() - entered) / pace[stage])); |
| + } |
| + shown = Math.max(shown, value); |
| + fill.style.transform = `scaleX(${Math.max(shown, 0.03)})`; |
| + fill.parentElement.setAttribute("aria-valuenow", String(Math.round(shown * 100))); |
| + } |
| + const seconds = Math.floor((performance.now() - opened) / 1000); |
| + if (elapsed && seconds >= 30) { |
| + elapsed.textContent = elapsed.dataset.template.replace("{elapsed}", seconds >= 60 ? `${Math.floor(seconds / 60)} min ${seconds % 60} s` : `${seconds} s`); |
| + elapsed.hidden = false; |
| + } |
| + }; |
| + const restoreDetails = () => { |
| + rotation = 0; |
| + for (const detail of progress.querySelectorAll(".claim-step-detail[data-original]")) { |
| + detail.textContent = detail.dataset.original; |
| + detail.classList.remove("is-swapping"); |
| + } |
| + }; |
| + const rotate = () => { |
| + const step = progress.querySelector('[aria-current="step"][data-hints]'); |
| + const detail = step?.querySelector(".claim-step-detail"); |
| + // Once stuck, the page stops saying it is still working. |
| + if (!detail || progress.dataset.stuck !== undefined) return; |
| + if (detail.dataset.original === undefined) detail.dataset.original = detail.textContent; |
| + const lines = [detail.dataset.original, ...step.dataset.hints.split("\n").filter(Boolean)]; |
| + rotation = (rotation + 1) % lines.length; |
| + const swap = () => { detail.textContent = lines[rotation]; detail.classList.remove("is-swapping"); }; |
| + if (calm.matches) swap(); |
| + else { detail.classList.add("is-swapping"); setTimeout(swap, 200); } |
| + }; |
| + // Stop the reassurance when the claim ends either way. |
| + const settle = () => { |
| + for (const timer of timers) clearInterval(timer); |
| + timers = []; |
| + restoreDetails(); |
| + stuck.hidden = true; |
| + delete progress.dataset.stuck; |
| + }; |
| + draw(); |
| + timers.push(setInterval(draw, 500), setInterval(rotate, 4500)); |
| + |
| const setStage = async n => { |
| stage = n; |
| + entered = performance.now(); |
| + shown = Math.max(shown, marks[Math.min(n, 3)]); |
| + restoreDetails(); |
| + draw(); |
| progress.dataset.stage = String(n); |
| for (const step of progress.querySelectorAll("[data-step]")) { |
| const k = Number(step.dataset.step); |
| @@ -164,10 +256,14 @@ |
| 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; |
| + // The fresh page carries the console link, which only it can name. |
| + const actions = page.querySelector(".claim-result"); |
| + if (actions) claim.querySelector(".claim-result")?.replaceWith(document.importNode(actions, true)); |
| + for (const link of claim.querySelectorAll(".claim-open")) link.href = url.href; |
| + for (const text of claim.querySelectorAll(".claim-open-address")) text.textContent = url.origin; |
| const address = claim.querySelector(".claim-address .claim-new"); |
| if (address) address.textContent = url.host; |
| - claim.querySelector(".claim-result-address").textContent = url.href; |
| + settle(); |
| heading.textContent = claim.dataset.completeHeading; |
| claim.dataset.state = "claimed"; |
| claim.querySelector(".claim-ticket")?.classList.add("is-settled"); |
| @@ -176,7 +272,7 @@ |
| progress.hidden = true; |
| setTimeout(() => claim.classList.remove("is-celebrating"), 1500); |
| }; |
| - reload.hidden = true; |
| + if (reload) reload.hidden = true; |
| const poll = async () => { |
| try { |
| const response = await fetch("/demo/claim/status", { |
| @@ -190,6 +286,9 @@ |
| (result.state === "claimed" && result.step === 3))) throw new Error(); |
| if (result.state === "stopping" || result.state === "aborted") { |
| await hold(); |
| + settle(); |
| + progress.querySelector(".claim-bar")?.remove(); |
| + elapsed?.remove(); |
| const failed = progress.querySelector('[aria-current="step"]'); |
| if (failed) { failed.classList.add("is-failed"); failed.removeAttribute("aria-current"); } |
| progress.dataset.stage = "0"; |
| @@ -200,20 +299,25 @@ |
| } else { |
| await advance(result.step); |
| if (result.state === "claimed") { await hold(); await finish(result); return; } |
| + claimingPolls++; |
| + if (isStuck() && stuck.hidden) { stuck.hidden = false; progress.dataset.stuck = ""; restoreDetails(); } |
| } |
| failures = 0; |
| } catch (_) { |
| if (++failures >= 3) { |
| + settle(); |
| status.classList.remove("claim-sr-only"); |
| setStatus(progress.dataset.pollFailed); |
| reload.hidden = false; |
| return; |
| } |
| } |
| - setTimeout(poll, 3000); |
| + // Once stuck, keep checking, more slowly: a late finish still lands. |
| + setTimeout(poll, stuck.hidden ? 3000 : 10000); |
| }; |
| - // The initial stage is already painted by the server. |
| - paint().then(() => { since = performance.now(); setTimeout(poll, minimum); }); |
| + // The initial stage is already painted by the server. A selection still |
| + // to be posted has no operation to poll yet: the form below posts it. |
| + if (progress.dataset.pending === undefined) paint().then(() => { since = performance.now(); setTimeout(poll, minimum); }); |
| } |
| if (!token) { |
| if (claim.dataset.reveal === "true" && claim.dataset.state === "claimed") { |
| @@ -225,13 +329,13 @@ |
| } |
| if (opening) opening.hidden = true; |
| if (missing) missing.hidden = false; |
| + // A resumed selection: the server painted the progress view first, so |
| + // post the chosen account straight away. It goes through the page's one |
| + // submit guard like a manual choice. |
| 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; } |
| + selection.requestSubmit(); |
| } |
| return; |
| } |
diff --git a/internal/console/templates/demo_claim.html b/internal/console/templates/demo_claim.html| index 13788753c..cc14c256c 100644 |
| --- a/internal/console/templates/demo_claim.html |
| +++ b/internal/console/templates/demo_claim.html |
| @@ -11,14 +11,21 @@ |
| #claim .claim-summary strong, #claim .claim-summary a { display: block; } |
| #claim .claim-summary p { margin: 0.5rem 0 0; } |
| #claim fieldset { border: 0; min-width: 0; margin: 1.5rem 0; } |
| -#claim legend { font-weight: 600; margin-bottom: 0.75rem; } |
| -#claim .claim-card { display: flex; align-items: flex-start; gap: 0.75rem; border: 1px solid var(--rule); border-radius: var(--rst-radius-sm); padding: 1rem; margin: 0 0 0.65rem; cursor: pointer; } |
| +#claim legend { margin-bottom: 0.6rem; font: 600 .78rem var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); } |
| +#claim .claim-card { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: .3rem .75rem; border: 1px solid var(--rule); border-radius: var(--rst-radius-sm); padding: .55rem .8rem; margin: 0 0 .4rem; cursor: pointer; } |
| #claim .claim-card:has(:checked) { background: var(--accent-soft); border-color: var(--accent); } |
| #claim .claim-card:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; } |
| #claim [tabindex="-1"]:focus { outline: none; } |
| #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 .claim-detail { display: block; } |
| +#claim .claim-card input { flex: none; width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--accent); } |
| +#claim .claim-row-name { font-weight: 600; overflow-wrap: anywhere; } |
| +#claim .claim-row-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .4rem .5rem; font-size: .8rem; color: var(--muted); } |
| +#claim .claim-row-meta .chip { margin: 0; } |
| +#claim .claim-row-note { grid-column: 2 / -1; font-size: .85rem; color: var(--muted); } |
| +@media (max-width: 30rem) { #claim .claim-row-meta { grid-column: 2 / -1; justify-content: flex-start; } } |
| +#claim .claim-search { margin: 0 0 .75rem; } |
| +#claim .claim-search input { display: block; width: 100%; min-height: 44px; } |
| +#claim .claim-search-empty { color: var(--muted); } |
| #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; } |
| @@ -52,7 +59,7 @@ |
| #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-address > * { 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; } |
| @@ -63,11 +70,19 @@ |
| #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 .claim-single { grid-template-columns: minmax(0,1fr) auto; cursor: default; } |
| +#claim .claim-single p { margin: 0; } |
| +@media (max-width: 30rem) { #claim .claim-single .claim-row-meta { grid-column: 1 / -1; } } |
| +#claim .claim-bar { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin: 0 0 .4rem; } |
| +#claim .claim-bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transform-origin: left; transform: scaleX(.03); transition: transform .5s linear; } |
| +#claim [data-stage="1"] .claim-bar i { transform: scaleX(.1); } |
| +#claim [data-stage="2"] .claim-bar i { transform: scaleX(.55); } |
| +#claim .claim-elapsed { font-size: .85rem; color: var(--muted); margin: 0 0 1rem; } |
| +#claim .claim-step-detail { transition: opacity .2s ease; } |
| +#claim .claim-step-detail.is-swapping { opacity: 0; } |
| +#claim .claim-stuck { border: 1px solid var(--rule); background: var(--accent-soft); border-radius: var(--rst-radius-sm); padding: 1rem; margin: 0 0 1.5rem; } |
| +#claim .claim-stuck p { margin: 0 0 .5rem; } |
| +#claim [data-stuck] [aria-current=step] .claim-node::before, #claim [data-stuck] [aria-current=step] .claim-node::after, #claim [data-stuck] .claim-track, #claim [data-stuck] .claim-track i, #claim [data-stuck] .claim-home { animation: none; } |
| #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); } |
| @@ -86,7 +101,8 @@ |
| #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-steps strong { font-size: 1.0625rem; } |
| +#claim .claim-step-detail { display: block; font-weight: 400; font-size: .85rem; margin-top: .25rem; } |
| #claim .claim-node { position: absolute; left: 0; top: 0; box-sizing: border-box; width: 26px; height: 26px; border: 2px solid var(--muted); border-radius: 50%; } |
| #claim .claim-node::before { content: ""; position: absolute; inset: -2px; box-sizing: border-box; width: 26px; height: 26px; border: 2px solid transparent; border-radius: 50%; transform-origin: center; } |
| #claim .claim-node::after { content: ""; position: absolute; inset: 0; margin: auto; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; opacity: 0; } |
| @@ -98,11 +114,14 @@ |
| #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-result { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; } |
| +#claim .claim-result .btn { border-radius: 10px; } |
| +#claim .claim-result .claim-open { display: inline-block; max-width: 100%; padding-block: .6rem; font: .9rem/1.4 ui-monospace,monospace; overflow-wrap: anywhere; } |
| +#claim .claim-result .claim-open .icon { width: 1em; height: 1em; margin-left: .35em; vertical-align: -.125em; } |
| #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 h2 { font-size: 1.4rem; } |
| +#claim .claim-next h3 { font-size: 1.0625rem; margin-bottom: .3rem; } |
| +#claim .claim-next p { font-size: .925rem; } |
| #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; } |
| @@ -153,11 +172,11 @@ |
| {{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-address"><a class="claim-old" href="https://{{.DemoHost}}" rel="noreferrer">{{.DemoHost}}</a><span class="claim-new">{{.URL}}</span></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}}"><span aria-hidden="true">{{.TimeLeft}}</span><span class="claim-sr-only">{{.TimeLeftAccessible}}</span></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" tabindex="-1">{{if eq .State "claimed"}}{{.Copy.completeHeading}}{{else if or (eq .State "stopping") (eq .State "aborted")}}{{.Copy.failureHeading}}{{else if .EmailPending}}{{.Copy.codeHeading}}{{else if and .Address (gt .Eligible 1)}}{{.Copy.accountsHeading}}{{else if eq .State "proof"}}{{.Copy.heading}}{{else}}{{.Copy.title}}{{end}}</h1> |
| +<h1 id="claim-heading" tabindex="-1">{{if eq .State "claimed"}}{{.Copy.completeHeading}}{{else if or (eq .State "stopping") (eq .State "aborted")}}{{.Copy.failureHeading}}{{else if .AutoSubmit}}{{.Copy.title}}{{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.accountsLabel}}</legend>{{range .Accounts}}{{template "claim_card" .}}{{end}}</fieldset>{{end}} |
| @@ -168,23 +187,12 @@ |
| <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-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 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> |
| - |
| -<a id="claim-reload" href="/demo/claim">{{.Copy.reload}}</a> |
| -</div>{{end}} |
| +{{if or (eq .State "claiming") (eq .State "stopping")}}{{template "claim_progress" .}}{{end}} |
| {{if eq .State "aborted"}}<p>{{.Copy.aborted}}</p>{{end}} |
| {{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> |
| +<p class="claim-result">{{with .ConsoleURL}}<a class="btn claim-console" href="{{.}}">{{$.Copy.openConsole}}</a>{{end}}<a class="claim-open" href="{{.URL}}" target="_blank" rel="noopener noreferrer"><span class="claim-open-address">{{.URL}}</span>{{icon "external-link"}}<span class="claim-sr-only"> {{.Copy.opensNewTab}}</span></a></p> |
| {{if .AccountSqid}}<section class="claim-next"><h2>{{.Copy.keepGoing}}</h2> |
| {{if .AccountSqid}}<h3>{{.Copy.sameChat}}</h3><p>{{.Copy.sameChatLine}}</p> |
| {{if .SourceSteps}}<h3>{{.Copy.agentHeading}}</h3><p>{{.Copy.agentDetail}}</p> |
| @@ -197,23 +205,31 @@ |
| {{end}} |
| {{if and .HasIntent .CanClaim}} |
| {{if .Address}} |
| +{{if .AutoSubmit}}{{template "claim_progress" .}} |
| +<form method="post" action="/demo/claim/select" data-auto-submit> |
| +<input type="hidden" name="nonce" value="{{.Nonce}}"><input type="hidden" name="csrf" value="{{.CSRF}}"> |
| +{{if .SelectedAccount}}<input type="hidden" name="accountId" value="{{.SelectedAccount}}">{{else}}<input type="hidden" name="create" value="1">{{end}} |
| +<noscript><button type="submit">{{.Copy.confirm}}</button></noscript> |
| +</form> |
| +{{else}} |
| <p>{{.Copy.identity}} <strong>{{.Address}}</strong></p> |
| -<form method="post" action="/demo/claim/select"{{if .AutoSubmit}} data-auto-submit{{end}}> |
| +<form method="post" action="/demo/claim/select"> |
| <input type="hidden" name="nonce" value="{{.Nonce}}"><input type="hidden" name="csrf" value="{{.CSRF}}"> |
| {{if .Single}} |
| -<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> |
| +<fieldset><legend>{{.Copy.accountsLabel}}</legend><div class="claim-single claim-card"><p><strong>{{.Copy.destination}}</strong></p>{{template "claim_meta" .Single}}</div> |
| <input type="hidden" name="accountId" value="{{.Single.Sqid}}"> |
| {{range .Accounts}}{{if .Reason}}{{template "claim_card" .}}{{end}}{{end}}</fieldset> |
| {{else if .Accounts}} |
| -<p>{{.Copy.accountsIntro}}</p><fieldset><legend>{{.Copy.accountsLabel}}</legend> |
| +<p>{{.Copy.accountsIntro}}</p> |
| +{{if .Searchable}}<p class="claim-search" hidden><input type="search" id="claim-search" aria-label="{{.Copy.searchLabel}}" placeholder="{{.Copy.searchLabel}}" aria-controls="claim-accounts" autocomplete="off" spellcheck="false"></p>{{end}} |
| +<fieldset id="claim-accounts"><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}}{{template "claim_slots" .}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}{{with .Reason}}<span class="claim-detail">{{.}}</span>{{end}}</span></label> |
| -{{end}}</fieldset> |
| +<label class="claim-card"><input type="radio" name="accountId" value="{{.Sqid}}"{{if .Reason}} disabled{{else}} required{{end}} data-button="{{.Button}}"><span class="claim-row-name">{{.Name}}</span>{{template "claim_meta" .}}{{with .Note}}<span class="claim-row-note">{{.}}</span>{{end}}</label> |
| +{{end}}{{if .Searchable}}<p id="claim-search-empty" class="claim-search-empty" aria-live="polite" hidden>{{.Copy.searchEmpty}}</p>{{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-working="{{.Copy.selectWorking}}" data-neutral="{{.Copy.choose}}">{{.Copy.confirm}}</button> |
| </form> |
| +{{end}} |
| {{else}} |
| {{if .EmailPending}} |
| <p class="claim-intro">{{.Copy.codeIntro}}</p> |
| @@ -243,8 +259,23 @@ |
| </html> |
| {{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}}{{template "claim_slots" .}}{{with .Room}}<span class="claim-detail">{{.}}</span>{{end}}<span class="claim-detail">{{.Reason}}</span></span></label> |
| +<label class="claim-card"><input type="radio" name="accountId" value="{{.Sqid}}" disabled><span class="claim-row-name">{{.Name}}</span>{{template "claim_meta" .}}{{with .Note}}<span class="claim-row-note">{{.}}</span>{{end}}</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}} |
| +{{define "claim_meta"}}<span class="claim-row-meta">{{with .Plan}}<span class="chip chip-env">{{.}}</span>{{end}}{{with .Usage}}<span class="claim-usage">{{.}}</span>{{end}}{{with .Status}}<span class="chip {{$.StatusClass}}">{{.}}</span>{{end}}</span>{{end}} |
| + |
| +{{define "claim_progress"}} |
| +<div id="claim-progress" data-stage="{{.Step}}"{{if .AutoSubmit}} data-pending{{end}}{{with .DeadlineIn}} data-deadline-in="{{.}}"{{end}} 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 id="claim-stuck" class="claim-stuck" role="alert" hidden><p><strong>{{.Copy.stuckHeading}}</strong></p><p class="claim-detail">{{.Copy.stuckDetail}}</p><a class="btn btn-sm" href="/demo/claim">{{.Copy.stuckAction}}</a></div> |
| +<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> |
| +{{if ne .State "stopping"}}<div class="claim-bar" role="progressbar" aria-label="{{.Copy.progressLabel}}" aria-valuemin="0" aria-valuemax="100"><i></i></div> |
| +<p id="claim-elapsed" class="claim-elapsed" data-template="{{.Copy.elapsed}}" hidden></p>{{end}} |
| +<ol class="claim-steps"> |
| +<li data-step="1" data-hints="{{.Copy.hintsCopying}}"{{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" data-hints="{{.Copy.hintsStarting}}"{{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> |
| +{{if not .AutoSubmit}} |
| +<a id="claim-reload" href="/demo/claim">{{.Copy.reload}}</a>{{end}} |
| +</div>{{end}} |
diff --git a/internal/console/testdata/demo_claim_resume_browser.mjs b/internal/console/testdata/demo_claim_resume_browser.mjs| index 0de1d29b7..6c8dd1421 100644 |
| --- a/internal/console/testdata/demo_claim_resume_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_resume_browser.mjs |
| @@ -51,11 +51,11 @@ async function key(key, code, number) { |
| await call('Input.dispatchKeyEvent', {type:'keyUp', key, code, windowsVirtualKeyCode:number}); |
| } |
| async function capture(state) { |
| - await captureClaim(call, evaluate, screenshots, state); |
| + await captureClaim(call, evaluate, screenshots, state, [360, 1280]); |
| await captureClaim(call, evaluate, '', state, [1100]); |
| assert.equal(security.length, 0, JSON.stringify(security)); |
| } |
| -const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 115000); |
| +const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 175000); |
| try { |
| const created = await call('Target.createTarget', {url:'about:blank'}, false); |
| session = (await call('Target.attachToTarget', {targetId:created.targetId, flatten:true}, false)).sessionId; |
| @@ -74,10 +74,12 @@ try { |
| window.addEventListener('submit', event => { |
| const form = event.target; |
| if (form.getAttribute('action') !== '/demo/claim/select') return; |
| + // A manual choice submits from the visible list with its button |
| + // disabled; a resumed one from the progress view, with no list at all. |
| claimSubmitted(JSON.stringify({ |
| - disabled:form.querySelector('button[type=submit]').disabled, |
| - visible:form.getBoundingClientRect().height > 0, |
| - auto:!document.getElementById('claim-resuming').hidden, |
| + disabled:form.querySelector('button[type=submit]')?.disabled ?? null, |
| + list:!!document.querySelector('#claim input[type=radio]'), |
| + auto:!!document.querySelector('#claim-progress[data-pending]'), |
| account:new FormData(form).get('accountId') |
| })); |
| }); |
| @@ -96,7 +98,7 @@ try { |
| await capture('one'); |
| 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-card .claim-row-name").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'); |
| @@ -108,9 +110,46 @@ try { |
| await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 2'); |
| const capacityCards = await evaluate('Array.from(document.querySelectorAll(".claim-card"), card => ({text:card.innerText,disabled:card.querySelector("input").disabled}))'); |
| assert(capacityCards.every(card=>card.disabled)); |
| - assert(capacityCards.some(card=>card.text.includes('Full: 3 of 3 apps and instances in use'))); |
| - assert(capacityCards.some(card=>card.text.includes('Not enough room: 2 of 3 apps and instances in use. This demo needs room for one app and its instance.'))); |
| + assert(capacityCards.some(card=>card.text.includes('Full') && card.text.includes('3 of 3 running'))); |
| + assert(capacityCards.some(card=>card.text.includes('No room') && card.text.includes('2 of 3 running') && card.text.includes('Needs room for an app and its instance.'))); |
| await capture('capacity'); |
| + // The thirty-account picker: one line per account, no sentinel, no meter, |
| + // the accounts that can take it first, and a search box that filters. |
| + await call('Network.setCookies', {cookies:[ |
| + {name:'carlos_console_session',value:single.pickerSession,url:single.pickerTarget,path:'/',httpOnly:true,sameSite:'Lax'}, |
| + {name:'carlos_demo_claim_flow',value:single.pickerCookie,url:single.pickerTarget,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| + ]}); |
| + await call('Page.navigate',{url:single.pickerTarget+'/demo/claim'}); |
| + await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 30'); |
| + assert.equal(await evaluate('document.body.innerText.includes("2305843009213693951") || !!document.querySelector("meter")'), false, 'sentinel or meter shown'); |
| + assert.equal(await evaluate('document.querySelector(".claim-search").hidden'), false, 'script did not reveal the search box'); |
| + assert.deepEqual(await evaluate('(() => { const d = Array.from(document.querySelectorAll(".claim-card input"), i => i.disabled); return d.indexOf(true) === -1 || d.slice(d.indexOf(true)).every(Boolean); })()'), true, 'eligible rows must come first'); |
| + assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card")).some(c => c.innerText.includes("17 running") && c.innerText.includes("Has room"))'), true, 'sponsored row'); |
| + assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card")).some(c => c.innerText.includes("View only") && c.innerText.includes("Ask an owner"))'), true, 'viewer row'); |
| + // A row is one line at desktop width: its height is a single line plus padding. |
| + await call('Emulation.setDeviceMetricsOverride', {width:1280, height:900, deviceScaleFactor:1, mobile:false}); |
| + assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:not(:disabled))")).every(c => c.getBoundingClientRect().height < 56)'), true, 'eligible rows wrap at desktop width'); |
| + await captureClaim(call, evaluate, screenshots, 'picker-30', [360, 1280]); |
| + await evaluate('document.querySelector(".claim-card input:not(:disabled)").click()'); |
| + const pickedLabel = await evaluate('document.querySelector("#claim button[type=submit]").textContent'); |
| + await evaluate('document.getElementById("claim-search").focus()'); |
| + for (const ch of 'TEAM-2') await call('Input.insertText', {text:ch}); |
| + await until('Array.from(document.querySelectorAll(".claim-card")).filter(c => !c.hidden).length === 10'); |
| + assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card")).filter(c => !c.hidden).every(c => c.querySelector(".claim-row-name").textContent.startsWith("team-2"))'), true); |
| + assert.equal(await evaluate('document.querySelector(".claim-card input:checked")?.closest("label").hidden'), true, 'test needs the chosen row filtered out'); |
| + assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'), pickedLabel, 'filtering changed the choice'); |
| + const submissionsBefore = submissions.length; |
| + await key('Enter', 'Enter', 13); |
| + await new Promise(r => setTimeout(r, 300)); |
| + assert.equal(submissions.length, submissionsBefore, 'Enter in the search box submitted the form'); |
| + assert.equal(await evaluate('location.pathname + location.search'), '/demo/claim'); |
| + await captureClaim(call, evaluate, screenshots, 'picker-search', [360, 1280]); |
| + for (const ch of 'zz') await call('Input.insertText', {text:ch}); |
| + await until('document.getElementById("claim-search-empty").hidden === false'); |
| + assert.equal(await evaluate('document.querySelectorAll(".claim-card:not([hidden])").length'), 0); |
| + assert.equal(await evaluate('!!document.querySelector(".claim-card input:checked")'), true, 'a filtered-out choice was cleared'); |
| + await captureClaim(call, evaluate, screenshots, 'picker-empty', [360]); |
| + process.stdout.write('picker: thirty rows, eligible first, search filters, Enter stays put\n'); |
| await call('Network.setCookies', {cookies:[ |
| {name:'carlos_console_session',value:sessionToken,url:target,path:'/',httpOnly:true,sameSite:'Lax'}, |
| {name:'carlos_demo_claim_flow',value:flowCookie,url:target,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| @@ -147,8 +186,10 @@ try { |
| await evaluate(`document.querySelector('input[value='+${JSON.stringify(account)}+']').click()`); |
| 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 plan', 'You can view this account but not add apps. Ask one of its owners.']); |
| + assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:not(:disabled))")).every(card => card.innerText.includes("Has room") && card.innerText.includes(" running"))'),true); |
| + assert.deepEqual(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:disabled) .chip, .claim-card:has(input:disabled) .claim-row-note")).map(el => el.textContent)'),['View only', 'Ask an owner to add apps.']); |
| + assert.equal(await evaluate('document.querySelector(".claim-card:last-of-type input").disabled'),true,'the view-only account must sort last'); |
| + assert.equal(await evaluate('!!document.querySelector(".claim-search")'),false,'three accounts need no search box'); |
| 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'); |
| @@ -162,9 +203,9 @@ try { |
| assert.equal(await evaluate('location.hash'),''); |
| assert.equal(security.length,0,JSON.stringify(security)); |
| assert.deepEqual(submissions, [ |
| - {disabled:true,visible:true,auto:false,account}, |
| - {disabled:true,visible:true,auto:true,account} |
| - ],'manual and automatic submissions must disable the button, retain the form and preserve the selected account'); |
| + {disabled:true,list:true,auto:false,account}, |
| + {disabled:null,list:false,auto:true,account} |
| + ],'a manual choice disables its button; a resumed one posts the same account from the progress view, with no list painted'); |
| process.stdout.write('after: keyboard choice, redirect, callback, JS auto-submit; no CSP violations\n'); |
| await until('document.querySelector("li[aria-current=step]")?.dataset.step === "2"'); |
| assert.equal(await evaluate('document.getElementById("claim-status").textContent'),'Starting your app'); |
| @@ -180,7 +221,11 @@ try { |
| assert.equal(await evaluate('window.liveWrites'),0,'unchanged poll rewrote live region'); |
| await until('document.getElementById("claim").dataset.state === "claimed"'); |
| await capture('done'); |
| - assert.equal(await evaluate('document.querySelector(".claim-result a").textContent'),'Open your app'); |
| + assert.equal(await evaluate('document.querySelector(".claim-result .claim-console").textContent'),'Open in the console'); |
| + assert.equal(await evaluate('document.querySelector(".claim-result .claim-console").pathname.startsWith('+JSON.stringify('/a/'+account+'/apps/')+')'),true,'console link must name the claimed account'); |
| + assert.equal(await evaluate('document.querySelector(".claim-result .claim-open").target'),'_blank'); |
| + assert.equal(await evaluate('new URL(document.querySelector(".claim-result .claim-open").href).origin === document.querySelector(".claim-result .claim-open-address").textContent'),true); |
| + assert.equal(await evaluate('document.querySelector(".claim-result .claim-open svg").getAttribute("aria-hidden")'),'true'); |
| 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'); |
| @@ -250,6 +295,32 @@ try { |
| 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'); |
| + // A long "Starting your app": the bar sits inside the step's band and |
| + // never goes back, and the step's detail rotates through reassurance. |
| + await call('Page.navigate',{url:target+'/demo/claim?testProgress=starting'}); |
| + await until('document.querySelector("li[aria-current=step]")?.dataset.step === "2"'); |
| + const original = await evaluate('document.querySelector("li[aria-current=step] .claim-step-detail").textContent'); |
| + const bar = 'Number(document.querySelector(".claim-bar").getAttribute("aria-valuenow"))'; |
| + const first = await evaluate(bar); |
| + assert(first >= 55 && first < 100, 'bar outside the starting band: '+first); |
| + await until('document.querySelector("li[aria-current=step] .claim-step-detail").textContent !== '+JSON.stringify(original)); |
| + const later = await evaluate(bar); |
| + assert(later >= first && later < 100, 'bar went back or finished early: '+first+' then '+later); |
| + assert.equal(await evaluate('document.getElementById("claim-elapsed").hidden'),true,'elapsed shown before 30 s'); |
| + assert.equal(await evaluate('document.getElementById("claim-stuck").hidden'),true,'stuck before the deadline'); |
| + await capture('starting-hint'); |
| + // Past the server's deadline plus grace, still reporting progress: stuck. |
| + await call('Page.navigate',{url:target+'/demo/claim?testProgress=stuck'}); |
| + await until('!!document.getElementById("claim-progress")'); |
| + assert.equal(await evaluate('document.getElementById("claim-stuck").hidden'),true,'stuck before polling'); |
| + await until('document.getElementById("claim-stuck")?.hidden === false'); |
| + assert.equal(await evaluate('document.getElementById("claim-stuck").getAttribute("role")'),'alert'); |
| + assert.equal(await evaluate('document.querySelector("#claim-stuck a").getAttribute("href")'),'/demo/claim'); |
| + assert.equal(await evaluate('document.getElementById("claim-progress").hasAttribute("data-stuck")'),true); |
| + assert.equal(await evaluate('document.querySelector("li[aria-current=step] .claim-step-detail").textContent'),original,'stuck page still rotates reassurance'); |
| + await capture('stuck'); |
| + assert.equal(security.length,0,JSON.stringify(security)); |
| + process.stdout.write('reassurance: bar in band and monotonic, hints rotate, stuck after the deadline\n'); |
| } finally { |
| clearTimeout(timer); |
| const closed = new Promise(resolve => chrome.once('exit',resolve)); |