TypeScript
fix(desktop): restart prompt returns after relaunching with a downloaded update (#18095)
Rakshith Bhatd445fdba5d41
diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.tsindex f2249e3c964..969cd6fb40b 100644--- a/apps/desktop/src/electron/ElectronUpdater.test.ts+++ b/apps/desktop/src/electron/ElectronUpdater.test.ts@@ -1,9 +1,27 @@+// @effect-diagnostics nodeBuiltinImport:off -- Build real electron-updater disk fixtures with its SHA-512 encoding.+import * as NodeServices from "@effect/platform-node/NodeServices";+import * as NodeCrypto from "node:crypto";+import * as NodeEvents from "node:events";+import * as NodeModule from "node:module";+import * as NodePath from "node:path";+import * as Deferred from "effect/Deferred";+import * as FileSystem from "effect/FileSystem";+import * as Option from "effect/Option";+import { AppImageUpdater } from "electron-updater/out/AppImageUpdater.js";+import { DebUpdater } from "electron-updater/out/DebUpdater.js";+import { MacUpdater } from "electron-updater/out/MacUpdater.js";+import { GenericProvider } from "electron-updater/out/providers/GenericProvider.js";+import type { UpdateDownloadedEvent } from "electron-updater/out/types.js";+import { NsisUpdater } from "electron-updater/out/NsisUpdater.js";+import * as DesktopUpdates from "../updates/DesktopUpdates.ts";+import { flushCallbacks, makeHarness } from "../updates/updatesTestHarness.ts";import { assert, describe, it } from "@effect/vitest";import * as Effect from "effect/Effect";import type { VerifyUpdateCodeSignature } from "electron-updater";import { beforeEach, vi } from "vite-plus/test";-const { autoUpdaterMock } = vi.hoisted(() => ({+const { autoUpdaterMock, updaterOverride } = vi.hoisted(() => ({+ updaterOverride: { current: undefined as import("electron-updater").AppUpdater | undefined },autoUpdaterMock: {allowDowngrade: false,allowPrerelease: false,@@ -24,7 +42,9 @@ const { autoUpdaterMock } = vi.hoisted(() => ({}));vi.mock("electron-updater", () => ({- autoUpdater: autoUpdaterMock,+ get autoUpdater() {+ return updaterOverride.current ?? autoUpdaterMock;+ },}));import * as ElectronUpdater from "./ElectronUpdater.ts";@@ -221,3 +241,205 @@ describe("ElectronUpdater", () => {);});});++describe("installed electron-updater cache recovery", () => {+ it.effect.each([+ {+ name: "Intel Mac",+ platform: "darwin",+ Updater: MacUpdater,+ selected: "x64.zip",+ other: "arm64.zip",+ rosetta: false,+ },+ {+ name: "Apple Silicon running Intel",+ platform: "darwin",+ Updater: MacUpdater,+ selected: "arm64.zip",+ other: "x64.zip",+ rosetta: true,+ },+ {+ name: "Windows",+ platform: "win32",+ Updater: NsisUpdater,+ selected: "x64.exe",+ other: "arm64.exe",+ rosetta: false,+ },+ {+ name: "Debian",+ platform: "linux",+ Updater: DebUpdater,+ selected: "x64.deb",+ other: "x64.AppImage",+ rosetta: false,+ },+ {+ name: "AppImage",+ platform: "linux",+ Updater: AppImageUpdater,+ selected: "x64.AppImage",+ other: "x64.deb",+ rosetta: false,+ },+ ] as const)("restores only the package selected by $name", (scenario) =>+ Effect.scoped(+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const directory = yield* fs.makeTempDirectoryScoped();+ const cacheDirectory = NodePath.join(directory, "custom-updater-cache", "pending");+ const configPath = NodePath.join(directory, "app-update.yml");+ yield* fs.writeFileString(configPath, "updaterCacheDirName: custom-updater-cache\n");+ yield* fs.makeDirectory(cacheDirectory, { recursive: true });++ const require = NodeModule.createRequire(import.meta.url);+ require("electron");+ const electronModule = require.cache[require.resolve("electron")]!;+ const childProcess = require("node:child_process") as typeof import("node:child_process");+ const originalElectron = electronModule.exports;+ const originalArch = Object.getOwnPropertyDescriptor(process, "arch")!;+ yield* Effect.acquireRelease(+ Effect.sync(() => {+ // MacUpdater's native Squirrel bridge and host probes are OS boundaries.+ electronModule.exports = { autoUpdater: new NodeEvents.EventEmitter() };+ Object.defineProperty(process, "arch", { value: "x64", configurable: true });+ return vi+ .spyOn(childProcess, "execFileSync")+ .mockReturnValue(scenario.rosetta ? "sysctl.proc_translated: 1" : "x86_64");+ }),+ (probe) =>+ Effect.sync(() => {+ probe.mockRestore();+ Object.defineProperty(process, "arch", originalArch);+ electronModule.exports = originalElectron;+ updaterOverride.current = undefined;+ }),+ );++ const extensions =+ scenario.platform === "darwin"+ ? ["arm64.dmg", "x64.dmg", "arm64.zip", "x64.zip"]+ : scenario.platform === "win32"+ ? ["arm64.exe", "x64.exe"]+ : ["arm64.AppImage", "x64.AppImage", "arm64.deb", "x64.deb"];+ const files = extensions.map((extension) => {+ const url = `T3-Code-1.2.4-${extension}`;+ return { url, sha512: NodeCrypto.createHash("sha512").update(url).digest("base64") };+ });+ const info = {+ version: "1.2.4",+ releaseDate: "2026-10-01T00:00:00Z",+ files,+ path: files[0]!.url,+ sha512: files[0]!.sha512,+ };+ yield* Effect.acquireRelease(+ Effect.sync(() =>+ vi.spyOn(GenericProvider.prototype, "getLatestVersion").mockResolvedValue(info),+ ),+ (feed) => Effect.sync(() => feed.mockRestore()),+ );++ // A fresh instance for each launch forces disk validation rather than in-memory reuse.+ yield* Effect.forEach([scenario.other, scenario.selected], (cachedExtension) =>+ Effect.scoped(+ Effect.gen(function* () {+ const cached = files.find((file) => file.url.endsWith(`-${cachedExtension}`))!;+ yield* fs.writeFileString(NodePath.join(cacheDirectory, cached.url), cached.url);+ yield* fs.writeFileString(+ NodePath.join(cacheDirectory, "update-info.json"),+ JSON.stringify({+ fileName: cached.url,+ sha512: cached.sha512,+ isAdminRightsRequired: false,+ }),+ );+ const updater = new scenario.Updater(undefined, {+ version: "1.2.3",+ name: "T3 Code",+ isPackaged: true,+ appUpdateConfigPath: configPath,+ userDataPath: directory,+ baseCachePath: directory,+ whenReady: () => Promise.resolve(),+ relaunch: vi.fn(),+ quit: vi.fn(),+ onQuit: vi.fn(),+ });+ updater.logger = null;+ const networkDownload = vi.fn(() =>+ Promise.reject(new Error("unexpected network download")),+ );+ Object.assign(updater, { httpExecutor: { download: networkDownload } });+ if (updater instanceof MacUpdater) {+ // Keep real selection, executeDownload, and hash validation; stop at native handoff.+ Object.assign(updater, {+ updateDownloaded: async (_file: unknown, event: UpdateDownloadedEvent) => {+ updater.emit("update-downloaded", event);+ return [];+ },+ });+ }+ updaterOverride.current = updater;+ assert.deepEqual(+ yield* ElectronUpdater.make.pendingDownloadDirectory,+ Option.some(cacheDirectory),+ );++ const inspected = Deferred.makeUnsafe<void>();+ const downloadFinished = Deferred.makeUnsafe<void>();+ const download = vi.spyOn(updater, "downloadUpdate");+ const harness = makeHarness({+ platform: scenario.platform,+ runningUnderArm64Translation: scenario.rosetta,+ env: scenario.selected.endsWith("AppImage")+ ? { APPIMAGE: "/test/T3-Code.AppImage" }+ : {},+ updater: {+ ...ElectronUpdater.make,+ downloadUpdate: ElectronUpdater.make.downloadUpdate.pipe(+ Effect.ensuring(Deferred.succeed(downloadFinished, undefined)),+ ),+ },+ fileSystem: {+ ...fs,+ readFileString: (path, encoding) =>+ path === "/missing/resources/package-type" && scenario.selected.endsWith("deb")+ ? Effect.succeed("deb")+ : fs.readFileString(path, encoding),+ exists: (path) =>+ fs.exists(path).pipe(Effect.tap(() => Deferred.succeed(inspected, undefined))),+ },+ });+ yield* Effect.scoped(+ Effect.gen(function* () {+ const updates = yield* DesktopUpdates.DesktopUpdates;+ yield* updates.configure;+ // AppImage activation reads the host environment; the fixture is intentionally not installed.+ vi.spyOn(updater, "isUpdaterActive").mockReturnValue(true);+ assert.isTrue((yield* updates.check("startup")).checked);+ yield* Deferred.await(inspected);+ yield* flushCallbacks;++ if (cachedExtension === scenario.other) {+ assert.equal(download.mock.calls.length, 0);+ assert.equal((yield* updates.getState).status, "available");+ } else {+ yield* Deferred.await(downloadFinished);+ yield* flushCallbacks;+ assert.equal(download.mock.calls.length, 1);+ assert.equal((yield* updates.getState).status, "downloaded");+ assert.equal((yield* updates.getState).downloadedVersion, "1.2.4");+ }+ assert.equal(networkDownload.mock.calls.length, 0);+ }),+ ).pipe(Effect.provide(harness.layer));+ }),+ ),+ );+ }),+ ).pipe(Effect.provide(NodeServices.layer)),+ );+});diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.tsindex 9cd357f11ca..77709c4a2f3 100644--- a/apps/desktop/src/electron/ElectronUpdater.ts+++ b/apps/desktop/src/electron/ElectronUpdater.ts@@ -1,6 +1,7 @@import * as Context from "effect/Context";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";+import * as Option from "effect/Option";import * as Schema from "effect/Schema";import * as Scope from "effect/Scope";@@ -68,6 +69,7 @@ export class ElectronUpdater extends Context.Service<readonly setAllowDowngrade: (value: boolean) => Effect.Effect<void>;readonly setFullChangelog: (value: boolean) => Effect.Effect<void>;readonly setDisableDifferentialDownload: (value: boolean) => Effect.Effect<void>;+ readonly pendingDownloadDirectory: Effect.Effect<Option.Option<string>>;readonly checkForUpdates: Effect.Effect<void, ElectronUpdaterCheckForUpdatesError>;readonly downloadUpdate: Effect.Effect<void, ElectronUpdaterDownloadUpdateError>;readonly quitAndInstall: (options: {@@ -163,6 +165,17 @@ export const make = ElectronUpdater.of({autoUpdater.disableDifferentialDownload = value;return Effect.void;}),+ // Use the updater's helper so cache lookup follows the same configuration as downloads.+ pendingDownloadDirectory: Effect.tryPromise(() =>+ (+ autoUpdater as unknown as {+ getOrCreateDownloadHelper: () => Promise<{ readonly cacheDirForPendingUpdate: string }>;+ }+ ).getOrCreateDownloadHelper(),+ ).pipe(+ Effect.map((helper) => helper.cacheDirForPendingUpdate),+ Effect.option,+ ),checkForUpdates: Effect.suspend(() => {const channel = autoUpdater.channel;return Effect.tryPromise({diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.tsindex 94bfbe44c36..5233f370f7e 100644--- a/apps/desktop/src/updates/DesktopUpdates.test.ts+++ b/apps/desktop/src/updates/DesktopUpdates.test.ts@@ -273,6 +273,116 @@ describe("DesktopUpdates", () => {).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));});+ it.effect("reuses an update an earlier launch downloaded once its check finishes", () => {+ const releaseCheck = Deferred.makeUnsafe<void>();+ const harness = makeHarness({+ cachedDownloadSha512: "sha-1.2.4",+ // electron-updater reports update-available while the check is running.+ checkForUpdates: Effect.sync(() =>+ harness.emit("update-available", {+ version: "1.2.4",+ files: [{ url: "T3-Code-1.2.4.zip", sha512: "sha-1.2.4" }],+ }),+ ).pipe(Effect.andThen(Deferred.await(releaseCheck))),+ downloadUpdate: Effect.sync(() => harness.emit("update-downloaded", { version: "1.2.4" })),+ });++ return Effect.scoped(+ Effect.gen(function* () {+ const updates = yield* DesktopUpdates.DesktopUpdates;+ yield* updates.configure;++ const check = yield* Effect.forkChild(updates.check("startup"));+ yield* flushCallbacks;+ assert.equal(harness.downloadCount(), 0);+ assert.equal((yield* updates.getState).status, "available");++ yield* Deferred.succeed(releaseCheck, undefined);+ yield* Fiber.join(check);+ yield* flushCallbacks;++ assert.equal(harness.downloadCount(), 1);+ const state = yield* updates.getState;+ assert.equal(state.status, "downloaded");+ assert.equal(state.downloadedVersion, "1.2.4");+ }),+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));+ });++ it.effect.each([+ { name: "a newer release", cachedDownloadSha512: "older-release" },+ { name: "an interrupted download", cachedFileExists: false },+ { name: "unfinished metadata", cachedDownloadInfo: "{" },+ ])("keeps $name click-to-download", (cache) => {+ const harness = makeHarness({ cachedDownloadSha512: "release-sha", ...cache });++ return Effect.scoped(+ Effect.gen(function* () {+ const updates = yield* DesktopUpdates.DesktopUpdates;+ yield* updates.configure;+ harness.emit("update-available", {+ version: "1.2.5",+ files: [{ url: "T3-Code-1.2.5.zip", sha512: "release-sha" }],+ });+ yield* flushCallbacks;++ assert.equal(harness.downloadCount(), 0);+ assert.equal((yield* updates.getState).status, "available");+ assert.isTrue((yield* updates.download).accepted);+ assert.equal(harness.downloadCount(), 1);+ }),+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));+ });++ it.effect.each(["quitting", "newer release", "no longer available"] as const)(+ "abandons pending cache recovery after %s",+ (change) => {+ const releaseCheck = Deferred.makeUnsafe<void>();+ const harness = makeHarness({+ cachedDownloadSha512: "cached-release",+ checkForUpdates: Effect.sync(() =>+ harness.emit("update-available", {+ version: "1.2.4",+ files: [{ url: "T3-Code-1.2.4.zip", sha512: "cached-release" }],+ }),+ ).pipe(Effect.andThen(Deferred.await(releaseCheck))),+ });++ return Effect.scoped(+ Effect.gen(function* () {+ const updates = yield* DesktopUpdates.DesktopUpdates;+ yield* updates.configure;+ const check = yield* Effect.forkChild(updates.check("startup"));+ yield* flushCallbacks;+ assert.equal((yield* updates.getState).status, "available");+ assert.equal(harness.downloadCount(), 0);++ if (change === "quitting") {+ const desktop = yield* DesktopState.DesktopState;+ yield* Ref.set(desktop.quitting, true);+ } else if (change === "newer release") {+ harness.emit("update-available", {+ version: "1.2.5",+ files: [{ url: "T3-Code-1.2.5.zip", sha512: "new-release" }],+ });+ } else {+ harness.emit("update-not-available");+ }+ yield* flushCallbacks;+ yield* Deferred.succeed(releaseCheck, undefined);+ yield* Fiber.join(check);+ yield* flushCallbacks;++ assert.equal(harness.downloadCount(), 0);+ assert.equal(+ (yield* updates.getState).status,+ change === "no longer available" ? "up-to-date" : "available",+ );+ }),+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));+ },+ );+it.effect("preserves a queued installer when the feed has no update", () => {const harness = makeHarness();diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.tsindex ae3c2588fab..a2b97043854 100644--- a/apps/desktop/src/updates/DesktopUpdates.ts+++ b/apps/desktop/src/updates/DesktopUpdates.ts@@ -68,8 +68,17 @@ const UpdateInfo = Schema.Struct({// fail the decode and block the update state transition. The shape is// validated defensively in normalizeDesktopUpdateReleaseNotes.releaseNotes: Schema.optional(Schema.Unknown),+ files: Schema.optional(Schema.Unknown),});+const ReleaseFile = Schema.Struct({ url: Schema.String, sha512: Schema.String });+type ReleaseFile = typeof ReleaseFile.Type;+const ReleaseFiles = Schema.Array(ReleaseFile);++const CachedDownloadInfo = Schema.fromJsonString(+ Schema.Struct({ fileName: Schema.String, sha512: Schema.String }),+);+const DownloadProgressInfo = Schema.Struct({percent: Schema.Number,});@@ -83,6 +92,8 @@ const encodeInstallRecord = Schema.encodeEffect(DesktopUpdateInstallRecord);const decodeAppUpdateYmlConfig = Schema.decodeUnknownEffect(AppUpdateYmlConfig);const decodeUpdateInfo = Schema.decodeUnknownEffect(UpdateInfo);const decodeDownloadProgressInfo = Schema.decodeUnknownEffect(DownloadProgressInfo);+const decodeReleaseFiles = Schema.decodeUnknownOption(ReleaseFiles);+const decodeCachedDownloadInfo = Schema.decodeUnknownEffect(CachedDownloadInfo);const currentIsoTimestamp = DateTime.now.pipe(Effect.map(DateTime.formatIso));@@ -335,6 +346,32 @@ function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): booleanreturn runtimeInfo.hostArch === "arm64" && runtimeInfo.appArch === "x64";}+// Match electron-updater 6.8.9's MacUpdater.filterFilesForArch and Provider.findFile+// for T3's package feeds. Matching any artifact can trigger a different download.+function selectUpdateFile(+ files: ReadonlyArray<ReleaseFile>,+ platform: NodeJS.Platform,+ isDebPackage: boolean,+ runtimeInfo: DesktopRuntimeInfo,+): ReleaseFile | undefined {+ let candidates = files;+ if (platform === "darwin") {+ const isArm64File = (file: ReleaseFile) => file.url.includes("arm64");+ const preferArm64 = runtimeInfo.hostArch === "arm64" && files.some(isArm64File);+ candidates = files.filter((file) => isArm64File(file) === preferArm64);+ }+ const extension =+ platform === "darwin"+ ? ".zip"+ : platform === "win32"+ ? ".exe"+ : isDebPackage+ ? ".deb"+ : ".appimage";+ const packageFiles = candidates.filter((file) => file.url.toLowerCase().endsWith(extension));+ return packageFiles.find((file) => file.url.includes(runtimeInfo.appArch)) ?? packageFiles[0];+}+/** @public Service construction is part of the canonical Effect module API. */export const make = Effect.gen(function* () {const config = yield* DesktopConfig.DesktopConfig;@@ -453,6 +490,15 @@ export const make = Effect.gen(function* () {),);+ const awaitIdleUpdateAction = Effect.scoped(+ Effect.gen(function* () {+ const completions = yield* PubSub.subscribe(finishedUpdateActions);+ while (Option.isSome(yield* activeUpdateAction)) {+ yield* PubSub.take(completions);+ }+ }),+ );+const applyAutoUpdaterChannel = Effect.fn("desktop.updates.applyAutoUpdaterChannel")(function* (channel: DesktopUpdateChannel,) {@@ -853,6 +899,44 @@ export const make = Effect.gen(function* () {);}).pipe(Effect.withSpan("desktop.updates.startPollers"));+ const cachedDownloadSha512 = Effect.gen(function* () {+ const pendingDirectory = yield* electronUpdater.pendingDownloadDirectory;+ if (Option.isNone(pendingDirectory)) return Option.none<string>();+ const info = yield* fileSystem+ .readFileString(environment.path.join(pendingDirectory.value, "update-info.json"))+ .pipe(Effect.flatMap(decodeCachedDownloadInfo));+ const fileExists = yield* fileSystem.exists(+ environment.path.join(pendingDirectory.value, info.fileName),+ );+ return fileExists ? Option.some(info.sha512) : Option.none<string>();+ }).pipe(Effect.orElseSucceed(() => Option.none<string>()));++ // downloadUpdate validates the cached bytes and restores install readiness.+ // Only resume the selected artifact; a cache miss would start a network download.+ const resumeCachedDownload = Effect.fn("desktop.updates.resumeCachedDownload")(function* (+ version: string,+ files: unknown,+ ) {+ const releaseFiles = decodeReleaseFiles(files);+ if (Option.isNone(releaseFiles)) return;+ const updateFile = selectUpdateFile(+ releaseFiles.value,+ environment.platform,+ isDebPackage,+ environment.runtimeInfo,+ );+ if (!updateFile) return;+ const cachedSha512 = yield* cachedDownloadSha512;+ if (Option.isNone(cachedSha512) || updateFile.sha512 !== cachedSha512.value) return;++ // update-available arrives while its check still holds the action reservation.+ yield* awaitIdleUpdateAction;+ if (yield* Ref.get(desktopState.quitting)) return;+ const state = yield* Ref.get(updateStateRef);+ if (state.status !== "available" || state.availableVersion !== version) return;+ yield* downloadAvailableUpdate;+ });+const handleUpdateAvailable = Effect.fn("desktop.updates.handleUpdateAvailable")(function* (raw: unknown,) {@@ -892,6 +976,9 @@ export const make = Effect.gen(function* () {releaseNoteGroups: releaseNotes.length,omittedReleaseCount,});+ if (state.downloadedVersion !== info.version) {+ yield* resumeCachedDownload(info.version, info.files);+ }}),),Effect.catchCause((cause) => {diff --git a/apps/desktop/src/updates/updatesTestHarness.ts b/apps/desktop/src/updates/updatesTestHarness.tsindex 1d8c21a42df..2c016c2c4d6 100644--- a/apps/desktop/src/updates/updatesTestHarness.ts+++ b/apps/desktop/src/updates/updatesTestHarness.ts@@ -26,6 +26,13 @@ export interface UpdatesHarnessOptions {readonly setUpdateChannelError?: DesktopAppSettings.DesktopSettingsWriteError;readonly setDisableDifferentialDownload?: Effect.Effect<void>;readonly downloadUpdate?: Effect.Effect<void>;+ /** sha512 of a download an earlier launch left in electron-updater's cache. */+ readonly cachedDownloadSha512?: string;+ readonly cachedDownloadInfo?: string;+ readonly cachedFileExists?: boolean;+ readonly updater?: ElectronUpdater.ElectronUpdater["Service"];+ readonly fileSystem?: FileSystem.FileSystem;+ readonly runningUnderArm64Translation?: boolean;readonly quitAndInstall?: Effect.Effect<void, ElectronUpdater.ElectronUpdaterQuitAndInstallError>;readonly stopBackend?: Effect.Effect<void>;readonly startBackend?: Effect.Effect<void>;@@ -37,6 +44,8 @@ export interface UpdatesHarnessOptions {readonly installRecord?: string | undefined;}+const PENDING_DOWNLOAD_DIRECTORY = "/cache/t3code-updater/pending";+export function makeHarness(options: UpdatesHarnessOptions = {}) {let checkCount = 0;let quitAndInstallCount = 0;@@ -65,7 +74,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {}};- const layerUpdater = Layer.succeed(ElectronUpdater.ElectronUpdater, {+ const stubUpdater = {setFeedURL: (options) =>Effect.sync(() => {feedUrls.push(options);@@ -84,6 +93,11 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {fullChangelog = value;}),setDisableDifferentialDownload: () => options.setDisableDifferentialDownload ?? Effect.void,+ pendingDownloadDirectory: Effect.succeed(+ options.cachedDownloadSha512 === undefined+ ? Option.none()+ : Option.some(PENDING_DOWNLOAD_DIRECTORY),+ ),checkForUpdates: Effect.sync(() => {checkCount += 1;}).pipe(Effect.andThen(options.checkForUpdates ?? Effect.void)),@@ -105,7 +119,11 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {removeListener(eventName, listener as unknown as (...args: readonly unknown[]) => void);}),).pipe(Effect.asVoid),- } satisfies ElectronUpdater.ElectronUpdater["Service"]);+ } satisfies ElectronUpdater.ElectronUpdater["Service"];+ const layerUpdater = Layer.succeed(+ ElectronUpdater.ElectronUpdater,+ options.updater ?? stubUpdater,+ );const layerWindow = Layer.succeed(ElectronWindow.ElectronWindow, {create: () => Effect.die("unexpected BrowserWindow creation"),@@ -161,7 +179,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {appPath: "/repo",isPackaged: true,resourcesPath: "/missing/resources",- runningUnderArm64Translation: false,+ runningUnderArm64Translation: options.runningUnderArm64Translation ?? false,}).pipe(Layer.provide(Layer.mergeAll(@@ -218,7 +236,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {let previousInstallRecord = options.installRecord;const isInstallRecord = (path: string) =>path.endsWith(DesktopUpdates.DESKTOP_UPDATE_INSTALL_RECORD_FILE);- const layerFileSystem = FileSystem.layerNoop({+ const stubFileSystem = FileSystem.layerNoop({readFileString: (path) => {const installRecord = isInstallRecord(path)? (installRecords.get(path) ?? previousInstallRecord)@@ -226,15 +244,28 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {if (installRecord !== undefined) return Effect.succeed(installRecord);return path === "/missing/resources/package-type" && options.packageType !== undefined? Effect.succeed(options.packageType)- : Effect.fail(- PlatformError.systemError({- module: "FileSystem",- method: "readFileString",- _tag: "NotFound",- pathOrDescriptor: path,- }),- );+ : path === `${PENDING_DOWNLOAD_DIRECTORY}/update-info.json` &&+ options.cachedDownloadSha512 !== undefined+ ? Effect.succeed(+ options.cachedDownloadInfo ??+ JSON.stringify({+ fileName: "update.zip",+ sha512: options.cachedDownloadSha512,+ }),+ )+ : Effect.fail(+ PlatformError.systemError({+ module: "FileSystem",+ method: "readFileString",+ _tag: "NotFound",+ pathOrDescriptor: path,+ }),+ );},+ exists: (path) =>+ Effect.succeed(+ options.cachedFileExists !== false && path === `${PENDING_DOWNLOAD_DIRECTORY}/update.zip`,+ ),makeDirectory: () => Effect.void,writeFileString: (path, data) =>Effect.sync(() => {@@ -249,6 +280,9 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {}),});+ const layerFileSystem = options.fileSystem+ ? Layer.succeed(FileSystem.FileSystem, options.fileSystem)+ : stubFileSystem;const layer = DesktopUpdates.layer.pipe(Layer.provide(layerFileSystem),Layer.provideMerge(layerUpdater),