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
28 changes: 28 additions & 0 deletions apps/web/src/components/sidebar/updateEverything.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
37 changes: 26 additions & 11 deletions apps/web/src/components/sidebar/updateEverything.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface UpdateEverythingMachine {
readonly serverConfig: {
readonly environment: ServerConfig["environment"];
readonly settings: Pick<ServerConfig["settings"], "continueThreadsAfterServerUpdate">;
/** 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
Expand All @@ -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;
Expand Down Expand Up @@ -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<UpdateEverythingMachine>,
targetVersion: string,
): ServerUpdateTarget[] {
): UpdateEverythingServer[] {
return machines.flatMap((machine) => {
const config = machine.serverConfig;
if (
Expand All @@ -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 [
{
Expand All @@ -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,
},
];
});
Expand Down
13 changes: 5 additions & 8 deletions apps/web/src/components/sidebar/useUpdateEverything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Loading