review: install only from downloaded status, report install failures via errorContext

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-08-13 17:17:38 -07:00
1 parent f6022f33d0
commit efb25b1596
5 files changed
+71 -7

No files matched your search

@@ -9,6 +9,7 @@ import * as Queue from "effect/Queue";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";
import * as ElectronUpdater from "../electron/ElectronUpdater.ts";
import * as DesktopTelemetryPublisher from "../telemetry/DesktopTelemetryPublisher.ts";
import * as DesktopRemoteUpdates from "./DesktopRemoteUpdates.ts";
import * as DesktopUpdates from "./DesktopUpdates.ts";
@@ -101,6 +102,40 @@ describe("DesktopRemoteUpdates", () => {
);
});
it.effect("reports a failed outcome when quitAndInstall fails", () => {
const harness = makeHarness({
quitAndInstall: Effect.fail(
new ElectronUpdater.ElectronUpdaterQuitAndInstallError({
channel: "latest",
isSilent: true,
isForceRunAfter: true,
cause: new Error("spawn failed"),
}),
),
});
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
Effect.gen(function* () {
yield* Queue.offer(requests, request("req-4"));
yield* settle;
harness.emit("update-available", { version: "1.2.4" });
yield* settle;
harness.emit("update-downloaded", { version: "1.2.4" });
yield* settle;
// Install failures reduce to status "downloaded" + errorContext
// "install"; the run must still end with a failed report after the
// premature "installing" one.
const terminals = terminalReports(reports);
assert.deepEqual(
terminals.map((report) => report.outcome),
["installing", "failed"],
);
assert.equal(terminals[1]?.state.errorContext, "install");
}),
);
});
it.effect("reports up-to-date without installing when there is no update", () => {
const harness = makeHarness();
@@ -97,7 +97,12 @@ export const listen: Effect.Effect<
outcome: "failed",
reason: "The desktop app could not start the install.",
});
} else if (result.state.status === "error") {
} else if (
result.state.status === "error" ||
result.state.errorContext === "install"
) {
// Install failures reduce to status "downloaded" with
// errorContext "install", not to "error".
yield* publishReport(result.state, {
outcome: "failed",
reason: result.state.message ?? "The desktop app failed to install the update.",
@@ -46,7 +46,7 @@ describe("nextRemoteDesktopUpdateStep", () => {
});
});
it("installs as soon as a download is present", () => {
it("installs only from the downloaded status the updater will accept", () => {
assert.deepEqual(
nextRemoteDesktopUpdateStep(
makeState({ status: "downloaded", downloadedVersion: "1.2.4" }),
@@ -55,16 +55,35 @@ describe("nextRemoteDesktopUpdateStep", () => {
),
{ action: "install" },
);
// A downloadedVersion left over from an earlier local download wins even
// when the status has moved on.
// A previous install failure keeps status "downloaded", so a remote run
// retries the install.
assert.deepEqual(
nextRemoteDesktopUpdateStep(
makeState({ status: "idle", downloadedVersion: "1.2.4" }),
makeState({
status: "downloaded",
downloadedVersion: "1.2.4",
errorContext: "install",
message: "quitAndInstall failed",
}),
NO_ATTEMPTS,
null,
),
{ action: "install" },
);
// A leftover downloadedVersion on an error state (background updater
// error) must fail instead of reporting an install the updater refuses.
assert.deepEqual(
nextRemoteDesktopUpdateStep(
makeState({
status: "error",
downloadedVersion: "1.2.4",
message: "background updater error",
}),
NO_ATTEMPTS,
null,
),
{ action: "done", outcome: "failed", reason: "background updater error" },
);
});
it("rides along while a check or download is already in flight", () => {
+5 -1
View File
@@ -42,7 +42,11 @@ export function nextRemoteDesktopUpdateStep(
reason: disabledReason ?? "Automatic updates are disabled on this machine.",
};
}
if (state.downloadedVersion !== null || state.status === "downloaded") {
// Only "downloaded" is installable: installDownloadedUpdate rejects any
// other status. A leftover downloadedVersion on an "error" state (e.g. a
// background updater error) must fall through to the error branch instead
// of reporting an install that the updater will refuse.
if (state.status === "downloaded") {
return { action: "install" };
}
if (state.status === "downloading" || state.status === "checking") {
@@ -26,6 +26,7 @@ export interface UpdatesHarnessOptions {
>;
readonly setUpdateChannelError?: DesktopAppSettings.DesktopSettingsWriteError;
readonly setDisableDifferentialDownload?: Effect.Effect<void>;
readonly quitAndInstall?: Effect.Effect<void, ElectronUpdater.ElectronUpdaterQuitAndInstallError>;
readonly stopBackend?: Effect.Effect<void>;
readonly env?: Record<string, string | undefined>;
}
@@ -82,7 +83,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
quitAndInstall: () =>
Effect.sync(() => {
quitAndInstallCount += 1;
}),
}).pipe(Effect.andThen(options.quitAndInstall ?? Effect.void)),
on: (eventName, listener) =>
Effect.acquireRelease(
Effect.sync(() => {