mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The backend now turns agent requests into durable connection intents. > - Operators need a clear path to inspect, configure, and finish those requests. > - The experience must preserve identity, agent access, and interrupted setup state. > - This pull request adds the connection intent setup experience across the app UI. > - The benefit is one guided flow from agent request to governed connection. ## Linked Issues or Issue Description Refs #11965 This is stack 9 of 11. It depends on stack 8 and replaces another reviewable part of #11965. ## What Changed - Add connection intent cards and setup flow integration. - Add browse, connection, app detail, and sidebar experience updates. - Preserve exact draft identity and access choices across resume and OAuth recovery. - Add focused UI, architecture, policy, and end-to-end coverage. - Keep transient retained-connection lookup failures retryable instead of misclassifying them as missing targets. - Align the dark-mode E2E contract with the intentionally hidden Gateways and Profiles sidebar tabs. ## Verification - `pnpm -r typecheck` - Focused UI result: 372 tests passed across 20 files. - AppsConnect regression suite: 80/80 passed, including failed connection and application lookups during retained reconnect. - `pnpm --filter @paperclipai/ui exec vitest run src/components/AppsSidebar.test.tsx` (1 passed) - `pnpm check:token-gates` - `pnpm --filter @paperclipai/db check:migrations` - `pnpm build` ## Risks - An interrupted OAuth flow can leave a durable draft that needs resume. - The UI resumes the exact draft and keeps its identity and agent access settings. - Retained reconnect retries refetch connections and applications together to avoid mixing partial snapshots. - Gateways and Profiles remain route-accessible but intentionally absent from the sidebar until their existing ship gate is lifted. - The change does not add a database migration. > I checked `ROADMAP.md`. This stack continues the existing app connection work from #11965 and does not duplicate another planned item. ## Model Used OpenAI Codex, GPT-5. The runtime model ID and context window were not exposed. The model used reasoning, tool use, and code execution. ## 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 linked the public source pull request with `Refs #` - [x] I have not referenced internal or instance-local Paperclip issues or links - [x] My branch name describes the change 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: Paperclip <noreply@paperclip.ing>
227 lines
6.7 KiB
TypeScript
227 lines
6.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
import type { ToolApplication, ToolConnection } from "@paperclipai/shared";
|
|
import { getConnectableAppDefinition } from "@paperclipai/shared";
|
|
import {
|
|
isConnectionDefinitionUnavailable,
|
|
isVercelConnectUnavailable,
|
|
readConnectionIntentOAuthOutcome,
|
|
retainedReconnectMatches,
|
|
requestedConnectionSetupResolution,
|
|
requestedConnectionEntry,
|
|
} from "./ConnectionSetupFlow";
|
|
|
|
const origin = "https://paperclip.test";
|
|
const interactionId = "interaction-123";
|
|
|
|
function event(data: unknown, eventOrigin = origin) {
|
|
return { origin: eventOrigin, data };
|
|
}
|
|
|
|
describe("connection intent OAuth window messages", () => {
|
|
it.each(["connected", "declined", "failed"] as const)(
|
|
"accepts a matching %s outcome",
|
|
(outcome) => {
|
|
expect(
|
|
readConnectionIntentOAuthOutcome(
|
|
event({
|
|
type: "paperclip.connection-intent.oauth",
|
|
interactionId,
|
|
outcome,
|
|
}),
|
|
origin,
|
|
interactionId,
|
|
),
|
|
).toBe(outcome);
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
[
|
|
"foreign origin",
|
|
event(
|
|
{
|
|
type: "paperclip.connection-intent.oauth",
|
|
interactionId,
|
|
outcome: "connected",
|
|
},
|
|
"https://attacker.test",
|
|
),
|
|
],
|
|
[
|
|
"wrong interaction",
|
|
event({
|
|
type: "paperclip.connection-intent.oauth",
|
|
interactionId: "other",
|
|
outcome: "connected",
|
|
}),
|
|
],
|
|
[
|
|
"wrong message type",
|
|
event({ type: "other", interactionId, outcome: "connected" }),
|
|
],
|
|
[
|
|
"unknown outcome",
|
|
event({
|
|
type: "paperclip.connection-intent.oauth",
|
|
interactionId,
|
|
outcome: "authorized",
|
|
}),
|
|
],
|
|
["non-object payload", event("connected")],
|
|
])("ignores a %s message", (_label, candidate) => {
|
|
expect(
|
|
readConnectionIntentOAuthOutcome(candidate, origin, interactionId),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("retained reconnect definition lookup", () => {
|
|
const connection = { applicationId: "app-1" } as ToolConnection;
|
|
|
|
it("restores a hidden provider only for its exact retained application", () => {
|
|
const githubApplication = {
|
|
id: "app-1",
|
|
applicationKey: "github",
|
|
metadata: { sourceTemplateKey: "github" },
|
|
} as unknown as ToolApplication;
|
|
|
|
expect(requestedConnectionEntry({
|
|
requestedAppKey: "github",
|
|
galleryApps: [],
|
|
reconnectConnection: connection,
|
|
applications: [githubApplication],
|
|
})?.slug).toBe("github");
|
|
expect(requestedConnectionEntry({
|
|
requestedAppKey: "notion",
|
|
galleryApps: [],
|
|
reconnectConnection: connection,
|
|
applications: [githubApplication],
|
|
})).toBeNull();
|
|
});
|
|
|
|
it("ends unavailable retained reconnects instead of leaving them loading", () => {
|
|
expect(requestedConnectionSetupResolution({
|
|
reconnectConnectionId: "connection-1",
|
|
hasRequestedEntry: false,
|
|
supportedMethodCount: 0,
|
|
unsupportedOAuth: false,
|
|
vercelUnavailable: false,
|
|
definitionUnavailable: false,
|
|
})).toBe("reconnect_unavailable");
|
|
expect(requestedConnectionSetupResolution({
|
|
reconnectConnectionId: "connection-1",
|
|
hasRequestedEntry: true,
|
|
supportedMethodCount: 0,
|
|
unsupportedOAuth: false,
|
|
vercelUnavailable: false,
|
|
definitionUnavailable: false,
|
|
})).toBe("reconnect_unavailable");
|
|
expect(requestedConnectionSetupResolution({
|
|
reconnectConnectionId: null,
|
|
hasRequestedEntry: false,
|
|
supportedMethodCount: 0,
|
|
unsupportedOAuth: false,
|
|
vercelUnavailable: false,
|
|
definitionUnavailable: false,
|
|
})).toBe("fallback");
|
|
expect(requestedConnectionSetupResolution({
|
|
reconnectConnectionId: "connection-1",
|
|
hasRequestedEntry: true,
|
|
supportedMethodCount: 1,
|
|
unsupportedOAuth: false,
|
|
vercelUnavailable: false,
|
|
definitionUnavailable: false,
|
|
})).toBe("ready");
|
|
});
|
|
|
|
it("does not expose a hidden provider without an exact reconnect target", () => {
|
|
expect(requestedConnectionEntry({
|
|
requestedAppKey: "github",
|
|
galleryApps: [],
|
|
reconnectConnection: null,
|
|
applications: [],
|
|
})).toBeNull();
|
|
const visibleNotion = getConnectableAppDefinition("notion")!;
|
|
expect(requestedConnectionEntry({
|
|
requestedAppKey: "notion",
|
|
galleryApps: [visibleNotion],
|
|
reconnectConnection: null,
|
|
applications: [],
|
|
})).toBe(visibleNotion);
|
|
});
|
|
|
|
it("does not apply fresh-setup availability to an exact retained reconnect", () => {
|
|
expect(isVercelConnectUnavailable({
|
|
credentialSource: "vercel_connect",
|
|
available: false,
|
|
retainedReconnectMatches: true,
|
|
})).toBe(false);
|
|
expect(isVercelConnectUnavailable({
|
|
credentialSource: "vercel_connect",
|
|
available: false,
|
|
retainedReconnectMatches: false,
|
|
})).toBe(true);
|
|
expect(isConnectionDefinitionUnavailable({
|
|
available: false,
|
|
reconnectConnectionId: "connection-1",
|
|
reconnectSourceMatches: true,
|
|
})).toBe(false);
|
|
expect(isConnectionDefinitionUnavailable({
|
|
available: false,
|
|
reconnectConnectionId: "connection-1",
|
|
reconnectSourceMatches: false,
|
|
})).toBe(true);
|
|
expect(isConnectionDefinitionUnavailable({
|
|
available: false,
|
|
reconnectConnectionId: undefined,
|
|
reconnectSourceMatches: true,
|
|
})).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("retained reconnect target matching", () => {
|
|
const connection = { applicationId: "app-1" } as ToolConnection;
|
|
const application = { id: "app-1", applicationKey: "custom-mcp" } as ToolApplication;
|
|
|
|
it("accepts a generic reconnect only for its exact retained application", () => {
|
|
expect(retainedReconnectMatches({
|
|
requestedAppKey: undefined,
|
|
byo: true,
|
|
applicationId: "app-1",
|
|
reconnectConnection: connection,
|
|
reconnectApplication: application,
|
|
})).toBe(true);
|
|
expect(retainedReconnectMatches({
|
|
requestedAppKey: undefined,
|
|
byo: true,
|
|
applicationId: "app-other",
|
|
reconnectConnection: connection,
|
|
reconnectApplication: application,
|
|
})).toBe(false);
|
|
});
|
|
|
|
it("keeps curated reconnects bound to their provider", () => {
|
|
const curated = {
|
|
id: "app-1",
|
|
applicationKey: "github",
|
|
metadata: { sourceTemplateKey: "github" },
|
|
} as unknown as ToolApplication;
|
|
expect(retainedReconnectMatches({
|
|
requestedAppKey: "github",
|
|
byo: false,
|
|
applicationId: "app-1",
|
|
reconnectConnection: connection,
|
|
reconnectApplication: curated,
|
|
})).toBe(true);
|
|
expect(retainedReconnectMatches({
|
|
requestedAppKey: "notion",
|
|
byo: false,
|
|
applicationId: "app-1",
|
|
reconnectConnection: connection,
|
|
reconnectApplication: curated,
|
|
})).toBe(false);
|
|
});
|
|
});
|