Open History to see the last commit
1import type { ServerUpdateState } from "@t3tools/client-runtime/state/server";
2import {
3 type DesktopUpdateChannel,
4 type EnvironmentId,
5 managedNightlyDeniedMessage,
6 managedUpdatesDenial,
7 type ServerConfig,
8 type ServerSelfUpdateCapability,
9} from "@t3tools/contracts";
10import { cliReleaseChannelOf, desktopUpdateChannelOf } from "@t3tools/shared/cliRelease";
11import { compareSemverVersions } from "@t3tools/shared/semver";
12
13import {
14 resolveServerSelfUpdateCapability,
15 resolveVersionMismatch,
16 supportsDesktopAppUpdate,
17} from "~/versionSkew";
18import type { ServerUpdateOutcome, ServerUpdateTarget } from "../ServerUpdateAction";
19
20export interface UpdateEverythingMachine {
21 readonly environmentId: EnvironmentId;
22 readonly label: string;
23 readonly serverConfig: {
24 readonly environment: ServerConfig["environment"];
25 readonly settings: Pick<ServerConfig["settings"], "continueThreadsAfterServerUpdate">;
26 readonly managedPolicy?: ServerConfig["managedPolicy"];
27 } | null;
28 readonly connected: boolean;
29 readonly hostedByThisApp: boolean;
30 readonly canMaintain: boolean;
31 readonly updateState: ServerUpdateState;
32}
33
34export interface RestartingMachine {
35 readonly environmentId: EnvironmentId;
36 readonly continuesThreads: boolean;
37}
38
39export function collectRestartingMachines(
40 machines: ReadonlyArray<UpdateEverythingMachine>,
41 servers: ReadonlyArray<Pick<ServerUpdateTarget, "environmentId">>,
42 installsLocal: boolean,
43): RestartingMachine[] {
44 const updated = new Set(servers.map((server) => server.environmentId));
45 return machines.flatMap((machine) => {
46 const config = machine.serverConfig;
47 if (
48 config === null ||
49 !machine.connected ||
50 !(updated.has(machine.environmentId) || (installsLocal && machine.hostedByThisApp))
51 ) {
52 return [];
53 }
54 return [
55 {
56 environmentId: machine.environmentId,
57 continuesThreads: config.settings.continueThreadsAfterServerUpdate === true,
58 },
59 ];
60 });
61}
62
63export interface SkippedMachine {
64 readonly environmentId: EnvironmentId;
65 readonly label: string;
66 readonly reason: string;
67}
68
69/** Skip current and app-hosted servers; the latter update with the app and would relaunch mid-run.
70 * Desktop-managed servers use their own feed. Each server's updater checks that it can install the
71 * release before it restarts, so no registry precheck runs here. */
72export function collectServerUpdateTargets(
73 machines: ReadonlyArray<UpdateEverythingMachine>,
74 targetVersion: string,
75): {
76 readonly targets: ServerUpdateTarget[];
77 readonly skipped: SkippedMachine[];
78} {
79 const targets: ServerUpdateTarget[] = [];
80 const skipped: SkippedMachine[] = [];
81 for (const machine of machines) {
82 const config = machine.serverConfig;
83 if (machine.hostedByThisApp) continue;
84 if (
85 config !== null &&
86 resolveVersionMismatch(config.environment.serverVersion, targetVersion) === null
87 ) {
88 continue;
89 }
90 const skip = (reason: string) =>
91 skipped.push({ environmentId: machine.environmentId, label: machine.label, reason });
92 const unavailable = unavailableReason(machine);
93 if (config === null || unavailable !== null) {
94 skip(unavailable ?? "not connected");
95 continue;
96 }
97 const selfUpdate = resolveServerSelfUpdateCapability(config);
98 const managedDenial = managedMachineUpdateDenial(
99 config,
100 selfUpdate === "desktop-managed" ? undefined : targetVersion,
101 );
102 if (managedDenial !== undefined) {
103 skip(managedDenial);
104 continue;
105 }
106 const desktopAppUpdate = supportsDesktopAppUpdate(config);
107 if (selfUpdate === null) {
108 skip("needs a manual update");
109 continue;
110 }
111 if (selfUpdate === "desktop-managed" && !desktopAppUpdate) {
112 skip("needs a newer desktop app");
113 continue;
114 }
115 const serverVersion = config.environment.serverVersion;
116 if (
117 selfUpdate !== "desktop-managed" &&
118 cliReleaseChannelOf(serverVersion) !== cliReleaseChannelOf(targetVersion)
119 ) {
120 skip(`on the ${cliReleaseChannelOf(serverVersion)} channel`);
121 continue;
122 }
123 const target: ServerUpdateTarget = {
124 environmentId: machine.environmentId,
125 serverLabel: machine.label,
126 selfUpdate,
127 installation: config.environment.capabilities.serverInstallation,
128 desktopAppUpdate,
129 targetVersion,
130 };
131 targets.push(target);
132 }
133 return { targets, skipped };
134}
135
136function unavailableReason(machine: UpdateEverythingMachine): string | null {
137 if (machine.serverConfig === null || !machine.connected) return "not connected";
138 if (!machine.canMaintain) return "no permission";
139 if (machine.updateState.status === "running") return "already updating";
140 return null;
141}
142
143/** The latest release on the track a fleet switches to, as npm reports it. */
144export interface ChannelSwitchRelease {
145 readonly channel: DesktopUpdateChannel;
146 readonly version: string;
147 readonly databaseMigration: number | undefined;
148}
149
150export const channelSwitchLabel = (channel: DesktopUpdateChannel) =>
151 channel === "nightly" ? "Nightly" : "Stable";
152
153/** Stable and Nightly each build their own commits, so either can hold migrations the other lacks.
154 * Crossing tracks needs proof that the target release knows every migration the database holds. */
155const crossesTrack = (fromVersion: string, release: ChannelSwitchRelease) =>
156 desktopUpdateChannelOf(fromVersion) !== release.channel;
157
158function channelSwitchBlockReason(
159 fromVersion: string,
160 release: ChannelSwitchRelease,
161 currentMigration: number | undefined,
162): string | null {
163 if (!crossesTrack(fromVersion, release)) return null;
164 const from = channelSwitchLabel(desktopUpdateChannelOf(fromVersion));
165 // Servers and releases from before this check report no migration number.
166 if (currentMigration === undefined) {
167 return `its server predates database checks; update it on ${from} first`;
168 }
169 if (release.databaseMigration === undefined) {
170 return `${release.version} predates database checks; wait for a newer ${channelSwitchLabel(release.channel)} release`;
171 }
172 return currentMigration > release.databaseMigration
173 ? `its database has changes ${release.version} does not support yet; stay on ${from} until ${channelSwitchLabel(release.channel)} has them`
174 : null;
175}
176
177/** This app's reinstall restarts every server it hosts, so each of their databases must allow the
178 * switch. `backendCount` is the desktop's own inventory: a backend still starting has no client
179 * entry yet. A cached config can outlive its connection, so only a connected server's head counts. */
180export function localSwitchBlockReason(
181 appVersion: string,
182 release: ChannelSwitchRelease,
183 hosted: ReadonlyArray<{
184 readonly connected: boolean;
185 readonly databaseMigration: number | undefined;
186 }>,
187 backendCount: number,
188): string | null {
189 if (!crossesTrack(appVersion, release)) return null;
190 if (
191 hosted.length === 0 ||
192 hosted.length < backendCount ||
193 hosted.some((server) => !server.connected)
194 ) {
195 return "its server is not connected, so its database cannot be checked";
196 }
197 return (
198 hosted
199 .map((server) => channelSwitchBlockReason(appVersion, release, server.databaseMigration))
200 .find((reason) => reason !== null) ?? null
201 );
202}
203
204/**
205 * The server refuses these with the same message; say so before the run instead of after.
206 * `targetVersion` is undefined when the server picks its own version, as desktop apps do.
207 */
208function managedMachineUpdateDenial(
209 config: NonNullable<UpdateEverythingMachine["serverConfig"]>,
210 targetVersion: string | undefined,
211): string | undefined {
212 const policy = config.managedPolicy;
213 return (
214 managedUpdatesDenial(policy) ??
215 (policy !== undefined &&
216 policy.limits?.updates?.allowNightly === false &&
217 targetVersion !== undefined &&
218 cliReleaseChannelOf(targetVersion) !== "stable"
219 ? managedNightlyDeniedMessage(policy.organization)
220 : undefined)
221 );
222}
223
224/** Servers move to the release; desktop-managed hosts reinstall their app on its track. A desktop
225 * host already current gets a track-only request, since its saved track may still differ. */
226export function collectChannelSwitchTargets(
227 machines: ReadonlyArray<UpdateEverythingMachine>,
228 release: ChannelSwitchRelease,
229): { readonly targets: ServerUpdateTarget[]; readonly skipped: SkippedMachine[] } {
230 const targets: ServerUpdateTarget[] = [];
231 const skipped: SkippedMachine[] = [];
232 for (const machine of machines) {
233 const config = machine.serverConfig;
234 if (machine.hostedByThisApp) continue;
235 const skip = (reason: string) =>
236 skipped.push({ environmentId: machine.environmentId, label: machine.label, reason });
237 const target = (
238 selfUpdate: ServerSelfUpdateCapability,
239 targetVersion: string,
240 ): ServerUpdateTarget => ({
241 environmentId: machine.environmentId,
242 serverLabel: machine.label,
243 selfUpdate,
244 installation: config?.environment.capabilities.serverInstallation,
245 desktopAppUpdate: config !== null && supportsDesktopAppUpdate(config),
246 targetVersion,
247 ...(selfUpdate === "desktop-managed" ? { channel: release.channel } : {}),
248 ...(release.databaseMigration === undefined
249 ? {}
250 : { targetDatabaseMigration: release.databaseMigration }),
251 });
252 const serverVersion = config?.environment.serverVersion;
253 const sameTrack = serverVersion !== undefined && isOnTrack(serverVersion, release.channel);
254 if (
255 config !== null &&
256 sameTrack &&
257 resolveVersionMismatch(serverVersion, release.version) === null
258 ) {
259 const move = trackSwitchMove(config, true);
260 if (
261 !("skip" in move) &&
262 move.selfUpdate === "desktop-managed" &&
263 unavailableReason(machine) === null &&
264 managedMachineUpdateDenial(config, release.version) === undefined
265 ) {
266 targets.push({ ...target(move.selfUpdate, serverVersion), trackOnly: true });
267 }
268 continue;
269 }
270 const unavailable = unavailableReason(machine);
271 if (config === null || serverVersion === undefined || unavailable !== null) {
272 skip(unavailable ?? "not connected");
273 continue;
274 }
275 const managedDenial = managedMachineUpdateDenial(config, release.version);
276 if (managedDenial !== undefined) {
277 skip(managedDenial);
278 continue;
279 }
280 const move = trackSwitchMove(config, sameTrack);
281 if ("skip" in move) {
282 skip(move.skip);
283 continue;
284 }
285 const blocked = channelSwitchBlockReason(
286 serverVersion,
287 release,
288 config.environment.databaseMigration,
289 );
290 if (blocked !== null) {
291 skip(blocked);
292 continue;
293 }
294 // Service launchers only accept newer versions, so leaving for an older release is manual.
295 if (
296 move.selfUpdate === "boot-service" &&
297 compareSemverVersions(release.version, serverVersion) <= 0
298 ) {
299 skip(
300 `run \`t3 update --channel ${release.channel === "nightly" ? "nightly" : "stable"} --allow-downgrade\` there`,
301 );
302 continue;
303 }
304 targets.push(target(move.selfUpdate, release.version));
305 }
306 return { targets, skipped };
307}
308
309/** A remote host on the other track that a switch can still move, for retrying a partial switch. */
310export function awaitsTrackSwitch(
311 machine: Pick<UpdateEverythingMachine, "serverConfig" | "hostedByThisApp">,
312 channel: DesktopUpdateChannel,
313): boolean {
314 const config = machine.serverConfig;
315 return (
316 !machine.hostedByThisApp &&
317 config !== null &&
318 !isOnTrack(config.environment.serverVersion, channel) &&
319 !("skip" in trackSwitchMove(config, false))
320 );
321}
322
323function isOnTrack(version: string, channel: DesktopUpdateChannel): boolean {
324 return cliReleaseChannelOf(version) !== "preview" && desktopUpdateChannelOf(version) === channel;
325}
326
327/** How a switch moves a host, or why it never can from here, whatever the release. */
328function trackSwitchMove(
329 config: NonNullable<UpdateEverythingMachine["serverConfig"]>,
330 sameTrack: boolean,
331): { readonly selfUpdate: ServerSelfUpdateCapability } | { readonly skip: string } {
332 if (cliReleaseChannelOf(config.environment.serverVersion) === "preview") {
333 return { skip: "runs a preview build" };
334 }
335 const selfUpdate = resolveServerSelfUpdateCapability(config);
336 if (selfUpdate === null) return { skip: "needs a manual update" };
337 if (selfUpdate !== "desktop-managed") return { selfUpdate };
338 if (config.environment.capabilities.desktopAppChannelSwitch !== true) {
339 return { skip: "needs a newer desktop app" };
340 }
341 // Squirrel.Mac renames the bundle for the new track and then cannot relaunch it.
342 if (!sameTrack && config.environment.platform.os === "darwin") {
343 return { skip: "switch the Mac app on that Mac" };
344 }
345 return { selfUpdate };
346}
347
348export interface UpdateEverythingSteps<Providers, Servers> {
349 readonly downloadLocal?: () => Promise<boolean>;
350 readonly updateProviders: () => Promise<Providers>;
351 readonly stageServers?: () => ReadonlyMap<EnvironmentId, Promise<unknown>>;
352 readonly updateServers: (
353 staged: ReadonlyMap<EnvironmentId, Promise<unknown>>,
354 ) => Promise<Servers>;
355}
356
357/** Finish provider installs before server restarts; servers stage meanwhile and each server's
358 * update waits only on its own stage. Install this app last when localReady; failed downloads skip
359 * only that install. */
360export async function runUpdateEverything<Providers, Servers>(
361 steps: UpdateEverythingSteps<Providers, Servers>,
362): Promise<{
363 readonly localReady: boolean;
364 readonly providers: Providers;
365 readonly servers: Servers;
366}> {
367 const staged = new Map(
368 Array.from(steps.stageServers?.() ?? [], ([id, stage]) => [id, stage.catch(() => undefined)]),
369 );
370 const [localReady, remote] = await Promise.all([
371 steps.downloadLocal?.() ?? Promise.resolve(true),
372 steps
373 .updateProviders()
374 .then(async (providers) => ({ providers, servers: await steps.updateServers(staged) })),
375 ]);
376 return { localReady, ...remote };
377}
378
379export type UpdateRunMachineStatus =
380 | "providers"
381 | "waiting"
382 | "downloading"
383 | "restarting"
384 | "done"
385 | "failed";
386
387export interface UpdateRunMachine {
388 readonly environmentId: EnvironmentId;
389 readonly label: string;
390 readonly updatesProviders: boolean;
391 readonly server: ServerUpdateTarget | null;
392 readonly handedOffVersion: string | null;
393 readonly startedAt: number;
394 readonly result: "done" | "failed" | null;
395 readonly failure: string | null;
396 readonly providerFailure: string | null;
397}
398
399export interface UpdateEverythingRun {
400 /** Track switches retry through their planner, which re-checks each database. */
401 readonly trackSwitch?: boolean;
402 readonly localVersion: string | null;
403 readonly phase: "providers" | "servers" | "countdown" | "installing";
404 readonly restartAt: number | null;
405 readonly machines: ReadonlyArray<UpdateRunMachine>;
406}
407
408export function resolveUpdateRunMachineStatus(
409 machine: UpdateRunMachine,
410 phase: UpdateEverythingRun["phase"],
411 serverState: ServerUpdateState,
412): UpdateRunMachineStatus {
413 if (machine.result !== null) return machine.result;
414 if (machine.handedOffVersion !== null) return "restarting";
415 if (phase === "providers" && machine.updatesProviders) return "providers";
416 if (machine.server !== null && serverState.status === "running") {
417 return serverState.stage === "resuming" ? "restarting" : "downloading";
418 }
419 return "waiting";
420}
421
422export function isServerUpdateHandedOff(state: ServerUpdateState): boolean {
423 return state.status === "running" && state.stage === "resuming";
424}
425
426export function closeFinishedUpdateRun(run: UpdateEverythingRun): UpdateEverythingRun | null {
427 return run.phase === "servers" &&
428 run.localVersion === null &&
429 run.machines.every((machine) => machine.result === "done")
430 ? null
431 : run;
432}
433
434const UPDATE_SLOW_AFTER_MS = 3 * 60 * 1000;
435
436export function formatUpdateElapsed(ms: number): string {
437 const minutes = Math.floor(ms / 60_000);
438 if (minutes < 1) return "<1m";
439 if (minutes < 60) return `${minutes}m`;
440 return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
441}
442
443export interface UpdateRunMachineView {
444 readonly machine: UpdateRunMachine;
445 readonly status: UpdateRunMachineStatus;
446}
447
448export type UpdateRunLocalState =
449 | { readonly status: "downloading"; readonly percent: number | null }
450 | { readonly status: "waiting" }
451 | null;
452
453export interface UpdateCapsuleView {
454 readonly tone: "default" | "slow" | "failed";
455 readonly label: string;
456 readonly slow?: { readonly status: string; readonly elapsed: string };
457 readonly action: "later" | "retry" | "dismiss" | null;
458}
459
460const isActive = (status: UpdateRunMachineStatus) => status !== "done" && status !== "failed";
461
462export function describeUpdateCapsule(
463 run: UpdateEverythingRun,
464 machines: ReadonlyArray<UpdateRunMachineView>,
465 local: UpdateRunLocalState,
466 now: number,
467): UpdateCapsuleView {
468 if (run.phase === "countdown" && run.restartAt !== null) {
469 const seconds = Math.max(0, Math.ceil((run.restartAt - now) / 1000));
470 return { tone: "default", label: `Restart in ${seconds}s`, action: "later" };
471 }
472 if (run.phase === "installing") {
473 return { tone: "default", label: "Restarting…", action: null };
474 }
475 const active = machines.filter(({ status }) => isActive(status) && status !== "waiting");
476 const slowest = active.toSorted((a, b) => a.machine.startedAt - b.machine.startedAt)[0];
477 if (slowest && now - slowest.machine.startedAt >= UPDATE_SLOW_AFTER_MS) {
478 return {
479 tone: "slow",
480 label: slowest.machine.label,
481 slow: {
482 status: RUN_STATUS_LABELS[slowest.status],
483 elapsed: formatUpdateElapsed(now - slowest.machine.startedAt),
484 },
485 action: null,
486 };
487 }
488 const done = machines.filter(({ status }) => status === "done").length;
489 if (machines.some(({ status }) => isActive(status))) {
490 return { tone: "default", label: `${done} of ${machines.length} updated`, action: null };
491 }
492 if (local?.status === "downloading") {
493 return {
494 tone: "default",
495 label: `Downloading${local.percent === null ? "" : ` ${Math.floor(local.percent)}%`}`,
496 action: null,
497 };
498 }
499 const failed = machines.filter(({ status }) => status === "failed");
500 if (failed.length > 0) {
501 return {
502 tone: "failed",
503 label: failed.length === 1 ? `${failed[0]!.machine.label} failed` : `${failed.length} failed`,
504 action:
505 !run.trackSwitch && failed.some(({ machine }) => machine.server !== null)
506 ? "retry"
507 : "dismiss",
508 };
509 }
510 return { tone: "default", label: `${done} of ${machines.length} updated`, action: null };
511}
512
513export const RUN_STATUS_LABELS: Record<UpdateRunMachineStatus, string> = {
514 providers: "updating providers",
515 waiting: "waiting",
516 downloading: "downloading",
517 restarting: "restarting",
518 done: "done",
519 failed: "failed",
520};
521
522export interface UpdateEverythingResult {
523 readonly localVersion: string | null;
524 readonly updatedServers: number;
525 readonly updatedProviders: number;
526 readonly failures: ReadonlyArray<string>;
527 readonly restarting: ReadonlyArray<string>;
528}
529
530export function collectUpdateEverythingResult(input: {
531 readonly localVersion: string | null;
532 readonly localFailures: ReadonlyArray<string>;
533 readonly servers: ReadonlyArray<{
534 readonly label: string;
535 readonly outcome: ServerUpdateOutcome;
536 }>;
537 readonly providers: ReadonlyArray<
538 | { readonly status: "interrupted" | "updated" }
539 | { readonly status: "failed"; readonly line: string }
540 >;
541}): UpdateEverythingResult {
542 return {
543 localVersion: input.localVersion,
544 updatedServers: input.servers.filter(({ outcome }) => outcome.status === "updated").length,
545 updatedProviders: input.providers.filter((outcome) => outcome.status === "updated").length,
546 restarting: [],
547 failures: [
548 ...input.localFailures.map((failure) => `This app: ${failure}`),
549 ...input.servers.flatMap(({ label, outcome }) =>
550 outcome.status === "failed" ? [`${label}: ${outcome.message}`] : [],
551 ),
552 ...input.providers.flatMap((outcome) => (outcome.status === "failed" ? [outcome.line] : [])),
553 ],
554 };
555}
556
557export function getUpdateEverythingToastView(
558 result: UpdateEverythingResult,
559 appVersion: string,
560): {
561 readonly type: "success" | "error";
562 readonly title: string;
563 readonly description?: string;
564} | null {
565 const parts = [
566 result.localVersion !== null && result.localVersion === appVersion ? "this app" : null,
567 countLabel(result.updatedServers, "server"),
568 countLabel(result.updatedProviders, "provider"),
569 ].filter((part) => part !== null);
570 const restarting =
571 result.restarting.length === 0
572 ? []
573 : [
574 `${joinList(result.restarting)} ${result.restarting.length === 1 ? "is" : "are"} still restarting.`,
575 ];
576 if (result.failures.length === 0) {
577 if (parts.length === 0) return null;
578 return {
579 type: "success",
580 title: `Updated ${joinList(parts)}`,
581 ...(restarting.length === 0 ? {} : { description: restarting.join("\n") }),
582 };
583 }
584 return {
585 type: "error",
586 title: parts.length === 0 ? "Update failed" : `Updated ${joinList(parts)}`,
587 description: [...result.failures, ...restarting].join("\n"),
588 };
589}
590
591export interface UpdateEverythingPlan {
592 readonly localVersion: string | null;
593 /** Machines whose servers this app hosts; this app's update restarts them. */
594 readonly localMachines: ReadonlyArray<{
595 readonly environmentId: EnvironmentId;
596 readonly label: string;
597 }>;
598 readonly servers: ReadonlyArray<
599 Pick<ServerUpdateTarget, "environmentId" | "serverLabel" | "selfUpdate" | "targetVersion">
600 >;
601 readonly providerMachines: ReadonlyArray<{
602 readonly environmentId: EnvironmentId;
603 readonly label: string;
604 readonly providers: ReadonlyArray<string>;
605 }>;
606 readonly skipped: ReadonlyArray<SkippedMachine>;
607}
608
609export interface UpdateEverythingRow {
610 readonly environmentId: EnvironmentId | null;
611 readonly label: string;
612 readonly app: "this-app" | "server" | "desktop-app" | null;
613 readonly skipped: string | null;
614 readonly providers: ReadonlyArray<string>;
615}
616
617function countLabel(count: number, noun: string): string | null {
618 return count === 0 ? null : `${count} ${noun}${count === 1 ? "" : "s"}`;
619}
620
621function joinList(parts: ReadonlyArray<string>): string {
622 if (parts.length <= 2) return parts.join(" and ");
623 return `${parts.slice(0, -1).join(", ")}, and ${parts.at(-1)}`;
624}
625
626/** One row per machine: this app's machines first, then servers, provider-only, and skipped. */
627export function describeUpdateEverything(plan: UpdateEverythingPlan): {
628 readonly summary: string;
629 readonly version: string | null;
630 readonly providerCount: number;
631 readonly rows: ReadonlyArray<UpdateEverythingRow>;
632} {
633 const providerCount = plan.providerMachines.reduce(
634 (count, machine) => count + machine.providers.length,
635 0,
636 );
637 const summary = `Update ${joinList(
638 [
639 plan.localVersion ? "this app" : null,
640 countLabel(plan.servers.length, "server"),
641 countLabel(providerCount, "provider"),
642 ].filter((part) => part !== null),
643 )}`;
644
645 const rows = new Map<EnvironmentId | null, UpdateEverythingRow>();
646 const update = (
647 environmentId: EnvironmentId | null,
648 label: string,
649 change: Partial<UpdateEverythingRow>,
650 ) => {
651 const row = rows.get(environmentId) ?? {
652 environmentId,
653 label,
654 app: null,
655 skipped: null,
656 providers: [],
657 };
658 rows.set(environmentId, { ...row, ...change });
659 };
660 if (plan.localVersion) {
661 if (plan.localMachines.length === 0) update(null, "This app", { app: "this-app" });
662 for (const machine of plan.localMachines) {
663 update(machine.environmentId, machine.label, { app: "this-app" });
664 }
665 }
666 for (const server of plan.servers) {
667 update(server.environmentId, server.serverLabel, {
668 app: server.selfUpdate === "desktop-managed" ? "desktop-app" : "server",
669 });
670 }
671 for (const machine of plan.providerMachines) {
672 update(machine.environmentId, machine.label, { providers: machine.providers });
673 }
674 for (const machine of plan.skipped) {
675 update(machine.environmentId, machine.label, { skipped: machine.reason });
676 }
677
678 return {
679 summary,
680 version:
681 plan.localVersion ??
682 plan.servers.find((server) => server.selfUpdate !== "desktop-managed")?.targetVersion ??
683 null,
684 providerCount,
685 rows: Array.from(rows.values()),
686 };
687}