From d5cdf43435cd35b9b09641e07d403db0dc6a2351 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 24 Nov 2026 13:57:23 -0500 Subject: [PATCH 1/2] Alert channel takes alerts only; an updates channel for the rest Settings, Alerts: the team alert channel says it gets alerts only, with optional ticks for requests for a person and updates, and a second team channel takes updates and requests for a person. --- dashboard/src/app/settings/alerts/page.tsx | 165 ++++++++++++++++++-- dashboard/src/lib/api.ts | 23 ++- docs/content/docs/concepts/aws-accounts.mdx | 2 +- 3 files changed, 173 insertions(+), 17 deletions(-) diff --git a/dashboard/src/app/settings/alerts/page.tsx b/dashboard/src/app/settings/alerts/page.tsx index 8f6dce0b..51eb3d51 100644 --- a/dashboard/src/app/settings/alerts/page.tsx +++ b/dashboard/src/app/settings/alerts/page.tsx @@ -9,6 +9,7 @@ import { type AlertBudget, type AlertEvent, type AlertNotifySettings, + type NotifyKind, type AlertRepeat, type AlertRoute, type AlertRule, @@ -670,7 +671,38 @@ function fmtTokens(n: number): string { return String(n); } -type AlertForm = { enabled: boolean; budget: string }; +type AlertForm = { + enabled: boolean; + budget: string; + /** What the alert channel takes beyond alerts: "", "action", "update" or "action,update". */ + alertExtra: string; + updatesEnabled: boolean; +}; + +const EXTRA_KINDS: { kind: NotifyKind; label: string; help: string }[] = [ + { + kind: "action", + label: "Requests for a person", + help: "A merge conflict that needs a call, a sign-in to renew, a plugin to approve.", + }, + { + kind: "update", + label: "Updates", + help: "Fix pull requests opened or merged, new log findings, security findings below critical.", + }, +]; + +/** The alert channel's kinds beyond alerts, as the form keeps them. */ +function extraOf(kinds?: NotifyKind[]): string { + return EXTRA_KINDS.filter((k) => kinds?.includes(k.kind)) + .map((k) => k.kind) + .join(","); +} + +/** The alert channel always takes alerts; the rest is the team's choice. */ +function alertKinds(extra: string): NotifyKind[] { + return ["alert", ...(extra.split(",").filter(Boolean) as NotifyKind[])]; +} /** A budget typed as "2M" and saved as 2000000 are the same; text that isn't a number is a change. */ const sameAlertField = (a: unknown, b: unknown, key: keyof AlertForm) => { @@ -681,20 +713,26 @@ const sameAlertField = (a: unknown, b: unknown, key: keyof AlertForm) => { }; /** - * The team channel (Teams, Slack or both) and the daily token budget for - * alert runs: two settings rows saved by one bar. Each still saves through - * its own request, as before. + * The team's two channels (alerts, and updates with requests for a person) + * and the daily token budget for alert runs: settings rows saved by one bar. + * Each still saves through its own request. */ function AlertSettings() { const { toast } = useToast(); const [notify, setNotify] = useState(null); const [notifyError, setNotifyError] = useState(false); + const [updates, setUpdates] = useState(null); + const [updatesError, setUpdatesError] = useState(false); const [budget, setBudget] = useState(null); const [budgetError, setBudgetError] = useState(false); const [draft, setDraft] = useState(draftFrom(NO_WEBHOOKS)); + const [updatesDraft, setUpdatesDraft] = useState(draftFrom(NO_WEBHOOKS)); const [saving, setSaving] = useState(false); const [problem, setProblem] = useState(null); - const form = useDirtyForm({ enabled: false, budget: "" }, { same: sameAlertField, disabled: !notify && !budget }); + const form = useDirtyForm( + { enabled: false, budget: "", alertExtra: "", updatesEnabled: false }, + { same: sameAlertField, disabled: !notify && !budget && !updates }, + ); const { reset } = form; /** Re-reads the saved channels (they come back as hints, never as addresses). */ @@ -706,22 +744,35 @@ function AlertSettings() { setDraft(draftFrom(s.webhooks)); }) .catch(() => {}); + api + .getUpdatesNotify() + .then((s) => { + setUpdates(s); + setUpdatesDraft(draftFrom(s.webhooks)); + }) + .catch(() => {}); }, []); useEffect(() => { let live = true; - Promise.allSettled([api.getAlertNotify(), api.getAlertBudget()]).then(([n, b]) => { + Promise.allSettled([api.getAlertNotify(), api.getAlertBudget(), api.getUpdatesNotify()]).then(([n, b, u]) => { if (!live) return; - const next: AlertForm = { enabled: false, budget: "" }; + const next: AlertForm = { enabled: false, budget: "", alertExtra: "", updatesEnabled: false }; if (n.status === "fulfilled") { setNotify(n.value); setDraft(draftFrom(n.value.webhooks)); next.enabled = n.value.enabled; + next.alertExtra = extraOf(n.value.kinds); } else setNotifyError(true); if (b.status === "fulfilled") { setBudget(b.value); next.budget = fmtTokens(b.value.daily_tokens); } else setBudgetError(true); + if (u.status === "fulfilled") { + setUpdates(u.value); + setUpdatesDraft(draftFrom(u.value.webhooks)); + next.updatesEnabled = u.value.enabled; + } else setUpdatesError(true); reset(next); }); return () => { @@ -730,19 +781,29 @@ function AlertSettings() { }, [reset]); const channelsDirty = !!notify && draftDirty(draft, notify.webhooks); - const notifyDirty = !!notify && (form.isDirty("enabled") || channelsDirty); + const kindsDirty = !!notify && form.isDirty("alertExtra"); + const notifyDirty = !!notify && (form.isDirty("enabled") || channelsDirty || kindsDirty); + const updatesChannelsDirty = !!updates && draftDirty(updatesDraft, updates.webhooks); + const updatesDirty = !!updates && (form.isDirty("updatesEnabled") || updatesChannelsDirty); const budgetDirty = !!budget && form.isDirty("budget"); - const count = (notify && form.isDirty("enabled") ? 1 : 0) + (channelsDirty ? 1 : 0) + (budgetDirty ? 1 : 0); + const count = + (notify && form.isDirty("enabled") ? 1 : 0) + + (channelsDirty ? 1 : 0) + + (kindsDirty ? 1 : 0) + + (updates && form.isDirty("updatesEnabled") ? 1 : 0) + + (updatesChannelsDirty ? 1 : 0) + + (budgetDirty ? 1 : 0); const n = parseTokens(form.values.budget); const budgetValid = n !== null && n <= 100_000_000; const channelsValid = draftValid(draft, notify?.webhooks, form.values.enabled); + const updatesValid = draftValid(updatesDraft, updates?.webhooks, form.values.updatesEnabled); const save = async () => { if (budgetDirty && !budgetValid) { setProblem("Enter a daily budget such as 500k or 2M, up to 100M."); return; } - if (notifyDirty && !channelsValid) { + if ((notifyDirty && !channelsValid) || (updatesDirty && !updatesValid)) { setProblem("Check the webhook addresses. A channel that is ticked needs a working address."); return; } @@ -751,11 +812,25 @@ function AlertSettings() { const failed: string[] = []; if (notifyDirty && notify) { try { - await api.saveAlertNotify({ enabled: form.values.enabled, ...channelsPayload(draft, notify.webhooks) }); + await api.saveAlertNotify({ + enabled: form.values.enabled, + kinds: alertKinds(form.values.alertExtra), + ...channelsPayload(draft, notify.webhooks), + }); } catch { failed.push("the team channel (check the webhook address)"); } } + if (updatesDirty && updates) { + try { + await api.saveUpdatesNotify({ + enabled: form.values.updatesEnabled, + ...channelsPayload(updatesDraft, updates.webhooks), + }); + } catch { + failed.push("the updates channel (check the webhook address)"); + } + } if (budgetDirty && n !== null) { try { await api.saveAlertBudget(n); @@ -765,8 +840,12 @@ function AlertSettings() { } } const edited = form.values; + const teamSaved = notifyDirty && !failed.some((f) => f.startsWith("the team")); + const updatesSaved = updatesDirty && !failed.some((f) => f.startsWith("the updates")); const next: AlertForm = { - enabled: notifyDirty && !failed.some((f) => f.startsWith("the team")) ? edited.enabled : form.saved.enabled, + enabled: teamSaved ? edited.enabled : form.saved.enabled, + alertExtra: teamSaved ? edited.alertExtra : form.saved.alertExtra, + updatesEnabled: updatesSaved ? edited.updatesEnabled : form.saved.updatesEnabled, budget: budgetDirty && !failed.includes("the budget") && n !== null ? fmtTokens(n) : form.saved.budget, }; reset(next); @@ -777,27 +856,34 @@ function AlertSettings() { } else { toast("Alert settings saved"); } - if (notifyDirty && !failed.some((f) => f.startsWith("the team"))) reloadChannels(); + if (teamSaved || updatesSaved) reloadChannels(); setSaving(false); }; const discard = () => { form.discard(); if (notify) setDraft(draftFrom(notify.webhooks)); + if (updates) setUpdatesDraft(draftFrom(updates.webhooks)); setProblem(null); }; + const extra = form.values.alertExtra.split(",").filter(Boolean); + const toggleExtra = (kind: NotifyKind, on: boolean) => { + const next = EXTRA_KINDS.map((k) => k.kind).filter((k) => (k === kind ? on : extra.includes(k))); + form.set("alertExtra", next.join(",")); + }; + const used = budget ? Math.min(100, (budget.used_24h_tokens / Math.max(budget.daily_tokens, 1)) * 100) : 0; return ( <> - + ( )} + {notify && ( +
+ Also post here (off by default) + {EXTRA_KINDS.map((k) => ( + + ))} +
+ )} +
+ ( + form.set("updatesEnabled", on)} + labelledBy={ids.labelId} + describedBy={ids.helpId} + disabled={!updates} + /> + )} + > + {updatesError ? ( +

Could not load the updates channel. Reload the page to try again.

+ ) : ( + + )}
request("/api/alert-notify"), - saveAlertNotify: (s: { enabled: boolean } & ChannelsInput) => + /** Left out, `kinds` keeps what the channel takes. */ + saveAlertNotify: (s: { enabled: boolean; kinds?: NotifyKind[] } & ChannelsInput) => request<{ ok: boolean }>("/api/alert-notify", { method: "PUT", body: JSON.stringify(s), }), + /** The team channel for updates and requests for a person. */ + getUpdatesNotify: () => request("/api/updates-notify"), + saveUpdatesNotify: (s: { enabled: boolean; kinds?: NotifyKind[] } & ChannelsInput) => + request<{ ok: boolean }>("/api/updates-notify", { + method: "PUT", + body: JSON.stringify(s), + }), /** Post a sample message to one channel: a URL being typed, or the destination's saved one. */ testNotify: (t: NotifyDestination & { channel: ChatChannel; url?: string }) => request<{ ok: boolean; error?: string }>("/api/notify/test", { @@ -3576,9 +3584,21 @@ export interface TopicAlarm { metric?: string | null; } +/** + * What a chat message is: an alert (a production alarm or incident, a failed + * deploy, a critical security finding), action (a person has to do + * something Coderhelm can't) or an update (a fix PR opened or merged, new + * findings). Each team channel takes the kinds it lists. + */ +export type NotifyKind = "alert" | "action" | "update"; + +/** A team channel: the alert channel or the updates channel. */ export interface AlertNotifySettings { enabled: boolean; webhooks: WebhooksView; + /** The kinds it takes. Saved before kinds existed: alerts only for the alert channel. */ + kinds?: NotifyKind[]; + default_kinds?: NotifyKind[]; } /** A chat channel Coderhelm posts to. */ @@ -3604,6 +3624,7 @@ export interface ChannelsInput { /** Whose saved webhook a test message uses (and which sample it posts). */ export type NotifyDestination = | { destination: "alerts" } + | { destination: "updates" } | { destination: "route"; topic_arn: string } | { destination: "recommendations" } | { destination: "reviewer"; repo: string }; diff --git a/docs/content/docs/concepts/aws-accounts.mdx b/docs/content/docs/concepts/aws-accounts.mdx index 543e6ffe..ad0125d5 100644 --- a/docs/content/docs/concepts/aws-accounts.mdx +++ b/docs/content/docs/concepts/aws-accounts.mdx @@ -77,7 +77,7 @@ Once on, the card is one line, for example "On: critical findings get a fix PR a ### Where fix PRs are posted -Fix PRs from findings, started automatically or by hand, post where new findings post. Until someone chooses otherwise, that is the team's alert channel, the same Teams or Slack channel production alerts post to (**Settings**, then **Alerts**, **Team channel and budget**). The automatic fix PR settings say where they post, or "Not posting anywhere" with a link to set up an alerts channel when none is set. Under **Post new findings to chat** you can instead pick channels of their own, or turn posting off; that choice stands. +Fix PRs from findings, started automatically or by hand, post where new findings post. Until someone chooses otherwise, that is the team's updates channel (**Settings**, then **Alerts**, **Team channels and budget**). Findings and fix PRs are updates, not alerts: they never post to the team's alert channel unless it is ticked to take updates too. That channel takes only alerts by default: production alarms and their follow ups, log incidents and critical security findings. The automatic fix PR settings say where they post, or "Not posting anywhere" with a link to set up an alerts channel when none is set. Under **Post new findings to chat** you can instead pick channels of their own, or turn posting off; that choice stands. Each fix PR posts one card: the finding's title and severity, its log group, how many lines and when it was first and last seen, the PR and its repository, one line on what it changes, and links to the PR and the finding. A finding's card posts once, even when its run is retried. When the PR merges or is closed, one follow-up card posts in the same channel and names the card it follows; Teams and Slack webhooks can't reply in a thread or edit a posted card. From 55b29af43e03de593a1bbc7845817edd6d46ed50 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 24 Nov 2026 15:22:33 -0500 Subject: [PATCH 2/2] Send kinds only when changed; e2e mocks and a test for the updates channel --- dashboard/e2e/integrations.spec.ts | 21 +++++++++++++++++++++ dashboard/e2e/settings-mock.ts | 4 ++++ dashboard/e2e/settings.spec.ts | 1 + dashboard/e2e/wide-data/review.ts | 1 + dashboard/src/app/settings/alerts/page.tsx | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dashboard/e2e/integrations.spec.ts b/dashboard/e2e/integrations.spec.ts index da820fae..1ac73551 100644 --- a/dashboard/e2e/integrations.spec.ts +++ b/dashboard/e2e/integrations.spec.ts @@ -202,6 +202,8 @@ async function mockApi(page: Page, init: Partial = {}): Promise { await shot(page, "alerts-team-channel-both"); }); + test("the alert channel takes alerts only unless ticked; updates and requests for a person have their own channel", async ({ page }) => { + const db = await mockApi(page); + await page.goto("/settings/alerts"); + const kinds = page.getByTestId("team-channel-kinds"); + await expect(kinds.getByRole("checkbox", { name: /Requests for a person/ })).not.toBeChecked(); + await expect(kinds.getByRole("checkbox", { name: /Updates/ })).not.toBeChecked(); + await kinds.getByRole("checkbox", { name: /Requests for a person/ }).check(); + const updates = page.getByTestId("updates-channel-row"); + await updates.getByRole("switch").click(); + const picker = page.getByTestId("updates-channels"); + await picker.getByRole("checkbox", { name: "Slack" }).check(); + await picker.getByRole("textbox", { name: "Slack webhook address" }).fill(SLACK_HOOK); + const bar = page.getByRole("region", { name: "Save changes" }); + await bar.getByRole("button", { name: "Save changes" }).click(); + await expect(page.getByText("Alert settings saved")).toBeVisible(); + expect(callsTo(db, "PUT", /\/api\/alert-notify$/).at(-1)!.body).toEqual({ enabled: true, kinds: ["alert", "action"] }); + expect(callsTo(db, "PUT", /\/api\/updates-notify$/).at(-1)!.body).toEqual({ enabled: true, slack_webhook: { url: SLACK_HOOK } }); + }); + test("a route can post to its own Slack channel and test it", async ({ page }) => { const db = await mockApi(page); await page.goto("/settings/alerts"); diff --git a/dashboard/e2e/settings-mock.ts b/dashboard/e2e/settings-mock.ts index 3d691cfa..fef9a215 100644 --- a/dashboard/e2e/settings-mock.ts +++ b/dashboard/e2e/settings-mock.ts @@ -223,6 +223,10 @@ export async function mockApi(page: Page, init: Partial = {}): Promise< return at("admin") ? json(r, { enabled: true, webhooks: { teams: { set: true, hint: TEAMS_HINT }, slack: { set: false, hint: "" } } }) : json(r, { error: "Forbidden" }, 403); } if (p === "/api/alert-notify" && method === "PUT") return json(r, { ok: true }); + if (p === "/api/updates-notify" && method === "GET") { + return at("admin") ? json(r, { enabled: false, kinds: ["action", "update"], webhooks: { teams: { set: false, hint: "" }, slack: { set: false, hint: "" } } }) : json(r, { error: "Forbidden" }, 403); + } + if (p === "/api/updates-notify" && method === "PUT") return json(r, { ok: true }); if (p === "/api/notify/test") return json(r, { ok: true }); if (p === "/api/alert-budget" && method === "GET") { return at("admin") ? json(r, { daily_tokens: 2_000_000, used_24h_tokens: 600_000, open_runs: 1, open_run_reserve_tokens: 50_000, max_runs_per_rule_per_day: 5 }) : json(r, { error: "Forbidden" }, 403); diff --git a/dashboard/e2e/settings.spec.ts b/dashboard/e2e/settings.spec.ts index 1ee24d08..6ff33f96 100644 --- a/dashboard/e2e/settings.spec.ts +++ b/dashboard/e2e/settings.spec.ts @@ -95,6 +95,7 @@ async function mockApi(page: Page, init: Partial = {}): Promise { if (path === "/api/alert-routes") return ALERT_ROUTES; if (path === "/api/alert-routes/alarms") return { alarms: [{ name: "production-payments-reconciliation-service-5xx-rate-above-threshold", state: "ALARM" }], messages: [] }; if (path === "/api/alert-budget") return { daily_tokens: 2_000_000, used_24h_tokens: 600_000, open_runs: 1, open_run_reserve_tokens: 50_000, max_runs_per_rule_per_day: 5 }; + if (path === "/api/updates-notify") return { enabled: false, kinds: ["action", "update"], webhooks: { teams: { set: false, hint: "" }, slack: { set: false, hint: "" } } }; if (path === "/api/alert-notify") return { enabled: true, webhooks: { teams: { set: true, hint: "example.environment.api.powerplatform.com …ab12" }, slack: { set: false, hint: "" } } }; // Support diff --git a/dashboard/src/app/settings/alerts/page.tsx b/dashboard/src/app/settings/alerts/page.tsx index 51eb3d51..be28cd60 100644 --- a/dashboard/src/app/settings/alerts/page.tsx +++ b/dashboard/src/app/settings/alerts/page.tsx @@ -814,7 +814,7 @@ function AlertSettings() { try { await api.saveAlertNotify({ enabled: form.values.enabled, - kinds: alertKinds(form.values.alertExtra), + ...(kindsDirty ? { kinds: alertKinds(form.values.alertExtra) } : {}), ...channelsPayload(draft, notify.webhooks), }); } catch {