From fc788ee58c399b21362e0e373928abd518ed2065 Mon Sep 17 00:00:00 2001 From: David McKay Date: Thu, 3 Dec 2026 10:10:24 -0800 Subject: [PATCH 1/2] Disconnect on the page of an app OpenBot signs you in to On OpenBot Desktop, Fireflies.ai (added as its own MCP server, which signs each person in) read "Connected" under "Your account" with nothing to press. Google Sheets, from the directory, has Disconnect on the same row. The only control on the page was the app's switch, which turns it off for every Bot, so a person couldn't take their own account back. The app's page draws two account rows: one for directory apps, with Disconnect, and one for apps OpenBot signs the person in to itself (a server added by its address that signs people in, and catalogue apps such as Notion), which had none. That second row now has the same Disconnect, in the same place, in both editions. It makes the write the person's own Connections page already makes (disconnectApp), and the row goes back to Connect. Where the app couldn't be asked to end the access, the row says where to finish it, as that page does. A sign-in the vendor withdrew offers Disconnect beside Reconnect. The server already ends this kind of connection; no API change. --- app/src/components/manage/plugin-page.tsx | 70 +++- app/src/lib/connections/disconnected-here.ts | 11 + .../routes/_authed/_app/connections.$key.tsx | 11 +- .../sign-in-app-disconnect-layout.fixture.tsx | 216 +++++++++++ .../sign-in-app-disconnect-layout.test.tsx | 352 ++++++++++++++++++ .../sign-in-app-page-disconnect.test.tsx | 306 +++++++++++++++ 6 files changed, 945 insertions(+), 21 deletions(-) create mode 100644 app/src/lib/connections/disconnected-here.ts create mode 100644 app/tests/sign-in-app-disconnect-layout.fixture.tsx create mode 100644 app/tests/sign-in-app-disconnect-layout.test.tsx create mode 100644 app/tests/sign-in-app-page-disconnect.test.tsx diff --git a/app/src/components/manage/plugin-page.tsx b/app/src/components/manage/plugin-page.tsx index 85ea1262dd..24c9fe70ee 100644 --- a/app/src/components/manage/plugin-page.tsx +++ b/app/src/components/manage/plugin-page.tsx @@ -46,6 +46,7 @@ import { ItemActions, ItemContent, ItemDescription, + ItemFooter, ItemTitle, } from "@/components/ui/item"; import { Separator } from "@/components/ui/separator"; @@ -71,6 +72,7 @@ import { import { vendorNameOf } from "@/lib/apps/vendor-name"; import { currentUserQueryOptions } from "@/lib/auth/queries"; import { isOrganizationAdmin } from "@/lib/auth/roles"; +import { disconnectedHere } from "@/lib/connections/disconnected-here"; import { ALWAYS_ON_APP } from "@/lib/connections/rows"; import { storeMcpToken } from "@/lib/credentials/mutations"; import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries"; @@ -84,6 +86,7 @@ import { atStart, useManagePaths } from "@/lib/manage-paths"; import { signsInForDirectory } from "@/lib/plugins/directory-state"; import { connectAccountMutationOptions, + disconnectBrokeredMutationOptions, grantPlugin, invalidatePlugins, } from "@/lib/plugins/mutations"; @@ -497,6 +500,20 @@ export function PluginPage({ window.location.href = authorizationUrl; }, }); + /* + * DISCONNECT, for an app OpenBot signs the person in to itself: the same write a directory app's + * row makes (disconnectApp). The app is asked to end the access where it can be, then OpenBot + * forgets the sign-in, and the row reads as not connected with Connect offered again. A refusal is + * said in the banner, and the row stays Connected. + * + * The row offered nothing here, and the app's switch was the only control on the page: Fireflies + * on OpenBot Desktop read "Connected" with no way to take the account back short of turning the + * app off for every Bot. + */ + const disconnectSelf = useMutation({ + ...disconnectBrokeredMutationOptions(queryClient), + ...report, + }); const entry = catalogue.data?.find((item) => item.key === key); const server = plugins.data?.find((item) => item.id === key); /* @@ -559,8 +576,8 @@ export function PluginPage({ * Everything the brokered row below reads and does, shared with the personal connected-accounts * screen that draws the same row. See `brokered-account-row.tsx`. * - * `connectSelf` above stays: it is the `user-oauth` row's Connect, which is a different row with - * no Disconnect beside it and nothing brokered to confirm. + * `connectSelf` and `disconnectSelf` above stay: they are the `user-oauth` row's Connect and + * Disconnect, which is a different row with nothing brokered to confirm. */ const brokeredAccount = useBrokeredAccount({ connectsWith: server?.connectsWith ?? null, @@ -1276,9 +1293,9 @@ export function PluginPage({ * and still this person's account and nobody else's. * * The two are drawn by different things, which is the honest arrangement rather than - * one row branching on `auth` in five places. A brokered account is ended from here as - * well as begun, and says so; an OAuth one is withdrawn at the vendor and this page - * offers no button pretending otherwise. + * one row branching on `auth` in five places. Both are ended from here as well as begun, + * with the same Disconnect under the row: connect, disconnect and reconnect work the + * same way whichever way an app is connected. */} {auth === "brokered" ? ( <> @@ -1356,16 +1373,22 @@ export function PluginPage({ Your account - + {/* Never clamped, as a directory app's row isn't: after a disconnect the app + couldn't carry out, it names the one step left, and that is the part a + clamp would cut. */} + {withdrawn ? `Your ${title} connection needs reconnecting.` - : personal - ? youConnected - ? `Connected. Your Bots use your ${vendorNameOf(title)} as you.` - : `Connect your ${vendorNameOf(title)} account so your Bots can use it.` - : youConnected - ? `Connected. A Bot with these tools uses your ${vendorNameOf(title)} as you. Everybody else connects their own.` - : `Connect your own account to try this app. ${reassurance}`} + : !youConnected && + disconnectSelf.data?.revocationRequested === false + ? disconnectedHere(title, entry?.vendor ?? title) + : personal + ? youConnected + ? `Connected. Your Bots use your ${vendorNameOf(title)} as you.` + : `Connect your ${vendorNameOf(title)} account so your Bots can use it.` + : youConnected + ? `Connected. A Bot with these tools uses your ${vendorNameOf(title)} as you. Everybody else connects their own.` + : `Connect your own account to try this app. ${reassurance}`} @@ -1415,6 +1438,27 @@ export function PluginPage({ )} + {/* + * DISCONNECT, ON A LINE OF ITS OWN UNDER THE SENTENCE, exactly where a directory + * app's row puts it (`BrokeredAccountRow`). Offered over a withdrawn grant too: + * Reconnect is one way out of that state, and ending the account is the other. + */} + {youConnected ? ( + + + + ) : null} )} diff --git a/app/src/lib/connections/disconnected-here.ts b/app/src/lib/connections/disconnected-here.ts new file mode 100644 index 0000000000..ec35fcde28 --- /dev/null +++ b/app/src/lib/connections/disconnected-here.ts @@ -0,0 +1,11 @@ +/** + * What a disconnect says when OpenBot ended its own copy of the sign-in but the app couldn't be + * asked to end it there: the app offers no way to, or didn't answer. Said plainly, so nobody + * believes they ended access the app still lists. + * + * Said by every page that disconnects an app OpenBot signs the person in to itself: the app's own + * page under Apps in either edition, and a person's page for it in the team edition. + */ +export function disconnectedHere(title: string, where: string): string { + return `Disconnected. No Bot can use your ${title} account now. To remove OpenBot from it too, use your ${where} account's third-party access settings.`; +} diff --git a/app/src/routes/_authed/_app/connections.$key.tsx b/app/src/routes/_authed/_app/connections.$key.tsx index 06ad95f604..572d91d1c1 100644 --- a/app/src/routes/_authed/_app/connections.$key.tsx +++ b/app/src/routes/_authed/_app/connections.$key.tsx @@ -50,6 +50,7 @@ import { currentUserQueryOptions } from "@/lib/auth/queries"; import { isOrganizationAdmin } from "@/lib/auth/roles"; import { useDropBrokerReturn } from "@/lib/connections/broker-return"; import { useConnectApp } from "@/lib/connections/connect-app"; +import { disconnectedHere } from "@/lib/connections/disconnected-here"; import { ALWAYS_ON_APP } from "@/lib/connections/rows"; import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries"; import { useAppsOpen } from "@/lib/enterprise/apps-open"; @@ -109,14 +110,8 @@ export function addedByMe( return addedBy.trim().toLowerCase() === email.trim().toLowerCase(); } -/** - * What a disconnect says when OpenBot ended its own copy of the sign-in but the app couldn't be - * asked to end it there: the app offers no way to, or didn't answer. Said plainly, so nobody - * believes they ended access the app still lists. - */ -export function disconnectedHere(title: string, where: string): string { - return `Disconnected. No Bot can use your ${title} account now. To remove OpenBot from it too, use your ${where} account's third-party access settings.`; -} +// The sentence after a disconnect the app couldn't be asked to carry out, shared with the app's page. +export { disconnectedHere }; /** The longest action name this page will repeat back. Real ones are far shorter. */ const MAX_LANDED_ACTION = 200; diff --git a/app/tests/sign-in-app-disconnect-layout.fixture.tsx b/app/tests/sign-in-app-disconnect-layout.fixture.tsx new file mode 100644 index 0000000000..e5018945ca --- /dev/null +++ b/app/tests/sign-in-app-disconnect-layout.fixture.tsx @@ -0,0 +1,216 @@ +import { QueryClientProvider } from "@tanstack/react-query"; +import { + createBrowserHistory, + createRootRoute, + createRoute, + createRouter, + Outlet, + RouterProvider, +} from "@tanstack/react-router"; +import { createRoot } from "react-dom/client"; +import { TooltipProvider } from "@/components/ui/tooltip"; +import { setCurrentOrganization } from "@/lib/organizations/current"; +import { queryClient } from "@/query-client"; +import { Route as ConnectionsAppRoute } from "@/routes/_authed/_app/connections.$key"; +import { ME_PATH, meResponse } from "./accounts-api"; +import { + APPS_SETTING_PATH, + appsSettingResponse, + DEPLOYMENT_PATH, +} from "./admin-settings-api"; +import { answerAppsApi, type TodayServer } from "./apps-api"; +import { + APP_ACCESS_REQUESTS_PATH, + appAccessRequestsResponse, +} from "./bot-grants-api"; +import { answerBotsList } from "./bots-api"; +import { + accountsPage, + connectionPage, + connectionResponse, + connectionsCall, + disconnectionResponse, + startResponse, + type TodayConnection, +} from "./connections-api"; + +/** + * Fireflies.ai and Google Sheets on OpenBot Desktop, each app's page under Apps, as a page of its + * own for sign-in-app-disconnect-layout.test.tsx to bundle and load in a browser. The app's own route + * for an app's page sits at `/connections/$key`, which in the personal edition is the whole app, with + * this page playing the server. + * + * Fireflies is added as its own MCP server, which signs each person in; Google Sheets is from the + * directory. Both are connected. `?answer=not-asked` answers a disconnect as the server does where + * the app couldn't be asked to end the access, and `?theme=dark` draws it dark. Every write the page + * sends is kept in order on `window.__events`. + */ +type Page = Window & { __events: string[] }; +const page = window as unknown as Page; +page.__events = []; +setCurrentOrganization("default"); + +const params = new URLSearchParams(location.search); +if (params.get("theme") === "dark") + document.documentElement.classList.add("dark"); +const notAsked = params.get("answer") === "not-asked"; + +const fireflies: TodayServer = { + id: "fireflies", + title: "Fireflies.ai", + vendor: "api.fireflies.ai", + url: "https://api.fireflies.ai/mcp", + provenance: "custom", + signIn: true, + dynamicClient: true, + accountMode: null, + ownerGrants: "any", + everyBot: true, + tools: [ + { + name: "fireflies_get_transcripts", + description: "List your meeting transcripts.", + effect: "read", + grantedTo: ["assistant"], + }, + ], +}; +const sheets: TodayServer = { + id: "composio-googlesheets", + title: "Google Sheets", + url: "composio://googlesheets", + provenance: "composio", + authScheme: "OAUTH2", + accountMode: "personal", + ownerGrants: "any", + everyBot: true, + tools: [ + { + name: "GOOGLESHEETS_BATCH_GET", + description: "Read values from a spreadsheet.", + effect: "read", + grantedTo: ["assistant"], + }, + ], +}; + +let rows: TodayConnection[] = [ + { serverId: "fireflies", scope: "" }, + { + serverId: "composio-googlesheets", + verified: true, + verifiedAt: "2026-11-20T09:00:00.000Z", + probe: null, + checkable: false, + canAddAccount: true, + }, +]; + +const original = window.fetch.bind(window); +window.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { + const url = new URL(String(input), location.origin); + const path = url.pathname; + const method = (init?.method ?? "GET").toUpperCase(); + if (!path.startsWith("/api/")) return original(input, init); + if (method !== "GET") page.__events.push(`${method} ${path}`); + if (path === DEPLOYMENT_PATH) + return Response.json({ + generativeUi: true, + selfHostBanner: false, + localEvaluation: true, + edition: "personal", + }); + if (path === ME_PATH) + return meResponse({ user: { id: "usr_me", role: "admin", name: "Me" } }); + if (path === APPS_SETTING_PATH) return appsSettingResponse(false); + if (path === APP_ACCESS_REQUESTS_PATH) return appAccessRequestsResponse([]); + const call = connectionsCall(path, init); + if (call?.operation === "list") return connectionPage(rows); + if (call?.operation === "get") { + const row = rows.find((held) => held.serverId === call.appId); + if (row) return connectionResponse(row); + } + if (call?.operation === "accounts") + return accountsPage([ + { + id: "acct-1", + identity: "me@example.com", + label: "me@example.com", + isDefault: true, + connectedAt: "2026-11-20T09:00:00.000Z", + }, + ]); + if (call?.operation === "disconnect") { + rows = rows.filter((row) => row.serverId !== call.appId); + return disconnectionResponse(!notAsked); + } + if (call?.operation === "connect") + return startResponse({ + authorizationUrl: `https://sign-in.example/${call.appId}`, + }); + if (call?.operation === "confirm") return Response.json({ connected: true }); + const apps = answerAppsApi(input, init, { + servers: [fireflies, sheets], + catalogue: [], + botsMayCallBack: true, + redirectUri: "https://openbot.example/callback", + composioConfigured: true, + provider: "composio", + }); + if (apps) return apps; + const bots = answerBotsList(input, init, { visible: [] }); + if (bots) return bots; + return Response.json({ error: "Not found." }, { status: 404 }); +}) as typeof fetch; + +queryClient.setDefaultOptions({ queries: { retry: false } }); + +const root = createRootRoute({ component: Outlet }); +const authed = createRoute({ + id: "/_authed", + getParentRoute: () => root, + component: Outlet, +}); +const app = createRoute({ + id: "/_app", + getParentRoute: () => authed, + component: Outlet, +}); +const connections = createRoute({ + path: "/connections", + getParentRoute: () => app, + component: () => ( +
+ +
+ ), +}); +const connectionsIndex = createRoute({ + path: "/", + getParentRoute: () => connections, + component: () =>

Apps

, +}); +const appPage = ( + ConnectionsAppRoute as unknown as { update: (options: unknown) => unknown } +).update({ id: "/$key", path: "/$key", getParentRoute: () => connections }); +const router = createRouter({ + routeTree: root.addChildren([ + authed.addChildren([ + app.addChildren([ + connections.addChildren([connectionsIndex, appPage as never]), + ]), + ]), + ]), + history: createBrowserHistory(), +}); + +const mount = document.getElementById("root"); +if (mount) { + createRoot(mount).render( + + + + + , + ); +} diff --git a/app/tests/sign-in-app-disconnect-layout.test.tsx b/app/tests/sign-in-app-disconnect-layout.test.tsx new file mode 100644 index 0000000000..08192927a9 --- /dev/null +++ b/app/tests/sign-in-app-disconnect-layout.test.tsx @@ -0,0 +1,352 @@ +import { afterAll, beforeAll, describe, expect } from "bun:test"; +import { existsSync, mkdirSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import type { Browser, BrowserType, Locator, Page } from "playwright-core"; +import { compile } from "tailwindcss"; +import { myConnectionPath } from "./connections-api"; +import { test } from "./renderer-crash"; + +/** + * Disconnect on Fireflies.ai's page on OpenBot Desktop, in a real browser, beside Google Sheets'. + * + * Fireflies, added as its own MCP server that signs each person in, read "Connected" under "Your + * account" with nothing to press; Google Sheets, from the directory, has Disconnect and Connect + * another account under the same row. Now Fireflies has the same Disconnect in the same place, and + * pressing it ends the account and puts Connect back. sign-in-app-page-disconnect.test.tsx holds the + * behaviour; this drives it with a real mouse in the app's stylesheet, at a desktop window's width + * and a phone's, and measures the two rows against each other. + * + * OPENBOT_APP_BROWSER=1 bun test app/tests/sign-in-app-disconnect-layout.test.tsx + * + * Chromium by default, as CI has it. OPENBOT_APP_ENGINES=chromium,webkit adds WebKit. With + * OPENBOT_APP_SHOTS= each step is saved as sign-in-app-disconnect----.png. + */ +const asked = process.env.OPENBOT_APP_BROWSER === "1"; +const shots = process.env.OPENBOT_APP_SHOTS; +const engines = (process.env.OPENBOT_APP_ENGINES ?? "chromium") + .split(",") + .map((engine) => engine.trim()) + .filter((engine) => engine === "chromium" || engine === "webkit") as ( + | "chromium" + | "webkit" +)[]; + +const APP = join(import.meta.dir, ".."); +const ORIGIN = "http://openbot.test"; +const WIDTHS = { + desktop: { width: 1000, height: 900 }, + phone: { width: 390, height: 844 }, +} as const; + +/** The fixture bundled for the browser. `@/lib/marks` is Vite's `import.meta.glob`, so no marks. */ +async function bundle(): Promise { + const built = await Bun.build({ + entrypoints: [ + join(import.meta.dir, "sign-in-app-disconnect-layout.fixture.tsx"), + ], + target: "browser", + define: { "process.env.NODE_ENV": JSON.stringify("production") }, + plugins: [ + { + name: "no-marks", + setup(build) { + build.onResolve({ filter: /^@\/lib\/marks$/ }, () => ({ + path: "marks", + namespace: "no-marks", + })); + build.onLoad({ filter: /.*/, namespace: "no-marks" }, () => ({ + contents: "export const markFor = () => null;", + loader: "js", + })); + }, + }, + ], + }); + if (!built.success) throw new AggregateError(built.logs, "bundle failed"); + const script = built.outputs.find((output) => output.kind === "entry-point"); + if (!script) throw new Error("bundle has no entry point"); + return script.text(); +} + +/** The directory of an installed package, from the app or the repository root. */ +function packageDir(name: string): string { + const dir = [ + join(APP, "node_modules", name), + join(APP, "..", "node_modules", name), + ].find(existsSync); + if (!dir) throw new Error(`no package ${name}`); + return dir; +} + +/** Where `@import "[/]"` lands, by the package's `style` export as Vite reads it. */ +function packageStylesheet(id: string): string { + const parts = id.split("/"); + const name = id.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]; + const dir = packageDir(name); + const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")); + const subpath = `.${id.slice(name.length)}`; + const entry = pkg.exports?.[subpath]; + const file = + typeof entry === "string" + ? entry + : (entry?.style ?? entry?.default ?? pkg.main ?? "index.css"); + return join(dir, file); +} + +/** The app's stylesheet, built by Tailwind for these classes, as the app's build does. */ +async function stylesheet(classes: string[]): Promise { + const tailwind = dirname(Bun.resolveSync("tailwindcss/package.json", APP)); + const entry = join(APP, "src", "styles.css"); + const compiler = await compile(readFileSync(entry, "utf8"), { + base: dirname(entry), + loadStylesheet: async (id, base) => { + const path = + id === "tailwindcss" + ? join(tailwind, "index.css") + : id.startsWith(".") + ? join(base, id) + : packageStylesheet(id); + return { path, base: dirname(path), content: readFileSync(path, "utf8") }; + }, + }); + return compiler.build(classes); +} + +const browsers = new Map(); +let script: string; + +beforeAll(async () => { + if (!asked) return; + script = await bundle(); + const playwright = await import("playwright-core"); + for (const engine of engines) { + const type: BrowserType = playwright[engine]; + browsers.set( + engine, + // The CI job installs full Chromium without the headless shell. + await type.launch(engine === "chromium" ? { channel: "chromium" } : {}), + ); + } +}, 120_000); + +afterAll(async () => { + for (const browser of browsers.values()) await browser.close(); +}); + +/** Styled for everything now on the page. */ +async function style(page: Page) { + const classes = await page.evaluate(() => + [...document.querySelectorAll("[class]")].flatMap((element) => [ + ...element.classList, + ]), + ); + await page.addStyleTag({ content: await stylesheet([...new Set(classes)]) }); + await page.evaluate(() => document.fonts.ready); + await page.evaluate(() => + Promise.race([ + Promise.all( + document + .getAnimations() + .map((motion) => motion.finished.catch(() => undefined)), + ), + new Promise((done) => setTimeout(done, 1_500)), + ]), + ); +} + +/** The fixture at `path`, in a window `width` wide. */ +async function open( + engine: string, + theme: "light" | "dark", + width: keyof typeof WIDTHS, + path: string, +): Promise { + const browser = browsers.get(engine); + if (!browser) throw new Error(`no ${engine}`); + const page = await browser.newPage({ + viewport: WIDTHS[width], + colorScheme: theme, + reducedMotion: "reduce", + }); + page.on("pageerror", (error) => console.error(error)); + const figtree = join(packageDir("@fontsource-variable/figtree"), "files"); + await page.route(`${ORIGIN}/**`, (route) => { + const at = new URL(route.request().url()).pathname; + if (at === "/sign-in-app-disconnect.js") + return route.fulfill({ contentType: "text/javascript", body: script }); + const font = join(figtree, at.split("/").pop() ?? ""); + if (at.startsWith("/files/") && existsSync(font)) + return route.fulfill({ path: font }); + // The fixture answers the API itself; anything that reaches the network has nowhere to go. + if (at.startsWith("/api/")) return route.fulfill({ status: 404 }); + return route.fulfill({ + contentType: "text/html", + body: `
`, + }); + }); + const join_ = path.includes("?") ? "&" : "?"; + await page.goto(`${ORIGIN}${path}${join_}theme=${theme}`); + return page; +} + +async function shoot(page: Page, step: string, name: string) { + if (!shots) return; + mkdirSync(shots, { recursive: true }); + await page.screenshot({ + path: join(shots, `sign-in-app-disconnect-${step}-${name}.png`), + fullPage: true, + }); +} + +/** The "Your account" row. */ +function accountRow(page: Page): Locator { + return page + .locator("[data-slot=item]") + .filter({ has: page.getByText("Your account", { exact: true }) }); +} + +/** Where Disconnect sits in its row, and how big it is, in CSS pixels. */ +async function disconnectPlace(page: Page) { + const row = accountRow(page); + return row.evaluate((element) => { + const box = element.getBoundingClientRect(); + const button = [...element.querySelectorAll("button")].find( + (candidate) => candidate.textContent?.trim() === "Disconnect", + ); + if (!button) return null; + const place = button.getBoundingClientRect(); + const title = element.querySelector("[data-slot=item-title]"); + const titleBox = title?.getBoundingClientRect(); + const footer = button.closest("[data-slot=item-footer]"); + const first = footer?.querySelector("button")?.getBoundingClientRect(); + return { + inFooter: footer !== null, + // Where the footer's buttons start, from the row's left edge. + footerLeft: first ? Math.round(first.left - box.left) : null, + belowTitle: titleBox ? place.top >= titleBox.bottom : false, + height: Math.round(place.height), + fontSize: getComputedStyle(button).fontSize, + borderRadius: getComputedStyle(button).borderRadius, + }; + }); +} + +/** Whether anything runs off the side of the window. */ +const sideways = (page: Page) => + page.evaluate(() => document.documentElement.scrollWidth > innerWidth); + +/** What the page wrote, in order. */ +const events = (page: Page) => + page.evaluate(() => (window as unknown as { __events: string[] }).__events); + +describe.skipIf(!asked)( + "Disconnect on an app's page, for an app that signs in", + () => { + for (const engine of engines) + for (const theme of ["light", "dark"] as const) + for (const width of ["desktop", "phone"] as const) { + const name = `${engine}-${theme}-${width}`; + + test(`Fireflies.ai has Disconnect where Google Sheets has it, and pressing it puts Connect back, in ${name}`, async () => { + // Google Sheets first: the row Fireflies has to match. + const sheetsPage = await open( + engine, + theme, + width, + "/connections/composio-googlesheets", + ); + let sheets: Awaited>; + try { + await accountRow(sheetsPage) + .getByRole("button", { name: "Disconnect" }) + .waitFor({ timeout: 15_000 }); + await style(sheetsPage); + await shoot(sheetsPage, "google-sheets", name); + sheets = await disconnectPlace(sheetsPage); + expect( + await accountRow(sheetsPage) + .getByRole("button", { name: /Connect another account/ }) + .count(), + ).toBe(1); + } finally { + await sheetsPage.close(); + } + + const page = await open( + engine, + theme, + width, + "/connections/fireflies", + ); + try { + await page + .getByText("Connected. Your Bots use your", { exact: false }) + .waitFor({ timeout: 15_000 }); + await style(page); + // Taken before anything is asked of the row, so it shows the page as it is. + await shoot(page, "fireflies", name); + expect(await sideways(page)).toBe(false); + const fireflies = await disconnectPlace(page); + expect(fireflies).not.toBeNull(); + // The same control, in the same place, at the same size, as Google Sheets'. + expect(fireflies).toEqual(sheets); + + await accountRow(page) + .getByRole("button", { name: "Disconnect" }) + .click(); + await accountRow(page) + .getByRole("button", { name: /^Connect/ }) + .waitFor({ timeout: 15_000 }); + await style(page); + await shoot(page, "fireflies-disconnected", name); + expect(await sideways(page)).toBe(false); + expect( + await accountRow(page) + .getByRole("button", { name: "Disconnect" }) + .count(), + ).toBe(0); + expect(await accountRow(page).innerText()).toContain( + "Connect your Fireflies.ai account so your Bots can use it.", + ); + expect(await events(page)).toEqual([ + `POST ${myConnectionPath("fireflies", "disconnect")}`, + ]); + } finally { + await page.close(); + } + }, 90_000); + + test(`Fireflies.ai says what is left to do where it couldn't be asked to end the access, in ${name}`, async () => { + const page = await open( + engine, + theme, + width, + "/connections/fireflies?answer=not-asked", + ); + try { + const disconnect = accountRow(page).getByRole("button", { + name: "Disconnect", + }); + await disconnect.waitFor({ timeout: 15_000 }); + await disconnect.click(); + await page + .getByText("To remove OpenBot from it too", { exact: false }) + .waitFor({ timeout: 15_000 }); + await style(page); + await shoot(page, "fireflies-not-asked", name); + expect(await sideways(page)).toBe(false); + // Said whole: the step left is the end of the sentence. + const sentence = accountRow(page).locator( + "[data-slot=item-description]", + ); + const clipped = await sentence.evaluate( + (element) => element.scrollHeight > element.clientHeight + 1, + ); + expect(clipped).toBe(false); + } finally { + await page.close(); + } + }, 90_000); + } + }, +); diff --git a/app/tests/sign-in-app-page-disconnect.test.tsx b/app/tests/sign-in-app-page-disconnect.test.tsx new file mode 100644 index 0000000000..011dd01cca --- /dev/null +++ b/app/tests/sign-in-app-page-disconnect.test.tsx @@ -0,0 +1,306 @@ +import { + afterAll, + afterEach, + beforeAll, + beforeEach, + describe, + expect, + test, +} from "bun:test"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { + createMemoryHistory, + createRootRoute, + createRouter, + RouterProvider, +} from "@tanstack/react-router"; +import { cleanup, render, waitFor, within } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { PluginPage } from "@/components/manage/plugin-page"; +import { agentKeys } from "@/lib/agents/queries"; +import { authKeys } from "@/lib/auth/queries"; +import { disconnectedHere } from "@/lib/connections/disconnected-here"; +import { deploymentKeys } from "@/lib/deployment/queries"; +import { APPS_SETTING_PATH, appsSettingResponse } from "./admin-settings-api"; +import { + type AppsFixture, + answerAppsApi, + type TodayCatalogueItem, + type TodayServer, +} from "./apps-api"; +import { + APP_ACCESS_REQUESTS_PATH, + appAccessRequestsResponse, +} from "./bot-grants-api"; +import { + connectionPage, + connectionsCall, + connectionsProblem, + disconnectionResponse, + startResponse, + type TodayConnection, +} from "./connections-api"; +import { settleReactWork } from "./settle-react-work"; + +/** + * DISCONNECT ON THE APP'S PAGE, FOR AN APP OPENBOT SIGNS YOU IN TO ITSELF. + * + * Reported from OpenBot Desktop 1.2.9: Fireflies.ai, added as its own MCP server that signs each + * person in, read "Connected" under "Your account" with nothing to press. Google Sheets, from the + * directory, has Disconnect on the same row. The only control on the Fireflies page was its switch, + * which turns the app off for every Bot, so a person could not take their own account back. + * + * The same row draws every app OpenBot signs in to itself: a server added by its address that signs + * each person in (Fireflies), and a catalogue app (Notion), in the personal edition and on an admin's + * page in the team edition. Each now has Disconnect under the row, as a directory app does. Pressing + * it ends the account (disconnectApp), and the row goes back to Connect. The API is answered in its + * own shapes. + */ + +beforeAll(() => GlobalRegistrator.register({ url: "http://localhost/" })); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + await GlobalRegistrator.unregister(); +}); + +/** Fireflies.ai, added by its own MCP server's address, which signs each person in. */ +const fireflies: TodayServer = { + id: "fireflies", + title: "Fireflies.ai", + vendor: "api.fireflies.ai", + url: "https://api.fireflies.ai/mcp", + summary: "", + docsUrl: "", + provenance: "custom", + hasCredential: false, + toolsRefreshedAt: null, + lastError: null, + addedBy: "me@example.com", + dynamicClient: true, + signIn: true, + authScheme: null, + tools: [], + withdrawn: [], + accountMode: null, + sharedVendorConnected: false, + ownerGrants: "any", + ownerGrantsChosen: null, +}; +/** Notion from OpenBot's catalogue, signed in to by OpenBot itself. */ +const notionEntry: TodayCatalogueItem = { + key: "notion", + title: "Notion", + vendor: "Notion", + summary: "Pages and databases.", + docsUrl: "", + auth: "user-oauth", + perInstance: false, +}; +const notion: TodayServer = { + ...fireflies, + id: "notion", + title: "Notion", + vendor: "Notion", + url: "https://mcp.notion.com/mcp", + provenance: "first-party", + hasCredential: true, + dynamicClient: false, + signIn: false, +}; + +const FIXTURE: AppsFixture = { + catalogue: [notionEntry], + servers: [fireflies, notion], + botsMayCallBack: true, + redirectUri: "https://openbot.example/callback", + composioConfigured: true, + authorizesPerAction: false, + provider: "composio", +}; + +let rows: TodayConnection[] = []; +/** How the server answers a disconnect: the app asked to end it, not asked, or a refusal. */ +let disconnectAnswer: "revoked" | "not-asked" | "fails" = "revoked"; +const writes: string[] = []; + +const originalFetch = global.fetch; +beforeEach(() => { + rows = [ + { serverId: "fireflies", scope: "" }, + { serverId: "notion", scope: "read" }, + ]; + disconnectAnswer = "revoked"; + writes.length = 0; + global.fetch = Object.assign( + async (input: RequestInfo | URL, init?: RequestInit) => { + const path = new URL(String(input), "http://openbot.invalid").pathname; + if (path === APPS_SETTING_PATH) return appsSettingResponse(false); + if (path === APP_ACCESS_REQUESTS_PATH) + return appAccessRequestsResponse([]); + const call = connectionsCall(input, init); + if (call?.operation === "list") return connectionPage(rows); + if (call?.operation === "connect") { + writes.push(`connect ${call.appId}`); + return startResponse({ + authorizationUrl: `https://sign-in.example/${call.appId}`, + }); + } + if (call?.operation === "disconnect") { + writes.push(`disconnect ${call.appId}`); + if (disconnectAnswer === "fails") + return connectionsProblem( + 502, + "Couldn't disconnect this account. Press Disconnect again. It's safe to repeat. Ask an admin if it keeps happening.", + ); + rows = rows.filter((row) => row.serverId !== call.appId); + return disconnectionResponse(disconnectAnswer === "revoked"); + } + const apps = answerAppsApi(input, init, FIXTURE); + if (apps) return apps; + return Response.json({ error: "not served" }, { status: 404 }); + }, + { preconnect: originalFetch.preconnect }, + ); +}); +afterEach(() => { + global.fetch = originalFetch; +}); + +/** An app's page, as OpenBot Desktop's one person reads it, or as an admin does in the team edition. */ +function draw(key: string, edition: "personal" | "team") { + const queries = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + queries.setQueryData(deploymentKeys.capabilities(), { + generativeUi: true, + selfHostBanner: false, + localEvaluation: edition === "personal", + edition, + hostedSignIn: edition === "team", + }); + queries.setQueryData(authKeys.currentUser(), { + id: "usr_me", + email: "me@example.com", + name: "Me", + role: "admin", + } as never); + const bots = [{ id: "bot-1", name: "General Assistant", hidden: false }]; + queries.setQueryData(agentKeys.list(false), bots); + queries.setQueryData(agentKeys.list(true), bots); + const router = createRouter({ + history: createMemoryHistory({ initialEntries: ["/"] }), + routeTree: createRootRoute({ + component: () => , + }), + }); + const view = render( + + + , + ); + return { view, user: userEvent.setup({ document }) }; +} + +/** The "Your account" row, by its title. */ +async function accountRow(view: ReturnType["view"]) { + const title = await view.findByText("Your account"); + const row = title.closest("[data-slot=item]"); + if (!(row instanceof HTMLElement)) throw new Error("no account row"); + return row; +} + +const CASES = [ + ["fireflies", "Fireflies.ai", "personal", "a server added by its address"], + ["fireflies", "Fireflies.ai", "team", "a server added by its address"], + ["notion", "Notion", "personal", "a catalogue app"], + ["notion", "Notion", "team", "a catalogue app"], +] as const; + +describe("Disconnect on the page of an app OpenBot signs you in to", () => { + test.each(CASES)( + "%s (%s) in the %s edition: Disconnect ends the account, and the row goes back to Connect", + async (key, _title, edition) => { + const { view, user } = draw(key, edition); + const row = await accountRow(view); + await waitFor(() => expect(row.textContent).toContain("Connected.")); + // Under the row, on a line of its own, as a directory app's Disconnect is. + const footer = row.querySelector("[data-slot=item-footer]"); + expect(footer).not.toBeNull(); + const disconnect = within(footer as HTMLElement).getByRole("button", { + name: "Disconnect", + }); + await user.click(disconnect); + await waitFor(() => expect(writes).toEqual([`disconnect ${key}`])); + const connect = await within(row).findByRole("button", { + name: /^Connect/, + }); + expect(connect).toBeTruthy(); + expect(within(row).queryByRole("button", { name: "Disconnect" })).toBe( + null, + ); + expect(row.textContent).not.toContain("Connected."); + expect(row.textContent).toContain( + edition === "personal" + ? "so your Bots can use it." + : "Connect your own account to try this app.", + ); + // Nothing refused. (The team edition's page reads more than this file serves, so the + // whole page's alerts would also name those.) + expect(within(row).queryByRole("alert")).toBeNull(); + expect(view.queryByText(/Couldn't disconnect/)).toBeNull(); + }, + ); + + test("says what is still standing where the app couldn't be asked to end it", async () => { + disconnectAnswer = "not-asked"; + const { view, user } = draw("fireflies", "personal"); + const row = await accountRow(view); + await user.click( + await within(row).findByRole("button", { name: "Disconnect" }), + ); + await within(row).findByText( + disconnectedHere("Fireflies.ai", "Fireflies.ai"), + ); + expect(within(row).getByRole("button", { name: /^Connect/ })).toBeTruthy(); + }); + + test("a disconnect the server refused says so, and the account stays connected", async () => { + disconnectAnswer = "fails"; + const { view, user } = draw("fireflies", "personal"); + const row = await accountRow(view); + await user.click( + await within(row).findByRole("button", { name: "Disconnect" }), + ); + const alert = await view.findByRole("alert"); + expect(alert.textContent).toContain("Couldn't disconnect this account."); + expect(row.textContent).toContain("Connected."); + expect( + within(row).getByRole("button", { name: "Disconnect" }), + ).toBeTruthy(); + }); + + test("a sign-in the vendor withdrew offers Reconnect, and Disconnect beside it", async () => { + rows = [{ serverId: "fireflies", revoked: true, scope: "" }]; + const { view, user } = draw("fireflies", "personal"); + const row = await accountRow(view); + await within(row).findByText( + "Your Fireflies.ai connection needs reconnecting.", + ); + expect(within(row).getByRole("button", { name: "Reconnect" })).toBeTruthy(); + await user.click(within(row).getByRole("button", { name: "Disconnect" })); + await waitFor(() => expect(writes).toEqual(["disconnect fireflies"])); + await within(row).findByRole("button", { name: /^Connect/ }); + }); + + test("an app not connected has no Disconnect, only Connect", async () => { + rows = []; + const { view } = draw("fireflies", "personal"); + const row = await accountRow(view); + await within(row).findByRole("button", { name: /^Connect/ }); + expect(within(row).queryByRole("button", { name: "Disconnect" })).toBe( + null, + ); + }); +}); From 4e15fd16a7b2c586155dd06761ee184c8ff049b8 Mon Sep 17 00:00:00 2001 From: David McKay Date: Thu, 3 Dec 2026 10:21:31 -0800 Subject: [PATCH 2/2] Run the Disconnect layout test in the real-browser jobs --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1029fc5034..a96c710ffe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -775,6 +775,7 @@ jobs: app/tests/sidebar-current-row.test.tsx app/tests/sidebar-window-buttons.test.tsx app/tests/sidebar-zoom-drag.test.tsx + app/tests/sign-in-app-disconnect-layout.test.tsx app/tests/sign-in-reconnect-layout.test.tsx app/tests/sign-in-returns-there.test.tsx app/tests/sign-in-with-apple-layout.test.tsx