mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 00:05:49 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Chat connections let people start and continue that work from Slack. > - Setup mixed app creation, credentials, URL verification, account linking, and testing on the same screens. > - People also needed a safe way to link their own Slack identity after the first operator finished setup. > - This pull request gives each step a clear place and keeps membership approval separate from identity linking. > - It also makes connection details easier to use and fixes misleading callback health behind HTTPS proxies. ## Linked Issues or Issue Description **Subsystem affected** Cross-cutting: chat routes and services, shared contracts, and the Apps board UI. **Problem or motivation** Slack onboarding made users find settings without enough guidance. A second user needed operator help to link their account. Activity stopped at 100 records, and TLS termination could mark working callbacks as stale. **Proposed solution** Use six setup steps with editable app names, a generated manifest, credential guidance, URL verification, account linking, and an optional message test. Send each Slack user a private, expiring confirmation link. Require company membership or an approved access request before linking. Add cursor pagination and tolerate the internal HTTP hop in callback diagnostics. **Roadmap alignment** This improves the existing connected-app surface and supports CEO Chat without changing the task-and-comments model. The maintainer requested and reviewed the flow during a live Slack test drive. **Additional context** Related work: #7, #3349, #13000, and #13620. Those cover broader chat capabilities, older webhook paths, or plugins. This PR improves the existing native connector's setup and account-linking flow. HTTPS documentation was published separately in paperclipai/paperclip-docs#128. ## What Changed - Split Slack onboarding into six clickable sidebar steps. Keep secondary and primary actions on one row. - Generate the Slack creation link and read-only manifest from editable app, bot, and command names. Add credential prefix validation and direct instructions. - Add live account-link status and an optional mention-based message test. - Add private, single-use Slack account invitations and membership access requests. Retain cloud authentication/bootstrap checks and enforce the chat rollout flag in all identity APIs. Default new Slack connections to linked users only. - Put Settings, Access, Conversations, and Activity in the sidebar. Simplify conversation rows and remove active header badges. - Add 25-item activity pages, stable timestamp/ID cursors, and replay safety across pages. Preserve the legacy array API for clients without pagination parameters. - Fix false callback warnings when HTTPS terminates at a proxy. Keep host, port, and path drift detection. - Document the setup flow, pagination, callback diagnostics, and shared wizard footer rule. ## Verification - Passed: `pnpm -r typecheck`, `pnpm build`, and `pnpm check:token-gates`. - Passed: focused Slack callback and pagination integration tests; UI clipboard, wizard, pagination, and activity tests; OpenAPI route tests. The final access-gate fix also passes 27 focused tests covering cloud authentication/bootstrap, nonmember invitations, token validity, and the server-enforced rollout flag. - Passed: all 1,002 chat integration tests, 6,356 UI tests, and all 11 provider browser scenarios (including mobile light/dark navigation). After rebase, the identity route, sidebar, and 25 clipboard tests pass. - The full local `pnpm test:run` was attempted. The first run found 14 Slack fixtures that needed explicit guest access; those are fixed and the complete chat suite passes. Unrelated embedded PostgreSQL startup/resource failures and timeouts prevented a clean full local run. All CI checks pass on `2d858b036`, including the full chat, server, workspace, build, typecheck, and browser suites. - Live test drive: Slack app creation, credential setup, URL verification, private account confirmation, mention messages, and thread replies. Verified the callback warning clears for the existing proxied connection. - Review: create a Slack connection, follow the six steps, link a second user's account, and browse older activity with Next and Previous. ## Risks - Identity invitations carry a temporary capability. Tokens are hashed, expire after 15 minutes, work once, and require explicit confirmation by a company member. Access requests do not grant membership. - New Slack connections reject unlinked people by default. Existing connection settings remain intact. - Activity is a live ledger. Updated action rows can move forward in time. Older pages do not poll. - Proxy tolerance affects health display only. Slack signature checks and proxy authentication settings remain unchanged. - No database migration or package-lock changes. ## Model Used OpenAI Codex, based on GPT-6, with reasoning, repository tools, code execution, and browser verification. The runtime does not expose an exact model build ID or context-window size. ## 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 (targeted suites; full local-run limitations documented above) - [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: Paperclip <noreply@paperclip.ing>
228 lines
7.3 KiB
TypeScript
228 lines
7.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { flushSync } from "react-dom";
|
|
import { createRoot } from "react-dom/client";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { AppsSidebar } from "./AppsSidebar";
|
|
import { AppsSidebar as ProductionAppsSidebar } from "./AppsSidebar.production";
|
|
import { contextualSidebarStyles } from "./contextual-sidebar-styles";
|
|
|
|
const sidebarNavItemMock = vi.hoisted(() => vi.fn());
|
|
const route = vi.hoisted(() => ({ pathname: "/SLA/apps" }));
|
|
const mockToolsApi = vi.hoisted(() => ({
|
|
listActionRequests: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/lib/router", () => ({
|
|
useLocation: () => route,
|
|
Link: ({
|
|
children,
|
|
to,
|
|
onClick,
|
|
className,
|
|
}: {
|
|
children: React.ReactNode;
|
|
to: string;
|
|
onClick?: () => void;
|
|
className?: string;
|
|
}) => (
|
|
<a href={to} onClick={onClick} className={className}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("@/context/CompanyContext", () => ({
|
|
useCompany: () => ({
|
|
selectedCompanyId: "company-1",
|
|
selectedCompany: { id: "company-1", name: "Paperclip" },
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/context/SidebarContext", () => ({
|
|
useSidebar: () => ({
|
|
isMobile: false,
|
|
setSidebarOpen: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/api/tools", () => ({
|
|
toolsApi: mockToolsApi,
|
|
}));
|
|
|
|
vi.mock("./SidebarNavItem", () => ({
|
|
SidebarNavItem: (props: {
|
|
to: string;
|
|
label: string;
|
|
end?: boolean;
|
|
liveCount?: number;
|
|
badge?: number;
|
|
}) => {
|
|
sidebarNavItemMock(props);
|
|
return <div data-to={props.to}>{props.label}</div>;
|
|
},
|
|
}));
|
|
|
|
vi.mock("./SidebarNavItem.production", () => ({
|
|
SidebarNavItem: (props: {
|
|
to: string;
|
|
label: string;
|
|
end?: boolean;
|
|
liveCount?: number;
|
|
badge?: number;
|
|
}) => {
|
|
sidebarNavItemMock(props);
|
|
return <div data-to={props.to}>{props.label}</div>;
|
|
},
|
|
}));
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
// React 19 does not export a usable `act` in this vitest/jsdom setup; use a
|
|
// flushSync-based helper (PAP-12371 gotcha).
|
|
async function act(callback: () => void | Promise<void>) {
|
|
let result: void | Promise<void> = undefined;
|
|
flushSync(() => {
|
|
result = callback();
|
|
});
|
|
await result;
|
|
}
|
|
|
|
async function flushReact() {
|
|
for (let i = 0; i < 5; i += 1) {
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
await new Promise((resolve) => window.setTimeout(resolve, 0));
|
|
});
|
|
}
|
|
}
|
|
|
|
describe("AppsSidebar", () => {
|
|
let container: HTMLDivElement;
|
|
|
|
beforeEach(() => {
|
|
route.pathname = "/SLA/apps";
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
mockToolsApi.listActionRequests.mockResolvedValue({ actionRequests: [] });
|
|
});
|
|
|
|
afterEach(() => {
|
|
container.remove();
|
|
document.body.innerHTML = "";
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it.each([AppsSidebar, ProductionAppsSidebar])("shows chat navigation in place of browse and review", async (Sidebar) => {
|
|
route.pathname = "/SLA/apps/chat/endpoint-a/conversations";
|
|
const root = createRoot(container);
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
await act(async () => root.render(<QueryClientProvider client={queryClient}><Sidebar /></QueryClientProvider>));
|
|
await flushReact();
|
|
expect(container.textContent).not.toMatch(/Browse|Review/);
|
|
for (const tab of ["settings", "access", "conversations", "activity"]) {
|
|
expect(container.querySelector(`[data-to="/apps/chat/endpoint-a/${tab}"]`)).not.toBeNull();
|
|
}
|
|
await act(async () => root.unmount());
|
|
queryClient.clear();
|
|
});
|
|
|
|
it("renders the consolidated connector and review doors without a redundant contextual heading", async () => {
|
|
const root = createRoot(container);
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: { queries: { retry: false } },
|
|
});
|
|
|
|
await act(async () => {
|
|
root.render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<AppsSidebar />
|
|
</QueryClientProvider>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
expect(container.textContent).not.toContain("Apps");
|
|
expect(container.querySelector('nav[aria-label="Connectors"]')).not.toBeNull();
|
|
expect(container.textContent).not.toContain("Developer");
|
|
expect(container.textContent).not.toContain("Advanced setup for developers");
|
|
expect(container.textContent).not.toContain("Most teams");
|
|
expect(container.textContent).not.toMatch(/you (?:won'?t|will not) need this/i);
|
|
// Paste-config discovery now lives inside the custom connector row;
|
|
// assert both advanced setup items remain absent at the item level below.
|
|
|
|
expect(sidebarNavItemMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps", label: "Browse", end: true }),
|
|
);
|
|
expect(sidebarNavItemMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps/review", label: "Review" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ label: "Connections" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ label: "Needs attention" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ label: "Run your own" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ label: "Paste a config" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ label: "Applications" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps/advanced/gateways", label: "Gateways" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps/advanced/profiles", label: "Profiles" }),
|
|
);
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(expect.objectContaining({ label: "Rules" }));
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(expect.objectContaining({ label: "Health" }));
|
|
expect(sidebarNavItemMock).not.toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps/advanced/audit" }),
|
|
);
|
|
expect(container.querySelector('[data-slot="contextual-sidebar-nav"]')?.className).toBe(
|
|
contextualSidebarStyles.nav,
|
|
);
|
|
expect(
|
|
Array.from(container.querySelectorAll('[data-slot="contextual-sidebar-group"]')).every(
|
|
(group) => group.className === contextualSidebarStyles.group,
|
|
),
|
|
).toBe(true);
|
|
|
|
await act(async () => {
|
|
root.unmount();
|
|
});
|
|
});
|
|
|
|
it("uses Connectors terminology throughout the classic contextual sidebar", async () => {
|
|
const root = createRoot(container);
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: { queries: { retry: false } },
|
|
});
|
|
|
|
await act(async () => {
|
|
root.render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<ProductionAppsSidebar />
|
|
</QueryClientProvider>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
expect(container.textContent).toContain("Connectors");
|
|
expect(container.textContent).not.toContain("Apps");
|
|
expect(sidebarNavItemMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({ to: "/apps", label: "Browse", end: true }),
|
|
);
|
|
|
|
await act(async () => {
|
|
root.unmount();
|
|
});
|
|
});
|
|
});
|