Add a desktop handoff to mobile Cloud onboarding (#23326)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Onboarding asks users to connect a model before they can finish
setting up their agent.
> - Cloud users can start setup on a phone, where provider sign-in and
key entry can be difficult.
> - They need a way to find the same workspace on a computer.
> - This pull request adds a copyable link on the mobile model step and
defers agent creation while the handoff is offered.
> - A user can open the link on desktop or continue on the phone.

## Linked Issues or Issue Description

**Subsystem affected**
React onboarding UI and its Cloud health metadata.

**Problem or motivation**
On a phone, the Cloud model step does not explain how to find the same
onboarding page on a computer. The fresh agent draft is local to that
browser and can leave a provisional agent behind.

**Proposed solution**
Offer Continue on desktop and Keep going here at the start of the mobile
model step. Copy the workspace's HTTPS `/onboarding` link. Ask users to
sign in to the same account on desktop and explain that they may need to
enter their choices again.

**Alternatives considered**
The original invite URL would carry an invite token. Copying the
workspace's onboarding URL lets Cloud handle sign-in through its
existing entry flow.

**Roadmap alignment**
This is a focused improvement to the existing onboarding wizard. It uses
the current Cloud workspace entry flow and keeps model selection
available on mobile.

**Additional context**
Refs #23315 for naming-step setup drafts. Related prior work: #3594
covered a native iOS-to-web handoff token and is closed.

## What Changed

- Add the Cloud mobile handoff panel and clipboard fallback.
- Prefer the canonical tenant HTTPS origin and build a clean
`/onboarding` URL. Older tenants can use the current HTTPS tenant
origin.
- Defer the provisional agent in the naming and model steps while the
mobile handoff is available. Desktop and self-hosted sessions keep the
early-draft behavior from #23315.
- Render the step indicators as round dots inside the step buttons so
the mobile touch-height rule does not stretch them.
- Add browser coverage for the Cloud and self-hosted paths and unit
coverage for URL handling.

## Verification

- Passed 52 focused Vitest tests for the onboarding route, stepper,
handoff URL, and shared clipboard policy.
- Passed UI typecheck, the test-budget guard, and `git diff --check`.
- Passed 23 tests in desktop Chrome with four workers, including the
affected CI browser shard and the upstream early-draft regression. The
handoff scenarios cover the mobile dots, clipboard success and manual
fallback, same-workspace desktop re-entry via simulated sign-in,
continuing on mobile, and the self-hosted flow.
- Manual reproduction: use a fresh Cloud test workspace and a 390 × 844
viewport. Enter an agent name and proceed to Connect a model. Open
Continue on desktop and copy the link. Open it on desktop and sign in
with the same account if needed. A real Cloud sign-in was outside the
local fixture.

## Risks

- Setup choices from the phone may need to be entered again on desktop.
- Real Cloud sign-in and in-app mobile browsers still need a live tenant
check. No database migration is needed.

## Model Used

- OpenAI Codex with GPT-6.2 Sol (`gpt-6.2-sol`) for branch preparation
and verification. Used the terminal and Chromium. The context window
size is not available in the session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <1504818+scotttong@users.noreply.github.com>
This commit is contained in:
scotttongandScott Tong authored and GitHub committed 2026-11-30 22:42:48 +00:00
1 parent d71d039ad7
commit adc4501689
8 files changed
+394 -15

No files matched your search

@@ -0,0 +1,178 @@
import { randomUUID } from "node:crypto";
import { expect, test } from "@playwright/test";
import type { BrowserContext, BrowserContextOptions } from "@playwright/test";
const controlPlane = "https://my.paperclip.app";
const canonicalTenant = "https://example-workspace.paperclip.app";
const stackSlug = "example-workspace";
const mobileOptions: BrowserContextOptions = {
viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, serviceWorkers: "block",
};
test("a Cloud mobile visitor copies the canonical tenant, can sign in there on desktop, or can keep going", async ({ browser, request, baseURL }, testInfo) => {
const companyResponse = await request.post("/api/companies", { data: { name: `Mobile handoff ${randomUUID()}` } });
expect(companyResponse.ok()).toBe(true);
const company = await companyResponse.json();
const healthResponse = await request.get("/api/health");
expect(healthResponse.ok()).toBe(true);
const cloudHealth = {
...await healthResponse.json(),
cloud: {
managed: true, managedBy: "paperclip-cloud", cloudBaseUrl: controlPlane, stackSlug,
runtimeIdentity: { canonicalOrigin: canonicalTenant, stackSlug },
},
};
const featureResponse = await request.get("/api/instance/settings/experimental");
expect(featureResponse.ok()).toBe(true);
const featureSettings = { ...await featureResponse.json(), enableConferenceRoomChat: true };
const mobile = await browser.newContext({ ...mobileOptions, baseURL });
const continuedMobile = await browser.newContext({ ...mobileOptions, baseURL });
const desktop = await browser.newContext({ baseURL, viewport: { width: 1280, height: 1080 }, serviceWorkers: "block", reducedMotion: "reduce" });
let desktopSignedIn = false;
let cloudRedirects = 0;
async function fixture(context: BrowserContext, workspace: { id: string }, needsDesktopSignIn = false) {
await context.route("**/api/health", (route) => route.fulfill({
json: { ...cloudHealth, ...(needsDesktopSignIn ? { deploymentMode: "authenticated", bootstrapStatus: "ready" } : {}) },
}));
await context.route("**/api/auth/get-session", async (route) => {
if (needsDesktopSignIn && !desktopSignedIn) {
return route.fulfill({ status: 401, json: { error: "Board authentication required" } });
}
const response = await route.fetch();
const session = await response.json();
delete session.boardBootstrap;
return route.fulfill({ response, json: session });
});
if (needsDesktopSignIn) {
await context.route((url) => url.pathname === "/api/cli-auth/me", (route) => route.fulfill({
json: { userId: "local-board", isInstanceAdmin: false, companyIds: [workspace.id] },
}));
await context.route(`${controlPlane}/v1/stacks/${stackSlug}/entry-redirect?**`, (route) => {
cloudRedirects++;
expect(new URL(route.request().url()).searchParams.get("returnTo")).toBe("/onboarding");
desktopSignedIn = true;
return route.fulfill({ status: 302, headers: { Location: new URL("/onboarding", baseURL).href } });
});
}
await context.route((url) => url.pathname === "/api/companies", (route) => route.request().method() === "GET"
? route.fulfill({ json: [workspace] }) : route.continue());
await context.route("**/api/instance/settings/experimental", (route) => route.request().method() === "GET"
? route.fulfill({ json: featureSettings }) : route.continue());
}
try {
await mobile.grantPermissions(["clipboard-read", "clipboard-write"]);
await fixture(mobile, company);
await fixture(desktop, company, true);
const page = await mobile.newPage();
const mobileHealth = page.waitForResponse((response) => new URL(response.url()).pathname === "/api/health");
await page.goto(`/${company.issuePrefix}/onboarding?invite=not-for-desktop#phone`);
expect((await (await mobileHealth).json()).cloud).toEqual(cloudHealth.cloud);
await page.locator("#onboarding-agent-name").fill("Scout");
await expect.poll(() => page.evaluate(() => matchMedia("(width < 40rem)").matches)).toBe(true);
await page.getByRole("button", { name: "Next", exact: true }).click();
const nudge = page.getByRole("region", { name: "Setup is easier on desktop" });
await expect(nudge).toBeVisible();
await expect(page.getByRole("heading", { name: "Connect a model" })).toBeVisible();
await expect(page.getByRole("radio").first()).toBeVisible();
const progress = page.locator('button[aria-current="step"]').locator("..");
const dots = progress.locator('button > span[aria-hidden="true"]');
await expect(dots).toHaveCount(3);
expect(await dots.evaluateAll((indicators) => indicators.every((indicator) => {
const { width, height } = indicator.getBoundingClientRect();
return width > 0 && width === height && parseFloat(getComputedStyle(indicator).borderTopLeftRadius) >= width / 2;
}))).toBe(true);
await page.screenshot({ path: testInfo.outputPath("mobile-01-nudge.png"), animations: "disabled" });
await nudge.getByRole("button", { name: "Continue on desktop" }).click();
const handoff = nudge.getByRole("textbox", { name: "Desktop setup link" });
const destination = new URL("/onboarding", canonicalTenant);
await expect(handoff).toHaveValue(destination.href);
await expect(nudge).toContainText("You may need to re-enter setup choices.");
const copy = nudge.getByRole("button", { name: "Copy setup link" });
await expect(copy).toBeInViewport();
await page.screenshot({ path: testInfo.outputPath("mobile-cloud-https-handoff.png"), animations: "disabled" });
await copy.click();
const copied = nudge.getByRole("button", { name: "Link copied" });
await expect(copied).toBeVisible();
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(destination.href);
await page.evaluate(() => {
Object.defineProperty(navigator.clipboard, "writeText", {
value: async () => {
throw new DOMException("Clipboard access denied", "NotAllowedError");
},
});
Object.defineProperty(document, "execCommand", { value: () => false });
});
await copied.click();
await expect(nudge.getByText("Automatic copy is unavailable. Copy the selected link manually.")).toBeVisible();
await expect(handoff).toBeFocused();
expect(await handoff.evaluate((element: HTMLInputElement) =>
element.value.slice(element.selectionStart ?? 0, element.selectionEnd ?? 0))).toBe(destination.href);
expect(await (await request.get(`/api/companies/${company.id}/agents`)).json()).toEqual([]);
const desktopPage = await desktop.newPage();
await desktopPage.goto(destination.pathname);
const desktopName = desktopPage.locator("#onboarding-agent-name");
await expect(desktopName).toBeVisible({ timeout: 25_000 });
await desktopName.scrollIntoViewIfNeeded();
expect(cloudRedirects).toBe(1);
expect(new URL(desktopPage.url()).pathname).toBe(destination.pathname);
await expect(desktopName).not.toHaveValue("Scout");
await expect(desktopPage.getByRole("region", { name: "Setup is easier on desktop" })).toHaveCount(0);
await desktopPage.screenshot({ path: testInfo.outputPath("mobile-03-desktop-handoff.png"), animations: "disabled" });
await expect.poll(async () => (await (await request.get(`/api/companies/${company.id}/agents`)).json()))
.toEqual([expect.objectContaining({ pauseReason: "setup" })]);
const continuedResponse = await request.post("/api/companies", { data: { name: `Continue mobile ${randomUUID()}` } });
expect(continuedResponse.ok()).toBe(true);
const continuedCompany = await continuedResponse.json();
await fixture(continuedMobile, continuedCompany);
const continuedPage = await continuedMobile.newPage();
await continuedPage.goto(`/${continuedCompany.issuePrefix}/onboarding`);
await continuedPage.locator("#onboarding-agent-name").fill("Scout");
await continuedPage.getByRole("button", { name: "Next", exact: true }).click();
const continuedNudge = continuedPage.getByRole("region", { name: "Setup is easier on desktop" });
await continuedNudge.getByRole("button", { name: "Keep going here" }).click();
await expect(continuedNudge).toHaveCount(0);
await expect(continuedPage.getByRole("radio").first()).toBeFocused();
await expect(continuedPage.getByRole("heading", { name: "Connect a model" })).toBeVisible();
await expect.poll(async () => (await (await request.get(`/api/companies/${continuedCompany.id}/agents`)).json())
.map((agent: { name: string }) => agent.name)).toEqual(["Scout"]);
await continuedPage.screenshot({ path: testInfo.outputPath("mobile-04-kept-going.png"), animations: "disabled" });
} finally {
await mobile.close();
await continuedMobile.close();
await desktop.close();
}
});
test("self-hosted mobile onboarding keeps its original model step and agent draft", async ({ browser, request, baseURL }) => {
const response = await request.post("/api/companies", { data: { name: `Local mobile ${randomUUID()}` } });
expect(response.ok()).toBe(true);
const company = await response.json();
const origin = await request.get("/api/health");
expect(origin.ok()).toBe(true);
expect((await origin.json()).cloud).toBeUndefined();
const features = await request.get("/api/instance/settings/experimental");
expect(features.ok()).toBe(true);
const featureSettings = { ...await features.json(), enableConferenceRoomChat: true };
const mobile = await browser.newContext({ ...mobileOptions, baseURL });
try {
await mobile.route("**/api/instance/settings/experimental", (route) => route.request().method() === "GET"
? route.fulfill({ json: featureSettings }) : route.continue());
const page = await mobile.newPage();
await page.goto(`/${company.issuePrefix}/onboarding`);
await page.locator("#onboarding-agent-name").fill("Local Scout");
await page.getByRole("button", { name: "Next", exact: true }).click();
await expect(page.getByRole("heading", { name: "Connect a model" })).toBeVisible();
await expect(page.getByRole("radio").first()).toBeVisible();
await expect(page.getByRole("button", { name: "Continue on desktop" })).toHaveCount(0);
await expect.poll(async () => (await (await request.get(`/api/companies/${company.id}/agents`)).json())
.map((agent: { name: string }) => agent.name)).toEqual(["Local Scout"]);
} finally {
await mobile.close();
}
});