diff --git a/tests/runner-e2e/product-journeys/cloud-onboarding.test.ts b/tests/runner-e2e/product-journeys/cloud-onboarding.test.ts index 68adbdd2d53..ba0d913cd6c 100644 --- a/tests/runner-e2e/product-journeys/cloud-onboarding.test.ts +++ b/tests/runner-e2e/product-journeys/cloud-onboarding.test.ts @@ -18,14 +18,15 @@ vi.mock("./onboarding-first-task.js", async () => { }) }; }); -type Entry = "first-run" | "portfolio" | "create-form"; +type Entry = "beta-welcome" | "first-run" | "portfolio" | "create-form"; type Control = { role: string; name: string; scope?: string; fill?(value: string): void; click?(): void; select?(value: string): void }; /** Visible control contracts only; no browser, Cloud API, or provider is started. */ -function fixture(entry: Entry, options: { intentFailure?: boolean; qualificationFailure?: boolean; traceFailure?: boolean } = {}) { +function fixture(entry: Entry, options: { legacyRunnerPicker?: boolean; intentFailure?: boolean; qualificationFailure?: boolean; traceFailure?: boolean } = {}) { let stage: string = entry, name = "", apiMode = false, source = false, advanced = false, runnerOpen = false; let modelsOpen = false, model = "", runner = "", saved = false, hired = false; const fields: Record = {}, events: string[] = []; + let hasCodex = false, intendsFeedback = false; const gateway = { baseUrl: "https://owned-gateway.example.test/v1", model: "gpt-5.4-mini", apiKey: "synthetic-test-key" }; const connection = { id: "connection", name: "My owned-gateway.example.test", provider: "openai", method: "api_key", status: "connected" }; const create = () => { @@ -34,6 +35,11 @@ function fixture(entry: Entry, options: { intentFailure?: boolean; qualification events.push("create:workspace"); stage = "agent"; }; const controls = (): Control[] => { + if (stage === "beta-welcome") return [ + { role: "checkbox", name: "OpenAI Codex", click() { hasCodex = true; } }, + { role: "checkbox", name: "I intend to provide feedback on the Paperclip closed beta.", click() { intendsFeedback = true; } }, + { role: "button", name: "Continue", click() { expect(hasCodex && intendsFeedback).toBe(true); stage = "first-run"; } }, + ]; if (stage === "portfolio") return [{ role: "link", name: "Create a new organization", click() { stage = "create-form"; } }]; if (stage === "first-run" || stage === "create-form") return [ { role: "textbox", name: stage === "first-run" ? "Name" : "Organization name", fill(value) { name = value; } }, @@ -50,7 +56,7 @@ function fixture(entry: Entry, options: { intentFailure?: boolean; qualification { role: "button", name: apiMode ? "Use subscription instead" : "Use API key instead", click() { apiMode = !apiMode; } }, { role: "radio", name: apiMode ? "OpenAI API key" : "OpenAI Subscription", click() { source = true; } }, ]; - if (source && apiMode) result.push({ role: "button", name: "Use a custom gateway", click() { stage = "gateway"; } }); + if (source && apiMode && (advanced || options.legacyRunnerPicker)) result.push({ role: "button", name: "Use a custom gateway", click() { stage = "gateway"; } }); if (stage === "gateway") { result.push({ role: "dialog", name: "Custom gateway connection" }); for (const field of ["Provider URL", "API key", ...(modelsOpen ? ["Model IDs"] : [])]) result.push({ @@ -64,9 +70,9 @@ function fixture(entry: Entry, options: { intentFailure?: boolean; qualification } if (saved) result.push({ role: "combobox", name: "Model", select(value) { expect(value).toBe(gateway.model); model = value; } }); if (source) result.push({ role: "summary", name: "Advanced", click() { advanced = true; } }); - if (advanced) result.push({ role: "button", name: "Runner", click() { runnerOpen = true; } }); + if (advanced && options.legacyRunnerPicker) result.push({ role: "button", name: "Runner", click() { runnerOpen = true; } }); if (runnerOpen) result.push({ role: "option", name: "Paperclip Runner (default)", click() { runner = "paperclip"; runnerOpen = false; } }); - if (saved && model && runner) result.push({ role: "button", name: "Connect", click() { + if (saved && model && (!options.legacyRunnerPicker || runner)) result.push({ role: "button", name: "Connect", click() { expect(events).toContain("qualified"); events.push("paid:connect"); hired = true; } }); return result; @@ -77,6 +83,7 @@ function fixture(entry: Entry, options: { intentFailure?: boolean; qualification or(other: { resolve(): Control[] }) { return locator(() => [...resolve(), ...other.resolve()]); }, resolve, async isVisible() { return resolve().length > 0; }, + async check() { const control = resolve()[0]; if (control?.role !== "checkbox" || !control.click) throw new Error("No visible checkbox"); control.click(); }, async fill(value: string) { const control = resolve()[0]; if (!control?.fill) throw new Error("No visible text field"); control.fill(value); }, async click() { const control = resolve()[0]; if (!control?.click) throw new Error("No visible action"); events.push(`click:${control.name}`); control.click(); }, async selectOption(value: string) { const control = resolve()[0]; if (!control?.select) throw new Error("No visible native model picker"); control.select(value); }, @@ -134,7 +141,7 @@ describe("Cloud onboarding visible controls", () => { expect(f.input.evidence.checks.map(check => check.id)).toEqual(["fresh-workspace", "ui-connection-and-native-agent"]); expect(f.events).not.toContain("native:verified"); }); - it.each(["first-run", "portfolio", "create-form"] as const)("creates from %s with intent before dispatch and qualification before paid Connect", async entry => { + it.each(["beta-welcome", "first-run", "portfolio", "create-form"] as const)("creates from %s with intent before dispatch and qualification before paid Connect", async entry => { const f = fixture(entry); const result = await cloudOnboarding(f.input); expect(result.startingState).toBe("onboarding"); @@ -143,6 +150,12 @@ describe("Cloud onboarding visible controls", () => { expect(f.events.indexOf("qualified")).toBeLessThan(f.events.indexOf("paid:connect")); expect(f.events).toContain("native:verified"); }); + it("can still choose the native runner on tenants with a separate runner picker", async () => { + const f = fixture("first-run", { legacyRunnerPicker: true }); + await cloudOnboarding(f.input); + expect(f.events).toContain("click:Paperclip Runner (default)"); + expect(f.events).toContain("native:verified"); + }); it("does not dispatch workspace creation without durable ownership", async () => { const f = fixture("first-run", { intentFailure: true }); await expect(cloudOnboarding(f.input)).rejects.toThrow("ownership unavailable"); diff --git a/tests/runner-e2e/product-journeys/cloud-onboarding.ts b/tests/runner-e2e/product-journeys/cloud-onboarding.ts index 215871b411d..13dee60bb90 100644 --- a/tests/runner-e2e/product-journeys/cloud-onboarding.ts +++ b/tests/runner-e2e/product-journeys/cloud-onboarding.ts @@ -28,9 +28,16 @@ export async function cloudOnboarding(input: CloudOnboardingInput): Promise + {slackFeedback && } {!isCloud ? ( diff --git a/ui/src/components/SidebarAccountMenu.test.tsx b/ui/src/components/SidebarAccountMenu.test.tsx index fada5185d75..42b95c88cb2 100644 --- a/ui/src/components/SidebarAccountMenu.test.tsx +++ b/ui/src/components/SidebarAccountMenu.test.tsx @@ -128,6 +128,7 @@ describe("SidebarAccountMenu", () => { let container: HTMLDivElement; beforeEach(() => { + vi.stubGlobal("ResizeObserver", class { observe() {} unobserve() {} disconnect() {} }); container = document.createElement("div"); document.body.appendChild(container); mockAuthApi.getSession.mockResolvedValue({ @@ -472,7 +473,7 @@ describe("SidebarAccountMenu", () => { }); }); - it.each([SidebarAccountMenu, ProductionSidebarAccountMenu])("hides cloud feedback and signs out through the harness (%#)", async (AccountMenu) => { + it.each([SidebarAccountMenu, ProductionSidebarAccountMenu])("opens the current Cloud Slack channel and signs out through the harness (%#)", async (AccountMenu) => { const root = createRoot(container); const onOpenChange = vi.fn(); const queryClient = new QueryClient({ @@ -488,7 +489,8 @@ describe("SidebarAccountMenu", () => { cloudBaseUrl: "https://cloud.example.test", }, }); - queryClient.setQueryData(queryKeys.cloud.stacks, cloudStacksPortfolio("owner")); + const channelUrl = "https://slack.com/app_redirect?channel=CTEST"; + queryClient.setQueryData(queryKeys.cloud.stacks, { ...cloudStacksPortfolio("owner"), slackFeedback: { href: channelUrl } }); await act(async () => { root.render( @@ -506,6 +508,9 @@ describe("SidebarAccountMenu", () => { await flushReact(); expect(container.querySelector('a[aria-label="Share feedback"]')).toBeNull(); + const slack = container.querySelector('button[aria-label="Slack the Paperclip team"]'); + expect(slack?.getAttribute("aria-haspopup")).toBe("dialog"); + expect(slack?.querySelector("img")?.getAttribute("src")).toBe("/brands/apps/slack.svg"); // Cloud manages invitations in the stack's People settings, reached with a // same-tab top-level navigation rather than the in-app router. @@ -534,6 +539,13 @@ describe("SidebarAccountMenu", () => { expect(mockNavigateTopLevel).toHaveBeenCalledWith("/cloud/logout"); expect(onOpenChange).toHaveBeenCalledWith(false); + await act(() => slack!.click()); + const dialog = document.body.querySelector('[data-slot="dialog-content"]'); + expect(dialog?.textContent).toContain("inbox for the Slack invitation"); + const channel = dialog?.querySelector("a"); + expect(channel?.getAttribute("href")).toBe(channelUrl); + expect(channel?.target).toBe("_blank"); + await act(async () => { root.unmount(); }); @@ -557,7 +569,8 @@ describe("SidebarAccountMenu", () => { // Company roles can differ from Cloud roles; the Members page only offers // the Cloud invite link to the current stack's owner/admin, so the menu // must match rather than send a plain member to People settings. - queryClient.setQueryData(queryKeys.cloud.stacks, cloudStacksPortfolio("member")); + const message = "Open the invitation emailed to your organization’s owner."; + queryClient.setQueryData(queryKeys.cloud.stacks, { ...cloudStacksPortfolio("member"), slackFeedback: { message } }); await act(async () => { root.render( @@ -576,6 +589,17 @@ describe("SidebarAccountMenu", () => { expect(popover?.querySelector('a[href="/company/settings/members?tab=invites"]')).toBeNull(); expect(popover?.querySelector('a[aria-label="View profile"]')).not.toBeNull(); + const slack = container.querySelector('button[aria-label="Slack the Paperclip team"]'); + expect(slack).not.toBeNull(); + await act(() => slack!.click()); + await flushReact(); + const dialog = document.body.querySelector('[data-slot="dialog-content"]'); + expect(dialog?.querySelector('[data-slot="dialog-description"]')?.textContent).toBe(message); + expect(dialog?.querySelector("a")).toBeNull(); + const done = Array.from(dialog!.querySelectorAll("button")).find((button) => button.textContent === "Got it"); + await act(() => done!.click()); + expect(document.body.querySelector('[data-slot="dialog-content"]')).toBeNull(); + await act(async () => { root.unmount(); }); diff --git a/ui/src/components/SidebarAccountMenu.tsx b/ui/src/components/SidebarAccountMenu.tsx index abc1b650933..fbde77d4eba 100644 --- a/ui/src/components/SidebarAccountMenu.tsx +++ b/ui/src/components/SidebarAccountMenu.tsx @@ -13,7 +13,8 @@ import { Link } from "@/lib/router"; import { authApi } from "@/api/auth"; import { queryKeys } from "@/lib/queryKeys"; import { useCloudInstance } from "@/hooks/useCloudInstance"; -import { useCloudInviteUrl } from "@/hooks/useCloudInviteUrl"; +import { useCloudSidebarLinks } from "@/hooks/useCloudSidebarLinks"; +import { SidebarSlackFeedback } from "./SidebarSlackFeedback"; import { useCanInviteCompanyMembers } from "@/hooks/useCompanyInviteAccess"; import { useHiddenSettings } from "@/hooks/useHiddenSettings"; import { useSignOut } from "@/hooks/useSignOut"; @@ -129,7 +130,7 @@ export function SidebarAccountMenu({ // On Cloud the shortcut exists only for the current stack's owner/admin and // only once the stack metadata is known; the in-app Invites tab is never a // fallback there because it drives a different invitation flow. - const cloudInviteUrl = useCloudInviteUrl(); + const { inviteUrl: cloudInviteUrl, slackFeedback } = useCloudSidebarLinks(cloud); // Self-hosted invites need the `users:invite` grant. Offer the shortcut only // to boards with role-default access (company owner/admin/operator, // instance admins, local boards). The server checks the actual grants. @@ -275,6 +276,7 @@ export function SidebarAccountMenu({ + {slackFeedback && } {!isCloud ? ( diff --git a/ui/src/components/SidebarSlackFeedback.tsx b/ui/src/components/SidebarSlackFeedback.tsx new file mode 100644 index 00000000000..c091464767d --- /dev/null +++ b/ui/src/components/SidebarSlackFeedback.tsx @@ -0,0 +1,42 @@ +import type { CloudStackPortfolio } from "@/api/cloud"; +import { cn } from "@/lib/utils"; +import { Button } from "./ui/button"; +import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog"; +import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip"; + +const label = "Slack the Paperclip team"; + +export function SidebarSlackFeedback({ feedback, className }: { + feedback: NonNullable; + className: string; +}) { + const triggerClass = cn("group flex size-8 shrink-0 items-center justify-center rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", className); + const logo = ; + return ( + + + + + + + + {label} + + + + Your private Slack channel + + {"message" in feedback ? feedback.message : "Open your shared channel to talk with the Paperclip team. If you still need to join, check your organization owner’s inbox for the Slack invitation."} + + + + {"href" in feedback ? ( + + ) : ( + + )} + + + + ); +} diff --git a/ui/src/hooks/useCloudInviteUrl.ts b/ui/src/hooks/useCloudInviteUrl.ts deleted file mode 100644 index 874490ccfe7..00000000000 --- a/ui/src/hooks/useCloudInviteUrl.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import { cloudApi } from "@/api/cloud"; -import { queryKeys } from "@/lib/queryKeys"; -import { cloudStackInviteUrl } from "@/lib/cloudLinks"; -import { useCloudInstance } from "./useCloudInstance"; - -/** - * Where the signed-in user invites people on a Paperclip Cloud instance, or - * null when no Cloud invite link should be offered. - * - * Mirrors the Members page: Cloud manages human invitations in the current - * stack's People settings, and only that stack's owner or admin may invite - * (company roles can differ from Cloud roles, so the company membership is - * not enough). Resolves to null on self-hosted instances, while the stack - * portfolio is still loading or has failed, for every other stack role, and - * when the stack slug or cloud base URL is unknown. - * - * Callers must not substitute the in-app Invites tab when this is null on a - * Cloud instance: that tab drives in-app invitations, a different flow from - * Cloud People settings. Offer no shortcut instead. - */ -export function useCloudInviteUrl(): string | null { - const cloud = useCloudInstance(); - const isCloud = Boolean(cloud); - const cloudStacksQuery = useQuery({ - queryKey: queryKeys.cloud.stacks, - queryFn: () => cloudApi.listStacks(), - enabled: isCloud, - staleTime: 30_000, - }); - if (!cloud) return null; - // Read from data, not `isError`: a cached stack list stays answerable while - // a transient refetch fails. A no-data failure leaves the current stack - // unknown,which falls through to `null` for every role below. - const currentStack = cloudStacksQuery.data?.stacks.find((stack) => stack.isCurrent); - if (currentStack?.role !== "owner" && currentStack?.role !== "admin") return null; - return cloudStackInviteUrl(cloud.cloudBaseUrl, currentStack.stackSlug); -} diff --git a/ui/src/hooks/useCloudSidebarLinks.ts b/ui/src/hooks/useCloudSidebarLinks.ts new file mode 100644 index 00000000000..91a08180f93 --- /dev/null +++ b/ui/src/hooks/useCloudSidebarLinks.ts @@ -0,0 +1,30 @@ +import { useQuery } from "@tanstack/react-query"; +import { cloudApi } from "@/api/cloud"; +import type { CloudInstanceHealthStatus } from "@/api/health"; +import { queryKeys } from "@/lib/queryKeys"; +import { cloudStackInviteUrl } from "@/lib/cloudLinks"; + +/** + * Resolve the current tenant's feedback and invitation shortcuts from one portfolio read. + * + * Cloud owns feedback availability. Its People settings link is limited to + * stack owners and admins, matching the Members page's invitation shortcut. + */ +export function useCloudSidebarLinks(cloud: CloudInstanceHealthStatus | null) { + const isCloud = Boolean(cloud); + const cloudStacksQuery = useQuery({ + queryKey: queryKeys.cloud.stacks, + queryFn: () => cloudApi.listStacks(), + enabled: isCloud, + staleTime: 30_000, + }); + if (!cloud) return { inviteUrl: null, slackFeedback: undefined }; + // Read from data, not `isError`: a cached stack list stays answerable while + // a transient refetch fails. A no-data failure leaves the current stack + // unknown, so the invitation shortcut stays hidden. + const currentStack = cloudStacksQuery.data?.stacks.find((stack) => stack.isCurrent); + const inviteUrl = currentStack?.role === "owner" || currentStack?.role === "admin" + ? cloudStackInviteUrl(cloud.cloudBaseUrl, currentStack.stackSlug) + : null; + return { inviteUrl, slackFeedback: cloudStacksQuery.data?.slackFeedback }; +} diff --git a/ui/src/hooks/useCompanyInviteAccess.ts b/ui/src/hooks/useCompanyInviteAccess.ts index b24ab7f652d..0c5f75f1ee7 100644 --- a/ui/src/hooks/useCompanyInviteAccess.ts +++ b/ui/src/hooks/useCompanyInviteAccess.ts @@ -35,7 +35,7 @@ export function canInviteCompanyMembers( * Whether the signed-in board may invite people to the selected company on a * self-hosted instance. Pass `enabled: false` on Cloud, where invitations live * in the stack's People settings and use a different rule - * (see `useCloudInviteUrl`). + * (see `useCloudSidebarLinks`). */ export function useCanInviteCompanyMembers(enabled = true): boolean { const company = useOptionalCompany(); diff --git a/ui/storybook/stories/navigation-preferences/navigation-layout.stories.tsx b/ui/storybook/stories/navigation-preferences/navigation-layout.stories.tsx index b602a08b8c4..684b81e9ec6 100644 --- a/ui/storybook/stories/navigation-preferences/navigation-layout.stories.tsx +++ b/ui/storybook/stories/navigation-preferences/navigation-layout.stories.tsx @@ -1,4 +1,5 @@ import { useEffect, type ReactNode } from "react"; +import { useQuery } from "@tanstack/react-query"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { Bot, @@ -34,6 +35,9 @@ import { Tabs } from "@/components/ui/tabs"; import { BreadcrumbProvider, useBreadcrumbs, type Breadcrumb } from "@/context/BreadcrumbContext"; import { useNavigate } from "@/lib/router"; import { cn } from "@/lib/utils"; +import { healthApi } from "@/api/health"; +import { queryKeys } from "@/lib/queryKeys"; +import { prepareFixtureApi } from "../../support/capability-gaps/api"; import { storybookAgents, storybookIssues, @@ -369,6 +373,43 @@ type Story = StoryObj; export const BoardChromeMatrix: Story = {}; +function CloudSidebar() { + useQuery({ queryKey: queryKeys.health, queryFn: healthApi.get }); + return ( +
+
+ +
+ ); +} + +export const CloudSlackFeedback: Story = { + render: () => , + beforeEach: ({ parameters }) => prepareFixtureApi([ + { path: "/api/health", read: () => ({ status: "ok", deploymentMode: "authenticated", cloud: { + managed: true, managedBy: "paperclip-cloud", stackSlug: "example", cloudBaseUrl: "https://cloud.example.test", + } }) }, + { path: "/api/cloud/stacks", read: () => ({ + stacks: [{ displayName: "Example", stackSlug: "example", primaryHost: "example.test", lifecycleState: "active", sleepState: "awake", role: "owner", isCurrent: true }], + slackFeedback: parameters.invitePending + ? { message: "We emailed a Slack invitation to your organization’s owner. Check that inbox and accept the invitation to join your private channel with the Paperclip team." } + : { href: "https://slack.com/app_redirect?channel=CEXAMPLE" }, + }) }, + ]).cleanup, + parameters: { + layout: "fullscreen", + paperclip: { + capabilities: ["navigation-preferences/navigation"], implementation: "production", boundary: "fixtures", + notes: "Mounts the workspace sidebar and account footer with a simulated Cloud portfolio. The Slack channel ID is a fixture.", + }, + }, +}; + +export const CloudSlackInvitationPending: Story = { + ...CloudSlackFeedback, + parameters: { ...CloudSlackFeedback.parameters, invitePending: true }, +}; + // PAP-10676 verification harness: renders the real Sidebar at a fixed width so a // screenshot of the expanded state and a screenshot of the pinned-collapsed rail // can be overlaid. The icon column must be pixel-identical between the two — the