From 4f5522a7e66ec8f8264545596599dba229780d59 Mon Sep 17 00:00:00 2001
From: Nam Rodriguez
Date: Fri, 6 Nov 2026 11:52:49 -0500
Subject: [PATCH 1/2] Settings, System: one press of Update does the whole job
Pressing Update while the release check ran showed a red error toast,
a version read from before a press brought the Update button back, a
double click could send two requests, and a newer release could take
over the card as a second Update button while one ran. Now a press
shows progress at once and can't be repeated; a press recorded while
the check runs shows Checking with who pressed it; a read older than
the press shows Starting until the updater shows the update; a newer
release is only mentioned while one runs and offered once it ends.
Error toasts are kept for real failures and say what to do; 409 states
show in the card. Polling no longer drops unsaved settings, an old
release list no longer reads as up to date, and the update sections
come first on the page.
---
dashboard/e2e/selfhost.spec.ts | 13 +-
dashboard/e2e/update-press.spec.ts | 308 +++++++++++++++++++++
dashboard/e2e/update-state-derive.spec.ts | 57 +++-
dashboard/src/app/settings/system/page.tsx | 195 +++++++++----
dashboard/src/components/native-update.tsx | 28 +-
dashboard/src/lib/api.ts | 43 ++-
dashboard/src/lib/update-state.ts | 99 ++++++-
7 files changed, 672 insertions(+), 71 deletions(-)
create mode 100644 dashboard/e2e/update-press.spec.ts
diff --git a/dashboard/e2e/selfhost.spec.ts b/dashboard/e2e/selfhost.spec.ts
index 41bd0258..638e99ff 100644
--- a/dashboard/e2e/selfhost.spec.ts
+++ b/dashboard/e2e/selfhost.spec.ts
@@ -298,11 +298,6 @@ for (const [name, viewport] of [["desktop", { width: 1280, height: 800 }], ["pho
await expect(page.getByTestId("update-history")).toContainText("health check failed after deploying v1.1.5");
await expect(page.getByTestId("update-history")).toContainText("auto-update window");
- await page.getByRole("button", { name: "Update to v2.0.0" }).click();
- await expect.poll(() => systemCalls.map((c) => c.path)).toContain("/api/system/update");
- // No version: the updater reads GitHub first and installs the newest release at that moment.
- expect(systemCalls.find((c) => c.path === "/api/system/update")!.body).toEqual({});
-
await page.getByRole("switch", { name: "Install updates automatically" }).click();
await pickOption(page.getByRole("combobox", { name: "Day" }), "sat");
await pickOption(page.getByRole("combobox", { name: "Hour" }), "22");
@@ -312,6 +307,14 @@ for (const [name, viewport] of [["desktop", { width: 1280, height: 800 }], ["pho
await page.getByRole("button", { name: "Roll back to the previous version" }).click();
await expect.poll(() => systemCalls.map((c) => c.path)).toContain("/api/system/rollback");
+ await page.getByRole("button", { name: "Update to v2.0.0" }).click();
+ await expect.poll(() => systemCalls.map((c) => c.path)).toContain("/api/system/update");
+ // No version: the updater reads GitHub first and installs the newest release at that moment.
+ expect(systemCalls.find((c) => c.path === "/api/system/update")!.body).toEqual({});
+ // Pressed: the card shows it starting at once, and the button isn't offered again.
+ await expect(status).toHaveAttribute("data-state", "starting");
+ await expect(page.getByRole("button", { name: /^Update to/ })).toHaveCount(0);
+
const width = await page.evaluate(() => document.documentElement.scrollWidth);
expect(width).toBeLessThanOrEqual(viewport.width);
await expect(page.getByTestId("install-version").first()).toHaveCount(name === "desktop" ? 1 : await page.getByTestId("install-version").count());
diff --git a/dashboard/e2e/update-press.spec.ts b/dashboard/e2e/update-press.spec.ts
new file mode 100644
index 00000000..610dd81f
--- /dev/null
+++ b/dashboard/e2e/update-press.spec.ts
@@ -0,0 +1,308 @@
+import { expect, test, type Page, type Route } from "@playwright/test";
+
+// Settings, System: one press of Update does the whole job. The button shows
+// progress at once and can't be pressed twice; pressing it while the
+// release check runs is recorded, never an error; while an update runs a
+// newer release is only mentioned, never a second Update button; error
+// toasts are kept for real failures and say what to do.
+
+const NOW = Date.now();
+const ago = (min: number) => new Date(NOW - min * 60_000).toISOString();
+const unix = (min: number) => Math.floor((NOW - min * 60_000) / 1000);
+const pass = (key: string, label: string) => ({ key, group: "Install", label, status: "pass", detail: `${label}: fine.` });
+const CHECKS = [pass("url", "Web address answers"), pass("github_app", "GitHub accepts the app's keys"), pass("email_identity", "Email sender verified"), pass("model", "Claude answers a test call")];
+const NOTES = "## What changed\n\n- Faster reviews on large pull requests (#812)\n- Jira links keep their labels (#815)";
+const rel = (v: string, extra: Record = {}) => ({ version: v, notes: NOTES, published_at: "2026-11-05T16:00:00Z", url: `https://example.org/releases/${v}`, breaking: false, ...extra });
+const SETTINGS = { auto: false, channel: "stable", day: "sun", hour: 3, timezone: "UTC", majors: "ask", digest: "weekly" };
+const OK_HISTORY = [{ id: "UPDATE#1", version: "v0.8.45", from_version: "v0.8.44", actor: "auto", mode: "update", status: "succeeded", started_at: "2026-11-02T03:00:00Z", finished_at: "2026-11-02T03:14:00Z" }];
+const CS_LINK = "https://us-east-1.console.aws.amazon.com/cloudformation/home#/stacks/changesets/changes?stackId=x&changeSetId=y";
+const PENDING = (v: string, min = 1) => ({ version: v, checked_at: ago(min), started_at: ago(min), ok: false, pending: true, results: [], progress: { step: "signature", started_at: ago(min), build: "IN_PROGRESS" } });
+
+type V = Record;
+interface World {
+ v: V;
+ update?: (body: V, w: World) => { status: number; body: unknown };
+ rollback?: (w: World) => { status: number; body: unknown };
+ apply?: (w: World) => { status: number; body: unknown };
+ save?: (body: V, w: World) => { status: number; body: unknown };
+ uninstall?: (body: V) => { status: number; body: unknown };
+ check?: (w: World) => { status: number; body: unknown };
+}
+
+
+async function setup(page: Page, w: World) {
+ const calls: string[] = [];
+ const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
+ await page.route((url) => url.pathname === "/runtime-config.js", (route) =>
+ route.fulfill({ contentType: "text/javascript", body: `window.__CODERHELM_CONFIG__ = ${JSON.stringify({ apiUrl: "", streamUrl: "", selfHosted: true, version: "v0.8.45" })};` }),
+ );
+ await page.route((url) => !["localhost", "127.0.0.1"].includes(url.hostname), (route) => route.abort());
+ await page.route((url) => ["localhost", "127.0.0.1"].includes(url.hostname) && /^\/(api|auth)\//.test(url.pathname), async (route) => {
+ const p = new URL(route.request().url()).pathname;
+ const method = route.request().method();
+ calls.push(`${method} ${p}`);
+ if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: null, email: "admin@acme.example", avatar_url: "", role: "owner", auth_provider: "email", mfa_enabled: true, platform_admin: true });
+ if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme", status: "active", current: true }] });
+ if (p === "/api/banners") return json(route, { banners: [] });
+ if (p === "/api/system/version" || p === "/api/system/releases/check") {
+ return json(route, {
+ self_hosted: true,
+ current: { version: "v0.8.45", commit: "0123456789abcdef0123456789abcdef01234567", released_at: "2026-11-01T00:00:00Z", config_fingerprint: "0a3bb7ad772e" },
+ latest: null, update_available: false, running: false, settings: SETTINGS, history: OK_HISTORY,
+ releases: { fetched_at: unix(2), stale: false, reason: null, error: null, behind: null },
+ install: { stage: "acme", region: "us-east-1" },
+ native: { stack: "coderhelm-acme", can_apply: true, auto_apply: true, pending: null },
+ uninstall: { delete_data: false, changed_by: null, changed_at: null },
+ ...w.v,
+ });
+ }
+ if (p === "/api/system/preflight") return json(route, { checked_at: ago(0.2), ready: true, current: "v0.8.45", latest: null, blockers: [], checks: CHECKS });
+ if (p === "/api/system/update" && w.update) {
+ await new Promise((r) => setTimeout(r, 600));
+ const r = w.update(route.request().postDataJSON() as V, w);
+ return json(route, r.body, r.status);
+ }
+ if (p === "/api/system/update/apply" && w.apply) { const r = w.apply(w); return json(route, r.body, r.status); }
+ if (p === "/api/system/rollback" && w.rollback) { const r = w.rollback(w); return json(route, r.body, r.status); }
+ if (p === "/api/system/update-check" && w.check) { const r = w.check(w); return json(route, r.body, r.status); }
+ if (p === "/api/system/auto-update" && w.save) { const r = w.save(route.request().postDataJSON() as V, w); return json(route, r.body, r.status); }
+ if (p === "/api/system/uninstall-mode" && w.uninstall) { const r = w.uninstall(route.request().postDataJSON() as V); return json(route, r.body, r.status); }
+ if (p === "/api/system/hybrid" || p === "/api/hybrid") return json(route, { registered: false });
+ if (p === "/api/system/models") return json(route, { provider: "bedrock", inference_prefix: "us.", model_ids: {}, source: "deploy", updated_at: null, updated_by: null, deploy_default: { provider: "bedrock", inference_prefix: "us." }, region: "us-east-1", models: ["claude-opus-5-5", "claude-sonnet-5-5"], bedrock_ids: { "claude-opus-5-5": "us.anthropic.claude-opus-5-5", "claude-sonnet-5-5": "us.anthropic.claude-sonnet-5-5" }, prefixes: ["us.", "eu.", ""] });
+ if (p === "/api/system/domain") return json(route, { available: true, status: "aws", code: "aws", domain: { state: "none" }, check: null });
+ return json(route, {});
+ });
+ return calls;
+}
+
+
+const status = (page: Page) => page.getByTestId("update-status");
+const toasts = (page: Page) => page.getByTestId("toast");
+const updateButtons = (page: Page) => page.getByRole("button", { name: /^Update to / });
+const PREPARING = (v: string) => ({
+ native: { stack: "coderhelm-acme", can_apply: true, auto_apply: true, pending: { status: "preparing", version: v, id: "UPDATE#2", actor: "admin@acme.example", started_at: ago(0) } },
+ history: [{ id: "UPDATE#2", version: v, from_version: "v0.8.45", actor: "admin@acme.example", mode: "update", status: "preparing", started_at: ago(0) }, ...OK_HISTORY],
+});
+const posts = (calls: string[], p: string) => calls.filter((c) => c === `POST ${p}`).length;
+
+test.describe("Update: one press does the whole job", () => {
+ test("pressed while the release check runs: Checking, who pressed, no toast, nothing more to press", async ({ page }) => {
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true },
+ update: (_b, w) => {
+ const request = { version: "v0.8.46", actor: "admin@acme.example", requested_at: ago(0), status: "waiting", waiting_for: "the release check" };
+ w.v = { ...w.v, model_check: PENDING("v0.8.46", 0), update_request: request };
+ return { status: 200, body: { ok: true, state: "checking", version: "v0.8.46", model_check: PENDING("v0.8.46", 0), request } };
+ },
+ };
+ const calls = await setup(page, w);
+ await page.goto("/settings/system/");
+ const button = page.getByRole("button", { name: "Update to v0.8.46" });
+ await button.click();
+ // Progress shows at once, and the button can't be pressed again meanwhile.
+ await expect(status(page).getByRole("button", { name: "Starting…" })).toBeDisabled();
+ await expect(status(page)).toHaveAttribute("data-state", "checking-release");
+ await expect(status(page)).toContainText("Checking v0.8.46 before it can be applied");
+ await expect(page.getByTestId("update-requested")).toContainText("admin@acme.example pressed Update");
+ await expect(page.getByTestId("update-requested")).toContainText("it starts by itself once the check passes");
+ await expect(updateButtons(page)).toHaveCount(0);
+ await page.waitForTimeout(800);
+ await expect(toasts(page)).toHaveCount(0);
+ expect(posts(calls, "/api/system/update")).toBe(1);
+ // The check passes and the updater starts it: the card moves on by itself.
+ w.v = { ...w.v, model_check: { version: "v0.8.46", checked_at: ago(0), ok: true, results: [] }, update_request: { version: "v0.8.46", status: "started", id: "UPDATE#2" }, ...PREPARING("v0.8.46") };
+ await expect(status(page)).toHaveAttribute("data-state", "preparing", { timeout: 20_000 });
+ expect(posts(calls, "/api/system/update")).toBe(1);
+ });
+
+ test("a double click sends one request and the button never comes back while it starts", async ({ page }) => {
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true, model_check: { version: "v0.8.46", checked_at: ago(5), ok: true, results: [] } },
+ update: (_b, w) => {
+ w.v = { ...w.v, ...PREPARING("v0.8.46") };
+ return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "preparing", state: "started" } };
+ },
+ };
+ const calls = await setup(page, w);
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).dblclick();
+ await expect(status(page)).toHaveAttribute("data-state", "preparing");
+ await expect(updateButtons(page)).toHaveCount(0);
+ expect(posts(calls, "/api/system/update")).toBe(1);
+ await expect(toasts(page)).toHaveCount(0);
+ });
+
+ test("a read from before the press never brings the Update button back: Starting until the updater shows it", async ({ page }) => {
+ let pressed = false;
+ let reads = 0;
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true, model_check: { version: "v0.8.46", checked_at: ago(5), ok: true, results: [] } },
+ update: () => { pressed = true; return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "preparing", state: "started" } }; },
+ };
+ const calls = await setup(page, w);
+ await page.route((url) => url.pathname === "/api/system/version", async (route) => {
+ if (pressed && ++reads > 2) w.v = { ...w.v, ...PREPARING("v0.8.46") };
+ return route.fallback();
+ });
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "starting");
+ await expect(status(page)).toContainText("Starting the update to v0.8.46");
+ await expect(status(page)).toContainText("there's nothing more to press");
+ await expect(updateButtons(page)).toHaveCount(0);
+ await expect(status(page)).toHaveAttribute("data-state", "preparing", { timeout: 20_000 });
+ expect(posts(calls, "/api/system/update")).toBe(1);
+ });
+
+ test("a newer release out while one prepares: mentioned quietly, never a second Update button", async ({ page }) => {
+ await setup(page, { v: { latest: rel("v0.8.47"), update_available: true, ...PREPARING("v0.8.46") } });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toHaveAttribute("data-state", "preparing");
+ await expect(status(page)).toContainText("Preparing the update to v0.8.46");
+ await expect(page.getByTestId("update-next")).toHaveText("v0.8.47 is out too; it's next after this one.");
+ await expect(updateButtons(page)).toHaveCount(0);
+ await expect(page.getByTestId("release-notes")).toHaveCount(0);
+ });
+
+ test("a newer release out while the pressed one is checked: still Checking the pressed one, the newer one mentioned", async ({ page }) => {
+ await setup(page, {
+ v: {
+ latest: rel("v0.8.47"), update_available: true, model_check: PENDING("v0.8.46", 2),
+ update_request: { version: "v0.8.46", actor: "admin@acme.example", requested_at: ago(2), status: "waiting", waiting_for: "the release check" },
+ },
+ });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toHaveAttribute("data-state", "checking-release");
+ await expect(status(page)).toContainText("Checking v0.8.46");
+ await expect(page.getByTestId("update-next")).toContainText("v0.8.47 is out too");
+ await expect(updateButtons(page)).toHaveCount(0);
+ });
+
+ test("once the update finished, the newer release is offered once", async ({ page }) => {
+ await setup(page, { v: { current: { version: "v0.8.46", commit: null, released_at: null, config_fingerprint: null }, latest: rel("v0.8.47"), update_available: true, history: [{ id: "UPDATE#2", version: "v0.8.46", from_version: "v0.8.45", actor: "admin@acme.example", mode: "update", status: "succeeded", started_at: ago(20), finished_at: ago(1) }, ...OK_HISTORY] } });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toHaveAttribute("data-state", "available");
+ await expect(updateButtons(page)).toHaveCount(1);
+ await expect(page.getByTestId("update-next")).toHaveCount(0);
+ });
+
+ test("a press that ended says why in the card", async ({ page }) => {
+ await setup(page, { v: { latest: rel("v0.8.46"), update_available: true, update_request: { version: "v0.8.46", actor: "admin@acme.example", requested_at: ago(30), status: "ended", reason: "the update to v0.8.45 is still running; this one can start once it finishes", ended_at: ago(25) } } });
+ await page.goto("/settings/system/");
+ await expect(page.getByTestId("update-ended")).toContainText("didn't apply it: the update to v0.8.45 is still running");
+ });
+});
+
+test.describe("Update: error toasts only for real failures", () => {
+ test("a real 500: a toast that says what went wrong and what to do, and Update works again", async ({ page }) => {
+ let n = 0;
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true },
+ update: (_b, w) => {
+ n += 1;
+ if (n === 1) return { status: 500, body: {} };
+ w.v = { ...w.v, ...PREPARING("v0.8.46") };
+ return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "preparing", state: "started" } };
+ },
+ };
+ await setup(page, w);
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(toasts(page)).toHaveText(["Couldn't start the update: the server didn't answer (error 500). Nothing changed; try again in a minute."]);
+ await expect(status(page)).toHaveAttribute("data-state", "available");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "preparing");
+ });
+
+ test("a model the release calls refused: the card shows it with the fix, no toast", async ({ page }) => {
+ const mc = { version: "v0.8.46", checked_at: ago(1), ok: false, provider: "bedrock", results: [{ model: "claude-sonnet-5-5", id: "us.anthropic.claude-sonnet-5-5", status: "fail", code: "terms", detail: "The terms for this model haven't been accepted in this AWS account.", fix: "Accept the terms in the Bedrock console.", required: true }] };
+ await setup(page, {
+ v: { latest: rel("v0.8.46"), update_available: true },
+ update: (_b, w) => { w.v = { ...w.v, model_check: mc }; return { status: 409, body: { error: "Update to v0.8.46 needs your action: The terms for this model haven't been accepted in this AWS account.", model_check: mc } }; },
+ });
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "needs-action");
+ await page.waitForTimeout(800);
+ await expect(toasts(page)).toHaveCount(0);
+ });
+
+ test("a refusal with its reason: the toast names it", async ({ page }) => {
+ await setup(page, { v: { latest: rel("v0.8.46"), update_available: true }, update: () => ({ status: 400, body: { error: "the update to v0.8.45 is still running; this one can start once it finishes" } }) });
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(toasts(page)).toHaveText(["Couldn't start the update: the update to v0.8.45 is still running; this one can start once it finishes."]);
+ });
+
+ test("Apply after it was applied in the AWS console: the card shows it applying, no toast", async ({ page }) => {
+ const prepared = { version: "v0.8.46", status: "review", counts: { add: 2, modify: 5, remove: 0 }, parts: ["Api"], link: CS_LINK, id: "UPDATE#2", can_apply: true, data_changes: [], permission_changes: [], admin_changes: [] };
+ const calls = await setup(page, {
+ v: { latest: rel("v0.8.46"), update_available: true, native: { stack: "coderhelm-acme", can_apply: true, auto_apply: true, pending: prepared } },
+ apply: (w) => {
+ w.v = { ...w.v, running: true, native: { stack: "coderhelm-acme", can_apply: true, auto_apply: true, pending: { ...prepared, status: "running", execution: "EXECUTE_IN_PROGRESS", applied_by: "someone in the AWS console", executed_at: ago(1) } } };
+ return { status: 400, body: { error: "no prepared update is waiting for you (reload the page)" } };
+ },
+ });
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Apply v0.8.46" }).dblclick();
+ await expect(status(page)).toHaveAttribute("data-state", "updating");
+ await expect(page.getByTestId("native-update-progress")).toContainText("It was applied in the AWS console.");
+ await expect(toasts(page)).toHaveCount(0);
+ expect(posts(calls, "/api/system/update/apply")).toBe(1);
+ });
+
+ test("settings saves: a refusal and a 502 each say what to do; polling never drops an unsaved change", async ({ page }) => {
+ let n = 0;
+ await setup(page, {
+ v: { latest: rel("v0.8.46"), update_available: true, ...PREPARING("v0.8.46") },
+ save: (b) => { n += 1; if (n === 1) return { status: 400, body: { error: "timezone: an IANA name such as Europe/Berlin" } }; if (n === 2) return { status: 502, body: {} }; return { status: 200, body: { settings: b } }; },
+ });
+ await page.clock.install({ time: new Date(NOW) });
+ await page.goto("/settings/system/");
+ await page.getByTestId("channel-beta").click();
+ // The page reads the version route every 10 seconds while it prepares.
+ await page.clock.fastForward(21_000);
+ await expect(page.getByTestId("channel-beta").getByRole("radio")).toBeChecked();
+ await page.getByRole("button", { name: "Save changes" }).click();
+ await expect(toasts(page).last()).toHaveText("Couldn't save the update settings: timezone: an IANA name such as Europe/Berlin.");
+ await page.getByRole("button", { name: "Save changes" }).click();
+ await expect(toasts(page).last()).toHaveText("Couldn't save the update settings: the server didn't answer (error 502). Nothing changed; try again in a minute.");
+ await expect(page.getByTestId("channel-beta").getByRole("radio")).toBeChecked();
+ await page.getByRole("button", { name: "Save changes" }).click();
+ await expect(toasts(page).last()).toHaveText("Update settings saved");
+ });
+});
+
+test.describe("Version and updates: the page", () => {
+ test("an old release list never says up to date, and Check for updates is the action", async ({ page }) => {
+ await setup(page, { v: { releases: { fetched_at: unix(60 * 80), stale: true, reason: null, error: null, behind: null } } });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toHaveAttribute("data-state", "stale");
+ await expect(status(page)).toContainText("Not checked for updates lately");
+ await expect(page.locator("#version")).not.toContainText("up to date");
+ });
+
+ test("update sections come first: Version, Automatic updates, Update history, then the install", async ({ page }) => {
+ await setup(page, { v: {} });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toBeVisible();
+ const ids = await page.locator("main section[id], main [id]").evaluateAll((els) => els.map((e) => e.id).filter((i) => ["version", "auto", "history", "health", "models", "domain", "hybrid", "uninstall"].includes(i)));
+ expect(ids).toEqual(["version", "auto", "history", "health", "models", "domain", "hybrid", "uninstall"]);
+ });
+
+ test("nothing to roll back to: a line that says so, no dead button", async ({ page }) => {
+ await setup(page, { v: { history: [] } });
+ await page.goto("/settings/system/");
+ await expect(page.getByTestId("rollback")).toHaveCount(0);
+ await expect(page.getByTestId("rollback-note")).toContainText("Nothing to roll back to yet");
+ });
+
+ test("the version route doesn't answer: what happened and Try again", async ({ page }) => {
+ await setup(page, { v: {} });
+ await page.route((url) => url.pathname === "/api/system/version", (route) => route.fulfill({ status: 502, contentType: "application/json", body: "{}" }));
+ await page.goto("/settings/system/");
+ await expect(page.getByText("Couldn't load this install's version")).toBeVisible();
+ await expect(page.getByText("The server didn't answer.")).toBeVisible();
+ await expect(page.getByRole("button", { name: "Try again" })).toBeVisible();
+ });
+});
diff --git a/dashboard/e2e/update-state-derive.spec.ts b/dashboard/e2e/update-state-derive.spec.ts
index eff97ff9..6b518a87 100644
--- a/dashboard/e2e/update-state-derive.spec.ts
+++ b/dashboard/e2e/update-state-derive.spec.ts
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
-import { deriveUpdateState, followEvery, type UpdateState } from "../src/lib/update-state";
+import { deriveUpdateState, failureText, followEvery, nextAfter, withPress, type UpdateState } from "../src/lib/update-state";
import type { SystemPreflight, SystemVersion } from "../src/lib/api";
// The one function that maps the version route (and the preflight) to the
@@ -90,3 +90,58 @@ test.describe("deriveUpdateState: one coherent state", () => {
expect(followEvery(derive({}))).toBeNull();
});
});
+
+test.describe("an Update press: one state, never a second button", () => {
+ const waiting = { version: "v0.8.39", actor: "owner@example.org", requested_at: ago(2), status: "waiting" as const, waiting_for: "the release check" };
+ const pending = { ...STALE_CHECK, checked_at: ago(2), started_at: ago(2) };
+
+ test("a press waiting for the check is Checking, with who pressed", () => {
+ const s = derive({ model_check: pending, update_request: waiting });
+ expect(s.kind).toBe("checking");
+ if (s.kind === "checking") expect(s.request?.actor).toBe("owner@example.org");
+ });
+
+ test("a newer release listed while the pressed one is checked: still Checking the pressed one, the newer one next", () => {
+ const data = { ...BASE, latest: { version: "v0.8.40", notes: "", breaking: false }, model_check: pending, update_request: waiting };
+ const s = deriveUpdateState(data, null, NOW);
+ expect(s.kind === "checking" && s.version).toBe("v0.8.39");
+ expect(nextAfter(s, data)).toBe("v0.8.40");
+ });
+
+ test("the check passed but the updater hasn't started it yet: still Checking, not an Update button", () => {
+ expect(derive({ model_check: { version: "v0.8.39", checked_at: ago(0), ok: true, results: [] }, update_request: waiting }).kind).toBe("checking");
+ });
+
+ test("a press that ended: the offer, with the reason", () => {
+ const s = derive({ update_request: { ...waiting, status: "ended", reason: "a model was refused", ended_at: ago(1) } });
+ expect(s.kind).toBe("available");
+ if (s.kind === "available") expect(s.ended?.reason).toBe("a model was refused");
+ });
+
+ test("just pressed and the version route still reads as before: Starting, until it moves or the hold runs out", () => {
+ const before = derive({});
+ expect(before.kind).toBe("available");
+ const press = { version: "v0.8.39", at: NOW };
+ expect(withPress(before, press, NOW).kind).toBe("starting");
+ expect(followEvery(withPress(before, press, NOW))).toBe(3_000);
+ expect(withPress(before, press, NOW + 120_000).kind).toBe("available");
+ const preparing = derive({ native: { ...BASE.native!, pending: { version: "v0.8.39", status: "preparing", id: "UPDATE#b" } } });
+ expect(withPress(preparing, press, NOW).kind).toBe("preparing");
+ });
+
+ test("no newer release mentioned for the version in progress itself, or when nothing runs", () => {
+ const data = { ...BASE, native: { ...BASE.native!, pending: { version: "v0.8.39", status: "preparing", id: "UPDATE#b" } } };
+ expect(nextAfter(deriveUpdateState(data, null, NOW), data)).toBeNull();
+ expect(nextAfter(derive({}), BASE)).toBeNull();
+ });
+
+ test("an old release list is not up to date", () => {
+ expect(derive({ latest: null, update_available: false, releases: { fetched_at: Math.floor(NOW / 1000) - 4 * 86400, stale: true, reason: null, error: null, behind: null } }).kind).toBe("stale");
+ });
+
+ test("error toasts say what went wrong and what to do", () => {
+ expect(failureText("start the update", "", 502)).toBe("Couldn't start the update: the server didn't answer (error 502). Nothing changed; try again in a minute.");
+ expect(failureText("start the update", "Forbidden", 403)).toContain("only install admins");
+ expect(failureText("start the roll back", "an update is already running.", 400)).toBe("Couldn't start the roll back: an update is already running.");
+ });
+});
diff --git a/dashboard/src/app/settings/system/page.tsx b/dashboard/src/app/settings/system/page.tsx
index b0f00340..45a44420 100644
--- a/dashboard/src/app/settings/system/page.tsx
+++ b/dashboard/src/app/settings/system/page.tsx
@@ -1,9 +1,9 @@
"use client";
-import { useCallback, useEffect, useState, type ReactNode } from "react";
+import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
import Link from "next/link";
-import { api, type AutoUpdateSettings, type ModelCheck, type SystemPreflight, type SystemVersion, type UpdateEntry } from "@/lib/api";
-import { deriveUpdateState, followEvery, STATE_ID, type FailedTry, type UpdateState } from "@/lib/update-state";
+import { api, errorStatus, type AutoUpdateSettings, type ModelCheck, type SystemPreflight, type SystemVersion, type UpdateEntry } from "@/lib/api";
+import { deriveUpdateState, failureText, followEvery, isStateAnswer, nextAfter, STATE_ID, STARTING_HOLD_MS, withPress, type FailedTry, type UpdateState } from "@/lib/update-state";
import { CheckRow } from "@/components/install-checks";
import { DomainSection } from "@/components/domain-section";
import { HybridSection } from "@/components/hybrid-section";
@@ -137,24 +137,54 @@ function System() {
loadPreflight();
}, [loadPreflight]);
const form = useDirtyForm(DEFAULTS, { disabled: !data });
+ // An Update press the version route may not show yet: until it does, the
+ // card says Starting and never offers the button again.
+ const [press, setPress] = useState<{ version: string | null; at: number } | null>(null);
+ // One action at a time, whatever the clicks: a double click sends one request.
+ const acting = useRef(false);
+ // Only the newest read of the version route is shown: a slow poll that
+ // started before a press never replaces what the press led to.
+ const reads = useRef(0);
const load = useCallback(async () => {
+ const mine = ++reads.current;
try {
const v = await api.getSystemVersion();
+ if (mine !== reads.current) return;
setData(v);
setError(false);
- form.reset(withChannel(v.settings));
+ // The saved settings, without dropping what someone is changing: the
+ // page reads the version route again every few seconds while an update runs.
+ if (!dirtyRef.current) form.reset(withChannel(v.settings));
} catch {
- setError(true);
+ if (mine !== reads.current) return;
+ // A failed poll keeps what is on screen; only a page with nothing yet shows the error.
+ setError((had) => had || !dataRef.current);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ const dataRef = useRef(null);
+ dataRef.current = data;
+ const dirtyRef = useRef(false);
+ dirtyRef.current = form.dirty;
useEffect(() => {
load();
}, [load]);
- // The one update state, derived in one place (lib/update-state.ts).
- const state: UpdateState | null = data ? deriveUpdateState(data, pre) : null;
+ // The one update state, derived in one place (lib/update-state.ts), with a
+ // press the version route doesn't show yet laid over it.
+ const derived: UpdateState | null = data ? deriveUpdateState(data, pre) : null;
+ const state: UpdateState | null = derived ? withPress(derived, press) : null;
+ useEffect(() => {
+ if (!press) return;
+ // The updater's answer is on screen (or the hold ran out): the press is done.
+ if (state && state.kind !== "starting") {
+ setPress(null);
+ return;
+ }
+ const t = window.setTimeout(() => setPress(null), Math.max(0, press.at + STARTING_HOLD_MS - Date.now()));
+ return () => window.clearTimeout(t);
+ }, [press, state]);
// While something is happening (the release check, preparing, waiting for
// an OK that can also be given in the AWS console, applying), follow it:
// the version route reads CloudFormation each time, so the card moves from
@@ -170,7 +200,7 @@ function System() {
const header = (
);
@@ -178,7 +208,8 @@ function System() {
return (
{header}
-
+
+ The server didn't answer. Nothing changed on the install; try again in a minute.
Try again
@@ -207,47 +238,60 @@ function System() {
const blockers = (pre?.blockers ?? []).filter((b) => b.severity === "block");
const checkKeys = new Set((pre?.checks ?? []).map((c) => c.key));
const blocking = new Set(blockers.filter((b) => checkKeys.has(b.key)).map((b) => b.key));
- const busyUpdating = ["applying", "preparing", "review"].includes(state.kind);
+ const busyUpdating = ["applying", "preparing", "review", "starting", "checking"].includes(state.kind);
const failure = state.kind === "failed" ? state.failure : null;
const offered = !!latest && ["available", "blocked", "updater-down", "needs-action", "checking", "check-stalled", "failed"].includes(state.kind);
const save = async () => {
try {
const r = await api.setAutoUpdate(form.values);
- form.reset({ ...DEFAULTS, ...r.settings });
+ form.reset(withChannel({ ...DEFAULTS, ...r.settings }));
toast("Update settings saved");
} catch (e) {
- toast(e instanceof Error ? e.message : "Could not save", "error");
+ // Your changes stay on the page: Save again once it answers.
+ toast(failureText("save the update settings", e instanceof Error ? e.message : null, errorStatus(e)), "error");
}
};
const start = async (kind: "update" | "rollback", skipCheck = false) => {
+ if (acting.current) return;
+ acting.current = true;
setBusy(kind);
+ // Any read already on its way is from before this press.
+ reads.current += 1;
try {
if (kind === "update") {
// No version: the updater reads GitHub first and installs the newest
// release at this moment. Skipping a model check names the release
// whose check the admin read.
const r = await api.updateNow(skipCheck ? data.model_check?.version : undefined, skipCheck);
- if (!r.ok) {
- // A model the release calls was refused: show which, with its fix.
- if (r.model_check) setData({ ...data, model_check: r.model_check });
- toast(r.error, "error");
+ if (r.ok) {
+ // Started, or recorded while the release check runs (it starts by
+ // itself once the check passes): either way the card shows it.
+ setPress({ version: r.version ?? null, at: Date.now() });
+ if (r.state === "checking") {
+ setData((d) => (d ? { ...d, model_check: r.model_check ?? d.model_check, update_request: r.request ?? d.update_request } : d));
+ }
+ } else if (r.model_check || r.waiting || isStateAnswer(r.httpStatus)) {
+ // The release check holds it (a model it calls was refused, or the
+ // release isn't ready): the card shows which, with the fix.
+ if (r.model_check) setData((d) => (d ? { ...d, model_check: r.model_check } : d));
loadPreflight();
- return;
+ } else {
+ toast(failureText("start the update", r.error, r.httpStatus), "error");
}
- toast(data.native ? `Preparing ${r.version}, then it applies. This takes 10 to 20 minutes.` : `Updating to ${r.version}. This takes 10 to 20 minutes.`);
} else {
- const e = await api.rollbackInstall();
- toast(`Rolling back to ${e.version}.`);
+ await api.rollbackInstall();
}
- await load();
} catch (e) {
- toast(e instanceof Error ? e.message : "Could not start", "error");
+ toast(failureText(kind === "update" ? "start the update" : "start the roll back", e instanceof Error ? e.message : null, errorStatus(e)), "error");
} finally {
+ await load();
+ acting.current = false;
setBusy("");
}
};
+ const next = nextAfter(state, data);
return (
@@ -267,6 +311,7 @@ function System() {
load();
}}
onSkipModel={() => start("update", true)}
+ next={next}
/>
{!busyUpdating && data.current.version && }
@@ -276,22 +321,6 @@ function System() {
{latest && offered && }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
)}
-
-
start("rollback")}>
- {busy === "rollback" ? "Starting…" : "Roll back to the previous version"}
-
+
+ {canRollBack ? (
+
start("rollback")} data-testid="rollback">
+ {busy === "rollback" ? "Starting the roll back…" : "Roll back to the previous version"}
+
+ ) : null}
+
+ {!canRollBack
+ ? "Nothing to roll back to yet: once an update finishes here, you can go back to the version before it."
+ : busyUpdating
+ ? "You can roll back once the update in progress finishes."
+ : "Goes back to the version before the last update. Your data stays as it is."}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -504,6 +558,7 @@ function UpdateStatus({
onChanged,
onModelChecked,
onSkipModel,
+ next,
}: {
state: UpdateState;
data: SystemVersion;
@@ -512,6 +567,8 @@ function UpdateStatus({
onChanged: () => void;
onModelChecked: (c: ModelCheck | null) => void;
onSkipModel: () => void;
+ /** A release newer than the update in progress: mentioned, never a second button. */
+ next: string | null;
}) {
const current = data.current.version;
const latest = data.latest;
@@ -520,13 +577,14 @@ function UpdateStatus({
const beta = withChannel(data.settings).channel === "beta";
const healthLink =
See install health ;
const id = STATE_ID[state.kind];
+ const nextLine = next ?
{next} is out too; it's next after this one.
: null;
switch (state.kind) {
case "applying":
if (state.pending && data.native) {
return (
-
+
);
}
@@ -537,6 +595,7 @@ function UpdateStatus({
This takes 10 to 20 minutes. Coderhelm keeps running {on} until it finishes, and this page updates by itself.
+ {nextLine}
);
@@ -551,21 +610,47 @@ function UpdateStatus({
startedAt={state.kind === "preparing" ? state.startedAt : undefined}
startedBy={state.kind === "preparing" ? state.startedBy : undefined}
from={current}
+ next={nextLine}
/>
);
- case "checking":
+ case "starting":
+ return (
+ Starting the update to {state.version}…>}>
+
+ The updater has your request. This card moves on by itself in a few seconds; there's nothing more to press.
+
+
+
+
+ );
+
+ case "checking": {
+ const req = state.request;
+ const by = req?.actor && req.actor !== "AWS CLI" ? req.actor : null;
+ const waits = req?.waiting_for && req.waiting_for !== "the release check" ? req.waiting_for : null;
return (
Checking {state.version} before it can be applied>}>
{state.startedAt ? <>Started . > : null}
- Coderhelm checks the release's signature and checksums, then tries each model it calls. This usually takes about 5 minutes; this page moves on by itself, and then you can update.
+ Coderhelm checks the release's signature and checksums, then tries each model it calls. It takes about 5 minutes; this page moves on by itself.
+ {req ? (
+
+ {by ? <>{by} pressed Update> : <>Update was pressed>}
+ {req.requested_at ? <> > : null}: it starts by itself once the check passes{data.native ? ", then applies or asks for your OK as usual" : ""}. There's nothing more to press.
+ {waits ? <> Waiting because {waits.replace(/; try again.*$/, "")}.> : null}
+
+ ) : (
+ Then you can update, or it installs by itself in your maintenance window if automatic updates are on.
+ )}
+ {nextLine}
);
+ }
case "check-stalled":
return (
@@ -687,6 +772,11 @@ function UpdateStatus({
)}
{l.prerelease && A nightly beta: it reaches Stable after a day with no reported problem. You get these because the channel is Beta (nightly).
}
+ {state.ended?.reason ? (
+
+ The last press of Update{state.ended.requested_at ? <> ( )> : null} didn't apply it: {state.ended.reason.replace(/\.$/, "")}.
+
+ ) : null}
);
}
@@ -712,6 +802,15 @@ function UpdateStatus({
);
+ case "stale":
+ return (
+
+
+ You're on {current}. The list of releases was last read {state.fetchedAt ? : "a while ago"}, so a newer release may be out. Check for updates reads it now.
+
+
+ );
+
case "not-checked":
return (
@@ -751,7 +850,7 @@ function CheckAgain({ onChecked }: { onChecked: (c: ModelCheck | null) => void }
try {
onChecked((await api.checkUpdateModels()).model_check);
} catch (e) {
- toast(e instanceof Error ? e.message : "Could not start the check", "error");
+ toast(failureText("start the check again", e instanceof Error ? e.message : null, errorStatus(e)), "error");
} finally {
setBusy(false);
}
@@ -783,12 +882,12 @@ function ReleaseCheck({ data, onChecked }: { data: SystemVersion; onChecked: (v:
try {
onChecked(await api.checkReleases());
} catch (e) {
- toast(e instanceof Error ? e.message : "Could not check for updates", "error");
+ toast(failureText("check for updates", e instanceof Error ? e.message : null, errorStatus(e)), "error");
} finally {
setChecking(false);
}
};
- const primary = !!r && (!r.fetched_at || !!r.error || !!r.behind) && !data.latest;
+ const primary = !!r && (!r.fetched_at || !!r.error || !!r.behind || r.stale) && !data.latest;
return (
diff --git a/dashboard/src/components/native-update.tsx b/dashboard/src/components/native-update.tsx
index fbd8260c..93a89c3e 100644
--- a/dashboard/src/components/native-update.tsx
+++ b/dashboard/src/components/native-update.tsx
@@ -1,7 +1,8 @@
"use client";
-import { useState } from "react";
-import { api, type NativeUpdate } from "@/lib/api";
+import { useRef, useState, type ReactNode } from "react";
+import { api, errorStatus, type NativeUpdate } from "@/lib/api";
+import { failureText } from "@/lib/update-state";
import { Callout } from "@/components/callout";
import { Time } from "@/components/list";
import { Code } from "@/components/settings/code";
@@ -66,6 +67,7 @@ export function NativeUpdateCard({
startedBy,
appliedBy,
from,
+ next,
}: {
native: NativeUpdate;
phase: "preparing" | "review" | "applying";
@@ -78,10 +80,14 @@ export function NativeUpdateCard({
appliedBy?: string | null;
/** The version the install is on while it updates. */
from?: string | null;
+ /** A quiet line about a newer release, next after this one. */
+ next?: ReactNode;
}) {
const { toast } = useToast();
const [asking, setAsking] = useState(false);
const [busy, setBusy] = useState(false);
+ // One apply per click, whatever the clicks.
+ const acting = useRef(false);
const p = native.pending;
if (!p) return null;
const n = p.counts ?? { add: 0, modify: 0, remove: 0 };
@@ -94,17 +100,26 @@ export function NativeUpdateCard({
const version = p.version ?? "the update";
const apply = async () => {
- if (!p.id) return;
+ if (!p.id || acting.current) return;
+ acting.current = true;
setBusy(true);
try {
await api.applyUpdate(p.id, toConfirm ? p.confirm : "");
setAsking(false);
- toast(`Updating to ${version}. This takes 10 to 20 minutes.`);
- onChanged?.();
} catch (e) {
- toast(e instanceof Error ? e.message : "Could not apply the update", "error");
+ const status = errorStatus(e);
+ if (status === 400 || status === 409) {
+ // It moved on since this page read it (applied in the AWS console, or
+ // replaced by a newer one): the card shows where it is now.
+ setAsking(false);
+ } else {
+ toast(failureText(`apply ${version}`, e instanceof Error ? e.message : null, status), "error");
+ }
} finally {
+ acting.current = false;
setBusy(false);
+ // The card follows what happened: applying, or where the update is now.
+ onChanged?.();
}
};
@@ -163,6 +178,7 @@ export function NativeUpdateCard({
) : null}
{waiting ? : null}
{p.reason && !waiting ? {p.reason}
: null}
+ {next}
{canApply ? (
(toConfirm ? setAsking(true) : apply())} data-testid="native-update-apply">
diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts
index dd60c788..d5a9540c 100644
--- a/dashboard/src/lib/api.ts
+++ b/dashboard/src/lib/api.ts
@@ -93,7 +93,7 @@ export function movedUrl(v: unknown): string | null {
async function requestWithBody(
path: string,
options?: RequestInit,
-): Promise<({ ok: true } & T) | ({ ok: false; error: string } & Partial)> {
+): Promise<({ ok: true } & T) | ({ ok: false; error: string; httpStatus: number } & Partial)> {
const res = await fetch(`${apiBase()}${path}`, {
...options,
credentials: "include",
@@ -110,7 +110,7 @@ async function requestWithBody(
} catch {}
if (!res.ok) {
const error = typeof body.error === "string" && body.error ? body.error : httpErrorMessage(res.status);
- return { ...(body as Partial), ok: false, error };
+ return { ...(body as Partial), ok: false, error, httpStatus: res.status };
}
return { ...(body as T), ok: true };
}
@@ -1289,12 +1289,14 @@ export const api = {
request<{ ok: boolean; uninstall: UninstallMode }>("/api/system/uninstall-mode", { method: "PUT", body: JSON.stringify({ delete_data: deleteData, confirm }) }),
/**
* Update to `version` (default: the newest release, read from GitHub at
- * that moment, never the copy the page showed). Refused with the model check
- * when a model the release calls was refused; `skipCheck` passes only a
- * failure on a model the release doesn't call.
+ * that moment, never the copy the page showed). Pressed while the
+ * release's check runs, the press is recorded (`state: "checking"`) and
+ * the update starts by itself once the check passes. Refused (409) with
+ * the model check when a model the release calls was refused; `skipCheck`
+ * passes only a failure on a model the release doesn't call.
*/
updateNow: (version?: string, skipCheck = false) =>
- requestWithBody("/api/system/update", {
+ requestWithBody("/api/system/update", {
method: "POST",
body: JSON.stringify({ ...(version ? { version } : {}), ...(skipCheck ? { skip_check: true } : {}) }),
}),
@@ -4392,6 +4394,33 @@ export interface SystemModels {
results?: ModelAccess[];
}
+/**
+ * An admin's Update press that waits for the release check (lambda/updater,
+ * follow_request): it starts by itself once the check passes. `ended` says
+ * why it stopped; `started` names the update it became.
+ */
+export interface UpdateRequest {
+ version: string;
+ actor?: string;
+ requested_at?: string;
+ status: "waiting" | "started" | "ended";
+ /** What it waits for: the release check, or the release still publishing. */
+ waiting_for?: string;
+ reason?: string;
+ ended_at?: string;
+ id?: string;
+ /** The version an earlier press asked for, replaced by this one. */
+ replaces?: string;
+}
+
+/** What Update answers: the update it started, or the press recorded while the release check runs. */
+export type UpdateNowAnswer = Partial & {
+ version: string;
+ state?: "checking" | "started";
+ request?: UpdateRequest | null;
+ model_check?: ModelCheck | null;
+};
+
export interface SystemVersion {
self_hosted: boolean;
current: { version: string | null; commit: string | null; released_at: string | null; config_fingerprint: string | null };
@@ -4404,6 +4433,8 @@ export interface SystemVersion {
history?: UpdateEntry[];
/** The latest release's model check, once it has run. */
model_check?: ModelCheck | null;
+ /** An admin's Update press waiting for the release check, or how it ended (a day). */
+ update_request?: UpdateRequest | null;
/** Which install this is (its resources are coderhelm--*), for the uninstall page. */
install?: { stage: string; region: string } | null;
/** A native install (one CloudFormation stack): the stack and the update waiting for review. */
diff --git a/dashboard/src/lib/update-state.ts b/dashboard/src/lib/update-state.ts
index 22274274..5280f549 100644
--- a/dashboard/src/lib/update-state.ts
+++ b/dashboard/src/lib/update-state.ts
@@ -1,4 +1,4 @@
-import type { ModelCheck, NativeChangeSet, SystemPreflight, SystemVersion, UpdateBlocker, UpdateEntry } from "./api";
+import type { ModelCheck, NativeChangeSet, SystemPreflight, SystemVersion, UpdateBlocker, UpdateEntry, UpdateRequest } from "./api";
/**
* The one update state Settings, System shows, derived in one place from the
@@ -20,15 +20,17 @@ export type UpdateState =
| { kind: "applying"; version: string; startedAt: string | null; startedBy: string | null; appliedBy: string | null; pending: NativeChangeSet | null }
| { kind: "preparing"; version: string; startedAt: string | null; startedBy: string | null; pending: NativeChangeSet }
| { kind: "review"; version: string; pending: NativeChangeSet; need: "confirm" | "apply" | "aws-admin" }
- | { kind: "checking"; version: string; startedAt: string | null }
+ | { kind: "starting"; version: string; at: number }
+ | { kind: "checking"; version: string; startedAt: string | null; request: UpdateRequest | null }
| { kind: "check-stalled"; version: string; note: string; check: ModelCheck }
| { kind: "needs-action"; version: string; check: ModelCheck }
| { kind: "failed"; failure: FailedTry }
| { kind: "updater-down"; version: string; blocker: UpdateBlocker }
| { kind: "blocked"; version: string; checks: number }
- | { kind: "available"; version: string }
+ | { kind: "available"; version: string; ended: UpdateRequest | null }
| { kind: "behind"; version: string }
| { kind: "unreachable" }
+ | { kind: "stale"; fetchedAt: string | null }
| { kind: "not-checked" }
| { kind: "current"; done: UpdateEntry | null };
@@ -140,11 +142,23 @@ export function deriveUpdateState(data: SystemVersion, pre: SystemPreflight | nu
if (!current) return { kind: "development" };
+ // An admin pressed Update while the release check ran: the update starts by
+ // itself once it passes, so the card says Checking (never a second Update
+ // button), for the version they pressed, whatever newer release is listed.
+ const req = data.update_request ?? null;
+ const asked = req?.status === "waiting" && !atLeast(current, req.version) ? req : null;
+ if (asked) {
+ const c = data.model_check?.version === asked.version ? data.model_check : null;
+ const started = c?.pending ? (c.progress?.started_at ?? c.started_at ?? c.checked_at ?? null) : null;
+ const old = !!started && now - new Date(started).getTime() > CHECK_LIMIT_MS;
+ if (!c || c.pending ? !old : c.ok) return { kind: "checking", version: asked.version, startedAt: started ?? asked.requested_at ?? null, request: asked };
+ }
+
const mc = latest && data.model_check?.version === latest.version ? data.model_check : null;
if (latest && mc && !mc.ok) {
const started = mc.progress?.started_at ?? mc.started_at ?? mc.checked_at ?? null;
const old = !!started && now - new Date(started).getTime() > CHECK_LIMIT_MS;
- if (mc.pending && !old) return { kind: "checking", version: latest.version, startedAt: started };
+ if (mc.pending && !old) return { kind: "checking", version: latest.version, startedAt: started, request: null };
if (mc.pending || mc.stalled) {
const note = mc.stalled && mc.note ? mc.note : `Checking ${latest.version} didn't finish within 30 minutes.`;
return { kind: "check-stalled", version: latest.version, note, check: mc };
@@ -161,11 +175,17 @@ export function deriveUpdateState(data: SystemVersion, pre: SystemPreflight | nu
if (latest && updater) return { kind: "updater-down", version: latest.version, blocker: updater };
const checks = new Set(blockers.filter((b) => checkKeys.has(b.key)).map((b) => b.key)).size;
if (latest && checks > 0) return { kind: "blocked", version: latest.version, checks };
- if (latest) return { kind: "available", version: latest.version };
+ if (latest) {
+ // A press that ended (its check failed since, or AWS refused to start it): why, once.
+ const ended = req && req.status === "ended" && req.version === latest.version ? req : null;
+ return { kind: "available", version: latest.version, ended };
+ }
if (data.releases?.behind) return { kind: "behind", version: data.releases.behind.version };
if (data.releases?.error) return { kind: "unreachable" };
if (data.releases && !data.releases.fetched_at) return { kind: "not-checked" };
+ // An old copy of the release list can't say "up to date".
+ if (data.releases?.stale) return { kind: "stale", fetchedAt: new Date(data.releases.fetched_at! * 1000).toISOString() };
return { kind: "current", done: recentSuccess(data, now) };
}
@@ -184,6 +204,7 @@ export const STATE_ID: Record = {
applying: "updating",
preparing: "preparing",
review: "review",
+ starting: "starting",
checking: "checking-release",
"check-stalled": "check-stalled",
"needs-action": "needs-action",
@@ -193,6 +214,7 @@ export const STATE_ID: Record = {
available: "available",
behind: "behind",
unreachable: "unreachable",
+ stale: "stale",
"not-checked": "not-checked",
current: "current",
};
@@ -200,6 +222,9 @@ export const STATE_ID: Record = {
/** How often the page reads the version route again in this state (ms), or null: it moves on by itself. */
export function followEvery(s: UpdateState): number | null {
switch (s.kind) {
+ case "starting":
+ // Just pressed: read again soon, so the card moves on as soon as the updater does.
+ return 3_000;
case "preparing":
case "checking":
return 10_000;
@@ -212,3 +237,67 @@ export function followEvery(s: UpdateState): number | null {
return null;
}
}
+
+/** The version an update in progress (checking, preparing, waiting, applying) is for, or null. */
+export function inProgressVersion(s: UpdateState): string | null {
+ switch (s.kind) {
+ case "starting":
+ case "checking":
+ case "preparing":
+ case "review":
+ case "applying":
+ return s.version;
+ default:
+ return null;
+ }
+}
+
+/**
+ * A release newer than the update in progress: mentioned quietly ("it's
+ * next after this one"), never offered as a second Update button while one
+ * runs. Offered once the current one ends.
+ */
+export function nextAfter(s: UpdateState, data: SystemVersion): string | null {
+ const v = inProgressVersion(s);
+ const latest = data.latest?.version ?? null;
+ if (!v || !latest || latest === v || !atLeast(latest, v)) return null;
+ return latest;
+}
+
+/** How long a press shows "Starting" while the version route still reads as before it (a cache, a slow read). */
+export const STARTING_HOLD_MS = 90_000;
+
+/**
+ * The state with a press just made laid over it: until the updater's answer
+ * shows the update (checking, preparing, applying, or a reason it ended), a
+ * version read from before the press must not bring the Update button back.
+ */
+export function withPress(s: UpdateState, press: { version: string | null; at: number } | null, now: number = Date.now()): UpdateState {
+ if (!press || now - press.at > STARTING_HOLD_MS) return s;
+ if (s.kind !== "available" && s.kind !== "failed") return s;
+ if (s.kind === "failed" && s.failure.startedAt && new Date(s.failure.startedAt).getTime() >= press.at - 5_000) return s;
+ if (s.kind === "available" && s.ended?.ended_at && new Date(s.ended.ended_at).getTime() >= press.at - 5_000) return s;
+ const version = press.version ?? (s.kind === "available" ? s.version : s.failure.version);
+ return { kind: "starting", version, at: press.at };
+}
+
+/**
+ * The error toast for an update action that really failed: what went wrong
+ * and what to do, in plain words. Only for real failures (the server didn't
+ * answer, a refused permission, a refusal with its reason): a state such as
+ * "the release is being checked" is shown in the card instead.
+ */
+export function failureText(what: string, message: string | null | undefined, status: number | undefined): string {
+ if (status === undefined || status === 0 || status >= 500) {
+ return `Couldn't ${what}: the server didn't answer${status ? ` (error ${status})` : ""}. Nothing changed; try again in a minute.`;
+ }
+ if (status === 401) return `Couldn't ${what}: you're signed out. Sign in again, then try once more.`;
+ if (status === 403) return `Couldn't ${what}: only install admins can do this. Ask one of them, or sign in as one.`;
+ const why = (message ?? "").trim().replace(/\.$/, "");
+ return why ? `Couldn't ${what}: ${why}.` : `Couldn't ${what} (error ${status}). Reload the page to see where things stand.`;
+}
+
+/** A 4xx that is the install's state (it moved on since the page loaded), not a failure. */
+export function isStateAnswer(status: number | undefined): boolean {
+ return status === 409;
+}
From 0f380d6bd6b03929fb9f2f1a3a4b86fbe4b556cf Mon Sep 17 00:00:00 2001
From: Nam Rodriguez
Date: Fri, 6 Nov 2026 12:25:31 -0500
Subject: [PATCH 2/2] Settings, System: one decision per update, and Install
health lists only the install's problems
Update took three steps when a release changed IAM: Update, Review and
apply, then Confirm and apply in a dialog of raw CloudFormation ids. The
card next to Update now says one press includes changes to what
Coderhelm's own roles may do (inside the permission limit) and sends that
consent, so such a release goes from available to applying in one click.
A prepared update shows a plain summary and one Apply update, the raw
list behind Technical details, no dialog. An update that would replace
or remove data says what, in words, and one clearly worded button
applies exactly that.
Install health no longer shows the next release's check in progress as a
Warning: it is the update card's state. Optional items are a quiet
Optional line, the summary matches the items listed, and a fix never
links to the page it is on.
---
dashboard/e2e/selfhost.spec.ts | 27 ++--
dashboard/e2e/update-press.spec.ts | 136 ++++++++++++++++-
dashboard/e2e/update-states.spec.ts | 23 +--
dashboard/src/app/settings/setup/page.tsx | 3 +-
dashboard/src/app/settings/system/page.tsx | 27 +++-
dashboard/src/components/install-checks.tsx | 15 +-
dashboard/src/components/native-update.tsx | 154 +++++++++++---------
dashboard/src/lib/api.ts | 10 +-
dashboard/src/lib/update-state.ts | 10 ++
9 files changed, 300 insertions(+), 105 deletions(-)
diff --git a/dashboard/e2e/selfhost.spec.ts b/dashboard/e2e/selfhost.spec.ts
index 638e99ff..f1cf8a1a 100644
--- a/dashboard/e2e/selfhost.spec.ts
+++ b/dashboard/e2e/selfhost.spec.ts
@@ -555,7 +555,7 @@ test("System: a one-stack install's Update applies it, and shows it running", as
await expect(page.getByRole("button", { name: "Prepare the update to v2.0.0" })).toHaveCount(0);
await page.getByRole("button", { name: "Update to v2.0.0" }).click();
await expect.poll(() => systemCalls.map((c) => c.path)).toContain("/api/system/update");
- expect(systemCalls.find((c) => c.path === "/api/system/update")!.body).toEqual({});
+ expect(systemCalls.find((c) => c.path === "/api/system/update")!.body).toEqual({ accept_permissions: true });
});
test("System: a running one-stack update says so, with nothing to do and no console step", async ({ page }) => {
@@ -569,7 +569,7 @@ test("System: a running one-stack update says so, with nothing to do and no cons
await expect(page.getByRole("button", { name: "Update to v2.0.0" })).toHaveCount(0);
});
-test("System: data and permission changes are listed in a dialog and apply only once confirmed", async ({ page }) => {
+test("System: data and permission changes: said plainly on the card, one clearly worded press applies exactly them", async ({ page }) => {
const confirm = "c".repeat(64);
const { systemCalls } = await setup(page, SELF, {
signedIn: true,
@@ -582,20 +582,15 @@ test("System: data and permission changes are listed in a dialog and apply only
});
await page.goto("/settings/system/");
const card = page.getByTestId("native-update");
- await expect(card).toContainText("v2.0.0 needs your OK");
- await expect(page.getByTestId("native-update-hold")).toContainText("replace or remove data and change permissions");
+ await expect(card).toContainText("v2.0.0 would replace or remove data");
+ await expect(page.getByTestId("native-update-data-changes")).toHaveText("The Table table in Database (replaced)");
+ await expect(page.getByTestId("native-update-permissions")).toHaveText("It changes what 1 of Coderhelm's own roles may do, all inside this install's permission limit.");
await expect(card).not.toContainText("choose Execute");
- await page.getByRole("button", { name: "Review and apply" }).click();
- const dialog = page.getByTestId("native-update-confirm");
- await expect(dialog).toBeVisible();
- await expect(page.getByTestId("native-update-data-changes")).toContainText("Database.Table (AWS::DynamoDB::GlobalTable");
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ // The raw CloudFormation list is behind Technical details.
+ await card.getByText("Technical details").click();
await expect(page.getByTestId("native-update-permission-changes")).toContainText("Api.NewRole (AWS::IAM::Role Add");
- // Cancel sends nothing.
- await dialog.getByRole("button", { name: "Cancel" }).click();
- await expect(dialog).toHaveCount(0);
- expect(systemCalls.filter((c) => c.path === "/api/system/update/apply")).toEqual([]);
- await page.getByRole("button", { name: "Review and apply" }).click();
- await page.getByRole("button", { name: "Confirm and apply" }).click();
+ await page.getByRole("button", { name: "Replace the data and apply" }).click();
await expect.poll(() => systemCalls.find((c) => c.path === "/api/system/update/apply")?.body).toEqual({ id: PREPARED.id, confirm });
});
@@ -608,9 +603,9 @@ test("System: a prepared update with nothing to confirm applies with one press",
await page.goto("/settings/system/");
await expect(page.getByTestId("native-update")).toContainText("v2.0.0 is ready to apply");
await expect(page.getByTestId("native-update-hold")).toContainText("Auto-update was turned off before it ran");
- await page.getByRole("button", { name: "Apply v2.0.0" }).click();
+ await page.getByRole("button", { name: "Apply update" }).click();
await expect.poll(() => systemCalls.find((c) => c.path === "/api/system/update/apply")?.body).toEqual({ id: PREPARED.id });
- await expect(page.getByTestId("native-update-confirm")).toHaveCount(0);
+ await expect(page.getByRole("dialog")).toHaveCount(0);
});
test("System: a change to the deploy role or a boundary is the one update that goes to the AWS console", async ({ page }) => {
diff --git a/dashboard/e2e/update-press.spec.ts b/dashboard/e2e/update-press.spec.ts
index 610dd81f..372b7643 100644
--- a/dashboard/e2e/update-press.spec.ts
+++ b/dashboard/e2e/update-press.spec.ts
@@ -21,6 +21,8 @@ const PENDING = (v: string, min = 1) => ({ version: v, checked_at: ago(min), sta
type V = Record;
interface World {
v: V;
+ checks?: unknown[];
+ blockers?: unknown[];
update?: (body: V, w: World) => { status: number; body: unknown };
rollback?: (w: World) => { status: number; body: unknown };
apply?: (w: World) => { status: number; body: unknown };
@@ -56,7 +58,7 @@ async function setup(page: Page, w: World) {
...w.v,
});
}
- if (p === "/api/system/preflight") return json(route, { checked_at: ago(0.2), ready: true, current: "v0.8.45", latest: null, blockers: [], checks: CHECKS });
+ if (p === "/api/system/preflight") return json(route, { checked_at: ago(0.2), ready: !(w.blockers ?? []).length, current: "v0.8.45", latest: null, blockers: w.blockers ?? [], checks: w.checks ?? CHECKS });
if (p === "/api/system/update" && w.update) {
await new Promise((r) => setTimeout(r, 600));
const r = w.update(route.request().postDataJSON() as V, w);
@@ -244,7 +246,7 @@ test.describe("Update: error toasts only for real failures", () => {
},
});
await page.goto("/settings/system/");
- await page.getByRole("button", { name: "Apply v0.8.46" }).dblclick();
+ await page.getByRole("button", { name: "Apply update" }).dblclick();
await expect(status(page)).toHaveAttribute("data-state", "updating");
await expect(page.getByTestId("native-update-progress")).toContainText("It was applied in the AWS console.");
await expect(toasts(page)).toHaveCount(0);
@@ -306,3 +308,133 @@ test.describe("Version and updates: the page", () => {
await expect(page.getByRole("button", { name: "Try again" })).toBeVisible();
});
});
+
+test.describe("Install health: only the install's own problems", () => {
+ // The payload seen live: the next release's check running (sent by the
+ // gateway as a warning check), and Slack not set up.
+ const RUNNING_CHECK = {
+ key: "update_models", group: "Claude", label: "The next release's models answer", status: "warn",
+ detail: "Checking v0.8.47-beta.20261106's signature before reading the models it calls.",
+ why: "The update waits until every model it calls answers.",
+ fix: { text: "Wait a few minutes, then check again.", href: "/settings/system#readiness" },
+ };
+ const SLACK = { key: "slack", group: "Integrations", label: "Slack", status: "skip", detail: "Not connected.", why: "Run results and questions in your Slack channels." };
+ const live = {
+ v: {
+ settings: { ...SETTINGS, channel: "beta" },
+ latest: rel("v0.8.47-beta.20261106", { prerelease: true }), update_available: true,
+ model_check: PENDING("v0.8.47-beta.20261106", 1),
+ },
+ checks: [...CHECKS, RUNNING_CHECK, SLACK],
+ blockers: [{ key: "model_check_pending", severity: "block", detail: "Checking v0.8.47-beta.20261106's signature before reading the models it calls.", fix: { text: "Wait a few minutes, then check again." } }],
+ };
+
+ test("a release check in progress is the update card's state only, never a health warning", async ({ page }) => {
+ await setup(page, live);
+ await page.goto("/settings/system/");
+ await expect(status(page)).toHaveAttribute("data-state", "checking-release");
+ await expect(status(page)).toContainText("Checking v0.8.47-beta.20261106 before it can be applied");
+ const health = page.getByTestId("install-health");
+ await expect(health).toHaveAttribute("data-state", "healthy");
+ await expect(page.getByTestId("health-summary")).toHaveText("All 4 checks pass");
+ await expect(page.getByTestId("health-problems")).toHaveCount(0);
+ await expect(health).not.toContainText("Warning");
+ await expect(health).not.toContainText("signature");
+ await expect(health).not.toContainText("needs a look");
+ // Each line under the summary is exactly what it says: the optional item, by name.
+ await expect(page.getByTestId("health-optional").locator("li")).toHaveText(["Optional: Slack. Run results and questions in your Slack channels."]);
+ await expect(health.getByRole("link", { name: "Open in Coderhelm" })).toHaveCount(0);
+ });
+
+ test("a fix never links to the page it is on", async ({ page }) => {
+ const refused = { ...RUNNING_CHECK, status: "fail", detail: "Update to v0.8.47 needs your action: a model was refused.", fix: { text: "Accept the terms in the Bedrock console.", href: "/settings/system#readiness", url: "https://console.aws.amazon.com/bedrock/home#/modelaccess" } };
+ const elsewhere = { key: "github_app", group: "GitHub", label: "GitHub accepts the app's keys", status: "fail", detail: "GitHub refused the keys.", fix: { text: "Add new keys.", href: "/settings/integrations" } };
+ await setup(page, { v: {}, checks: [refused, elsewhere] });
+ await page.goto("/settings/system/");
+ await expect(page.locator("#check-update_models").getByRole("link", { name: "Open in Coderhelm" })).toHaveCount(0);
+ await expect(page.locator("#check-update_models").getByRole("link", { name: "Open the AWS console" })).toBeVisible();
+ await expect(page.locator("#check-github_app").getByRole("link", { name: "Open in Coderhelm" })).toHaveAttribute("href", /^\/settings\/integrations\/?$/);
+ await expect(page.getByTestId("health-summary")).toHaveText("2 checks fail");
+ });
+});
+
+test.describe("Update: one decision", () => {
+ const NATIVE = { stack: "coderhelm-acme", can_apply: true, auto_apply: true };
+ const ROLE_CHANGES = [
+ "LogAnalyzer.LogAnalyzerServiceRoleDefaultPolicy341691CC (AWS::IAM::Policy Modify: an IAM change)",
+ "LogAnalyzer.LogAnalyzerServiceRole1A2B3C4D (AWS::IAM::Role Modify: an IAM change)",
+ "Worker.WorkerServiceRoleDefaultPolicy5E6F7A8B (AWS::IAM::Policy Modify: an IAM change)",
+ ];
+ const prepared = (extra: Record) => ({ version: "v0.8.46", status: "review", id: "UPDATE#2", counts: { add: 0, modify: 3, remove: 0 }, parts: ["LogAnalyzer", "Worker"], link: CS_LINK, can_apply: true, admin_changes: [], ...extra });
+ const applying = (extra: Record = {}) => ({ ...NATIVE, pending: prepared({ status: "running", execution: "EXECUTE_IN_PROGRESS", executed_at: ago(0), applied_by: "admin@acme.example", ...extra }) });
+
+ test("an update that only changes what Coderhelm's roles may do: from Update available to Applying in one click", async ({ page }) => {
+ const bodies: V[] = [];
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true, native: { ...NATIVE, pending: null }, model_check: { version: "v0.8.46", checked_at: ago(5), ok: true, results: [] } },
+ update: (b, w) => {
+ bodies.push(b);
+ // The press agreed to permission changes: the updater prepares, sees
+ // only role changes, and applies them by itself.
+ w.v = { ...w.v, running: true, native: applying({ permission_changes: ROLE_CHANGES }) };
+ return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "preparing", state: "started" } };
+ },
+ };
+ const calls = await setup(page, w);
+ await page.goto("/settings/system/");
+ // What one press does is said next to the button, before pressing.
+ await expect(page.getByTestId("update-consent")).toHaveText(
+ "One press prepares and applies it. That includes any change to what Coderhelm's own roles may do, always inside this install's permission limit. If it would replace or remove data, it stops and asks you first.",
+ );
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "updating");
+ await expect(status(page)).toContainText("Applying v0.8.46");
+ expect(bodies).toEqual([{ accept_permissions: true }]);
+ expect(posts(calls, "/api/system/update/apply")).toBe(0);
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ await expect(toasts(page)).toHaveCount(0);
+ });
+
+ test("a prepared update with role changes: a plain summary and one Apply update, the raw list under Technical details", async ({ page }) => {
+ const calls = await setup(page, {
+ v: { latest: rel("v0.8.46"), update_available: true, native: { ...NATIVE, pending: prepared({ confirm: "c".repeat(64), data_changes: [], permission_changes: ROLE_CHANGES }) } },
+ apply: (w) => { w.v = { ...w.v, running: true, native: applying({ permission_changes: ROLE_CHANGES }) }; return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "running" } }; },
+ });
+ await page.goto("/settings/system/");
+ await expect(status(page)).toContainText("v0.8.46 is ready to apply");
+ await expect(page.getByTestId("native-update-permissions")).toHaveText("It changes what 2 of Coderhelm's own roles may do, all inside this install's permission limit.");
+ await expect(page.getByTestId("native-update-permission-changes")).toBeHidden();
+ await status(page).getByText("Technical details").click();
+ await expect(page.getByTestId("native-update-permission-changes")).toBeVisible();
+ await expect(page.getByTestId("native-update-permission-changes")).toContainText("LogAnalyzerServiceRoleDefaultPolicy341691CC");
+ await page.getByRole("button", { name: "Apply update" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "updating");
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ expect(posts(calls, "/api/system/update/apply")).toBe(1);
+ });
+
+ test("an update that would replace data: two clicks, the second one says exactly what it does", async ({ page }) => {
+ const data = ["Database.Table (AWS::DynamoDB::GlobalTable: Modify, replacement True)"];
+ const applied: V[] = [];
+ const w: World = {
+ v: { latest: rel("v0.8.46"), update_available: true, native: { ...NATIVE, pending: null }, model_check: { version: "v0.8.46", checked_at: ago(5), ok: true, results: [] } },
+ update: (_b, w) => {
+ w.v = { ...w.v, native: { ...NATIVE, pending: prepared({ confirm: "d".repeat(64), data_changes: data, permission_changes: [] }) } };
+ return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "preparing", state: "started" } };
+ },
+ };
+ w.apply = (w) => { w.v = { ...w.v, running: true, native: applying({ data_changes: data }) }; return { status: 200, body: { id: "UPDATE#2", version: "v0.8.46", status: "running" } }; };
+ await setup(page, w);
+ await page.route((url) => url.pathname === "/api/system/update/apply", (route) => { applied.push(route.request().postDataJSON() as V); return route.fallback(); });
+ await page.goto("/settings/system/");
+ await page.getByRole("button", { name: "Update to v0.8.46" }).click();
+ await expect(status(page)).toContainText("v0.8.46 would replace or remove data");
+ await expect(page.getByTestId("native-update-hold")).toContainText("Applying it replaces or removes this data, which can't be undone:");
+ await expect(page.getByTestId("native-update-data-changes")).toHaveText("The Table table in Database (replaced)");
+ await expect(page.getByTestId("native-update-hold")).toContainText("If what it changes is different by then, it asks you again.");
+ await page.getByRole("button", { name: "Replace the data and apply" }).click();
+ await expect(status(page)).toHaveAttribute("data-state", "updating");
+ expect(applied).toEqual([{ id: "UPDATE#2", confirm: "d".repeat(64) }]);
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ });
+});
diff --git a/dashboard/e2e/update-states.spec.ts b/dashboard/e2e/update-states.spec.ts
index 00d9aba0..1dd9de6f 100644
--- a/dashboard/e2e/update-states.spec.ts
+++ b/dashboard/e2e/update-states.spec.ts
@@ -139,7 +139,7 @@ test.describe("Version and updates: every state", () => {
await expect(page.getByRole("heading", { name: "Install health" })).toBeVisible();
await expect(health(page)).toHaveAttribute("data-state", "healthy");
await expect(page.getByTestId("health-summary")).toHaveText("All 9 checks pass");
- await expect(health(page)).toContainText("1 optional check not set up");
+ await expect(page.getByTestId("health-optional")).toHaveText("Optional: Slack. Not connected (optional).");
await expect(page.getByTestId("release-notes")).toHaveCount(0);
await shoot(page, "01-up-to-date");
const before = calls.filter((c) => c === "/api/system/preflight").length;
@@ -352,12 +352,12 @@ test.describe("Version and updates: every state", () => {
await expect(status(page).getByRole("progressbar")).toBeVisible();
});
- test("needs your OK: data and permission changes", async ({ page }) => {
+ test("data and permission changes: what it replaces, in words, and one clearly worded button", async ({ page }) => {
await setup(page, { version: { latest: LATEST, update_available: true, native: { stack: "coderhelm-acme", can_apply: true, auto_apply: true, pending: { ...PREPARED, can_apply: true, confirm: "c".repeat(64), data_changes: ["Database.Table (AWS::DynamoDB::GlobalTable: Modify, replacement True)"], permission_changes: ["Api.NewRole (AWS::IAM::Role Add)"], admin_changes: [] } } } });
await page.goto("/settings/system/");
await expect(status(page)).toHaveAttribute("data-state", "review");
- await expect(status(page)).toContainText("v0.9.0 needs your OK");
- await expect(status(page).getByRole("button", { name: "Review and apply" })).toBeVisible();
+ await expect(status(page)).toContainText("v0.9.0 would replace or remove data");
+ await expect(status(page).getByRole("button", { name: "Replace the data and apply" })).toBeVisible();
await shoot(page, "13-needs-your-ok");
});
@@ -486,13 +486,13 @@ test.describe("Version and updates: one truthful state", () => {
await oneState(page);
await expect(status(page)).toHaveAttribute("data-state", "preparing");
await expect(status(page)).toContainText(`Preparing the update to ${NEW}`);
- await expect(page.locator("main")).not.toContainText(`${OLD} needs your OK`);
+ await expect(page.locator("main")).not.toContainText(`${OLD} is ready`);
await expect(page.locator("main")).not.toContainText(`Checking ${NEW}`);
- await expect(page.getByRole("button", { name: "Review and apply" })).toHaveCount(0);
+ await expect(page.getByTestId("native-update-apply")).toHaveCount(0);
await shoot(page, "21-observed-contradiction");
});
- test("the same install once the updater reconciled it: v0.8.39 needs your OK, the permission list in the dialog", async ({ page }) => {
+ test("the same install once the updater reconciled it: v0.8.39 is ready, one Apply update, the raw list under Technical details", async ({ page }) => {
await setup(page, {
version: {
latest: LIVE_LATEST, update_available: true,
@@ -504,15 +504,16 @@ test.describe("Version and updates: one truthful state", () => {
await page.goto("/settings/system/");
await oneState(page);
await expect(status(page)).toHaveAttribute("data-state", "review");
- await expect(status(page)).toContainText(`${NEW} needs your OK`);
+ await expect(status(page)).toContainText(`${NEW} is ready to apply`);
await expect(status(page).getByTestId("update-steps").locator('[aria-current="step"]')).toContainText("waits for your OK");
- await expect(page.locator("main")).not.toContainText(OLD + " needs");
+ await expect(page.locator("main")).not.toContainText(OLD + " is ready");
// History keeps the older one as replaced, never as a second update waiting.
await expect(page.getByTestId("update-history").locator("li").nth(1).getByTestId("history-status")).toHaveText("Replaced");
// Install health is its own section and never reads as an update state.
await expect(page.getByTestId("health-summary")).toHaveText("All 9 checks pass");
await shoot(page, "22-needs-your-ok");
- await status(page).getByRole("button", { name: "Review and apply" }).click();
+ await expect(status(page).getByRole("button", { name: "Apply update" })).toBeVisible();
+ await status(page).getByText("Technical details").click();
await expect(page.getByTestId("native-update-permission-changes")).toContainText("Api.NewRole");
});
@@ -528,7 +529,7 @@ test.describe("Version and updates: one truthful state", () => {
await oneState(page);
await expect(status(page)).toHaveAttribute("data-state", "updating");
await expect(status(page)).toContainText(`Applying ${NEW}`);
- await expect(page.getByRole("button", { name: "Review and apply" })).toHaveCount(0);
+ await expect(page.getByTestId("native-update-apply")).toHaveCount(0);
await expect(page.getByTestId("native-update-apply")).toHaveCount(0);
});
diff --git a/dashboard/src/app/settings/setup/page.tsx b/dashboard/src/app/settings/setup/page.tsx
index c5b3900c..15f6eae2 100644
--- a/dashboard/src/app/settings/setup/page.tsx
+++ b/dashboard/src/app/settings/setup/page.tsx
@@ -12,6 +12,7 @@ import { Chip } from "@/components/list";
import { linkButton, primaryButton, secondaryButton } from "@/components/ui";
import { CheckIcon } from "@/components/icons";
import { CheckRow } from "@/components/install-checks";
+import { healthChecks } from "@/lib/update-state";
import { CodeBlock } from "@/components/code-block";
import { Redirect } from "@/components/redirect";
@@ -174,7 +175,7 @@ function Setup() {
/** The server-side checks, grouped, failing first within the summary. */
function InstallChecks({ data, state, onRecheck }: { data: SystemChecks | null; state: "loading" | "ready" | "failed"; onRecheck: () => void }) {
const groups: [string, SystemChecks["checks"]][] = [];
- for (const c of data?.checks ?? []) {
+ for (const c of healthChecks(data?.checks ?? [])) {
const g = groups.find(([name]) => name === c.group);
if (g) g[1].push(c);
else groups.push([c.group, [c]]);
diff --git a/dashboard/src/app/settings/system/page.tsx b/dashboard/src/app/settings/system/page.tsx
index 45a44420..4e8e27ff 100644
--- a/dashboard/src/app/settings/system/page.tsx
+++ b/dashboard/src/app/settings/system/page.tsx
@@ -3,7 +3,7 @@
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
import Link from "next/link";
import { api, errorStatus, type AutoUpdateSettings, type ModelCheck, type SystemPreflight, type SystemVersion, type UpdateEntry } from "@/lib/api";
-import { deriveUpdateState, failureText, followEvery, isStateAnswer, nextAfter, STATE_ID, STARTING_HOLD_MS, withPress, type FailedTry, type UpdateState } from "@/lib/update-state";
+import { deriveUpdateState, failureText, healthChecks, followEvery, isStateAnswer, nextAfter, STATE_ID, STARTING_HOLD_MS, withPress, type FailedTry, type UpdateState } from "@/lib/update-state";
import { CheckRow } from "@/components/install-checks";
import { DomainSection } from "@/components/domain-section";
import { HybridSection } from "@/components/hybrid-section";
@@ -264,7 +264,9 @@ function System() {
// No version: the updater reads GitHub first and installs the newest
// release at this moment. Skipping a model check names the release
// whose check the admin read.
- const r = await api.updateNow(skipCheck ? data.model_check?.version : undefined, skipCheck);
+ // A one-stack install that applies its own updates: the press is also
+ // the admin's OK for permission changes, as the card says next to it.
+ const r = await api.updateNow(skipCheck ? data.model_check?.version : undefined, skipCheck, !!data.native?.can_apply);
if (r.ok) {
// Started, or recorded while the release check runs (it starts by
// itself once the check passes): either way the card shows it.
@@ -772,6 +774,11 @@ function UpdateStatus({
)}
{l.prerelease && A nightly beta: it reaches Stable after a day with no reported problem. You get these because the channel is Beta (nightly).
}
+ {data.native?.can_apply ? (
+
+ One press prepares and applies it. That includes any change to what Coderhelm's own roles may do, always inside this install's permission limit. If it would replace or remove data, it stops and asks you first.
+
+ ) : null}
{state.ended?.reason ? (
The last press of Update{state.ended.requested_at ? <> ( )> : null} didn't apply it: {state.ended.reason.replace(/\.$/, "")}.
@@ -1019,11 +1026,11 @@ function ReleaseNotes({ version, notes, url }: { version: string; notes: string;
* while no check fails, and the Version status says so.
*/
function InstallHealth({ pre, state, blocking, onRecheck }: { pre: SystemPreflight | null; state: "loading" | "ready" | "failed"; blocking: Set; onRecheck: () => void }) {
- const checks = pre?.checks ?? [];
+ const checks = healthChecks(pre?.checks ?? []);
const failing = checks.filter((c) => c.status === "fail");
const warning = checks.filter((c) => c.status === "warn");
const passing = checks.filter((c) => c.status === "pass").length;
- const optional = checks.filter((c) => c.status === "skip").length;
+ const optional = checks.filter((c) => c.status === "skip");
const health = !pre ? state : failing.length ? "failing" : warning.length ? "warning" : "healthy";
const rerun = (
@@ -1056,7 +1063,6 @@ function InstallHealth({ pre, state, blocking, onRecheck }: { pre: SystemPreflig
{failing.some((c) => blocking.has(c.key)) ? `Updates won't start until ${failing.length === 1 ? "it passes" : "they pass"}. ` : ""}
- {optional ? `${plural(optional, "optional check")} not set up. ` : ""}
Checked .
@@ -1067,7 +1073,7 @@ function InstallHealth({ pre, state, blocking, onRecheck }: { pre: SystemPreflig
)}
{pre && failing.length + warning.length > 0 && (
-
+
{[...failing, ...warning].map((c) => (
{blocking.has(c.key) && Stops updates
}
@@ -1075,6 +1081,15 @@ function InstallHealth({ pre, state, blocking, onRecheck }: { pre: SystemPreflig
))}
)}
+ {pre && optional.length > 0 && (
+
+ {optional.map((c) => (
+
+ Optional: {c.label}. {c.why ?? c.detail}
+
+ ))}
+
+ )}
);
}
diff --git a/dashboard/src/components/install-checks.tsx b/dashboard/src/components/install-checks.tsx
index 733ac8fb..60f3ece0 100644
--- a/dashboard/src/components/install-checks.tsx
+++ b/dashboard/src/components/install-checks.tsx
@@ -1,6 +1,7 @@
"use client";
import Link from "next/link";
+import { usePathname } from "next/navigation";
import type { CheckFix, CheckStatus, InstallCheck } from "@/lib/api";
import { Chip, type Tone } from "@/components/list";
import { CodeBlock } from "@/components/code-block";
@@ -17,6 +18,9 @@ export const STATUS: Record
{fix.text && (
@@ -26,9 +30,9 @@ export function FixBlock({ fix, testId }: { fix: CheckFix; testId?: string }) {
)}
{fix.command && }
- {(fix.url || fix.href) && (
+ {(fix.url || href) && (
);
}
+
+/**
+ * How many of Coderhelm's own roles a list of permission changes touches:
+ * "LogAnalyzer.LogAnalyzerServiceRoleDefaultPolicy341691CC (AWS::IAM::Policy
+ * Modify: ...)" and "LogAnalyzer.LogAnalyzerServiceRole1A2B3C4D (AWS::IAM::Role
+ * Modify)" are one role.
+ */
+export function permissionRoles(changes: string[]): number {
+ const roles = new Set(
+ changes.map((c) =>
+ c
+ .split(" ")[0]
+ .replace(/[0-9A-F]{8}$/, "")
+ .replace(/(DefaultPolicy|Policy)$/, "")
+ .replace(/[0-9A-F]{8}$/, ""),
+ ),
+ );
+ return Math.max(1, roles.size);
+}
+
+/** "Api.Table (AWS::DynamoDB::GlobalTable: Modify, replacement True)" in words: "Table in Api (replaced)". */
+export function plainResource(c: string): string {
+ const m = /^([^.\s]+)\.(\S+)\s*\(([^)]*)\)/.exec(c);
+ if (!m) return c;
+ const [, part, id, what] = m;
+ const kind = /DynamoDB/.test(what) ? "table" : /S3::Bucket/.test(what) ? "bucket" : /Cognito/.test(what) ? "sign-in user pool" : /KMS/.test(what) ? "key" : /SecretsManager/.test(what) ? "secret" : "resource";
+ const how = /Remove|Delete/i.test(what) ? "removed" : "replaced";
+ return `The ${id} ${kind} in ${part} (${how})`;
+}
diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts
index d5a9540c..a0b1c6ff 100644
--- a/dashboard/src/lib/api.ts
+++ b/dashboard/src/lib/api.ts
@@ -1295,10 +1295,16 @@ export const api = {
* the model check when a model the release calls was refused; `skipCheck`
* passes only a failure on a model the release doesn't call.
*/
- updateNow: (version?: string, skipCheck = false) =>
+ updateNow: (version?: string, skipCheck = false, acceptPermissions = false) =>
requestWithBody("/api/system/update", {
method: "POST",
- body: JSON.stringify({ ...(version ? { version } : {}), ...(skipCheck ? { skip_check: true } : {}) }),
+ body: JSON.stringify({
+ ...(version ? { version } : {}),
+ ...(skipCheck ? { skip_check: true } : {}),
+ // The press agrees to changes of what Coderhelm's own roles may do,
+ // inside the install's permission limit; never to data changes.
+ ...(acceptPermissions ? { accept_permissions: true } : {}),
+ }),
}),
/** The next release's model check, run again now. */
checkUpdateModels: () => request<{ model_check: ModelCheck | null }>("/api/system/update-check", { method: "POST", body: "{}" }),
diff --git a/dashboard/src/lib/update-state.ts b/dashboard/src/lib/update-state.ts
index 5280f549..018a8f85 100644
--- a/dashboard/src/lib/update-state.ts
+++ b/dashboard/src/lib/update-state.ts
@@ -301,3 +301,13 @@ export function failureText(what: string, message: string | null | undefined, st
export function isStateAnswer(status: number | undefined): boolean {
return status === 409;
}
+
+/**
+ * The checks that are about the install itself. The release check of the
+ * next release (running, or stopped without an answer) is the update's own
+ * state, shown only in the Version card; an older gateway still sends it as
+ * a check, so it is left out here unless a model really was refused.
+ */
+export function healthChecks(checks: T[]): T[] {
+ return checks.filter((c) => c.key !== "update_models" || c.status === "fail");
+}