Skip to content
Open
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
15 changes: 3 additions & 12 deletions apps/desktop/src/updates/DesktopUpdates.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as NodeModule from "node:module";

import { assert, describe, it } from "@effect/vitest";
import { DESKTOP_UPDATE_RESTART_MARKER_FILE } from "@t3tools/contracts";
import { computeReleaseNotes } from "electron-updater/out/providers/GitHubProvider.js";
import * as Cause from "effect/Cause";
import * as Deferred from "effect/Deferred";
Expand All @@ -19,7 +18,6 @@ import * as TestClock from "effect/testing/TestClock";
import * as ElectronUpdater from "../electron/ElectronUpdater.ts";
import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopState from "../app/DesktopState.ts";
import * as DesktopUpdatePolicy from "./DesktopUpdatePolicy.ts";
import * as DesktopUpdates from "./DesktopUpdates.ts";
Expand Down Expand Up @@ -560,29 +558,23 @@ describe("DesktopUpdates", () => {
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
});

it.effect("marks the backend stop for an install as an update restart", () => {
let markersAtStop: ReadonlyArray<string> = [];
it.effect("marks the backend stop while an update is in progress", () => {
let inProgressAtStop: string | undefined;
const harness = makeHarness({
stopBackend: Effect.sync(() => {
markersAtStop = [...harness.updateRestartMarkers];
inProgressAtStop = harness.updateInProgressMarker();
}),
});

return Effect.scoped(
Effect.gen(function* () {
yield* TestClock.setTime(1_000);
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const updates = yield* DesktopUpdates.DesktopUpdates;
yield* updates.configure;
harness.emit("update-downloaded", { version: "1.2.4" });
yield* flushCallbacks;

assert.isTrue((yield* updates.install).accepted);
assert.deepEqual(markersAtStop, [
environment.path.join(environment.baseDir, "runtime", DESKTOP_UPDATE_RESTART_MARKER_FILE),
]);
// SSH launchers wait on this until the replacement backend publishes its runtime.
assert.deepEqual(JSON.parse(inProgressAtStop ?? "null"), {
startedAt: 1_000,
Expand Down Expand Up @@ -670,11 +662,11 @@ describe("DesktopUpdates", () => {

const installFiber = yield* updates.install.pipe(Effect.forkScoped);
yield* Deferred.await(stopping);
assert.equal(harness.updateRestartMarkers.size, 1);
assert.equal(harness.installRecords.size, 1);
assert.isDefined(harness.updateInProgressMarker());

yield* Fiber.interrupt(installFiber);
assert.equal(harness.updateRestartMarkers.size, 0);
assert.equal(harness.installRecords.size, 0);
assert.isUndefined(harness.updateInProgressMarker());
}),
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
Expand Down Expand Up @@ -709,7 +701,6 @@ describe("DesktopUpdates", () => {
"quitAndInstall",
"startBackend",
]);
assert.equal(harness.updateRestartMarkers.size, 0);
assert.isUndefined(harness.updateInProgressMarker());
assert.equal(harness.installRecords.size, 0);
}),
Expand Down
29 changes: 6 additions & 23 deletions apps/desktop/src/updates/DesktopUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DESKTOP_UPDATE_RESTART_MARKER_FILE,
DESKTOP_UPDATE_IN_PROGRESS_MARKER_FILE,
DESKTOP_UPDATE_IN_PROGRESS_TTL_MS,
DesktopUpdateChannelSchema,
Expand Down Expand Up @@ -696,19 +695,6 @@ export const make = Effect.gen(function* () {
}).pipe(Effect.withSpan("desktop.updates.downloadAvailableUpdate"));

const updateRestartMarkerDir = environment.path.join(environment.baseDir, "runtime");
const updateRestartMarkerPath = environment.path.join(
updateRestartMarkerDir,
DESKTOP_UPDATE_RESTART_MARKER_FILE,
);
const writeUpdateRestartMarker = fileSystem
.makeDirectory(updateRestartMarkerDir, { recursive: true })
.pipe(
Effect.andThen(fileSystem.writeFileString(updateRestartMarkerPath, "")),
Effect.catch((error) =>
logUpdaterWarning("Could not write the update restart marker.", { errorTag: error._tag }),
),
);

const updateInProgressMarkerPath = environment.path.join(
updateRestartMarkerDir,
DESKTOP_UPDATE_IN_PROGRESS_MARKER_FILE,
Expand All @@ -723,6 +709,7 @@ export const make = Effect.gen(function* () {
startedAt,
expiresAt: startedAt + DESKTOP_UPDATE_IN_PROGRESS_TTL_MS,
});
yield* fileSystem.makeDirectory(updateRestartMarkerDir, { recursive: true });
yield* fileSystem.writeFileString(updateInProgressTempPath, contents);
yield* fileSystem.rename(updateInProgressTempPath, updateInProgressMarkerPath);
}).pipe(
Expand All @@ -737,18 +724,17 @@ export const make = Effect.gen(function* () {
.remove(updateInProgressMarkerPath, { force: true })
.pipe(Effect.ignore);

// Failed or interrupted installs leave no replacement backend; later quits must release the tunnel.
const removeUpdateRestartMarker = fileSystem
.remove(updateRestartMarkerPath, { force: true })
.pipe(Effect.ignore);

const installRecordPath = environment.path.join(
updateRestartMarkerDir,
DESKTOP_UPDATE_INSTALL_RECORD_FILE,
);
const writeInstallRecord = (targetVersion: string) =>
encodeInstallRecord({ fromVersion: environment.appVersion, targetVersion }).pipe(
Effect.flatMap((text) => fileSystem.writeFileString(installRecordPath, text)),
Effect.flatMap((text) =>
fileSystem
.makeDirectory(updateRestartMarkerDir, { recursive: true })
.pipe(Effect.andThen(fileSystem.writeFileString(installRecordPath, text))),
),
Effect.catch((error) =>
logUpdaterWarning("Could not record the update install.", { errorTag: error._tag }),
),
Expand Down Expand Up @@ -791,7 +777,6 @@ export const make = Effect.gen(function* () {
finishUpdateAction("install"),
Ref.set(desktopState.quitting, false),
Ref.set(installRunningBackendsRef, []),
removeUpdateRestartMarker,
removeUpdateInProgressMarker,
removeInstallRecord,
],
Expand All @@ -809,7 +794,6 @@ export const make = Effect.gen(function* () {
if (!ownsRecovery) return;

yield* Ref.set(desktopState.quitting, false);
yield* removeUpdateRestartMarker;
yield* removeUpdateInProgressMarker;
yield* removeInstallRecord;
yield* Effect.gen(function* () {
Expand Down Expand Up @@ -873,7 +857,6 @@ export const make = Effect.gen(function* () {
yield* Ref.set(installRunningBackendsRef, []);

return yield* Effect.gen(function* () {
yield* writeUpdateRestartMarker;
yield* writeUpdateInProgressMarker;
const { downloadedVersion } = yield* Ref.get(updateStateRef);
if (downloadedVersion !== null) yield* writeInstallRecord(downloadedVersion);
Expand Down
4 changes: 0 additions & 4 deletions apps/desktop/src/updates/updatesTestHarness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
} satisfies DesktopAppSettings.DesktopAppSettings["Service"])
: DesktopAppSettings.layer;

const updateRestartMarkers = new Set<string>();
const updateMarkerContents = new Map<string, string>();
const installRecords = new Map<string, string>();
let previousInstallRecord = options.installRecord;
Expand Down Expand Up @@ -271,7 +270,6 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
Effect.sync(() => {
if (isInstallRecord(path)) installRecords.set(path, data);
else {
if (path.endsWith("/desktop-update-restart")) updateRestartMarkers.add(path);
updateMarkerContents.set(path, data);
}
}),
Expand All @@ -283,7 +281,6 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
}),
remove: (path) =>
Effect.sync(() => {
updateRestartMarkers.delete(path);
updateMarkerContents.delete(path);
installRecords.delete(path);
if (isInstallRecord(path)) previousInstallRecord = undefined;
Expand Down Expand Up @@ -316,7 +313,6 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
checkCount: () => checkCount,
quitAndInstalls: () => quitAndInstallCount,
installSteps,
updateRestartMarkers,
updateInProgressMarker: () =>
[...updateMarkerContents].find(([path]) => path.endsWith("/desktop-update-in-progress"))?.[1],
installRecords,
Expand Down
Loading
Loading