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
30 changes: 29 additions & 1 deletion dashboard/e2e/hybrid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,14 @@ test("GitHub: switch to Coderhelm's app, install on GitHub, edit repositories, u
await expect(row).toHaveAttribute("data-mode", "hosted");
expect(puts()).toContainEqual({ github_mode: "hosted" });

// Read before the click: once the browser is on its way to GitHub the
// page's address can already be the next one.
const origin = new URL(page.url()).origin;
const toGithub = page.waitForRequest((r) => r.url().startsWith("https://github.com/apps/coderhelm/installations/new?state=hyb_abc123"));
await row.getByTestId("hybrid-github-install").click();
await toGithub;
const link = calls.find((c) => c.method === "POST" && c.path === "/api/system/hybrid/github/link");
expect(link?.body).toEqual({ return_url: `${new URL(page.url()).origin}/settings/system/` });
expect(link?.body).toEqual({ return_url: `${origin}/settings/system/` });
});

test("GitHub links: repositories are edited and saved, and a link is removed", async ({ page }) => {
Expand All @@ -256,6 +259,9 @@ for (const [outcome, words, tone] of [
["linked_elsewhere", "already linked to another install", "error"],
["used_by_hosted_team", "used by a team on Coderhelm's hosted service", "error"],
["signin_failed", "didn't confirm who you are", "error"],
["no_write_access", "can't push to any repository", "error"],
["declined", "you chose Cancel", "error"],
["install_off", "verified and active", "error"],
] as const) {
test(`GitHub sent back ${outcome}: one sentence and the fix, and the address is cleaned`, async ({ page }) => {
await setup(page, SELF, { registered: true, verified: true, mode: "hosted" });
Expand Down Expand Up @@ -403,6 +409,28 @@ test("hosted: any other OAuth callback (404 from the hand-off) finishes as befor
expect(calls.filter((c) => c.path === "/hybrid/oauth/callback")).toHaveLength(1);
});

for (const [label, viewport] of [["1440", { width: 1440, height: 1000 }], ["390", { width: 390, height: 844 }]] as const) {
test(`linking refusals read plainly and fit at ${label}, and the install step names the Link confirmation`, async ({ page }) => {
await page.setViewportSize(viewport);
await setup(page, SELF, { registered: true, verified: true, mode: "hosted" });
await page.goto("/settings/system/#hybrid");
await expect(page.getByTestId("hybrid-github")).toContainText("press Link");
await expect(page.getByTestId("hybrid-github")).toContainText("only the repositories you can push to");
for (const [outcome, title, fix] of [
["no_write_access", "can't push to any repository in that installation", "get write access on GitHub"],
["declined", "you chose Cancel on Coderhelm's confirmation page", "choose Link"],
["install_off", "verified and active, so nothing was linked", "Press Check again"],
] as const) {
await page.goto(`/settings/system/?hybrid_github=${outcome}#hybrid`);
const box = page.getByTestId("hybrid-github-outcome");
await expect(box).toHaveAttribute("data-outcome", outcome);
await expect(box).toContainText(title);
await expect(box).toContainText(fix);
expect(await page.evaluate(() => document.scrollingElement!.scrollWidth <= window.innerWidth)).toBe(true);
}
});
}

test("on a phone the Hybrid section fits", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await setup(page, SELF, { registered: true, verified: true, mode: "hosted", links: [{ installation_id: 77, account: "example-org", repositories: ["example-org/web", "example-org/api"] }], name: { name: "example-org", hostname: "example-org.coderhelm.com", code: "ok" } });
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/hybrid-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function GithubRow({ hybrid, s }: RowProps) {
<div className="mt-4 min-w-0 space-y-3">
{s.github.links.length === 0 ? (
<div className="flex min-w-0 flex-wrap items-center justify-between gap-3 rounded-lg border border-zinc-800 bg-zinc-950/40 p-4">
<p className="min-w-0 flex-1 basis-56 text-sm text-zinc-300">Install Coderhelm&apos;s app on the GitHub account or organization that owns your repositories. GitHub brings you back here.</p>
<p className="min-w-0 flex-1 basis-56 text-sm text-zinc-300">Install Coderhelm&apos;s app on the GitHub account or organization that owns your repositories. Coderhelm then shows which install it is about to link: check that the address is this one and press Link. Tokens reach only the repositories you can push to.</p>
<button type="button" className={`${primaryButton} gap-1.5`} disabled={!!busy} onClick={() => void install()} data-testid="hybrid-github-install">
<span aria-hidden="true"><GitHubIcon /></span>
{busy === "link" ? "Opening GitHub…" : "Install on GitHub"}
Expand Down
15 changes: 15 additions & 0 deletions dashboard/src/lib/hybrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ export const GITHUB_OUTCOMES: Record<string, { ok: boolean; title: string; fix:
title: "The link couldn't be saved.",
fix: "Press Install on GitHub again. If it keeps failing, contact support.",
},
no_write_access: {
ok: false,
title: "Your GitHub account can't push to any repository in that installation, so nothing was linked.",
fix: "Ask someone who can push to those repositories to press Install on GitHub, or get write access on GitHub and try again.",
},
declined: {
ok: false,
title: "Nothing was linked: you chose Cancel on Coderhelm's confirmation page.",
fix: "If you meant to link it, press Install on GitHub again and choose Link.",
},
install_off: {
ok: false,
title: "Coderhelm doesn't see this install as verified and active, so nothing was linked.",
fix: "Press Check again below. If it says Coderhelm turned off this install's access, contact support.",
},
};

/** Why a name can't be used, when the server sent no words of its own. */
Expand Down
2 changes: 1 addition & 1 deletion docs/components/install/wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ export function InstallWizard() {
};
screen = (
<section data-testid="screen-github">
<Heading title="Install CoderHelm’s GitHub App" lead="One app on your organization, and you pick the repositories. GitHub asks you to sign in once, which proves the installation is yours." />
<Heading title="Install CoderHelm’s GitHub App" lead="One app on your organization, and you pick the repositories. GitHub asks you to sign in once, which proves the installation is yours. CoderHelm then shows which install it is about to link: check the address and press Link." />
{ho ? (
<Notice tone={ho.ok ? 'pass' : 'fail'} title={ho.title} testId="hybrid-github-outcome">
{ho.fix ? <p>{ho.fix}</p> : null}
Expand Down
22 changes: 22 additions & 0 deletions docs/e2e/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,28 @@ test('hybrid GitHub: install CoderHelm’s app and come back linked; refusals re
await expect(page.getByTestId('screen-ready')).toBeVisible();
});

for (const [label, viewport] of [['1440', { width: 1440, height: 1000 }], ['390', { width: 390, height: 844 }]] as const) {
test(`hybrid GitHub at ${label}: the confirmation step is named, and the new refusals say what to do`, async ({ page }) => {
await page.setViewportSize(viewport);
const m = newMock({ setup: withHybrid(setupDoc(HOSTED_GH), REG_OK, nameCheck('pass', 'ok')) });
const h = newHybrid();
await mockHybrid(page, h);
await seeded(page, m, HYBRID_STATE);
await expect(page.getByTestId('screen-github')).toContainText('check the address and press Link');
for (const [outcome, title, fix] of [
['no_write_access', 'can\u2019t push to any repository in that installation', 'get write access on GitHub'],
['declined', 'you chose Cancel on CoderHelm\u2019s confirmation page', 'choose Link'],
['install_off', 'verified and active, so nothing was linked', 'Press Check again'],
] as const) {
await page.goto(`/self-host/install/?hybrid_github=${outcome}`);
const box = page.getByTestId('hybrid-github-outcome');
await expect(box).toContainText(title);
await expect(box).toContainText(fix);
expect(await page.evaluate(() => document.scrollingElement!.scrollWidth <= window.innerWidth)).toBe(true);
}
});
}

test('hybrid GitHub: switching back to your own app is one click', async ({ page }) => {
const m = newMock({ setup: withHybrid(setupDoc(HOSTED_GH), REG_OK, nameCheck('pass', 'ok')) });
const h = newHybrid();
Expand Down
3 changes: 3 additions & 0 deletions docs/lib/install/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ export const HYBRID_GITHUB_OUTCOMES: Record<string, { ok: boolean; title: string
signin_failed: { ok: false, title: 'GitHub didn\u2019t finish signing you in.', fix: 'Press Install on GitHub again and allow the sign-in.' },
github_unreachable: { ok: false, title: 'CoderHelm couldn\u2019t reach GitHub.', fix: 'Press Install on GitHub again in a minute.' },
store_failed: { ok: false, title: 'CoderHelm couldn\u2019t save the link.', fix: 'Press Install on GitHub again in a minute.' },
no_write_access: { ok: false, title: 'Your GitHub account can\u2019t push to any repository in that installation, so nothing was linked.', fix: 'Ask someone who can push to those repositories to press Install on GitHub, or get write access on GitHub and try again.' },
declined: { ok: false, title: 'Nothing was linked: you chose Cancel on CoderHelm\u2019s confirmation page.', fix: 'If you meant to link it, press Install on GitHub again and choose Link.' },
install_off: { ok: false, title: 'CoderHelm doesn\u2019t see your install as verified and active, so nothing was linked.', fix: 'Press Check again. If it stays, open Settings, System, Hybrid in CoderHelm; if access was turned off, contact support.' },
};

/** What the install said when a hybrid call was refused, as one sentence and the fix. */
Expand Down
2 changes: 1 addition & 1 deletion docs/platform.lock.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"repo": "CoderHelm/coderhelm-platform",
"ref": "22548c6e2333e4055f25f3769fde531547c7f500"
"ref": "4fb3dc7a8696d360d02746f349c835df7ae58d76"
}
Loading