diff --git a/apps/web/src/components/sidebar/updateEverything.logic.test.ts b/apps/web/src/components/sidebar/updateEverything.logic.test.ts index b38f86655091e..e397057058cd8 100644 --- a/apps/web/src/components/sidebar/updateEverything.logic.test.ts +++ b/apps/web/src/components/sidebar/updateEverything.logic.test.ts @@ -61,6 +61,34 @@ describe("collectServerUpdateTargets", () => { ["other-desktop", "0.0.50"], ]); }); + + it("moves a server to the version its own updater offers, without waiting for npm", () => { + const offering = (id: string, serverVersion: string, offer: string) => { + const base = machine(id, serverVersion, "boot-service"); + return { + ...base, + serverConfig: { ...base.serverConfig!, availableUpdateVersion: offer }, + }; + }; + const targets = collectServerUpdateTargets( + [ + offering("forgejo", "0.0.45-forgejo.18", "0.0.45-forgejo.19"), + offering("ahead-of-client", "0.0.45-forgejo.19", "0.0.45-forgejo.20"), + machine("npm", "0.0.40", "boot-service"), + machine("desktop", "0.0.40", "desktop-managed"), + ], + "0.0.45", + ); + + expect( + targets.map((target) => [target.serverLabel, target.targetVersion, target.waitsForNpm]), + ).toEqual([ + ["forgejo", "0.0.45-forgejo.19", false], + ["ahead-of-client", "0.0.45-forgejo.20", false], + ["npm", "0.0.45", true], + ["desktop", "0.0.45", false], + ]); + }); }); describe("collectRestartingMachines", () => { diff --git a/apps/web/src/components/sidebar/updateEverything.logic.ts b/apps/web/src/components/sidebar/updateEverything.logic.ts index 2d8ae1fa42069..b562531022657 100644 --- a/apps/web/src/components/sidebar/updateEverything.logic.ts +++ b/apps/web/src/components/sidebar/updateEverything.logic.ts @@ -16,6 +16,9 @@ export interface UpdateEverythingMachine { readonly serverConfig: { readonly environment: ServerConfig["environment"]; readonly settings: Pick; + /** A newer version the server's own updater can install (this fork's + Forgejo helper reports it). */ + readonly availableUpdateVersion?: string; } | null; readonly connected: boolean; /** Served by the desktop app this client runs in (the primary backend or a @@ -26,6 +29,12 @@ export interface UpdateEverythingMachine { readonly updateState: ServerUpdateState; } +/** A server a run updates. `waitsForNpm` marks one that downloads + `targetVersion` from npm, so it waits until npm publishes it. */ +export interface UpdateEverythingServer extends ServerUpdateTarget { + readonly waitsForNpm: boolean; +} + /** A server that restarts during a run. */ export interface RestartingMachine { readonly environmentId: EnvironmentId; @@ -65,16 +74,17 @@ export function collectRestartingMachines( /** * The servers that "update everything" moves to `targetVersion`: connected, - * permitted, able to update over RPC, and behind the target. Two kinds stay - * out. Servers this app hosts would relaunch the app mid-run, and the app's - * own install updates them anyway. A service on another release channel + * permitted, able to update over RPC, and behind the target. A server whose + * own updater offers a newer version moves to that version instead, which it + * installs without npm. Two kinds stay out. Servers this app hosts would + * relaunch the app mid-run, and the app's own install updates them anyway. A service on another release channel * stays there; a desktop-managed server follows its own app's update feed, so * the channel rule does not apply to it. */ export function collectServerUpdateTargets( machines: ReadonlyArray, targetVersion: string, -): ServerUpdateTarget[] { +): UpdateEverythingServer[] { return machines.flatMap((machine) => { const config = machine.serverConfig; if ( @@ -92,12 +102,16 @@ export function collectServerUpdateTargets( return []; } const serverVersion = config.environment.serverVersion; - if (resolveVersionMismatch(serverVersion, targetVersion) === null) return []; - if ( - selfUpdate !== "desktop-managed" && - cliReleaseChannelOf(serverVersion) !== cliReleaseChannelOf(targetVersion) - ) { - return []; + // The updater only offers a version newer than the server on its own line. + const serverOffer = config.availableUpdateVersion; + if (serverOffer === undefined) { + if (resolveVersionMismatch(serverVersion, targetVersion) === null) return []; + if ( + selfUpdate !== "desktop-managed" && + cliReleaseChannelOf(serverVersion) !== cliReleaseChannelOf(targetVersion) + ) { + return []; + } } return [ { @@ -108,7 +122,8 @@ export function collectServerUpdateTargets( desktopAppUpdate, threadContinuation: supportsServerUpdateThreadContinuation(config), continueThreadsAfterServerUpdate: config.settings.continueThreadsAfterServerUpdate ?? false, - targetVersion, + targetVersion: serverOffer ?? targetVersion, + waitsForNpm: selfUpdate !== "desktop-managed" && serverOffer === undefined, }, ]; }); diff --git a/apps/web/src/components/sidebar/useUpdateEverything.ts b/apps/web/src/components/sidebar/useUpdateEverything.ts index 82a8dbba653d0..f2e9b9b11a95e 100644 --- a/apps/web/src/components/sidebar/useUpdateEverything.ts +++ b/apps/web/src/components/sidebar/useUpdateEverything.ts @@ -22,8 +22,9 @@ import { /** * The remote half of the sidebar update button: outdated providers on every * connected machine, and servers behind the version this client runs or is - * about to install (`localUpdateVersion`). Servers that install from npm appear - * only once npm confirms that version. `run` performs the whole pass, including + * about to install (`localUpdateVersion`), or behind the version their own + * updater offers. Servers that install from npm appear only once npm confirms + * that version. `run` performs the whole pass, including * this app's own download and install when given. */ export function useUpdateEverything(localUpdateVersion: string | null) { @@ -51,13 +52,9 @@ export function useUpdateEverything(localUpdateVersion: string | null) { ); const machines = useAtomValue(machinesAtom); const behindServers = collectServerUpdateTargets(machines, targetVersion); - // A desktop-managed server installs from its own app's update feed, so only - // servers that download t3 from npm wait for npm to publish the version. - const needsNpm = behindServers.some((server) => server.selfUpdate !== "desktop-managed"); + const needsNpm = behindServers.some((server) => server.waitsForNpm); const published = useNpmReleasePublished(needsNpm ? targetVersion : null); - const servers = published - ? behindServers - : behindServers.filter((server) => server.selfUpdate === "desktop-managed"); + const servers = published ? behindServers : behindServers.filter((server) => !server.waitsForNpm); const restarts = collectRestartingMachines(machines, servers, localUpdateVersion !== null); const providers = useProviderUpdates(); const updateServer = useServerUpdate();