Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dashboard/e2e/selfhost.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,32 @@ test("System: the domain section at 1440 and 390, no sideways scroll", async ({
}
});

test("System: the beta channel installs at any hour, a gap after the last install; stable keeps its window", async ({ page }) => {
const beta = { auto: true, channel: "beta", day: "sun", hour: 3, timezone: "UTC", majors: "ask", gap_hours: 2 };
const { systemCalls } = await setup(page, SELF, { signedIn: true, version: { settings: beta } });
await page.goto("/settings/system/");
const day = page.getByRole("combobox", { name: "Day" });
await pickOption(day, "any");
await expect(page.getByRole("combobox", { name: "Hour", exact: true })).toHaveCount(0);
await pickOption(page.getByRole("combobox", { name: "Hours between installs" }), "4");
await page.getByRole("button", { name: "Save changes" }).click();
await expect.poll(() => systemCalls.find((c) => c.path === "/api/system/auto-update")?.body).toMatchObject({ day: "any", gap_hours: 4, channel: "beta" });

// Stable has no Any hour: moving to it puts the window back on a day.
await page.getByTestId("channel-stable").click();
await expect(page.getByRole("combobox", { name: "Hour", exact: true })).toBeVisible();
await day.click();
await expect(page.getByRole("option", { name: "Any hour (beta)" })).toHaveCount(0);
});

test("System: an updater without Any hour never offers it", async ({ page }) => {
await setup(page, SELF, { signedIn: true, version: { settings: { auto: true, channel: "beta", day: "sun", hour: 3, timezone: "UTC", majors: "ask" } } });
await page.goto("/settings/system/");
await page.getByRole("combobox", { name: "Day" }).click();
await expect(page.getByRole("option", { name: "Monday" })).toBeVisible();
await expect(page.getByRole("option", { name: "Any hour (beta)" })).toHaveCount(0);
});

test("System: an update still being prepared shows that, before the change set has any details", async ({ page }) => {
// While preparing, the install sends only status and version.
await setup(page, SELF, {
Expand Down
49 changes: 41 additions & 8 deletions dashboard/src/app/settings/system/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const DAYS: [string, string][] = [
["sun", "Sunday"],
];

/** The beta channel's window: every hour, at least `gap_hours` after the last install. */
const ANY_HOUR = "any";
const GAP_HOURS = [1, 2, 3, 4, 6, 8, 12, 24];

const STATUS: Record<UpdateEntry["status"], { label: string; tone: "success" | "danger" | "waiting" | "neutral" }> = {
running: { label: "Running", tone: "waiting" },
preparing: { label: "Preparing", tone: "waiting" },
Expand Down Expand Up @@ -230,6 +234,13 @@ function System() {

const v = form.values;
const set = <K extends keyof AutoUpdateSettings>(k: K, val: AutoUpdateSettings[K]) => form.set(k, val);
// Any hour is the beta channel's only, and only from an updater that has it (it returns gap_hours).
const anyHourOffered = data?.settings?.gap_hours !== undefined && v.channel === "beta";
const setChannel = (c: AutoUpdateSettings["channel"]) => {
set("channel", c);
// Stable installs in its window: Any hour goes back to the default day, as the updater does.
if (c !== "beta" && v.day === ANY_HOUR) set("day", DEFAULTS.day);
};
const latest = data.latest;
const history = data.history ?? [];
const canRollBack = history.some((h) => h.status === "succeeded" && h.from_version);
Expand Down Expand Up @@ -330,21 +341,42 @@ function System() {
<SettingsRow
label="Install updates automatically"
layout="toggle"
help="Updates install during the hour you pick below. If anything goes wrong, Coderhelm switches back to the previous version and emails the admins."
help={v.day === ANY_HOUR
? "Each new beta installs within the hour it comes out, with the gap you pick below. If anything goes wrong, Coderhelm switches back to the previous version and emails the admins."
: "Updates install during the hour you pick below. If anything goes wrong, Coderhelm switches back to the previous version and emails the admins."}
control={(ids) => <Switch id={ids.inputId} checked={v.auto} onChange={(c) => set("auto", c)} labelledBy={ids.labelId} describedBy={ids.helpId} />}
/>
<SettingsRow
label="Maintenance window"
help="The only hour an automatic update may start."
help={v.day === ANY_HOUR ? "Any hour: a new beta starts at the next hourly check, once the last install is far enough back." : "The only hour an automatic update may start."}
control={(ids) => (
<div className="flex flex-wrap gap-2">
<Select id={ids.inputId} aria-label="Day" value={v.day} onChange={(d) => set("day", d)} options={DAYS.map(([k, label]) => ({ value: k, label }))} />
<Select
aria-label="Hour"
value={String(v.hour)}
onChange={(h) => set("hour", Number(h))}
options={Array.from({ length: 24 }, (_, h) => ({ value: String(h), label: `${String(h).padStart(2, "0")}:00` }))}
id={ids.inputId}
aria-label="Day"
value={v.day}
onChange={(d) => set("day", d)}
options={[
...(anyHourOffered || v.day === ANY_HOUR ? [{ value: ANY_HOUR, label: "Any hour (beta)" }] : []),
...DAYS.map(([k, label]) => ({ value: k, label })),
]}
/>
{v.day === ANY_HOUR ? (
<Select
aria-label="Hours between installs"
data-testid="update-gap"
value={String(v.gap_hours ?? 2)}
onChange={(g) => set("gap_hours", Number(g))}
options={GAP_HOURS.map((g) => ({ value: String(g), label: g === 1 ? "At least 1 hour apart" : `At least ${g} hours apart` }))}
/>
) : (
<Select
aria-label="Hour"
value={String(v.hour)}
onChange={(h) => set("hour", Number(h))}
options={Array.from({ length: 24 }, (_, h) => ({ value: String(h), label: `${String(h).padStart(2, "0")}:00` }))}
/>
)}
</div>
)}
/>
Expand Down Expand Up @@ -384,7 +416,7 @@ function System() {
name="update-channel"
value={c.value}
checked={v.channel === c.value}
onChange={() => set("channel", c.value)}
onChange={() => setChannel(c.value)}
className="mt-1 h-4 w-4 shrink-0 accent-sky-500"
/>
<span className="min-w-0">
Expand Down Expand Up @@ -530,6 +562,7 @@ function Working({ label }: { label: string }) {
/** "Sundays at 03:00 UTC": when automatic updates may start, or null when they're off. */
function windowText(s: AutoUpdateSettings | undefined): string | null {
if (!s?.auto) return null;
if (s.day === ANY_HOUR) return `any hour, at least ${plural(s.gap_hours ?? 2, "hour")} after the last install`;
const day = s.day === "daily" ? "every day" : `${DAYS.find(([k]) => k === s.day)?.[1] ?? s.day}s`;
return `${day} at ${String(s.hour).padStart(2, "0")}:00 ${s.timezone.replace(/_/g, " ")}`;
}
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5719,13 +5719,15 @@ export interface AutoUpdateSettings {
auto: boolean;
/** stable: releases only. beta: the nightly builds too (an updater from before calls it "preview"). */
channel: "stable" | "beta";
/** mon…sun, or daily */
/** mon…sun, daily, or any: every hour (the beta channel only), gap_hours after the last install. */
day: string;
hour: number;
timezone: string;
majors: "ask" | "auto";
/** How often the "What's new" email may go. Absent from an updater from before it existed. */
digest?: "weekly" | "biweekly" | "off";
/** With day "any": the hours at least between two installs. Absent from an updater that has no "any". */
gap_hours?: number;
}

export interface UpdateEntry {
Expand Down
Loading