Skip to content
Python

Open the account picker when adding a GitHub installation

Rohit C Prasad810fcd463756
diff --git a/surfaces/gui/e2e/github-page.spec.ts b/surfaces/gui/e2e/github-page.spec.ts
index 8ef577f8..242fadbe 100644
--- a/surfaces/gui/e2e/github-page.spec.ts
+++ b/surfaces/gui/e2e/github-page.spec.ts
@@ -42,7 +42,7 @@ test("add installation opens the modal; signed in installs a second org", async
await openGithubPage(page);
await page.getByTestId("add-installation-btn").click();
const modal = page.getByTestId("add-connection-modal");
- await expect(modal).toContainText("@ocw-agent App"); // one-click pane
+ await expect(modal).toContainText("installation picker"); // explicit add, not reconnect
await expect(modal).toContainText("Sign in to OpenWorker Cloud"); // signed out
// Manual PAT pane is right there too — both modes, one entry point
await modal.getByTestId("modal-pane-manual").click();
@@ -66,12 +66,10 @@ test("add installation opens the modal; signed in installs a second org", async
await expect(page.getByTestId("github-install-101")).toBeVisible(); // existing stays
});
-test("modal has ONE connect button and sends no flow — authorize-first lives in the broker", async ({
+test("Add installation explicitly requests the GitHub account picker", async ({
page,
}) => {
- // The broker's default github flow user-authorizes first (links existing installations,
- // redirects to the install page only when there are none) — so the modal's old
- // "Already installed? Link it" secondary and its flow=authorize are gone.
+ // Adding an installation must not silently link the existing account again.
await openGithubPage(page);
await page.getByTestId("connectors-breadcrumb").click();
await page.getByTestId("account-row").click();
@@ -88,7 +86,7 @@ test("modal has ONE connect button and sends no flow — authorize-first lives i
await page.getByTestId("add-installation-btn").click();
await expect(page.getByTestId("modal-link-github-install")).toHaveCount(0);
await page.getByTestId("modal-install-github-app").click();
- await expect.poll(() => flowSent).toBe("");
+ await expect.poll(() => flowSent).toBe("install");
});
test("disconnect removes one installation and keeps the rest", async ({ page }) => {
diff --git a/surfaces/gui/src/api.auth.test.ts b/surfaces/gui/src/api.auth.test.ts
index d65be6a9..2984d250 100644
--- a/surfaces/gui/src/api.auth.test.ts
+++ b/surfaces/gui/src/api.auth.test.ts
@@ -1,10 +1,22 @@
import { afterEach, expect, it, vi } from "vitest";
-import { getHealth, Session } from "./api";
+import { connectManaged, getHealth, Session } from "./api";
afterEach(() => {
vi.unstubAllGlobals();
});
+it("requests installation consent only for explicit GitHub additions", async () => {
+ const bodies: unknown[] = [];
+ vi.stubGlobal("fetch", vi.fn(async (_url: string, init?: RequestInit) => {
+ bodies.push(JSON.parse(String(init?.body)));
+ return { json: async () => ({ ok: true }) } as Response;
+ }));
+ await connectManaged("github");
+ await connectManaged("github", { flow: "install" });
+ await connectManaged("hubspot", { access: "read", flow: "install" });
+ expect(bodies).toEqual([{}, { flow: "install" }, { access: "read" }]);
+});
+
it("authenticates REST and session WebSocket calls with the launch token", async () => {
vi.stubGlobal("__COWORKER_API_TOKEN__", "launch-token");
const request = vi.fn(async (_url: string, init?: RequestInit) => {
diff --git a/surfaces/gui/src/api.ts b/surfaces/gui/src/api.ts
index 3c406976..89f6f37b 100644
--- a/surfaces/gui/src/api.ts
+++ b/surfaces/gui/src/api.ts
@@ -959,7 +959,7 @@ export async function cloudLogout(): Promise<{ ok: boolean }> {
export async function connectManaged(
name: string,
- options?: { access?: "read" | "write" },
+ options?: { access?: "read" | "write"; flow?: "install" },
): Promise<{ ok: boolean; error?: string }> {
const res = await fetch(
`${httpBase()}/v1/connectors/${encodeURIComponent(name)}/connect-managed`,
@@ -967,10 +967,11 @@ export async function connectManaged(
method: "POST",
headers: { "Content-Type": "application/json" },
// `access` names a broker-defined consent tier (hubspot read | write).
- // GitHub needs no flow choice: the broker is authorize-first — one connect
- // links an existing App installation or redirects on to the install page.
+ // Normal connect links existing grants; explicit Add installation opens
+ // GitHub's account/repository consent picker even when grants already exist.
body: JSON.stringify({
...(options?.access ? { access: options.access } : {}),
+ ...(name === "github" && options?.flow ? { flow: options.flow } : {}),
}),
},
);
diff --git a/surfaces/gui/src/components/connectors/AddConnectionModal.tsx b/surfaces/gui/src/components/connectors/AddConnectionModal.tsx
index 303b88c2..25114a82 100644
--- a/surfaces/gui/src/components/connectors/AddConnectionModal.tsx
+++ b/surfaces/gui/src/components/connectors/AddConnectionModal.tsx
@@ -25,12 +25,14 @@ export function AddConnectionModal({
c,
cloud,
title,
+ githubFlow,
onClose,
onChanged,
}: {
c: Connector;
cloud: CloudStatus | null;
title?: string; // e.g. "Add a workspace" — defaults to "Connect {title}"
+ githubFlow?: "install";
onClose: () => void;
onChanged: () => void;
}) {
@@ -99,7 +101,7 @@ export function AddConnectionModal({
) : c.name === "hubspot" ? (
<HubSpotOneClick c={c} cloud={cloud} />
) : c.name === "github" ? (
- <GithubOneClick c={c} cloud={cloud} />
+ <GithubOneClick c={c} cloud={cloud} flow={githubFlow} />
) : c.name === "slack" ? (
<SlackOneClick c={c} cloud={cloud} />
) : (
@@ -245,27 +247,24 @@ function SlackOneClick({ c, cloud }: { c: Connector; cloud: CloudStatus | null }
);
}
-function GithubOneClick({ c, cloud }: { c: Connector; cloud: CloudStatus | null }) {
+function GithubOneClick({ c, cloud, flow }: { c: Connector; cloud: CloudStatus | null; flow?: "install" }) {
const { t: tt } = useTranslation();
const [waiting, setWaiting] = useState(false);
const [error, setError] = useState<string | null>(null);
const go = async () => {
setError(null);
- const res = await connectManaged(c.name);
+ const res = await connectManaged(c.name, flow ? { flow } : undefined);
if (res.ok) setWaiting(true);
else setError(res.error || tt("modal.could_not_start_install"));
};
return (
<div className="px-5 py-4 space-y-3">
<p className="text-ui text-muted">
- {tt("modal.github_blurb")}
+ {tt(flow === "install" ? "modal.github_install_blurb" : "modal.github_blurb")}
</p>
{cloud?.signed_in ? (
- /* One button: the broker is authorize-first — it links an existing installation or
- redirects the same tab on to the install page (the old "Already installed? Link
- it" question and the Configure dead-end are gone). */
<button className={PILL_ACCENT + " w-full !py-2"} data-testid="modal-install-github-app" onClick={() => go()} disabled={waiting}>
- {waiting ? tt("cloud.check_browser") : tt("modal.connect_github")}
+ {waiting ? tt("cloud.check_browser") : tt(flow === "install" ? "modal.choose_github_account" : "modal.connect_github")}
</button>
) : cloud ? (
<CloudSignInInline />
diff --git a/surfaces/gui/src/components/connectors/GithubDetail.tsx b/surfaces/gui/src/components/connectors/GithubDetail.tsx
index 99d2caaf..946d275b 100644
--- a/surfaces/gui/src/components/connectors/GithubDetail.tsx
+++ b/surfaces/gui/src/components/connectors/GithubDetail.tsx
@@ -147,6 +147,7 @@ export function GithubDetail({ c, cloud, onChanged }: DetailProps) {
c={c}
cloud={cloud}
title={t("github.add_installation_title")}
+ githubFlow="install"
onClose={() => setAdding(false)}
onChanged={changed}
/>
diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.json
index 18d2bf76..c8a9feb5 100644
--- a/surfaces/gui/src/locales/en.json
+++ b/surfaces/gui/src/locales/en.json
@@ -937,7 +937,7 @@
"setup_blurb": "One @ocw-agent App, installed per account or org — you pick the repos on GitHub; each installation keeps its own allow-list.",
"setup_cloud_note": "One-click needs cloud sign-in; a PAT works without it.",
"manual_card_note": "Personal access token · tools only. Install the GitHub App to let @-mentions and the agent label reach this computer.",
- "triggers_foot": "Triggers: @ocw-agent mentions and the \"ocw-agent\" label. The agent replies as ocw-agent[bot].",
+ "triggers_foot": "Repository access is managed on GitHub. Event routing is configured separately in GitHub settings here.",
"all_repos": "all repos",
"selected_repos": "selected repos",
"install_revoked": "⚠ Installation revoked — reinstall",
@@ -1134,7 +1134,9 @@
"slack_blurb": "Opens Slack in your browser — approve @ocw for the workspace. No tokens; works for any number of workspaces.",
"add_to_slack": "Add to Slack",
"slack_recommended_foot": "relay · tokens stay on this computer",
- "github_blurb": "Opens GitHub in your browser — approve OpenWorker there. An existing @ocw-agent App installation links right up; otherwise you'll pick an account and repos. No tokens typed; the agent acts as ocw-agent[bot].",
+ "github_blurb": "Opens GitHub in your browser to authorize OpenWorker and link existing GitHub App installations. If none exist, GitHub will ask you to choose an account and repositories. No token needed.",
+ "github_install_blurb": "Choose the personal account or organization and repositories on GitHub. This opens the installation picker even if you already connected another account. Existing connections stay unchanged.",
+ "choose_github_account": "Choose account and repositories",
"connect_github": "Connect GitHub",
"github_recommended_foot": "relay · short-lived tokens, never stored",
"hubspot_blurb": "Opens HubSpot in your browser — pick the portal there. What agents may do is chosen NOW, at consent:",
diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.json
index 7f195c18..ca8ec9d4 100644
--- a/surfaces/gui/src/locales/zh.json
+++ b/surfaces/gui/src/locales/zh.json
@@ -922,7 +922,7 @@
"setup_blurb": "一个 @ocw-agent App,按账户或组织安装 —— 你在 GitHub 上选择仓库;每个安装保留自己的允许列表。",
"setup_cloud_note": "一键连接需要登录云服务;PAT 无需登录即可使用。",
"manual_card_note": "个人访问令牌 · 仅工具。安装 GitHub App 后 @-提及和 agent 标签才能到达本机。",
- "triggers_foot": "触发器:@ocw-agent 提及和 \"ocw-agent\" 标签。agent 以 ocw-agent[bot] 身份回复。",
+ "triggers_foot": "仓库访问权限在 GitHub 上管理。事件路由在此处的 GitHub 设置中单独配置。",
"all_repos": "所有仓库",
"selected_repos": "选定仓库",
"install_revoked": "⚠ 安装已撤销 —— 请重新安装",
@@ -1117,7 +1117,9 @@
"slack_blurb": "在浏览器中打开 Slack —— 为工作区授权 @ocw。无需令牌;适用于任意数量的工作区。",
"add_to_slack": "添加到 Slack",
"slack_recommended_foot": "中转 · 令牌仅保留在本机",
- "github_blurb": "在浏览器中打开 GitHub —— 在那里授权 OpenWorker。已有的 @ocw-agent App 安装会直接关联;否则你将选择账户和仓库。无需输入令牌;agent 以 ocw-agent[bot] 身份操作。",
+ "github_blurb": "在浏览器中打开 GitHub,授权 OpenWorker 并关联现有的 GitHub App 安装。如果尚未安装,GitHub 会让你选择账户和仓库。无需输入令牌。",
+ "github_install_blurb": "在 GitHub 上选择个人账户或组织及仓库。即使已经连接了其他账户,也会打开安装选择页面。现有连接保持不变。",
+ "choose_github_account": "选择账户和仓库",
"connect_github": "连接 GitHub",
"github_recommended_foot": "中转 · 短期令牌,从不存储",
"hubspot_blurb": "在浏览器中打开 HubSpot —— 在那里选择门户。agent 可执行的操作现在(授权时)选择:",