Skip to content

Commit f9891a9

Browse files
author
delivery engine
committed
A T3 checkout update shows in the sidebar's update pill, like the desktop and harness updates
Web only. The T3 checkout update now shows in the v2 sidebar's update area as a SidebarCheckoutUpdatePill placed next to SidebarProviderUpdatePill in SidebarChromeFooter, reusing the T3 sidebar update pill's tones, icons, small dismiss button and tooltip. One root-mounted controller (CheckoutUpdateProvider in CheckoutUpdateNotification.tsx, wrapping the app shell in __root.tsx) feeds both the pill and the retained toast. The toast is kept only for the legacy sidebar and Settings routes. Both are hidden until client settings load and when the server lacks the checkoutUpdate capability. CheckoutUpdate.logic.ts works out the states: phase titles (installing/building/restarting) that stay even when the server sends a message, undone vs could-not-update told apart even when an earlier undo is still on record, reason fallback to lastOutcome.reason, the pill view (available/starting/not-started notice/progress/undone/failed/reload/none) and the presentation choice. The controller blocks a second start before React re-renders and holds 'Starting…' until the server moves on (or passes on the request). A failed start says it did not start and allows retry. Start requests still in flight from a previous primary environment are ignored. The initiating tab reloads by itself and other tabs offer Reload. The loaded commit and initiating tab survive Settings navigation and a reconnect where the server briefly reports nothing. Offered-commit dismissal shares the existing t3code:checkout-update-dismissed:v1 key, outcome notices close locally, and a toast closed by the code no longer remembers a dismissal (this also fixes a failure toast that reopened after closing). Desktop updater files are unchanged; mobile is not changed because it has no checkout update screen. Task task-96df4b2119, revision 2, run run-f8807ae82d.
1 parent 4941e68 commit f9891a9

7 files changed

Lines changed: 929 additions & 80 deletions

File tree

Lines changed: 162 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import type { CheckoutUpdateState } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { checkoutUpdateView } from "./CheckoutUpdate.logic";
4+
import {
5+
availableUpdateLine,
6+
CHECKOUT_UPDATE_NOT_STARTED,
7+
checkoutUpdatePillView,
8+
checkoutUpdatePresentation,
9+
checkoutUpdateView,
10+
} from "./CheckoutUpdate.logic";
511

612
const A = "a".repeat(40);
713
const B = "b".repeat(40);
14+
const C = "c".repeat(40);
815
const idle: CheckoutUpdateState = {
916
running: { commit: A, subject: "Older work" },
1017
available: { commit: B, subject: "Newer work", behind: 3 },
@@ -13,33 +20,173 @@ const idle: CheckoutUpdateState = {
1320
checkedAt: null,
1421
lastOutcome: null,
1522
};
23+
const onA: { loadedCommit: string | null; dismissedCommit: string | null } = {
24+
loadedCommit: A,
25+
dismissedCommit: null,
26+
};
27+
const pillOptions = { starting: false, startFailed: false, closedKey: null as string | null };
28+
const pill = (state: CheckoutUpdateState | null, options: Partial<typeof onA> = {}) =>
29+
checkoutUpdatePillView(checkoutUpdateView(state, { ...onA, ...options }), pillOptions);
30+
31+
const undone: CheckoutUpdateState = {
32+
...idle,
33+
phase: "failed",
34+
message: "bbbbbbb did not start. T3 went back to aaaaaaa.",
35+
lastOutcome: { from: A, to: B, status: "rolled-back", reason: "bbbbbbb did not start." },
36+
};
37+
38+
describe("availableUpdateLine", () => {
39+
it.each([
40+
[{ commit: B, subject: "Newer work", behind: 1 }, "Newer work · 1 new commit"],
41+
[{ commit: B, subject: "Newer work", behind: 4 }, "Newer work · 4 new commits"],
42+
[{ commit: B, subject: "", behind: 2 }, "bbbbbbb · 2 new commits"],
43+
])("names the commit and how many: %o", (available, line) => {
44+
expect(availableUpdateLine(available)).toBe(line);
45+
});
46+
});
1647

1748
describe("checkoutUpdateView", () => {
18-
it("offers a newer commit until it is dismissed", () => {
19-
expect(checkoutUpdateView(idle, { loadedCommit: A, dismissedCommit: null })).toMatchObject({
49+
it("offers a newer commit until it is dismissed, then offers a newer one again", () => {
50+
expect(checkoutUpdateView(idle, onA)).toMatchObject({
2051
kind: "available",
52+
title: "T3 update available",
2153
description: "Newer work · 3 new commits",
2254
});
2355
expect(checkoutUpdateView(idle, { loadedCommit: A, dismissedCommit: B })).toBeNull();
56+
const newer = { ...idle, available: { commit: C, subject: "Newest", behind: 4 } };
57+
expect(checkoutUpdateView(newer, { loadedCommit: A, dismissedCommit: B })?.key).toBe(
58+
`available:${C}`,
59+
);
60+
});
61+
62+
it("says nothing when the server runs the newest commit", () => {
63+
expect(checkoutUpdateView({ ...idle, available: null }, onA)).toBeNull();
64+
expect(checkoutUpdateView(null, onA)).toBeNull();
65+
});
66+
67+
it("keeps the offer, or nothing, while the server checks", () => {
68+
const checking = { ...idle, phase: "checking" as const };
69+
expect(checkoutUpdateView(checking, onA)?.kind).toBe("available");
70+
expect(checkoutUpdateView(checking, { loadedCommit: A, dismissedCommit: B })).toBeNull();
71+
});
72+
73+
it.each([
74+
["installing", "Installing the T3 update"],
75+
["building", "Building the T3 update"],
76+
["restarting", "Restarting T3"],
77+
] as const)("names the %s phase even when the server says more", (phase, title) => {
78+
const view = checkoutUpdateView({ ...idle, phase, message: "Working on it." }, onA);
79+
expect(view).toMatchObject({ kind: "progress", title, description: "Working on it." });
80+
});
81+
82+
it("says an update that did not start was undone, with why", () => {
83+
expect(checkoutUpdateView(undone, onA)).toMatchObject({
84+
kind: "failed",
85+
title: "T3 update undone",
86+
description: "bbbbbbb did not start. T3 went back to aaaaaaa.",
87+
});
88+
expect(checkoutUpdateView({ ...undone, message: null }, onA)).toMatchObject({
89+
title: "T3 update undone",
90+
description: "bbbbbbb did not start.",
91+
});
92+
});
93+
94+
it("says an update that failed before restarting could not be made", () => {
95+
const failed = { ...idle, phase: "failed" as const, message: "Building the web app failed" };
96+
expect(checkoutUpdateView(failed, onA)).toMatchObject({
97+
title: "T3 could not update",
98+
description: "Building the web app failed",
99+
});
100+
// An earlier attempt's undo does not make this failure one.
101+
const afterEarlierUndo = { ...failed, lastOutcome: undone.lastOutcome };
102+
expect(checkoutUpdateView(afterEarlierUndo, onA)?.title).toBe("T3 could not update");
103+
expect(checkoutUpdateView(afterEarlierUndo, onA)?.key).not.toBe(
104+
checkoutUpdateView(undone, onA)?.key,
105+
);
24106
});
25107

26108
it("asks for a reload once the server runs another commit than the page", () => {
27109
const updated = { ...idle, running: { commit: B, subject: "Newer work" }, available: null };
28-
expect(checkoutUpdateView(updated, { loadedCommit: A, dismissedCommit: null })?.kind).toBe(
29-
"reload",
30-
);
110+
expect(checkoutUpdateView(updated, onA)).toMatchObject({
111+
kind: "reload",
112+
description: "Now on bbbbbbb: Newer work. Reload to use it.",
113+
});
114+
expect(checkoutUpdateView(updated, { loadedCommit: null, dismissedCommit: null })).toBeNull();
31115
});
116+
});
32117

33-
it("says an update that did not start was undone", () => {
34-
const undone: CheckoutUpdateState = {
35-
...idle,
36-
phase: "failed",
37-
message: "bbbbbbb did not start. T3 went back to aaaaaaa.",
38-
lastOutcome: { from: A, to: B, status: "rolled-back", reason: "bbbbbbb did not start." },
39-
};
40-
expect(checkoutUpdateView(undone, { loadedCommit: A, dismissedCommit: null })).toMatchObject({
41-
kind: "failed",
118+
describe("checkoutUpdatePillView", () => {
119+
it("offers the update with a dismiss that remembers the commit", () => {
120+
expect(pill(idle)).toMatchObject({
121+
tone: "info",
122+
title: "T3 update available",
123+
description: "Newer work · 3 new commits",
124+
action: "update",
125+
close: "dismiss",
126+
notice: null,
127+
});
128+
expect(pill(idle, { dismissedCommit: B })).toBeNull();
129+
});
130+
131+
it("holds the button while the start request is out, then says when it did not start", () => {
132+
const view = checkoutUpdateView(idle, onA);
133+
expect(checkoutUpdatePillView(view, { ...pillOptions, starting: true })).toMatchObject({
134+
action: "starting",
135+
close: null,
136+
});
137+
expect(checkoutUpdatePillView(view, { ...pillOptions, startFailed: true })).toMatchObject({
138+
action: "update",
139+
notice: CHECKOUT_UPDATE_NOT_STARTED,
140+
});
141+
});
142+
143+
it.each(["installing", "building", "restarting"] as const)(
144+
"shows the %s phase with no action",
145+
(phase) => {
146+
expect(pill({ ...idle, phase })).toMatchObject({
147+
tone: "loading",
148+
action: null,
149+
close: null,
150+
});
151+
},
152+
);
153+
154+
it("shows undone and failed outcomes until closed", () => {
155+
const view = checkoutUpdateView(undone, onA);
156+
expect(checkoutUpdatePillView(view, pillOptions)).toMatchObject({
157+
tone: "error",
42158
title: "T3 update undone",
159+
close: "close",
43160
});
161+
expect(checkoutUpdatePillView(view, { ...pillOptions, closedKey: view?.key ?? null })).toBe(
162+
null,
163+
);
164+
const failed = { ...idle, phase: "failed" as const, message: "Installing failed" };
165+
expect(pill(failed)).toMatchObject({ title: "T3 could not update", close: "close" });
166+
});
167+
168+
it("offers Reload once the server runs a newer commit", () => {
169+
const updated = { ...idle, running: { commit: B, subject: "Newer work" }, available: null };
170+
expect(pill(updated)).toMatchObject({ title: "T3 was updated", action: "reload" });
171+
});
172+
173+
it("shows nothing with no update", () => {
174+
expect(pill({ ...idle, available: null })).toBeNull();
175+
});
176+
});
177+
178+
describe("checkoutUpdatePresentation", () => {
179+
const v2 = { settingsHydrated: true, supported: true, legacySidebar: false };
180+
it.each([
181+
[{ ...v2, settingsHydrated: false, pathname: "/" }, "none"],
182+
[{ ...v2, supported: false, pathname: "/" }, "none"],
183+
[{ ...v2, legacySidebar: true, pathname: "/" }, "toast"],
184+
[{ ...v2, pathname: "/settings" }, "toast"],
185+
[{ ...v2, pathname: "/settings/connections" }, "toast"],
186+
[{ ...v2, pathname: "/settingsx" }, "pill"],
187+
[{ ...v2, pathname: "/board" }, "pill"],
188+
[{ ...v2, pathname: "/" }, "pill"],
189+
] as const)("%o shows %s", (input, presentation) => {
190+
expect(checkoutUpdatePresentation(input)).toBe(presentation);
44191
});
45192
});

‎apps/web/src/components/CheckoutUpdate.logic.ts‎

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ export type CheckoutUpdateView =
3030

3131
export const shortCommit = (commit: string) => commit.slice(0, 7);
3232

33-
const PROGRESS: Partial<Record<CheckoutUpdateState["phase"], string>> = {
34-
installing: "Installing the new version.",
35-
building: "Building the new version.",
36-
restarting: "Restarting. This page reconnects by itself.",
33+
// The title names the phase; the description is the server's own words when it has some.
34+
const PROGRESS: Partial<
35+
Record<CheckoutUpdateState["phase"], { readonly title: string; readonly description: string }>
36+
> = {
37+
installing: { title: "Installing the T3 update", description: "Installing the new version." },
38+
building: { title: "Building the T3 update", description: "Building the new version." },
39+
restarting: {
40+
title: "Restarting T3",
41+
description: "Restarting. This page reconnects by itself.",
42+
},
3743
};
3844

3945
export function availableUpdateLine(available: NonNullable<CheckoutUpdateState["available"]>) {
@@ -46,6 +52,19 @@ export function availableUpdateLine(available: NonNullable<CheckoutUpdateState["
4652
return [available.subject || shortCommit(available.commit), count].filter(Boolean).join(" · ");
4753
}
4854

55+
/**
56+
* A failed phase was undone when the supervisor went back to the running
57+
* commit after the new one did not start. `lastOutcome` outlives its attempt,
58+
* so a later install or build failure, whose message is its own, is not one.
59+
*/
60+
function isUndone(state: CheckoutUpdateState): boolean {
61+
const outcome = state.lastOutcome;
62+
if (outcome?.status !== "rolled-back" || outcome.from !== state.running.commit) return false;
63+
return (
64+
state.message === null || outcome.reason === null || state.message.startsWith(outcome.reason)
65+
);
66+
}
67+
4968
/**
5069
* The one thing to say, most pressing first: a page left on an older build,
5170
* an update under way, one that failed, then one on offer and not dismissed.
@@ -69,17 +88,21 @@ export function checkoutUpdateView(
6988
return {
7089
kind: "progress",
7190
key: `progress:${state.phase}`,
72-
title: "Updating T3",
73-
description: state.message ?? progress,
91+
title: progress.title,
92+
description: state.message ?? progress.description,
7493
};
7594
}
7695
if (state.phase === "failed") {
77-
const undone = state.lastOutcome?.status === "rolled-back";
96+
const undone = isUndone(state);
97+
const description =
98+
state.message ??
99+
state.lastOutcome?.reason ??
100+
"The update did not finish. T3 is still on the version it was.";
78101
return {
79102
kind: "failed",
80-
key: `failed:${state.message ?? ""}`,
103+
key: `failed:${undone ? "undone" : "error"}:${running}:${description}`,
81104
title: undone ? "T3 update undone" : "T3 could not update",
82-
description: state.message ?? "The update did not finish. T3 is still on the version it was.",
105+
description,
83106
};
84107
}
85108
if (state.available !== null && state.available.commit !== options.dismissedCommit) {
@@ -92,3 +115,66 @@ export function checkoutUpdateView(
92115
}
93116
return null;
94117
}
118+
119+
/** Where the checkout update is shown: the v2 sidebar's pill, a toast, or nowhere. */
120+
export type CheckoutUpdatePresentation = "none" | "toast" | "pill";
121+
122+
/**
123+
* The v2 sidebar footer holds the pill on every route but Settings, which swaps
124+
* the footer for its own nav. The legacy sidebar keeps the toast.
125+
*/
126+
export function checkoutUpdatePresentation(input: {
127+
readonly settingsHydrated: boolean;
128+
readonly supported: boolean;
129+
readonly legacySidebar: boolean;
130+
readonly pathname: string;
131+
}): CheckoutUpdatePresentation {
132+
if (!input.settingsHydrated || !input.supported) return "none";
133+
if (input.legacySidebar) return "toast";
134+
if (input.pathname === "/settings" || input.pathname.startsWith("/settings/")) return "toast";
135+
return "pill";
136+
}
137+
138+
/** The checkout update as the sidebar pill shows it. */
139+
export interface CheckoutUpdatePillView {
140+
readonly key: string;
141+
readonly tone: "info" | "loading" | "error";
142+
readonly title: string;
143+
readonly description: string;
144+
/** Said under the description, such as a start request that did not go through. */
145+
readonly notice: string | null;
146+
readonly action: "update" | "starting" | "reload" | null;
147+
/** `dismiss` remembers the offered commit; `close` only hides this notice. */
148+
readonly close: "dismiss" | "close" | null;
149+
}
150+
151+
export const CHECKOUT_UPDATE_NOT_STARTED = "The update did not start. Try again.";
152+
153+
export function checkoutUpdatePillView(
154+
view: CheckoutUpdateView | null,
155+
options: {
156+
readonly starting: boolean;
157+
readonly startFailed: boolean;
158+
/** A notice the person closed; hidden until the view's key changes. */
159+
readonly closedKey: string | null;
160+
},
161+
): CheckoutUpdatePillView | null {
162+
if (view === null || view.key === options.closedKey) return null;
163+
const base = { key: view.key, title: view.title, description: view.description, notice: null };
164+
switch (view.kind) {
165+
case "available":
166+
return {
167+
...base,
168+
tone: "info",
169+
notice: !options.starting && options.startFailed ? CHECKOUT_UPDATE_NOT_STARTED : null,
170+
action: options.starting ? "starting" : "update",
171+
close: options.starting ? null : "dismiss",
172+
};
173+
case "progress":
174+
return { ...base, tone: "loading", action: null, close: null };
175+
case "failed":
176+
return { ...base, tone: "error", action: null, close: "close" };
177+
case "reload":
178+
return { ...base, tone: "info", action: "reload", close: "close" };
179+
}
180+
}

0 commit comments

Comments
 (0)