carlos / platform Public

demo claims: tidy the claim page on phones; copyable CLI command

Label above a full-width field, one primary button and a quiet sign-in
line on the email and code steps. The result shows the CLI command as a
block with a copy button. Layout and copy only.

Squashed from demo-claim-mobile into main.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 80385b819c415af8210a1abcdff21cd3b9e127b1 parent 3e1a375
12 files changed, +300 −32
  • docs/superpowers/specs/LUNA-COPY-BRIEF-DEMO-CLAIM-MOBILE.md +17 −0
  • docs/superpowers/specs/LUNA-COPY-RESULT-DEMO-CLAIM-MOBILE.md +9 −0
  • internal/console/demo_claim_copy.go +15 −3
  • internal/console/demo_claim_csp_test.go +73 −0
  • internal/console/demo_claim_page.go +6 −0
  • internal/console/demo_claim_page_test.go +2 −1
  • internal/console/demo_claim_review_test.go +1 −1
  • internal/console/static/demo_claim.js +16 −0
  • internal/console/templates/demo_claim.html +29 −10
  • internal/console/testdata/demo_claim_browser.mjs +37 −1
  • internal/console/testdata/demo_claim_layout.mjs +64 −0
  • internal/console/testdata/demo_claim_resume_browser.mjs +31 −16

CI passed — run details

diff --git a/docs/superpowers/specs/LUNA-COPY-BRIEF-DEMO-CLAIM-MOBILE.md b/docs/superpowers/specs/LUNA-COPY-BRIEF-DEMO-CLAIM-MOBILE.md
new file mode 100644
index 000000000..960abe78f
--- /dev/null
+++ b/docs/superpowers/specs/LUNA-COPY-BRIEF-DEMO-CLAIM-MOBILE.md
@@ -0,0 +1,17 @@
+You are the copy-review gate itself for this set. Paul delegated copy review to you on 2026-10-25; your verdicts ARE the review. Do NOT run the copy-review skill or start any server. Do not edit any file. You are writing a review report into your final answer.
+
+The page: a signed-out person, often on a phone, opened a private link to keep a temporary demo app. This step asks for their email. An ordinary address gets a six-digit code by email. A Keymail address (Keymail is a sign-in service, so name it) is sent to Keymail in the browser instead. Someone with a console account can sign in directly, which reaches the same place; it must not read as a competing path. "Console" means the place they manage apps.
+
+House rules: plain words, short sentences, no marketing tone, no exclamation marks, no em or en dashes used as dashes, sentence case, full stops on sentences. Labels and button text have no full stop. Do not name the product.
+
+Answer with one markdown table, `| key | new | why |`, `unchanged` in why when you keep a string. Nothing else.
+
+| key | Surface | Draft |
+|---|---|---|
+| demoClaimEmailIntro | One sentence above the email field | To keep this demo, enter your email. We will send you a code, or take you to Keymail if that is your address. |
+| demoClaimSigninPrompt | Quiet line under the button, before the link | Already have a console account? |
+| demoClaimSignin | The link text after that prompt | Sign in |
+| demoClaimCodeIntro | One sentence above the code field | Enter the six-digit code from the email we sent you. |
+| demoClaimCLICommandLabel | Text above a command block on the result page | To deploy changes, sign in with the CLI: |
+| demoClaimCopy | Small button beside the command | Copy |
+| demoClaimCopied | That button briefly after copying | Copied |
diff --git a/docs/superpowers/specs/LUNA-COPY-RESULT-DEMO-CLAIM-MOBILE.md b/docs/superpowers/specs/LUNA-COPY-RESULT-DEMO-CLAIM-MOBILE.md
new file mode 100644
index 000000000..9262ee7b8
--- /dev/null
+++ b/docs/superpowers/specs/LUNA-COPY-RESULT-DEMO-CLAIM-MOBILE.md
@@ -0,0 +1,9 @@
+| key | new | why |
+|---|---|---|
+| demoClaimEmailIntro | To keep this demo, enter your email. We’ll send a six-digit code, or send you to Keymail to sign in. | Names Keymail as the sign-in service and explains what happens. |
+| demoClaimSigninPrompt | Already have a console account? | unchanged |
+| demoClaimSignin | Sign in | unchanged |
+| demoClaimCodeIntro | Enter the six-digit code from your email. | Shorter and clear. |
+| demoClaimCLICommandLabel | To deploy changes, sign in with the CLI: | unchanged |
+| demoClaimCopy | Copy | unchanged |
+| demoClaimCopied | Copied | unchanged |
\ No newline at end of file
diff --git a/internal/console/demo_claim_copy.go b/internal/console/demo_claim_copy.go
index d6de609db..5dfe6db9e 100644
--- a/internal/console/demo_claim_copy.go
+++ b/internal/console/demo_claim_copy.go
@@ -41,10 +41,14 @@ const (
demoClaimNeedsScript = "JavaScript is needed to open the private claim link."
// 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."
// CLAIM-EMAIL: email field label.
demoClaimEmailLabel = "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"
// CLAIM-EMAIL: code action.
@@ -54,7 +58,9 @@ const (
// CLAIM-EMAIL: awaiting proof.
demoClaimEmailSent = "Check your email for a code or confirmation link."
// CLAIM-KEYMAIL: ordinary sign-in action.
- demoClaimSignin = "Sign in to continue"
+ demoClaimSignin = "Sign in"
+ // CLAIM-SIGNIN-PROMPT: secondary console sign-in.
+ demoClaimSigninPrompt = "Already have a console account?"
// CLAIM-ACCOUNT: empty picker choice.
demoClaimChooseAccount = "Choose an account"
// CLAIM-ACCOUNT-NEW: zero membership confirmation.
@@ -67,8 +73,14 @@ const (
demoClaimComplete = "Your demo is now a permanent app."
// CLAIM-RESULT: result URL label.
demoClaimURLLabel = "Open app"
- // CLAIM-RESULT: next workflow.
- demoClaimCLINext = "To deploy changes, sign in with the CLI: carlos auth login --console %s"
+ // CLAIM-CLI-LABEL: next workflow.
+ demoClaimCLICommandLabel = "To deploy changes, sign in with the CLI:"
+ // CLAIM-RESULT: command format consumed by the existing page renderer.
+ demoClaimCLINext = "carlos auth login --console %s"
+ // CLAIM-COPY: command clipboard action.
+ demoClaimCopy = "Copy"
+ // CLAIM-COPIED: clipboard confirmation.
+ demoClaimCopied = "Copied"
// CLAIM-RETIRED: unsuccessful operation.
demoClaimAborted = "This claim did not finish. Open the original demo link to try again if the demo has not expired."
)
diff --git a/internal/console/demo_claim_csp_test.go b/internal/console/demo_claim_csp_test.go
index 9fb0cefc7..e56f4db9d 100644
--- a/internal/console/demo_claim_csp_test.go
+++ b/internal/console/demo_claim_csp_test.go
@@ -80,3 +80,76 @@ func TestDemoClaimPageRejectsUnsafeFormOrigin(t *testing.T) {
}
}
}
+
+func TestDemoClaimMobileMarkup(t *testing.T) {
+ s, _, token := claimTestServer(t)
+ b := newClaimBrowser(t, s, token)
+ check := func(body string) {
+ t.Helper()
+ for _, want := range []string{
+ demoClaimEmailIntro, demoClaimSigninPrompt,
+ `<label for="email">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>`,
+ } {
+ if !strings.Contains(body, want) {
+ t.Errorf("missing %q", want)
+ }
+ }
+ if strings.Contains(body, "Sign in to continue") || strings.Contains(body, " style=") || strings.Count(body, "<script") != 1 {
+ t.Error("old sign-in copy, inline styles or extra script")
+ }
+ }
+ check(b.request("GET", "/demo/claim", nil).Body.String())
+ if w := b.post("/demo/claim/prove", url.Values{"email": {"reader@example.com"}}); w.Code != 303 {
+ t.Fatalf("email proof: %d", w.Code)
+ }
+ w := b.request("GET", "/demo/claim", nil)
+ body := w.Body.String()
+ check(body)
+ for _, want := range []string{
+ demoClaimCodeIntro,
+ `<label for="code">Email 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>`,
+ } {
+ if !strings.Contains(body, want) {
+ t.Errorf("pending code missing %q", want)
+ }
+ }
+ if strings.Count(body, `action="/demo/claim/prove"`) != 2 || strings.Index(body, `id="code"`) > strings.Index(body, `id="email"`) {
+ t.Error("code must precede the reachable secondary email form")
+ }
+ _, rest, _ := strings.Cut(body, "<style>")
+ css, _, _ := strings.Cut(rest, "</style>")
+ sum := sha256.Sum256([]byte(css))
+ if !strings.Contains(w.Header().Get("Content-Security-Policy"), "style-src 'sha256-"+base64.StdEncoding.EncodeToString(sum[:])+"';") {
+ t.Error("pending code style hash does not match rendered bytes")
+ }
+}
+
+func TestDemoClaimCommandMarkup(t *testing.T) {
+ p := demoClaimPageData{State: "claimed", Copy: demoClaimBrowserCopy()}
+ p.Copy["next"] = "carlos auth login --console https://console.example.com"
+ var body strings.Builder
+ if err := demoClaimPageTemplate.ExecuteTemplate(&body, "demo_claim.html", p); err != nil {
+ t.Fatal(err)
+ }
+ for _, want := range []string{
+ `<p>To deploy changes, sign in with the CLI:</p>`,
+ `<pre><code id="claim-cli-command">` + p.Copy["next"] + `</code></pre>`,
+ `data-copy="Copy" data-copied="Copied" aria-live="polite" hidden>Copy</button>`,
+ } {
+ if !strings.Contains(body.String(), want) {
+ t.Errorf("missing %q", want)
+ }
+ }
+ js, err := staticFS.ReadFile("static/demo_claim.js")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(string(js), "innerHTML") || strings.Index(string(js), "history.replaceState") > strings.Index(string(js), "navigator.clipboard") {
+ t.Error("clipboard must follow fragment clearing and use textContent")
+ }
+}
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go
index 9dee722e5..af2b13b1f 100644
--- a/internal/console/demo_claim_page.go
+++ b/internal/console/demo_claim_page.go
@@ -541,6 +541,12 @@ func demoClaimBrowserCopy() map[string]string {
"noscript": demoClaimNeedsScript,
"identity": demoClaimIdentityLabel,
"email": demoClaimEmailLabel,
+ "emailIntro": demoClaimEmailIntro,
+ "codeIntro": demoClaimCodeIntro,
+ "signinPrompt": demoClaimSigninPrompt,
+ "cliCommandLabel": demoClaimCLICommandLabel,
+ "copy": demoClaimCopy,
+ "copied": demoClaimCopied,
"continue": demoClaimEmailContinue,
"code": demoClaimCodeLabel,
"prove": demoClaimCodeConfirm,
diff --git a/internal/console/demo_claim_page_test.go b/internal/console/demo_claim_page_test.go
index 12d7cfb47..9961491a1 100644
--- a/internal/console/demo_claim_page_test.go
+++ b/internal/console/demo_claim_page_test.go
@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "os"
"os/exec"
"regexp"
"strings"
@@ -196,7 +197,7 @@ func TestDemoClaimBrowserHeadless(t *testing.T) {
s.cfg.Origin = ts.URL
ctx, cancel := context.WithTimeout(t.Context(), 40*time.Second)
defer cancel()
- cmd := exec.CommandContext(ctx, node, "testdata/demo_claim_browser.mjs", chromium, t.TempDir(), ts.URL+"/demo/claim#"+token)
+ cmd := exec.CommandContext(ctx, node, "testdata/demo_claim_browser.mjs", chromium, t.TempDir(), ts.URL+"/demo/claim#"+token, os.Getenv("CARLOS_DEMO_CLAIM_SCREENSHOTS"))
output, err := cmd.CombinedOutput()
if err != nil {
mu.Lock()
diff --git a/internal/console/demo_claim_review_test.go b/internal/console/demo_claim_review_test.go
index f45f9ecc3..7d77f0a6a 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(), demoClaimEmailSent) {
+ if w := b.request("GET", "/demo/claim", nil); !strings.Contains(w.Body.String(), demoClaimCodeIntro) || !strings.Contains(w.Body.String(), `id="code"`) {
t.Fatal("withheld challenge missing")
}
}
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js
index b1c8f1b34..98debaa3c 100644
--- a/internal/console/static/demo_claim.js
+++ b/internal/console/static/demo_claim.js
@@ -9,6 +9,22 @@
}
});
}
+ const copy = document.getElementById("claim-copy");
+ const command = document.getElementById("claim-cli-command");
+ if (copy && command && typeof navigator.clipboard?.writeText === "function") {
+ copy.hidden = false;
+ let reset;
+ copy.addEventListener("click", async () => {
+ try {
+ await navigator.clipboard.writeText(command.textContent);
+ copy.textContent = copy.dataset.copied;
+ clearTimeout(reset);
+ reset = setTimeout(() => { copy.textContent = copy.dataset.copy; }, 2000);
+ } catch (_) {
+ copy.hidden = true;
+ }
+ });
+ }
const choice = document.querySelector('form[action="/demo/claim/select"]');
if (choice) {
const radios = choice.querySelectorAll('input[type="radio"]:not(:disabled)');
diff --git a/internal/console/templates/demo_claim.html b/internal/console/templates/demo_claim.html
index 1c701b957..fd7296ae6 100644
--- a/internal/console/templates/demo_claim.html
+++ b/internal/console/templates/demo_claim.html
@@ -23,7 +23,18 @@
#claim .claim-single p { margin-bottom: 0.35rem; }
#claim .claim-unavailable { font-size: 0.9rem; }
#claim button, #claim .btn { box-shadow: none; }
-#claim button[type=submit] { margin-top: 0.5rem; }
+#claim button[type=submit] { margin-top: 0.75rem; min-height: 44px; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
+#claim .claim-proof label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
+#claim .claim-proof input:not([type=hidden]) { display: block; width: 100%; min-height: 44px; font-size: 1rem; padding: 0.65rem 0.75rem; }
+#claim .claim-intro { margin: 0 0 1.25rem; }
+#claim .claim-signin, #claim .claim-email-change { margin-top: 1.5rem; }
+#claim .claim-signin { color: var(--muted); font-size: 0.9rem; }
+#claim .claim-email-change summary { color: var(--accent); cursor: pointer; padding: 0.5rem 0; }
+#claim .claim-email-change[open] summary { margin-bottom: 0.75rem; }
+#claim .claim-command { margin-top: 1.5rem; }
+#claim .claim-command pre { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.65rem 0; }
+#claim .claim-command code { font-size: 1em; }
+@media (max-width: 40rem) { #claim button[type=submit] { width: 100%; } }
#claim .claim-steps { list-style: decimal; padding-left: 1.6rem; margin: 1.5rem 0; }
#claim .claim-steps li { padding: 0.6rem 0 0.6rem 0.4rem; color: var(--muted); }
#claim .claim-steps [aria-current=step] { color: var(--ink); font-weight: 600; }
@@ -63,7 +74,12 @@
{{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><p>{{.Copy.next}}</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>
{{end}}
{{if and .HasIntent .CanClaim}}
{{if .Address}}
@@ -85,20 +101,23 @@
<button type="submit" data-neutral="{{.Copy.confirm}}">{{.Copy.confirm}}</button>
</form>
{{else}}
-<form 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" required>
-<button type="submit">{{.Copy.continue}}</button>
-</form>
{{if .EmailPending}}
-<p>{{.Copy.sent}}</p>
-<form method="post" action="/demo/claim/prove">
+<p class="claim-intro">{{.Copy.codeIntro}}</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="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>
</form>
+<details class="claim-email-change"><summary>{{.Copy.email}}</summary>
{{end}}
-<p><a href="/?next=%2Fdemo%2Fclaim">{{.Copy.signin}}</a></p>
+<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>
+</form>
+{{if .EmailPending}}</details>{{end}}
+<p class="claim-signin">{{.Copy.signinPrompt}} <a href="/?next=%2Fdemo%2Fclaim">{{.Copy.signin}}</a></p>
{{end}}
{{end}}
{{if eq .State "missing"}}<noscript><p>{{.Copy.noscript}}</p></noscript>{{end}}
diff --git a/internal/console/testdata/demo_claim_browser.mjs b/internal/console/testdata/demo_claim_browser.mjs
index aef4f283d..55b6e992d 100644
--- a/internal/console/testdata/demo_claim_browser.mjs
+++ b/internal/console/testdata/demo_claim_browser.mjs
@@ -1,7 +1,8 @@
import {spawn} from 'node:child_process';
import assert from 'node:assert/strict';
+import {captureClaim, watchClaimCSP} from './demo_claim_layout.mjs';
-const [binary, profile, target] = process.argv.slice(2);
+const [binary, profile, target, screenshots] = process.argv.slice(2);
const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu',
'--disable-dev-shm-usage', '--disable-background-networking', '--disable-component-update',
'--disable-default-apps', '--disable-extensions', '--disable-sync', '--no-proxy-server',
@@ -48,8 +49,10 @@ 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});
await call('Page.navigate', {url:target});
await until('location.hash === "" && !!document.getElementById("email")');
+ await captureClaim(call, evaluate, screenshots, 'email', [360, 390, 1100]);
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('#'));
@@ -63,6 +66,39 @@ 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]);
+ 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()');
+ await call('Input.insertText', {text:'another@example.com'});
+ await key('Tab','Tab',9);
+ await key('Enter','Enter',13);
+ await until('!!document.getElementById("code") && !document.querySelector(".claim-email-change").open');
+ assert.deepEqual(await evaluate('window.claimCSPViolations'), []);
+ await evaluate('document.getElementById("code").focus()');
+ 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');
+ await evaluate(`document.getElementById('code').form.addEventListener('submit', event => {
+ event.preventDefault();
+ const form = event.target;
+ window.claimCodeSubmission = {
+ code:new FormData(form).get('code'), nonce:new FormData(form).get('nonce'),
+ action:form.getAttribute('action'), method:form.method,
+ disabled:form.querySelector('button').disabled
+ };
+ }, {once:true})`);
+ await key('Enter','Enter',13);
+ await until('!!window.claimCodeSubmission');
+ const submitted = await evaluate('window.claimCodeSubmission');
+ assert(submitted.nonce);
+ assert.equal(submitted.code, '123456');
+ assert.equal(submitted.action, '/demo/claim/prove');
+ assert.equal(submitted.method, 'post');
+ assert.equal(submitted.disabled, true);
+ assert.deepEqual(await evaluate('window.claimCSPViolations'), []);
+ 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);
diff --git a/internal/console/testdata/demo_claim_layout.mjs b/internal/console/testdata/demo_claim_layout.mjs
new file mode 100644
index 000000000..a56208ef7
--- /dev/null
+++ b/internal/console/testdata/demo_claim_layout.mjs
@@ -0,0 +1,64 @@
+import assert from 'node:assert/strict';
+import {writeFile} from 'node:fs/promises';
+
+export async function captureClaim(call, evaluate, screenshots, state, widths = [360, 390]) {
+ for (const width of widths) {
+ await call('Emulation.setDeviceMetricsOverride', {width, height:900, deviceScaleFactor:1, mobile:false});
+ for (const theme of ['light', 'dark']) {
+ await call('Emulation.setEmulatedMedia', {features:[
+ {name:'prefers-color-scheme', value:theme},
+ {name:'prefers-reduced-motion', value:'reduce'}
+ ]});
+ await new Promise(resolve => setTimeout(resolve, 150));
+ const description = `${state}-${theme}-${width}`;
+ assert.equal(await evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth'), true, description+' overflows');
+ const check = await evaluate(`(() => {
+ const problems = [];
+ for (const input of document.querySelectorAll('#email, #code')) {
+ // Measure the secondary email form as well, then restore its disclosure.
+ const details = input.closest('details');
+ const wasOpen = details?.open;
+ if (details) details.open = true;
+ const rect = input.getBoundingClientRect();
+ const form = input.form.getBoundingClientRect();
+ const label = document.querySelector('label[for='+input.id+']').getBoundingClientRect();
+ if (rect.height < 44) problems.push(input.id+' height '+rect.height);
+ if (parseFloat(getComputedStyle(input).fontSize) < 16) problems.push(input.id+' font too small');
+ if (Math.abs(rect.width-form.width) > 1) problems.push(input.id+' not full width');
+ if (label.bottom > rect.top || Math.abs(label.left-rect.left) > 1) problems.push(input.id+' label not above');
+ if (details) details.open = wasOpen;
+ }
+ if (innerWidth <= 640) {
+ for (const button of document.querySelectorAll('#claim button[type=submit]:not(.btn-secondary)')) {
+ if (Math.abs(button.getBoundingClientRect().width-button.form.getBoundingClientRect().width) > 1) problems.push('primary button not full width');
+ }
+ }
+ const link = document.querySelector('.claim-result a');
+ if (link) {
+ const rect = link.getBoundingClientRect();
+ if (rect.left < 0 || rect.right > innerWidth || link.scrollWidth > link.clientWidth) problems.push('result address overflows');
+ }
+ const command = document.getElementById('claim-cli-command');
+ if (command) {
+ const rect = command.parentElement.getBoundingClientRect();
+ if (rect.left < 0 || rect.right > innerWidth) problems.push('command overflows');
+ if (getComputedStyle(command).userSelect === 'none') problems.push('command not selectable');
+ }
+ return problems;
+ })()`);
+ assert.deepEqual(check, [], description);
+ assert.deepEqual(await evaluate('window.claimCSPViolations'), [], description+' CSP');
+ if (screenshots) {
+ const shot = await call('Page.captureScreenshot', {format:'png', captureBeyondViewport:true});
+ await writeFile(`${screenshots}/${description}.png`, Buffer.from(shot.data, 'base64'));
+ }
+ }
+ }
+}
+
+export const watchClaimCSP = `
+ window.claimCSPViolations = [];
+ 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 4c08dfecd..6b06e9ccb 100644
--- a/internal/console/testdata/demo_claim_resume_browser.mjs
+++ b/internal/console/testdata/demo_claim_resume_browser.mjs
@@ -1,6 +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, sessionToken, flowCookie, account, screenshots, singleJSON] = process.argv.slice(2);
const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu',
@@ -51,21 +51,9 @@ async function key(key, code, number) {
await call('Input.dispatchKeyEvent', {type:'keyUp', key, code, windowsVirtualKeyCode:number});
}
async function capture(state) {
- for (const width of [360,1100]) {
- await call('Emulation.setDeviceMetricsOverride',{width,height:900,deviceScaleFactor:1,mobile:false});
- for (const scheme of ['light','dark']) {
- await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:scheme},{name:'prefers-reduced-motion',value:'reduce'}]});
- await new Promise(r=>setTimeout(r,150));
- assert.equal(await evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth'),true,state+' overflows at '+width);
- if (state === 'done') {
- assert.equal(await evaluate('(() => { const link = document.querySelector(".claim-result a"); const rect = link.getBoundingClientRect(); return rect.left >= 0 && rect.right <= innerWidth && link.scrollWidth <= link.clientWidth; })()'),true,'result address overflows at '+width);
- }
- if (screenshots) {
- const shot=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:true});
- await writeFile(screenshots+'/'+state+'-'+scheme+'-'+width+'.png',Buffer.from(shot.data,'base64'));
- }
- }
- }
+ await captureClaim(call, evaluate, screenshots, state);
+ await captureClaim(call, evaluate, '', state, [1100]);
+ assert.equal(security.length, 0, JSON.stringify(security));
}
const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 115000);
try {
@@ -75,6 +63,12 @@ try {
await call('Runtime.enable');
await call('Log.enable');
await call('Network.enable');
+ await call('Page.addScriptToEvaluateOnNewDocument', {source:watchClaimCSP});
+ const clipboardStub = await call('Page.addScriptToEvaluateOnNewDocument', {source:`
+ Object.defineProperty(navigator, 'clipboard', {configurable:true, value:{
+ writeText:async text => { window.claimClipboard = text; }
+ }});
+ `});
await call('Runtime.addBinding', {name:'claimSubmitted'});
await call('Page.addScriptToEvaluateOnNewDocument', {source:`
window.addEventListener('submit', event => {
@@ -191,6 +185,27 @@ try {
assert.equal(await evaluate('document.querySelector("#claim").innerText.split("Your demo is now a permanent app.").length-1'),1);
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);
+ await evaluate('document.getElementById("claim-copy").click()');
+ await until('document.getElementById("claim-copy").textContent === "Copied"');
+ assert.equal(await evaluate('window.claimClipboard'), 'carlos auth login --console '+target);
+ await until('document.getElementById("claim-copy").textContent === "Copy"');
+ await call('Page.removeScriptToEvaluateOnNewDocument', {identifier:clipboardStub.identifier});
+ const noClipboard = await call('Page.addScriptToEvaluateOnNewDocument', {source:
+ "Object.defineProperty(navigator, 'clipboard', {value:undefined})"});
+ await call('Page.navigate', {url:target+'/demo/claim'});
+ await until('document.readyState === "complete" && !!document.getElementById("claim-copy")');
+ assert.equal(await evaluate('document.getElementById("claim-copy").getBoundingClientRect().height'), 0);
+ assert.equal(await evaluate('document.getElementById("claim-cli-command").textContent'), 'carlos auth login --console '+target);
+ await call('Page.removeScriptToEvaluateOnNewDocument', {identifier:noClipboard.identifier});
+ await call('Network.setBlockedURLs', {urls:['*demo_claim.js*']});
+ await call('Page.navigate', {url:target+'/demo/claim'});
+ await until('document.readyState === "complete" && !!document.getElementById("claim-copy")');
+ assert.equal(await evaluate('document.getElementById("claim-copy").getBoundingClientRect().height'), 0);
+ assert.equal(await evaluate('document.getElementById("claim-cli-command").textContent'), 'carlos auth login --console '+target);
+ await call('Network.setBlockedURLs', {urls:[]});
+ assert.deepEqual(await evaluate('window.claimCSPViolations'), []);
+ process.stdout.write('clipboard: copied command, reset label, hidden without clipboard or script\n');
const requestsAtDone=statusRequests;
await new Promise(r=>setTimeout(r,3500));
assert.equal(statusRequests,requestsAtDone,'done kept polling');