Skip to content
Merged
18 changes: 14 additions & 4 deletions backend/__tests__/service/githubConnectRepositories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let nextRepoId = 1000;
const repo = (fullName, permissions = { push: true, pull: true }, id = (nextRepoId += 1)) => {
const [login, name] = fullName.split('/');
return {
id, name, full_name: fullName, owner: { login }, permissions,
id, name, full_name: fullName, owner: { login }, permissions, private: true,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};
};
const filler = (count) => Array.from({ length: count }, (_, i) => repo(`Outside-Team/filler-${i}`));
Expand Down Expand Up @@ -361,12 +361,22 @@ describe('F221: the picker for a person\'s own repositories', () => {
const res = await list(alice);
expect(res.status).toBe(200);
expect(res.body.repositories).toEqual([
{ installationId: INSTALL, owner: 'Outside-Team', repo: 'Widget' },
{ installationId: INSTALL, owner: 'Outside-Team', repo: 'Gadget' },
{ installationId: INSTALL, owner: 'Outside-Team', repo: 'Widget', private: true },
{ installationId: INSTALL, owner: 'Outside-Team', repo: 'Gadget', private: true },
]);
expect(res.body.truncated).toBe(false);
});

it('says which rows are public, and treats a row GitHub does not mark as private', async () => {
await giveUserToken(alice, 'alice-user-token');
const view = mockGithub.byToken['alice-user-token'];
const unmarked = repo('Outside-Team/Unmarked');
delete unmarked.private;
view.repositories[INSTALL] = [{ ...repo('Outside-Team/Open'), private: false }, unmarked];
const res = await list(alice);
expect(res.body.repositories.map((row) => [row.repo, row.private])).toEqual([['Open', false], ['Unmarked', true]]);
});

test('every request carries the caller\'s own token, and creates nothing', async () => {
await giveUserToken(alice, 'alice-user-token');
await giveUserToken(bob, 'bob-user-token');
Expand Down Expand Up @@ -436,7 +446,7 @@ describe('F221: the picker for a person\'s own repositories', () => {
await connectRepo(alice, { installationId: INSTALL, owner: 'Outside-Team', repo: 'Widget' });
mockGithub.byToken['alice-user-token'].installations[0].id = 7999;
mockGithub.byToken['alice-user-token'].repositories['7999'] = [repo('Outside-Team/Widget')];
expect((await list(alice)).body.repositories).toEqual([{ installationId: '7999', owner: 'Outside-Team', repo: 'Widget' }]);
expect((await list(alice)).body.repositories).toEqual([{ installationId: '7999', owner: 'Outside-Team', repo: 'Widget', private: true }]);
});

test('skips a suspended installation', async () => {
Expand Down
5 changes: 4 additions & 1 deletion backend/services/githubConnectProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ interface RepositoryEntry {
name?: unknown;
full_name?: unknown;
owner?: { login?: unknown };
private?: unknown;
permissions?: { admin?: unknown; maintain?: unknown; push?: unknown };
}

Expand Down Expand Up @@ -198,6 +199,7 @@ export interface ConnectableRepository {
installationId: string;
owner: string;
repo: string;
private: boolean;
}

/**
Expand Down Expand Up @@ -251,7 +253,8 @@ export const listConnectRepositories = async (
list.filter(canPush).forEach((repository) => {
const owner = String(repository?.owner?.login ?? '');
const repo = String(repository?.name ?? '');
if (owner && repo) repositories.push({ installationId, owner, repo });
// A row GitHub doesn't mark public is not called public.
if (owner && repo) repositories.push({ installationId, owner, repo, private: repository?.private !== false });
});
if (list.length < PAGE_SIZE) break;
if (page === LIST_MAX_PAGES) truncated = true;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/i18n/__tests__/zhNumberUnitSpacing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const OPAQUE_PLACEHOLDERS = [
'id',
// approvalCard.toolCall.verb names the branch a PR write lands on.
'head',
// tools.repoConnect.picked* names the owner/repo being connected.
'repository',
// podChat.deliveryHintOthers names the agent that was woken.
'woken',
// podChat.claimRun.label names the first and last task of a claim run (Latin task ids).
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,8 @@
"gatesTitle": "Pods that reach this channel",
"hostedMcpAppInstalledConnected": "{{provider}} App installed. {{provider}} is connected.",
"hostedMcpAppInstalledFinish": "{{provider}} App installed. Press Connect on {{provider}} to finish.",
"hostedMcpAccessNext": "Choose 'Only select repositories' to limit which private repos {{provider}} can read. Public repos are always readable.",
"hostedMcpAccessNext": "On GitHub, choose 'Only select repositories'.",
"hostedMcpAccessAll": "GitHub's install page opens on All repositories. Leave it there and Commonly Connect can reach every repository on the account or org you install it on, including new ones. Public repos are readable either way.",
"hostedMcpAccessOpen": "Open {{provider}}",
"hostedMcpReachNone": "{{provider}} is connected, but this account can't see any projects, so searches will come back empty. Add a project in {{provider}}, or connect an account that has one.",
"hostedMcpManualRevoke": "Your previous {{provider}} account may still have Commonly connected. Switch to it on {{provider}}, then remove Commonly there.",
Expand Down Expand Up @@ -2818,6 +2819,10 @@
"connectGithub": "Connect GitHub",
"none": "No repositories left to connect. To add more, install Commonly Connect on your account or org and pick the repositories.",
"choose": "Choose a repository",
"optionPrivate": "{{repository}} (private)",
"optionPublic": "{{repository}} (public)",
"pickedPrivate": "You're connecting {{repository}}, a private repository.",
"pickedPublic": "You're connecting {{repository}}, a public repository.",
"truncated": "This list may be incomplete.",
"connecting": "Connecting…",
"checkAgain": "Check again",
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,8 @@
"gatesTitle": "接入此频道的 Pod",
"hostedMcpAppInstalledConnected": "{{provider}} App 已安装,{{provider}} 已连接。",
"hostedMcpAppInstalledFinish": "{{provider}} App 已安装。在 {{provider}} 卡片上点「连接」完成设置。",
"hostedMcpAccessNext": "选择“Only select repositories”,限定 {{provider}} 可以读取哪些私有仓库。公开仓库始终可以读取。",
"hostedMcpAccessNext": "在 GitHub 上选择“Only select repositories”。",
"hostedMcpAccessAll": "GitHub 的安装页默认选中“All repositories”。如果不改,Commonly Connect 就能访问你安装到的账号或组织下的所有仓库,包括以后新建的。公开仓库无论怎么选都能读取。",
"hostedMcpAccessOpen": "打开 {{provider}}",
"hostedMcpReachNone": "{{provider}} 已连接,但这个账号看不到任何项目,所以搜索结果为空。请在 {{provider}} 里添加项目,或者连接一个有项目的账号。",
"hostedMcpManualRevoke": "你之前的 {{provider}} 账号可能仍保留对 Commonly 的授权。请在 {{provider}} 切换到那个账号,再在那里移除 Commonly。",
Expand Down Expand Up @@ -2819,6 +2820,10 @@
"connectGithub": "连接 GitHub",
"none": "没有其他可连接的仓库了。如需添加,请把 Commonly Connect 安装到你的账号或组织,再选择仓库。",
"choose": "选择仓库",
"optionPrivate": "{{repository}}(私有)",
"optionPublic": "{{repository}}(公开)",
"pickedPrivate": "你要连接的是私有仓库 {{repository}}。",
"pickedPublic": "你要连接的是公开仓库 {{repository}}。",
"truncated": "这个列表可能不完整。",
"connecting": "正在连接…",
"checkAgain": "重新检查",
Expand Down
38 changes: 30 additions & 8 deletions frontend/src/v2/__tests__/ConnectorsPage.githubAccessStep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ describe('connected, with the App not installed yet (next=access)', () => {
mockApi({ connectors: [githubRow], installables: [hostedGithub({ connections: [{ connectionId: 'i-gh', owner: 'sam', repo: '' }] })] });
renderPage();

const notice = (await screen.findByText(fill(en.connectors.hostedMcpAccessNext), { exact: false })).closest('p');
const notice = (await screen.findByText(en.connectors.hostedMcpAccessNext)).closest('.v2-cx-warning');
expect(notice).toHaveAttribute('role', 'status');
// GitHub's install page preselects "All repositories" and always reads
// public repos, so the notice names the choice; the link only opens the page.
// public repos, so the link carries the choice and what leaving it costs.
expect(notice).toHaveTextContent("On GitHub, choose 'Only select repositories'.");
expect(notice).toHaveTextContent(
"Choose 'Only select repositories' to limit which private repos GitHub can read. Public repos are always readable.",
'Leave it there and Commonly Connect can reach every repository on the account or org you install it on, including new ones.',
);
expect(notice).toHaveTextContent('Public repos are readable either way.');
const link = within(notice).getByRole('link', { name: fill(en.connectors.hostedMcpAccessOpen) });
expect(link).toHaveTextContent('Open GitHub');
expect(link).toHaveAttribute('href', accessPage);
Expand All @@ -133,10 +135,28 @@ describe('connected, with the App not installed yet (next=access)', () => {
});
renderPage();

expect(await screen.findByText(fill(en.connectors.hostedMcpAccessNext), { exact: false })).toBeInTheDocument();
expect(await screen.findAllByText(en.connectors.hostedMcpAccessNext)).not.toHaveLength(0);
const popover = await findPopover('GitHub');
expect(await within(popover).findByRole('link', { name: "Open GitHub's connected apps" })).toHaveAttribute('href', revokePage);
expect(window.location.search).toBe('');
// The page's notice carries the warning, so the popover leaves its own copy out.
expect(screen.getAllByText(en.connectors.hostedMcpAccessNext)).toHaveLength(1);
expect(within(popover).queryByText(en.connectors.hostedMcpAccessNext)).toBeNull();
expect(within(popover).queryByRole('link', { name: 'Choose what GitHub can reach' })).toBeNull();
});

it('keeps the warning on the entry once no notice is carrying it', async () => {
const revokePage = 'https://github.com/settings/apps/authorizations';
window.history.replaceState({}, '', `/v2/connectors?hostedMcp=connected&entryId=github-mcp&revokeAt=${encodeURIComponent(revokePage)}`);
mockApi({
connectors: [{ ...githubRow, config: { entryId: 'github-mcp', revokePage } }],
installables: [hostedGithub({ connections: [{ connectionId: 'i-gh', owner: 'sam', repo: '' }] })],
});
renderPage();

const popover = await findPopover('GitHub');
expect(await within(popover).findByText(en.connectors.hostedMcpAccessNext)).toBeInTheDocument();
expect(screen.getAllByText(en.connectors.hostedMcpAccessNext)).toHaveLength(1);
});

it('reads in zh-CN, keeping GitHub\'s own option label in English', async () => {
Expand All @@ -146,8 +166,10 @@ describe('connected, with the App not installed yet (next=access)', () => {
await act(async () => { await i18n.changeLanguage('zh-CN'); });
try {
renderPage();
const notice = (await screen.findByText('Only select repositories', { exact: false })).closest('p');
expect(notice).toHaveTextContent('选择“Only select repositories”,限定 GitHub 可以读取哪些私有仓库。公开仓库始终可以读取。');
const notice = (await screen.findByText('Only select repositories', { exact: false })).closest('.v2-cx-warning');
expect(notice).toHaveTextContent('在 GitHub 上选择“Only select repositories”。');
expect(notice).toHaveTextContent('Commonly Connect 就能访问你安装到的账号或组织下的所有仓库');
expect(notice).toHaveTextContent('公开仓库无论怎么选都能读取。');
expect(within(notice).getByRole('link', { name: '打开 GitHub' })).toHaveAttribute('href', accessPage);
} finally {
await act(async () => { await i18n.changeLanguage('en'); });
Expand All @@ -162,15 +184,15 @@ describe('connected, with the App not installed yet (next=access)', () => {
await pageReady();
await waitFor(() => expect(window.location.search).toBe(''));
await settle();
expect(screen.queryByText(fill(en.connectors.hostedMcpAccessNext), { exact: false })).toBeNull();
expect(screen.queryByText(en.connectors.hostedMcpAccessNext)).toBeNull();
});

it('leaves other query values in place', async () => {
window.history.replaceState({}, '', '/v2/connectors?hostedMcp=connected&entryId=github-mcp&next=access&keep=1');
mockApi({ connectors: [githubRow], installables: [hostedGithub()] });
renderPage();

await screen.findByText(fill(en.connectors.hostedMcpAccessNext), { exact: false });
await screen.findByText(en.connectors.hostedMcpAccessNext);
expect(window.location.search).toBe('?keep=1');
});
});
Expand Down
57 changes: 55 additions & 2 deletions frontend/src/v2/__tests__/ConnectorsPage.tools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,23 @@ describe('Connectors page: tools', () => {
expect(within(after).queryByRole('button', { name: 'Connect' })).toBeNull();
});

it('a live GitHub grant carries the install warning on its reach link', async () => {
const tool = 'github-mcp.list_issues';
const entry = {
...linearEntry,
installableId: 'github-mcp',
entryId: 'github-mcp',
label: 'GitHub MCP',
accessPage: 'https://github.com/apps/commonly-connect/installations/new',
tools: [{ name: tool, requiredWriteMode: 'read', irreversible: false }],
};
mockTools({ entries: [entry], grants: [{ ...grantLinear, tools: [tool] }] });
renderPage();
const { aside } = await openRow('GitHub MCP', 'View GitHub MCP in Launch pod');
const link = within(aside).getByRole('link', { name: 'Choose what GitHub MCP can reach' });
expect(link.closest('.v2-cx-warning')).toHaveTextContent("On GitHub, choose 'Only select repositories'.");
});

// A live grant takes the entry off the offer, so the page moves to the grant's
// details. Only the granter, who owns the connection, is sent there.
it('a live hosted grant keeps the reach link on its details for the granter only', async () => {
Expand Down Expand Up @@ -1645,8 +1662,8 @@ describe('F221: connecting your own repository', () => {
...linearEntry, installableId: 'github-mcp', label: 'GitHub MCP', entryId: 'github-mcp', repositoryConnect: true, accessPage: 'https://github.com/apps/connect/installations/new', connections: [],
};
const repos = [
{ installationId: '7001', owner: 'Outside-Team', repo: 'Widget' },
{ installationId: '7001', owner: 'Outside-Team', repo: 'Gadget' },
{ installationId: '7001', owner: 'Outside-Team', repo: 'Widget', private: true },
{ installationId: '7001', owner: 'Outside-Team', repo: 'Gadget', private: false },
];
const openStep = async ({ listed, refused, entries = [appEntry, hostedGithub] }) => {
const route = (url) => {
Expand Down Expand Up @@ -1690,6 +1707,42 @@ describe('F221: connecting your own repository', () => {
const step = await openStep({ listed: { repositories: [], truncated: false } });
const link = await within(step).findByRole('link');
expect(link).toHaveAttribute('href', hostedGithub.accessPage);
const warning = link.closest('.v2-cx-warning');
expect(warning).toHaveTextContent("On GitHub, choose 'Only select repositories'.");
expect(warning).toHaveTextContent('Commonly Connect can reach every repository on the account or org you install it on');
});

it('warns beside the install link on the offer, and only for GitHub', async () => {
mockTools({ entries: [hostedGithub, { ...linearEntry, accessPage: 'https://linear.example/access' }], grants: [], seats: { p1: [scout], p2: [] } });
renderPage();
const github = await openToolPopover('GitHub MCP');
expect(within(github).getByRole('link', { name: 'Choose what GitHub MCP can reach' }).closest('.v2-cx-warning')).not.toBeNull();
const linear = await openToolPopover('Linear');
expect(within(linear).queryByText("On GitHub, choose 'Only select repositories'.")).toBeNull();
});

it('labels each row and names the picked repository, public or private', async () => {
const step = await openStep({ listed: { repositories: repos, truncated: false } });
const select = await within(step).findByLabelText('repository');
expect(within(select).getByRole('option', { name: 'Outside-Team/Widget (private)' })).toHaveValue('Outside-Team/Widget');
expect(within(select).getByRole('option', { name: 'Outside-Team/Gadget (public)' })).toHaveValue('Outside-Team/Gadget');
expect(within(step).queryByRole('status')).toBeNull();
fireEvent.change(select, { target: { value: 'Outside-Team/Gadget' } });
expect(within(step).getByRole('status')).toHaveTextContent("You're connecting Outside-Team/Gadget, a public repository.");
fireEvent.change(select, { target: { value: 'Outside-Team/Widget' } });
expect(within(step).getByRole('status')).toHaveTextContent("You're connecting Outside-Team/Widget, a private repository.");
});

it('names the one repository it picked by itself', async () => {
const step = await openStep({ listed: { repositories: [repos[1]], truncated: false } });
expect(await within(step).findByText("You're connecting Outside-Team/Gadget, a public repository.")).toBeInTheDocument();
});

it('does not call a row public when the field is missing', async () => {
const { private: _dropped, ...unmarked } = repos[1];
const step = await openStep({ listed: { repositories: [unmarked], truncated: false } });
expect(await within(step).findByText("You're connecting Outside-Team/Gadget, a private repository.")).toBeInTheDocument();
expect(within(step).getByRole('option', { name: 'Outside-Team/Gadget (private)' })).toBeInTheDocument();
});

it('a member with a live grant can still connect another repository', async () => {
Expand Down
Loading
Loading