Skip to content

Commit f2943ee

Browse files
t3dotggclaude
andauthored
feat(updates): switch your whole fleet between Stable and Nightly in one step (pingdotgg#26288)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent d7935f1 commit f2943ee

41 files changed

Lines changed: 1959 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/ipc/methods/updates.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ export const getUpdateState = DesktopIpc.makeIpcMethod({
2323

2424
export const setUpdateChannel = DesktopIpc.makeIpcMethod({
2525
channel: IpcChannels.UPDATE_SET_CHANNEL_CHANNEL,
26-
payload: DesktopUpdateChannelSchema,
26+
payload: Schema.Struct({
27+
channel: DesktopUpdateChannelSchema,
28+
minimumVersion: Schema.optional(Schema.String),
29+
}),
2730
result: DesktopUpdateStateSchema,
28-
handler: Effect.fn("desktop.ipc.updates.setChannel")(function* (channel) {
31+
handler: Effect.fn("desktop.ipc.updates.setChannel")(function* ({ channel, minimumVersion }) {
2932
const updates = yield* DesktopUpdates.DesktopUpdates;
30-
return yield* updates.setChannel(channel);
33+
return yield* updates.setChannel(channel, { minimumVersion });
3134
}),
3235
});
3336

@@ -43,11 +46,14 @@ export const downloadUpdate = DesktopIpc.makeIpcMethod({
4346

4447
export const installUpdate = DesktopIpc.makeIpcMethod({
4548
channel: IpcChannels.UPDATE_INSTALL_CHANNEL,
46-
payload: Schema.Void,
49+
/** A version installs only that downloaded build, never one that replaced it. */
50+
payload: Schema.UndefinedOr(Schema.String),
4751
result: DesktopUpdateActionResultSchema,
48-
handler: Effect.fn("desktop.ipc.updates.install")(function* () {
52+
handler: Effect.fn("desktop.ipc.updates.install")(function* (expectedVersion) {
4953
const updates = yield* DesktopUpdates.DesktopUpdates;
50-
return yield* updates.install;
54+
if (expectedVersion === undefined) return yield* updates.install;
55+
const { accepted, completed, state } = yield* updates.installPrepared(expectedVersion);
56+
return { accepted, completed, state };
5157
}),
5258
});
5359

‎apps/desktop/src/preload.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,12 @@ contextBridge.exposeInMainWorld("desktopBridge", {
261261
};
262262
},
263263
getUpdateState: () => ipcRenderer.invoke(IpcChannels.UPDATE_GET_STATE_CHANNEL),
264-
setUpdateChannel: (channel) =>
265-
ipcRenderer.invoke(IpcChannels.UPDATE_SET_CHANNEL_CHANNEL, channel),
264+
setUpdateChannel: (channel, minimumVersion) =>
265+
ipcRenderer.invoke(IpcChannels.UPDATE_SET_CHANNEL_CHANNEL, { channel, minimumVersion }),
266266
checkForUpdate: () => ipcRenderer.invoke(IpcChannels.UPDATE_CHECK_CHANNEL),
267267
downloadUpdate: () => ipcRenderer.invoke(IpcChannels.UPDATE_DOWNLOAD_CHANNEL),
268-
installUpdate: () => ipcRenderer.invoke(IpcChannels.UPDATE_INSTALL_CHANNEL),
268+
installUpdate: (expectedVersion) =>
269+
ipcRenderer.invoke(IpcChannels.UPDATE_INSTALL_CHANNEL, expectedVersion),
269270
cliCommand: {
270271
getState: () => ipcRenderer.invoke(IpcChannels.CLI_COMMAND_GET_STATE_CHANNEL),
271272
install: () => ipcRenderer.invoke(IpcChannels.CLI_COMMAND_INSTALL_CHANNEL),

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
normalizeLinuxPasswordStorePreference,
2323
type LinuxPasswordStorePreference,
2424
} from "../linuxSecretStorage.ts";
25-
import { resolveDefaultDesktopUpdateChannel } from "../updates/updateChannels.ts";
25+
import { desktopUpdateChannelOf } from "@t3tools/shared/cliRelease";
2626
import { isValidDistroName } from "../wsl/wslPathParsing.ts";
2727

2828
export interface DesktopSettings {
@@ -180,7 +180,7 @@ export class DesktopAppSettings extends Context.Service<
180180
export function resolveDefaultDesktopSettings(appVersion: string): DesktopSettings {
181181
return {
182182
...DEFAULT_DESKTOP_SETTINGS,
183-
updateChannel: resolveDefaultDesktopUpdateChannel(appVersion),
183+
updateChannel: desktopUpdateChannelOf(appVersion),
184184
};
185185
}
186186

‎apps/desktop/src/updates/DesktopRemoteUpdates.test.ts‎

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,239 @@ describe("DesktopRemoteUpdates", () => {
119119
);
120120
});
121121

122+
it.effect("switches to the requested track before preparing its release", () => {
123+
// In-memory settings keep the channel write off real disk I/O.
124+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
125+
126+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
127+
Effect.gen(function* () {
128+
const updates = yield* DesktopUpdates.DesktopUpdates;
129+
yield* Queue.offer(requests, {
130+
...request("req-switch"),
131+
channel: "nightly",
132+
targetVersion: "1.2.4-nightly.20261027.1",
133+
});
134+
yield* settle;
135+
assert.equal((yield* updates.getState).channel, "nightly");
136+
137+
harness.emit("update-available", { version: "1.2.4-nightly.20261027.1" });
138+
yield* settle;
139+
harness.emit("update-downloaded", { version: "1.2.4-nightly.20261027.1" });
140+
yield* settle;
141+
142+
const terminals = terminalReports(reports);
143+
assert.deepEqual(
144+
terminals.map((report) => [report.requestId, report.outcome]),
145+
[["req-switch", "ready-to-install"]],
146+
);
147+
assert.equal(terminals[0]?.state.downloadedVersion, "1.2.4-nightly.20261027.1");
148+
}),
149+
);
150+
});
151+
152+
it.effect(
153+
"refuses a crossing whose feed has only an older build, and never offers it later",
154+
() => {
155+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
156+
157+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
158+
Effect.gen(function* () {
159+
const updates = yield* DesktopUpdates.DesktopUpdates;
160+
const older = "1.2.4-nightly.20261020.1";
161+
yield* Queue.offer(requests, {
162+
...request("req-older"),
163+
channel: "nightly",
164+
targetVersion: "1.2.4-nightly.20261027.1",
165+
});
166+
yield* settle;
167+
// Answers the track change's check, then the request's own check.
168+
harness.emit("update-available", { version: older });
169+
yield* settle;
170+
harness.emit("update-available", { version: older });
171+
yield* settle;
172+
173+
assert.deepEqual(
174+
terminalReports(reports).map((report) => [report.outcome, report.reason]),
175+
[["failed", "The desktop app found no build of 1.2.4-nightly.20261027.1."]],
176+
);
177+
// The saved track is the user's intent; a retry picks it up from here.
178+
assert.equal((yield* updates.getState).channel, "nightly");
179+
180+
// A plain update afterwards cannot reach the build the switch refused.
181+
yield* Queue.offer(requests, request("req-plain"));
182+
yield* settle;
183+
harness.emit("update-available", { version: older });
184+
yield* settle;
185+
assert.isNull((yield* updates.getState).availableVersion);
186+
assert.equal(harness.downloadCount(), 0);
187+
}),
188+
);
189+
},
190+
);
191+
192+
it.effect("only saves the track on a host already running the release", () => {
193+
const harness = makeHarness({ savedChannel: "nightly" });
194+
195+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
196+
Effect.gen(function* () {
197+
const updates = yield* DesktopUpdates.DesktopUpdates;
198+
yield* Queue.offer(requests, {
199+
...request("req-track-only"),
200+
channel: "latest",
201+
targetVersion: "1.2.3",
202+
});
203+
yield* settle;
204+
// Even with a newer build on the feed, the host only saves its track.
205+
harness.emit("update-available", { version: "1.2.4" });
206+
yield* settle;
207+
208+
assert.deepEqual(
209+
terminalReports(reports).map((report) => report.outcome),
210+
["up-to-date"],
211+
);
212+
assert.equal((yield* updates.getState).channel, "latest");
213+
assert.equal(harness.downloadCount(), 0);
214+
}),
215+
);
216+
});
217+
218+
it.effect("drops a retained download below the switch's checked release", () => {
219+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
220+
221+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
222+
Effect.gen(function* () {
223+
const updates = yield* DesktopUpdates.DesktopUpdates;
224+
// Downloaded earlier on this Stable host, before the switch checked 1.2.5.
225+
harness.emit("update-downloaded", { version: "1.2.4" });
226+
yield* settle;
227+
assert.equal((yield* updates.getState).downloadedVersion, "1.2.4");
228+
229+
yield* Queue.offer(requests, {
230+
...request("req-floor"),
231+
channel: "latest",
232+
targetVersion: "1.2.5",
233+
});
234+
yield* settle;
235+
harness.emit("update-available", { version: "1.2.5" });
236+
yield* settle;
237+
harness.emit("update-downloaded", { version: "1.2.5" });
238+
yield* settle;
239+
240+
assert.deepEqual(
241+
terminalReports(reports).map((report) => [
242+
report.outcome,
243+
report.state.downloadedVersion,
244+
]),
245+
[["ready-to-install", "1.2.5"]],
246+
);
247+
}),
248+
);
249+
});
250+
251+
it.effect("refuses to cross tracks remotely while WSL backends need their own checks", () => {
252+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void, wslBackend: true });
253+
254+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
255+
Effect.gen(function* () {
256+
const updates = yield* DesktopUpdates.DesktopUpdates;
257+
yield* Queue.offer(requests, {
258+
...request("req-wsl"),
259+
channel: "nightly",
260+
targetVersion: "1.2.4-nightly.20261027.1",
261+
});
262+
yield* settle;
263+
264+
assert.deepEqual(
265+
terminalReports(reports).map((report) => report.outcome),
266+
["failed"],
267+
);
268+
assert.include(terminalReports(reports)[0]?.reason ?? "", "Switch it on that machine");
269+
assert.equal((yield* updates.getState).channel, "latest");
270+
}),
271+
);
272+
});
273+
274+
it.effect("fails a switch that leaves a same-track host below the checked release", () => {
275+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
276+
277+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
278+
Effect.gen(function* () {
279+
yield* Queue.offer(requests, {
280+
...request("req-behind"),
281+
channel: "latest",
282+
targetVersion: "1.2.5",
283+
});
284+
yield* settle;
285+
// The feed lags npm and has nothing newer than this host's 1.2.3.
286+
harness.emit("update-not-available");
287+
yield* settle;
288+
harness.emit("update-not-available");
289+
yield* settle;
290+
291+
assert.deepEqual(
292+
terminalReports(reports).map((report) => [report.outcome, report.reason]),
293+
[["failed", "The desktop app found no build of 1.2.5."]],
294+
);
295+
}),
296+
);
297+
});
298+
299+
it.effect("fails a crossing to an older-numbered Stable that the feed does not offer", () => {
300+
const harness = makeHarness({
301+
appVersion: "1.2.4-nightly.20261027.1",
302+
beforeSetUpdateChannel: Effect.void,
303+
});
304+
305+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
306+
Effect.gen(function* () {
307+
yield* Queue.offer(requests, {
308+
...request("req-to-stable"),
309+
channel: "latest",
310+
targetVersion: "1.2.3",
311+
});
312+
yield* settle;
313+
harness.emit("update-not-available");
314+
yield* settle;
315+
harness.emit("update-not-available");
316+
yield* settle;
317+
318+
// Still on Nightly, though the target is numbered below this build.
319+
assert.deepEqual(
320+
terminalReports(reports).map((report) => [report.outcome, report.reason]),
321+
[["failed", "The desktop app found no build of 1.2.3."]],
322+
);
323+
}),
324+
);
325+
});
326+
327+
it.effect("accepts a newer build than the checked release on the requested track", () => {
328+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
329+
330+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
331+
Effect.gen(function* () {
332+
const newer = "1.2.4-nightly.20261028.2";
333+
yield* Queue.offer(requests, {
334+
...request("req-newer"),
335+
channel: "nightly",
336+
targetVersion: "1.2.4-nightly.20261027.1",
337+
});
338+
yield* settle;
339+
harness.emit("update-available", { version: newer });
340+
yield* settle;
341+
harness.emit("update-downloaded", { version: newer });
342+
yield* settle;
343+
344+
assert.deepEqual(
345+
terminalReports(reports).map((report) => [
346+
report.outcome,
347+
report.state.downloadedVersion,
348+
]),
349+
[["ready-to-install", newer]],
350+
);
351+
}),
352+
);
353+
});
354+
122355
it.effect("reports a failed outcome when quitAndInstall fails", () => {
123356
const harness = makeHarness({
124357
quitAndInstall: Effect.fail(
@@ -525,6 +758,42 @@ describe("DesktopRemoteUpdates", () => {
525758
);
526759
});
527760

761+
it.effect("cancels a track switch while its own feed check is still running", () => {
762+
const releaseCheck = Deferred.makeUnsafe<void>();
763+
const harness = makeHarness({
764+
beforeSetUpdateChannel: Effect.void,
765+
checkForUpdates: Deferred.await(releaseCheck),
766+
});
767+
768+
return runRemoteUpdatesTest(harness, ({ requests, cancellations }) =>
769+
Effect.gen(function* () {
770+
yield* Queue.offer(requests, {
771+
...request("req-switch-cancel"),
772+
channel: "nightly",
773+
targetVersion: "1.2.4-nightly.20261027.1",
774+
});
775+
yield* settle;
776+
const updates = yield* DesktopUpdates.DesktopUpdates;
777+
yield* Queue.offer(cancellations, {
778+
version: 1,
779+
type: "cancelDesktopUpdate",
780+
requestId: "req-switch-cancel",
781+
});
782+
yield* settle;
783+
// The next request starts without waiting for the cancelled switch's feed check.
784+
yield* Queue.offer(requests, {
785+
...request("req-switch-back"),
786+
channel: "latest",
787+
targetVersion: "1.2.3",
788+
});
789+
yield* settle;
790+
791+
assert.equal((yield* updates.getState).channel, "latest");
792+
yield* Deferred.succeed(releaseCheck, undefined);
793+
}),
794+
);
795+
});
796+
528797
it.effect("cancels an active preparation so the next request can run", () => {
529798
const releaseCheck = Deferred.makeUnsafe<void>();
530799
const harness = makeHarness({ checkForUpdates: Deferred.await(releaseCheck) });

0 commit comments

Comments
 (0)