Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
598 changes: 598 additions & 0 deletions dashboard/e2e/integrations-connect.spec.ts

Large diffs are not rendered by default.

44 changes: 28 additions & 16 deletions dashboard/e2e/integrations-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
const at = (min: Role) => LEVEL[db.role] >= LEVEL[min];
const forbidden = (r: Route) => json(r, { error: "Forbidden" }, 403);
await page.route((url) => url.hostname !== "localhost", (route) => route.abort());
await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (r) => {
// On the context, so a sign-in opened in its own tab is answered here too.
const context = page.context();
await context.route((url) => url.hostname !== "localhost", (route) => route.abort());
await context.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (r) => {
const req = r.request();
const p = new URL(req.url()).pathname;
const method = req.method();
Expand Down Expand Up @@ -630,8 +632,9 @@ test("a saved webhook shows only as a hint, is tested without the page knowing i
});
});

test("Figma signs in with the team's own app, its redirect URL and scopes shown, a key still possible", async ({ page }) => {
test("Figma signs in with the team's own app, its redirect URL and scopes shown, a key still possible", async ({ page, context }) => {
const db = await mockApi(page);
db.items = db.items.map((i) => (i.id === "figma" ? pluginCard("figma", "Figma", "docs", false, false) : i));
const figma = db.items.find((i) => i.id === "figma")!;
(figma.detail as Record<string, unknown>).own_app_redirect_uri = "https://coderhelm.example.com/settings/integrations/mcp-callback/";
(figma.detail as { plugin: Record<string, unknown> }).plugin.own_app = {
Expand All @@ -643,28 +646,33 @@ test("Figma signs in with the team's own app, its redirect URL and scopes shown,
guide: "https://developers.figma.com/docs/rest-api/oauth-apps/",
};
await page.goto("/settings/integrations#integration-figma");
// Where Coderhelm has no app of its own, the team's own app is the default way.
const panel = row(page, "figma").getByTestId("own-app");
await expect(panel).toContainText("Use my own Figma app");
await expect(panel).toBeVisible();
await expect(panel.getByTestId("own-app-redirect")).toHaveText("https://coderhelm.example.com/settings/integrations/mcp-callback/");
await expect(panel).toContainText("current_user:read, file_content:read");
await expect(panel.getByRole("link", { name: "www.figma.com/developers/apps" })).toHaveAttribute("href", "https://www.figma.com/developers/apps");
// The key form waits behind its disclosure.
await expect(row(page, "figma").getByText("Use a key instead")).toBeVisible();
const go = panel.getByRole("button", { name: "Save and connect with Figma" });
// A key waits with the other ways to connect, behind one disclosure.
await expect(row(page, "figma").getByTestId("other-ways").locator("summary")).toHaveText("Other ways to connect");
await expect(row(page, "figma").getByTestId("way-key")).toBeHidden();
const go = panel.getByRole("button", { name: "Save and sign in with Figma" });
await expect(go).toBeDisabled();
await panel.getByLabel("Client ID").fill("client-1");
await panel.getByLabel("Client secret").fill("secret-1");
const tab = context.waitForEvent("page");
await go.click();
// Saved, then sent to Figma's sign-in, whose answer the callback page finishes.
// Saved, then Figma's sign-in opens in its own tab, whose answer the callback page finishes.
await (await tab).waitForEvent("close");
await expect.poll(() => db.calls.some((c) => c.path === "/api/mcp-servers/oauth/callback")).toBe(true);
const saved = db.calls.find((c) => c.method === "PUT" && c.path === "/api/mcp-servers/apps/figma");
expect(saved?.body).toEqual({ client_id: "client-1", client_secret: "secret-1" });
expect(db.calls.some((c) => c.method === "POST" && c.path === "/api/mcp-servers/app-figma/connect")).toBe(true);
await expect(page).toHaveURL(/\/settings\/integrations\/#integration-figma$/);
await expect(page).toHaveURL(/\/settings\/integrations\/?#integration-figma$/);
});

test("Figma signs in with Coderhelm's app in one click; my own app and a key are the other choices", async ({ page }) => {
test("Figma signs in with Coderhelm's app in one click; my own app and a key are the other choices", async ({ page, context }) => {
const db = await mockApi(page);
db.items = db.items.map((i) => (i.id === "figma" ? pluginCard("figma", "Figma", "docs", false, false) : i));
const figma = db.items.find((i) => i.id === "figma")!;
const detail = figma.detail as Record<string, unknown> & { plugin: Record<string, unknown> };
detail.own_app_redirect_uri = "https://app.coderhelm.com/settings/integrations/mcp-callback/";
Expand All @@ -679,13 +687,17 @@ test("Figma signs in with Coderhelm's app in one click; my own app and a key are
};
await page.goto("/settings/integrations#integration-figma");
const card = row(page, "figma");
const ours = card.getByTestId("coderhelm-app");
await expect(ours).toContainText("current_user:read, file_content:read");
// The own app's steps and the key wait behind their disclosures.
await expect(card.getByText("Use my own Figma app", { exact: true }).first()).toBeVisible();
await expect(card.getByText("Use a key instead", { exact: true })).toBeVisible();
// What it will do in plain words; the scope names wait behind Details.
await expect(card.getByTestId("access")).toHaveText("Coderhelm reads Figma with this sign-in. It can't change anything in Figma.");
await expect(card.getByTestId("scopes")).toBeHidden();
// The own app's steps and the key wait together, behind one disclosure.
await expect(card.getByTestId("other-ways").locator("summary")).toHaveText("Other ways to connect");
await expect(card.getByTestId("own-app")).toBeHidden();
await ours.getByRole("button", { name: "Sign in with Figma" }).click();
await expect(card.getByTestId("way-key")).toBeHidden();
await expect(card.getByRole("button", { name: "Sign in with Figma" })).toHaveCount(1);
const tab = context.waitForEvent("page");
await card.getByRole("button", { name: "Sign in with Figma" }).click();
await (await tab).waitForEvent("close");
await expect.poll(() => db.calls.some((c) => c.path === "/api/mcp-servers/oauth/callback")).toBe(true);
expect(db.calls.some((c) => c.method === "POST" && c.path === "/api/mcp-servers/apps/figma/coderhelm")).toBe(true);
expect(db.calls.some((c) => c.method === "PUT" && c.path === "/api/mcp-servers/apps/figma")).toBe(false);
Expand Down
62 changes: 42 additions & 20 deletions dashboard/e2e/mcp-servers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ function refresh(s: McpServer) {
async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend> {
const db: Backend = { role: "admin", me: "dana@example.com", admins: 1, servers: [], calls: [], ...init };
const json = (r: Route, body: unknown, status = 200) => r.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
await page.route((url) => url.hostname !== "localhost", (route) => route.abort());
await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (r) => {
// On the context, so a sign-in opened in its own tab is answered here too.
const context = page.context();
await context.route((url) => url.hostname !== "localhost", (route) => route.abort());
await context.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (r) => {
const req = r.request();
const url = new URL(req.url());
const p = url.pathname;
Expand Down Expand Up @@ -234,7 +236,7 @@ async function shot(page: Page, name: string) {

const row = (page: Page, id: string) => page.getByTestId(`integration-${id}`);

test("adds a server that signs in with OAuth, comes back from the sign-in, and picks its tools", async ({ page }) => {
test("adds a server that signs in with OAuth, connects it in its own tab, and picks its tools", async ({ page, context }) => {
const db = await mockApi(page);
await page.goto("/settings/integrations");
const section = page.locator("#mcp-servers");
Expand All @@ -252,16 +254,24 @@ test("adds a server that signs in with OAuth, comes back from the sign-in, and p
await expect(dialog.getByRole("group", { name: "Who signs in" })).toBeVisible();
await shot(page, "mcp-add-oauth");

await dialog.getByRole("button", { name: "Add and connect" }).click();
// Back from the sign-in page, on the server's own row with its tools.
await expect(page).toHaveURL(/\/settings\/integrations\/#integration-mcp:docs$/);
await dialog.getByRole("button", { name: "Add server" }).click();
// Added, and opened on its own row: Connect is the one thing to do next,
// with nothing about tools or history yet.
await expect(page).toHaveURL(/\/settings\/integrations\/?#integration-mcp:docs$/);
const added = row(page, "mcp:docs").getByTestId("integration-panel");
await expect(added.getByTestId("mcp-manage")).toHaveCount(0);
const tab = context.waitForEvent("page");
await added.getByRole("button", { name: "Connect", exact: true }).click();
// The sign-in finishes in its own tab, which closes; this page never left.
await (await tab).waitForEvent("close");
await expect(row(page, "mcp:docs")).toHaveAttribute("data-status", "connected");
await expect(page).toHaveURL(/\/settings\/integrations\/?#integration-mcp:docs$/);
const callback = db.calls.find((c) => c.path === "/api/mcp-servers/oauth/callback");
expect(callback?.body).toEqual({ state: "state-docs", code: "code-1", iss: ISSUER });
const created = db.calls.find((c) => c.path === "/api/mcp-servers" && c.method === "POST");
expect(created?.body).toMatchObject({ url: "https://mcp.docs.example.com/mcp", name: "Docs", sharing: "shared" });

const panel = row(page, "mcp:docs").getByTestId("integration-panel");
await expect(panel.getByTestId("mcp-status")).toContainText("Connected");
const picker = panel.getByTestId("mcp-tool-picker");
await expect(picker.getByTestId("mcp-tool")).toHaveCount(4);
await expect(picker.locator('[data-tool="search_docs"]').getByTestId("mcp-tool-access")).toHaveText("Reads");
Expand Down Expand Up @@ -299,7 +309,9 @@ test("a server that takes a key checks it, keeps it sealed and never shows it ag
expect(created?.body).toMatchObject({ header_name: "X-API-Key", header_value: KEY, name: "Search" });

const panel = row(page, "mcp:search").getByTestId("integration-panel");
await expect(panel.getByTestId("mcp-status")).toContainText("Key in X-API-Key");
// How it signs in is a detail, behind Details.
await panel.getByTestId("panel-details").locator("summary").click();
await expect(panel.getByTestId("panel-details")).toContainText("A key, sent in the X-API-Key header");
await expect(page.locator("body")).not.toContainText(KEY);
// A key server has no sign-in to start.
await expect(panel.getByRole("button", { name: /^Connect/ })).toHaveCount(0);
Expand Down Expand Up @@ -347,7 +359,7 @@ test("with two admins, newly allowed tools wait for the other admin", async ({ p
expect(db.servers[0].tools.find((t) => t.name === "search_docs")?.approved).toBe(true);
});

test("a connection that needs reconnecting says why and reconnects", async ({ page }) => {
test("a connection that needs reconnecting says why and reconnects", async ({ page, context }) => {
const why = "The sign-in server refused (invalid_grant: refresh token revoked). Reconnect to sign in again.";
await mockApi(page, {
servers: [server({ status: "needs_reconnect", status_reason: why, my_connection: { status: "needs_reconnect", status_reason: why, connected_at: "" } })],
Expand All @@ -360,41 +372,51 @@ test("a connection that needs reconnecting says why and reconnects", async ({ pa
await r.getByRole("button", { name: /^Docs, Needs reconnecting\. Reconnect/ }).click();
const panel = r.getByTestId("integration-panel");
await expect(panel.getByTestId("mcp-status-reason")).toHaveText(why);
// The reason and its one action sit together.
await expect(panel.getByTestId("mcp-attention")).toContainText("Needs reconnecting");
await shot(page, "mcp-needs-reconnect");
await panel.getByRole("button", { name: "Reconnect" }).click();
await expect(page).toHaveURL(/#integration-mcp:docs$/);
const tab = context.waitForEvent("page");
await panel.getByTestId("mcp-attention").getByRole("button", { name: "Reconnect" }).click();
await (await tab).waitForEvent("close");
await expect(row(page, "mcp:docs")).toHaveAttribute("data-status", "connected");
});

test("a catalog server offers its vendor's sign-in first and keeps the key as a fallback", async ({ page }) => {
test("a catalog server offers its vendor's sign-in first and keeps the key as a fallback", async ({ page, context }) => {
const db = await mockApi(page);
await page.goto("/settings/integrations");
await row(page, "linear").getByRole("button", { name: /^Linear, Not connected/ }).click();
const panel = row(page, "linear").getByTestId("integration-panel");
await expect(panel.getByTestId("oauth-offer")).toContainText("No key to paste");
await expect(panel.getByText("Use a key instead")).toBeVisible();
await expect(panel.getByTestId("access")).toHaveText(
"You sign in at Linear, then pick which of its tools agents may use. Agents get none until you do, and tools that only read are marked.",
);
// A key is another way to connect, behind one disclosure.
await expect(panel.getByTestId("other-ways").locator("summary")).toHaveText("Other ways to connect");
await expect(panel.getByLabel("API key")).toBeHidden();
await shot(page, "mcp-catalog-oauth");
const tab = context.waitForEvent("page");
await panel.getByRole("button", { name: "Sign in with Linear" }).click();
await expect(page).toHaveURL(/#integration-linear$/);
await (await tab).waitForEvent("close");
expect(db.calls.find((c) => c.path === "/api/mcp-servers" && c.method === "POST")?.body).toEqual({ catalog_id: "linear" });
await expect(row(page, "linear")).toHaveAttribute("data-status", "connected");
await expect(row(page, "linear").getByTestId("integration-panel").getByTestId("mcp-tool-picker")).toBeVisible();
});

test("a member connects their own account to a server each person signs in to", async ({ page }) => {
test("a member connects their own account to a server each person signs in to", async ({ page, context }) => {
const db = await mockApi(page, { role: "member", me: "sam@example.com", servers: [server({ sharing: "personal", my_connection: null })] });
await page.goto("/settings/integrations");
const r = row(page, "mcp:docs");
await expect(r).toHaveAttribute("data-status", "not_connected");
await r.getByRole("button", { name: /^Docs, Not connected/ }).click();
const panel = r.getByTestId("integration-panel");
await expect(panel.getByTestId("mcp-status-reason")).toHaveText("Each person connects their own account. You haven't yet.");
await expect(panel.getByTestId("mcp-status-reason")).toHaveText(
"Each person signs in to Docs with their own account. Agents use it for that person's work, with only the tools an admin allowed.",
);
// Members don't pick tools or remove servers.
await expect(panel.getByRole("button", { name: "Save tools" })).toHaveCount(0);
await expect(panel.getByRole("button", { name: /^Remove/ })).toHaveCount(0);
const tab = context.waitForEvent("page");
await panel.getByRole("button", { name: "Connect your account" }).click();
await expect(page).toHaveURL(/#integration-mcp:docs$/);
await (await tab).waitForEvent("close");
expect(db.calls.some((c) => c.path === "/api/mcp-servers/oauth/callback")).toBe(true);
await expect(row(page, "mcp:docs")).toHaveAttribute("data-status", "connected");
});
Expand All @@ -419,7 +441,7 @@ test("a key for a server whose vendor takes one connects to that server", async
await page.goto("/settings/integrations");
await row(page, "linear").getByRole("button", { name: /^Linear, Not connected/ }).click();
const panel = row(page, "linear").getByTestId("integration-panel");
await panel.getByText("Use a key instead").click();
await panel.getByTestId("other-ways").locator("summary").click();
const form = panel.getByTestId("remote-key-form");
await form.getByLabel("API key").fill("lin_api_example");
await form.getByRole("button", { name: "Connect with this key" }).click();
Expand Down Expand Up @@ -454,7 +476,7 @@ test("a server no key works for says why, with no key form", async ({ page }) =>
const hosting = row(page, "hosting").getByTestId("integration-panel");
await expect(hosting.getByRole("button", { name: "Sign in with Hosting" })).toBeVisible();
await expect(hosting.getByTestId("key-unavailable")).toHaveText("Hosting's MCP server takes no key: use Sign in with Hosting.");
await expect(hosting.getByText("Use a key instead")).toHaveCount(0);
await expect(hosting.getByTestId("other-ways")).toHaveCount(0);
await expect(hosting.locator("input")).toHaveCount(0);
await row(page, "cache").getByRole("button", { name: /^Cache, Not connected/ }).click();
const cache = row(page, "cache").getByTestId("integration-panel");
Expand Down
5 changes: 4 additions & 1 deletion dashboard/e2e/oauth-callback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ test("an expired knowledge state still reads as Knowledge from its tag", async (

test("a state from an older gateway (no kind) still finishes through the API", async ({ page }) => {
const calls = await mockApi(page, () => ({ status: 200, body: { server: { id: "ks-notion", name: "Notion (knowledge)", catalog_id: "source:notion" }, tools_error: null } }));
// Knowledge reads ?connected= and takes it out of the address at once, so
// the arrival is caught as it happens rather than by polling the address.
const arrived = page.waitForURL(/\/knowledge\/\?connected=notion$/, { waitUntil: "commit" });
await page.goto("/settings/integrations/mcp-callback/?code=c1&state=plainrandomstate");
await expect(page).toHaveURL(/\/knowledge\/\?connected=notion$/);
await arrived;
expect(calls.callback).toHaveLength(1);
});

Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/app/connections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RoleGuard } from "@/components/role-guard";
import { Page, PageHeader } from "@/components/page";
import { BrandIcon } from "@/components/brand-icons";
import { AddMcpServerDialog, McpServerPanel } from "@/components/mcp-servers";
import { PluginPanel } from "@/components/mcp-server-panel";
import { CatalogPanel } from "@/components/mcp-server-panel";
import { Chip, List, ListError, ListSection, ListSkeleton, type Tone } from "@/components/list";
import { linkButton, secondaryButton } from "@/components/ui";
import { EmptyState } from "@/components/empty-state";
Expand Down Expand Up @@ -100,9 +100,9 @@ function ConnectionsPage() {
</div>
{open === item.id && (
<div id={panelId} className="border-t border-zinc-800 bg-zinc-950/40 px-4 pb-4 pt-3 sm:pl-[3.75rem]">
{item.reason && <p className="text-sm text-zinc-400">{item.reason}</p>}
{remote && <McpServerPanel server={remote} canEdit={canEdit} onChanged={load} onRemoved={added ? () => setOpen("") : undefined} />}
{!added && canEdit && <PluginPanel item={item} onChanged={load} onClose={() => setOpen("")} />}
<p className="text-sm text-zinc-400">{item.does}</p>
{added && remote && <McpServerPanel server={remote} canEdit={canEdit} onChanged={load} onRemoved={() => setOpen("")} />}
{!added && <CatalogPanel item={item} canEdit={canEdit} onChanged={load} onClose={() => setOpen("")} />}
<p className="mt-4">
<button type="button" onClick={() => setOpen("")} className={linkButton}>
Close
Expand Down
Loading
Loading