Skip to content

Commit 69db351

Browse files
test(web): pin when the track switch dialog only saves the track
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c8eab52 commit 69db351

3 files changed

Lines changed: 92 additions & 16 deletions

File tree

‎apps/web/src/components/settings/UpdateTrackSwitchDialog.tsx‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
type ChannelSwitchRelease,
1919
} from "../sidebar/updateEverything.logic";
2020
import { isHostedByThisApp, useUpdateEverything } from "../sidebar/useUpdateEverything";
21-
import { prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
21+
import { nothingToMove, prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
2222
import {
2323
AlertDialog,
2424
AlertDialogClose,
@@ -81,16 +81,15 @@ function SwitchPlan({
8181
const [checking, setChecking] = useState(false);
8282
const everything = useUpdateEverything(switchesLocal ? release.version : null, release);
8383
const label = channelSwitchLabel(release.channel);
84-
// Skipped rows say why; track-only hosts are not rows but still get a request.
85-
const movesNothing = !switchesLocal && everything.rows.every((row) => row.skipped !== null);
86-
const savesNothing =
87-
movesNothing &&
88-
!everything.hasUpdates &&
89-
(updateState?.channel ?? "latest") === release.channel;
90-
const whyNothingMoves =
91-
everything.rows.length === 0 && !crossesLocal
92-
? `Every connected machine is already on ${label}.`
93-
: `No machine can switch to ${label} now.`;
84+
const idle = nothingToMove({
85+
label,
86+
channel: release.channel,
87+
savedChannel: updateState?.channel ?? "latest",
88+
switchesLocal,
89+
crossesLocal,
90+
rows: everything.rows,
91+
hasTargets: everything.hasUpdates,
92+
});
9493
// This app's reinstall restarts every server it hosts, so each of their databases must allow it.
9594
const localBlocked = localSwitchBlockReason(
9695
APP_VERSION,
@@ -166,7 +165,7 @@ function SwitchPlan({
166165
providerCount={0}
167166
rows={everything.rows}
168167
notes={[
169-
...(movesNothing && !savesNothing ? [`${whyNothingMoves} This only saves the track.`] : []),
168+
...(idle.note === null ? [] : [idle.note]),
170169
...(crossesLocal && updatesOff
171170
? ["This app's updates are off here, so reinstall it yourself to switch."]
172171
: []),
@@ -180,9 +179,7 @@ function SwitchPlan({
180179
disabledReason={
181180
switchesLocal && localBlocked !== null
182181
? `This app cannot switch: ${localBlocked}.`
183-
: savesNothing
184-
? whyNothingMoves
185-
: null
182+
: idle.disabledReason
186183
}
187184
onConfirm={() => void run()}
188185
/>

‎apps/web/src/components/settings/updateTrackSwitch.logic.test.ts‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DesktopUpdateChannel, DesktopUpdateState } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
4+
import { nothingToMove, prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
55

66
const STABLE = "0.1.3";
77

@@ -74,3 +74,59 @@ describe("prepareLocalTrackSwitch", () => {
7474
expect(undo.saved).toEqual(["latest"]);
7575
});
7676
});
77+
78+
describe("nothingToMove", () => {
79+
const skippedRemote = {
80+
skipped: "its server predates database checks; update it on Nightly first",
81+
};
82+
const stableSwitch = {
83+
label: "Stable",
84+
channel: "latest" as const,
85+
savedChannel: "latest" as const,
86+
switchesLocal: false,
87+
crossesLocal: false,
88+
rows: [skippedRemote],
89+
hasTargets: false,
90+
};
91+
92+
it("disables a switch that would neither move a machine nor save a track", () => {
93+
expect(nothingToMove(stableSwitch)).toEqual({
94+
note: null,
95+
disabledReason: "No machine can switch to Stable now.",
96+
});
97+
});
98+
99+
it("says a switch only saves the track when no machine moves", () => {
100+
const onlySaves = { note: "No machine can switch to Stable now. This only saves the track." };
101+
expect(nothingToMove({ ...stableSwitch, savedChannel: "nightly" })).toEqual({
102+
...onlySaves,
103+
disabledReason: null,
104+
});
105+
// A desktop host already on the track still gets its saved track changed.
106+
expect(nothingToMove({ ...stableSwitch, hasTargets: true })).toEqual({
107+
...onlySaves,
108+
disabledReason: null,
109+
});
110+
// With its updater off, this app stays on the other track.
111+
expect(
112+
nothingToMove({ ...stableSwitch, rows: [], crossesLocal: true, savedChannel: "nightly" }),
113+
).toEqual({
114+
...onlySaves,
115+
disabledReason: null,
116+
});
117+
expect(nothingToMove({ ...stableSwitch, rows: [], savedChannel: "nightly" })).toEqual({
118+
note: "Every connected machine is already on Stable. This only saves the track.",
119+
disabledReason: null,
120+
});
121+
});
122+
123+
it("stays out of a switch that moves a machine", () => {
124+
const none = { note: null, disabledReason: null };
125+
expect(nothingToMove({ ...stableSwitch, switchesLocal: true, crossesLocal: true })).toEqual(
126+
none,
127+
);
128+
expect(nothingToMove({ ...stableSwitch, rows: [skippedRemote, { skipped: null }] })).toEqual(
129+
none,
130+
);
131+
});
132+
});

‎apps/web/src/components/settings/updateTrackSwitch.logic.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ export async function prepareLocalTrackSwitch(
4848
: (local.message ?? `This app found no build of ${input.version} to install.`),
4949
};
5050
}
51+
52+
/** When no machine moves, confirming only saves the track; when that track is already saved too,
53+
* confirming would do nothing. Track-only hosts are not rows but still get a request. */
54+
export function nothingToMove(input: {
55+
readonly label: string;
56+
readonly channel: DesktopUpdateChannel;
57+
readonly savedChannel: DesktopUpdateChannel;
58+
readonly switchesLocal: boolean;
59+
readonly crossesLocal: boolean;
60+
readonly rows: ReadonlyArray<{ readonly skipped: string | null }>;
61+
readonly hasTargets: boolean;
62+
}): { readonly note: string | null; readonly disabledReason: string | null } {
63+
if (input.switchesLocal || input.rows.some((row) => row.skipped === null)) {
64+
return { note: null, disabledReason: null };
65+
}
66+
const reason =
67+
input.rows.length === 0 && !input.crossesLocal
68+
? `Every connected machine is already on ${input.label}.`
69+
: `No machine can switch to ${input.label} now.`;
70+
return !input.hasTargets && input.savedChannel === input.channel
71+
? { note: null, disabledReason: reason }
72+
: { note: `${reason} This only saves the track.`, disabledReason: null };
73+
}

0 commit comments

Comments
 (0)