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
28 changes: 24 additions & 4 deletions dashboard/e2e/hybrid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ async function setup(page: Page, cfg: Record<string, unknown> | null = SELF, ini
if (p === "/api/system/hybrid/settings" && method === "PUT") {
if (body?.github_mode) s.mode = body.github_mode as State["mode"];
if (Array.isArray(body?.integrations)) s.hosted = new Set(body!.integrations as string[]);
// Other apps, per tool: only the tools named change.
for (const [id, v] of Object.entries((body?.apps as Record<string, string> | undefined) ?? {})) {
if (v === "coderhelm") s.hosted.add(id);
else s.hosted.delete(id);
}
if (body?.sharing) s.sharing = body.sharing as State["sharing"];
return json(route, status(s));
}
Expand Down Expand Up @@ -285,16 +290,31 @@ for (const [outcome, words, tone] of [
});
}

test("other apps: each choice sends the hosted list; direct and unavailable say so", async ({ page }) => {
test("other apps: a new install shows Coderhelm's app selected for every tool", async ({ page }) => {
// What the install answers when nobody chose: Coderhelm's app for each tool.
const { puts } = await setup(page, SELF, { registered: true, verified: true, hosted: new Set(["jira", "notion", "confluence", "google_drive"]) });
await page.goto("/settings/system/");
for (const id of ["jira", "notion", "confluence", "google_drive"]) {
const row = page.getByTestId(`hybrid-integration-${id}`);
await expect(row.getByRole("button", { name: "Use Coderhelm's app (easiest)" })).toHaveAttribute("aria-pressed", "true");
await expect(row.getByRole("button", { name: "Use my own app (fully private)" })).toHaveAttribute("aria-pressed", "false");
await expect(row).toContainText("Through Coderhelm");
}
// Showing the defaults saves nothing.
expect(puts()).toEqual([]);
});

test("other apps: each choice sends only that tool; direct and unavailable say so", async ({ page }) => {
const { puts } = await setup(page, SELF, { registered: true, verified: true });
await page.goto("/settings/system/");
const jira = page.getByTestId("hybrid-integration-jira");
await expect(jira).toContainText("Ticket events and the sign-in.");
await jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" }).click();
await expect.poll(() => (puts().at(-1)?.integrations as string[] | undefined)?.slice().sort()).toEqual(["jira", "notion"]);
await expect.poll(() => puts().at(-1)).toEqual({ apps: { jira: "coderhelm" } });
await expect(jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" })).toHaveAttribute("aria-pressed", "true");
await page.getByTestId("hybrid-integration-notion").getByRole("button", { name: "Use my own app (fully private)" }).click();
await expect.poll(() => puts().at(-1)?.integrations).toEqual(["jira"]);
await expect.poll(() => puts().at(-1)).toEqual({ apps: { notion: "own" } });
await expect(page.getByTestId("hybrid-integration-notion").getByRole("button", { name: "Use my own app (fully private)" })).toHaveAttribute("aria-pressed", "true");
await expect(page.getByTestId("hybrid-integration-confluence")).toHaveAttribute("data-mode", "hosted");
await expect(page.getByTestId("hybrid-integration-slack_notifications")).toContainText("Works from your install, no app needed");
await expect(page.getByTestId("hybrid-integration-mcp_apps")).toContainText("Works from your install, no app needed");
Expand Down Expand Up @@ -381,7 +401,7 @@ test("integration pages: the app choice saves the same settings, and links to Sy
await page.goto("/settings/integrations/jira/");
const jira = page.getByTestId("hybrid-app-choice");
await jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" }).click();
await expect.poll(() => (puts().at(-1)?.integrations as string[] | undefined)?.slice().sort()).toEqual(["jira", "notion"]);
await expect.poll(() => puts().at(-1)).toEqual({ apps: { jira: "coderhelm" } });
});

test("integration pages before registering point to Settings, System, Hybrid", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/hybrid-app-choice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Link from "next/link";
import { useState } from "react";
import { HYBRID_HREF, canUseCoderhelm, hostedIntegrations, useHybrid } from "@/lib/hybrid";
import { HYBRID_HREF, appChoice, canUseCoderhelm, useHybrid } from "@/lib/hybrid";
import { Segmented } from "./segmented";
import { useToast } from "./toast";
import { linkButton } from "./ui";
Expand Down Expand Up @@ -44,7 +44,7 @@ export function HybridAppChoice({ id, name, className = "" }: { id: string; name
if (next === value || busy) return;
setBusy(true);
try {
await hybrid.save(id === "github" ? { github_mode: next === "coderhelm" ? "hosted" : "own" } : { integrations: hostedIntegrations(s, id, next === "coderhelm") });
await hybrid.save(id === "github" ? { github_mode: next === "coderhelm" ? "hosted" : "own" } : appChoice(id, next === "coderhelm"));
toast(next === "coderhelm" ? `${name} now uses Coderhelm's app` : `${name} now uses your own app`);
} catch (e) {
toast(e instanceof Error ? e.message : "Could not save", "error");
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/hybrid-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Link from "next/link";
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { api, type HybridCheck, type HybridGithubLink, type HybridIntegration, type HybridNameCheck, type HybridStatus } from "@/lib/api";
import { GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, cleanName, hostedIntegrations, useHybrid, type HybridState } from "@/lib/hybrid";
import { GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, appChoice, cleanName, useHybrid, type HybridState } from "@/lib/hybrid";
import { Callout } from "./callout";
import { CopyButton } from "./copy-button";
import { useConfirm } from "./confirm-dialog";
Expand Down Expand Up @@ -657,7 +657,7 @@ function IntegrationItem({ i, hybrid, s }: { i: HybridIntegration } & RowProps)
value={value}
disabled={!!busy}
onChange={(v) =>
void act("set", () => hybrid.save({ integrations: hostedIntegrations(s, i.id, v === "coderhelm") }), v === "coderhelm" ? `${i.name} uses Coderhelm's app` : `${i.name} uses your own app`)
void act("set", () => hybrid.save(appChoice(i.id, v === "coderhelm")), v === "coderhelm" ? `${i.name} uses Coderhelm's app` : `${i.name} uses your own app`)
}
options={[
{ value: "coderhelm", label: "Use Coderhelm's app (easiest)" },
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4626,8 +4626,10 @@ export interface HybridNameCheck {

export interface HybridSettingsPatch {
github_mode?: "own" | "hosted";
/** The hosted-app integrations among jira, notion, confluence, google_drive (github follows github_mode). */
/** The hosted-app integrations among jira, notion, confluence, google_drive (github follows github_mode). Older installs; newer ones take `apps`. */
integrations?: string[];
/** Other apps, per tool (jira, notion, confluence, google_drive): only the tools named change. A tool nobody chose uses Coderhelm's app. */
apps?: Record<string, "coderhelm" | "own">;
sharing?: { enabled: boolean; payloads: boolean };
/** Settings, Integrations, Jira: link a hosted team's Jira site through Coderhelm. */
jira_link?: boolean;
Expand Down
9 changes: 3 additions & 6 deletions dashboard/src/lib/hybrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ export function canUseCoderhelm(i: HybridIntegration | undefined): boolean {
return i?.mode === "hosted" && i.offered !== false;
}

/** The hosted-app integrations after switching `id` on or off (GitHub follows its own mode). */
export function hostedIntegrations(status: HybridStatus, id: string, useCoderhelm: boolean): string[] {
const now = new Set(status.integrations.filter((i) => i.id !== "github" && canUseCoderhelm(i) && i.uses_coderhelm).map((i) => i.id));
if (useCoderhelm) now.add(id);
else now.delete(id);
return [...now];
/** The settings change for one Other apps tool (GitHub follows its own mode). Only that tool changes. */
export function appChoice(id: string, useCoderhelm: boolean): HybridSettingsPatch {
return { apps: { [id]: useCoderhelm ? "coderhelm" : "own" } };
}
24 changes: 20 additions & 4 deletions docs/components/install/wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import {
HYBRID_GITHUB_OUTCOMES,
NAME_ZONE,
SETUPS,
ALL_HOSTED_APPS,
ALL_OWN_APPS,
OTHER_APPS,
appsBody,
wantsHybrid,
STEP_TIME,
type Setup,
cleanName,
Expand Down Expand Up @@ -877,7 +882,7 @@ export function InstallWizard() {
const [hyb, setHyb] = useState<{ error: { title: string; fix: string } | null; claimRefused: boolean; settingsSent: boolean; lastTry: number; busy: boolean }>({ error: null, claimRefused: false, settingsSent: false, lastTry: 0, busy: false });
const [newName, setNewName] = useState('');
const [hybridOutcome, setHybridOutcome] = useState<string | null>(null);
const hybridWanted = !!s && (s.domainChoice === 'coderhelm' || s.githubChoice === 'hosted' || s.jiraChoice === 'hosted' || s.emailTransport === 'coderhelm');
const hybridWanted = !!s && wantsHybrid(s);
useEffect(() => {
// A closed install (someone signed up) answers no setup calls: nothing to send.
if (!s || !hybridWanted || !s.url || !setup || setup.closed || !s.setupToken || hyb.busy) return;
Expand All @@ -892,7 +897,8 @@ export function InstallWizard() {
path = '/settings';
// CoderHelm's Jira app: Link through CoderHelm turned on now, so the
// install reports hybrid_jira and the Jira step can follow the link.
body = { ...body, github_mode: s.githubChoice, sharing: { enabled: s.sharing, payloads: false }, ...(s.jiraChoice === 'hosted' ? { jira_link: true } : {}) };
// Other apps: each tool's choice, applied as the install registers.
body = { ...body, github_mode: s.githubChoice, sharing: { enabled: s.sharing, payloads: false }, apps: appsBody(s), ...(s.jiraChoice === 'hosted' ? { jira_link: true } : {}) };
} else if (s.domainChoice === 'coderhelm' && !nm && !hyb.claimRefused && cleanName(s.coderhelmName)) {
path = '/name';
body = { ...body, name: cleanName(s.coderhelmName) };
Expand Down Expand Up @@ -993,8 +999,8 @@ export function InstallWizard() {
const hybrid = s.setup === 'hybrid';
const pickSetup = (id: Setup) =>
update(id === 'hybrid'
? { setup: 'hybrid', domainChoice: 'coderhelm', githubChoice: 'hosted', jiraChoice: 'hosted' }
: { setup: 'private', domainChoice: s.domainChoice === 'coderhelm' ? 'aws' : s.domainChoice, githubChoice: 'own', jiraChoice: 'own' });
? { setup: 'hybrid', domainChoice: 'coderhelm', githubChoice: 'hosted', jiraChoice: 'hosted', appChoices: { ...ALL_HOSTED_APPS } }
: { setup: 'private', domainChoice: s.domainChoice === 'coderhelm' ? 'aws' : s.domainChoice, githubChoice: 'own', jiraChoice: 'own', appChoices: { ...ALL_OWN_APPS } });
screen = (
<section data-testid="screen-start">
<Heading title="Install CoderHelm in your AWS account" lead="About 25 minutes, mostly waiting. You press a few buttons; this page does the rest and checks every step." />
Expand Down Expand Up @@ -1080,6 +1086,16 @@ export function InstallWizard() {
title="Use CoderHelm’s Jira app"
help="Link your Jira site through CoderHelm’s Jira app instead of setting up your own. Events come through CoderHelm, checked and re-signed; your install never holds the app’s secret and calls Jira through CoderHelm. Needs a team on app.coderhelm.com that runs the Jira app on your site."
/>
{OTHER_APPS.map((a) => (
<Toggle
key={a.id}
checked={(s.appChoices ?? ALL_HOSTED_APPS)[a.id] !== 'own'}
onChange={(v) => update({ appChoices: { ...ALL_HOSTED_APPS, ...s.appChoices, [a.id]: v ? 'hosted' : 'own' } })}
testId={`hosted-${a.id}`}
title={a.title}
help={`${a.help} Nothing passes through CoderHelm until someone connects it.`}
/>
))}
<Toggle
checked={s.sharing}
onChange={(v) => update({ sharing: v })}
Expand Down
36 changes: 33 additions & 3 deletions docs/e2e/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ test('more options: domain, sender, sign-up and updates go to AWS; a bad hostnam
await expect(page.getByLabel('Company email domain')).toHaveCount(0);
await page.getByTestId('require-two-factor').check();
await page.getByTestId('auto-update').check();
await page.getByLabel('Day').selectOption('daily');
await page.getByLabel('Hour').selectOption('02:00');
await page.getByLabel('Day', { exact: true }).selectOption('daily');
await page.getByLabel('Hour', { exact: true }).selectOption('02:00');
await page.getByLabel('Time zone').fill('Europe/Berlin');
await pickModels(page);
await page.getByTestId('launch').click();
Expand Down Expand Up @@ -958,6 +958,8 @@ test('hybrid: registers, sends the choices and claims the name by itself, then f
await expect.poll(() => h.calls.map((c) => c.path)).toContain('/name');
const settings = h.calls.find((c) => c.path === '/settings')!;
expect(settings.body).toMatchObject({ github_mode: 'hosted', sharing: { enabled: false, payloads: false } });
// Every Other apps tool on CoderHelm's app, as the guide defaults them.
expect(settings.body.apps).toEqual({ jira: 'coderhelm', notion: 'coderhelm', confluence: 'coderhelm', google_drive: 'coderhelm' });
expect(h.calls.find((c) => c.path === '/name')!.body.name).toBe('example-co');
m.setup = withHybrid(setupDoc(HOSTED_GH), REG_OK, nameCheck('wait', 'cert_pending'));
await expect(page.getByTestId('address-status')).toContainText('Waiting for AWS to issue the certificate');
Expand Down Expand Up @@ -1140,7 +1142,7 @@ test('hybrid Jira: the toggle sits next to GitHub, on by default, can be turned
await page.locator('[data-setup="hybrid"]').click();
const options = page.getByTestId('hybrid-options');
await expect(jira).toBeChecked();
await expect(options.locator('label')).toHaveText([/Use CoderHelm’s GitHub App/, /Use CoderHelm’s Jira app/, /Share delivery data/]);
await expect(options.locator('label')).toHaveText([/Use CoderHelm’s GitHub App/, /Use CoderHelm’s Jira app/, /Use CoderHelm’s Notion app/, /Use CoderHelm’s Confluence app/, /Use CoderHelm’s Google Drive app/, /Share delivery data/]);
await expect(options.locator('label').nth(1)).toContainText('your install never holds the app’s secret');
await expect(options.locator('label').nth(1)).toContainText('Events come through CoderHelm, checked and re-signed');
// The whole row is the control, with the hand cursor.
Expand All @@ -1165,6 +1167,34 @@ test('hybrid Jira: the toggle sits next to GitHub, on by default, can be turned
await expect(page.getByTestId('hosted-jira')).toBeChecked();
});

test('hybrid other apps: Notion, Confluence and Google Drive are on by default, each says what passes through CoderHelm, and fully private turns them off', async ({ page }) => {
await mock(page, newMock());
await mockHybrid(page, newHybrid());
await page.goto('/self-host/install/');
const options = page.getByTestId('hybrid-options');
for (const id of ['notion', 'confluence', 'google_drive']) await expect(page.getByTestId(`hosted-${id}`)).toBeChecked();
const notion = options.locator('label', { hasText: 'Use CoderHelm’s Notion app' });
await expect(notion).toContainText('CoderHelm keeps the sign-in (encrypted) and hands your install an access token when it syncs.');
await expect(notion).toContainText('Nothing passes through CoderHelm until someone connects it.');
await expect(options.locator('label', { hasText: 'Use CoderHelm’s Google Drive app' })).toContainText('read-only Drive access');
await notion.click();
await expect(page.getByTestId('hosted-notion')).not.toBeChecked();
await expect(page.getByTestId('hosted-confluence')).toBeChecked();
// Fully private hides them; hybrid again brings every one back on.
await page.locator('[data-setup="private"]').click();
await expect(page.getByTestId('hosted-notion')).toHaveCount(0);
await page.locator('[data-setup="hybrid"]').click();
for (const id of ['notion', 'confluence', 'google_drive']) await expect(page.getByTestId(`hosted-${id}`)).toBeChecked();
});

test('hybrid other apps: the choices are applied to the install as it registers, a tool turned off as its own app', async ({ page }) => {
const m = newMock({ setup: withHybrid(setupDoc(NO_APP), REG_OK) });
const h = newHybrid();
await mockHybrid(page, h);
await seeded(page, m, { ...JIRA_STATE, jiraChoice: 'own', appChoices: { notion: 'hosted', confluence: 'own', google_drive: 'hosted' } });
await expect.poll(() => h.calls.find((c) => c.path === '/settings')?.body.apps).toEqual({ jira: 'own', notion: 'coderhelm', confluence: 'own', google_drive: 'coderhelm' });
});

test('hybrid Jira: the guide turns on Link through CoderHelm with the setup key, and only when chosen', async ({ page, browser }) => {
const m = newMock({ setup: withHybrid(setupDoc(NO_APP), REG_OK) });
const h = newHybrid();
Expand Down
Loading
Loading