Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DesktopUpdates.test.ts

1,244 lines47.4 KB

1import * as NodeModule from "node:module";
2​
3import { assert, describe, it } from "@effect/vitest";
4import { DESKTOP_UPDATE_RESTART_MARKER_FILE } from "@t3tools/contracts";
5import { computeReleaseNotes } from "electron-updater/out/providers/GitHubProvider.js";
6import * as Cause from "effect/Cause";
7import * as Deferred from "effect/Deferred";
8import * as Duration from "effect/Duration";
9import * as Effect from "effect/Effect";
10import * as Fiber from "effect/Fiber";
11import * as Layer from "effect/Layer";
12import * as Logger from "effect/Logger";
13import * as Option from "effect/Option";
14import * as References from "effect/References";
15import * as Ref from "effect/Ref";
16import * as Stream from "effect/Stream";
17import * as TestClock from "effect/testing/TestClock";
18​
19import * as ElectronUpdater from "../electron/ElectronUpdater.ts";
20import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
21import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
22import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
23import * as DesktopState from "../app/DesktopState.ts";
24import * as DesktopUpdatePolicy from "./DesktopUpdatePolicy.ts";
25import * as DesktopUpdates from "./DesktopUpdates.ts";
26import { flushCallbacks, makeHarness } from "./updatesTestHarness.ts";
27​
28type ReleaseFeed = Parameters<typeof computeReleaseNotes>[2];
29type RunningVersion = Parameters<typeof computeReleaseNotes>[0];
30​
31// electron-updater's own dependencies, which apps/desktop does not declare.
32const requireFromUpdater = NodeModule.createRequire(
33 NodeModule.createRequire(import.meta.url).resolve("electron-updater"),
34);
35const { parseXml } = requireFromUpdater("builder-util-runtime") as {
36 parseXml: (xml: string) => ReleaseFeed;
37};
38const semver = requireFromUpdater("semver") as { parse: (version: string) => RunningVersion };
39​
40const releaseTitle = (version: string) =>
41 version.includes("-nightly.")
42 ? `T3 Code Nightly ${version} (0123456789ab)`
43 : `T3 Code v${version}`;
44​
45const releaseFeed = (...versions: ReadonlyArray<string>) =>
46 parseXml(
47 `<feed xmlns="http://www.w3.org/2005/Atom">${versions
48 .map(
49 (version) =>
50 `<entry><link rel="alternate" type="text/html" href="https://github.com/pingdotgg/t3code/releases/tag/v${version}"/><title>${releaseTitle(version)}</title><content type="html">&lt;ul&gt;&lt;li&gt;${version} change&lt;/li&gt;&lt;/ul&gt;</content></entry>`,
51 )
52 .join("")}</feed>`,
53 );
54​
55/** The update info electron-updater's GitHub provider reports when /releases/latest names `version`. */
56const stableUpdateInfo = (
57 feed: ReleaseFeed,
58 version: string,
59 runningVersion: string,
60 fullChangelog: boolean,
61) => {
62 const latestRelease =
63 feed
64 .getElements("entry")
65 .find((entry) => entry.element("link").attribute("href").endsWith(`/tag/v${version}`)) ??
66 feed.element("entry");
67 return {
68 version,
69 releaseName: latestRelease.elementValueOrEmpty("title"),
70 releaseNotes: computeReleaseNotes(
71 semver.parse(runningVersion),
72 fullChangelog,
73 feed,
74 latestRelease,
75 ),
76 };
77};
78​
79describe("DesktopUpdates", () => {
80 it.effect("updates Linux .deb installs and leaves other non-AppImage installs off", () =>
81 Effect.gen(function* () {
82 const linuxState = (packageType: string | undefined) =>
83 Effect.scoped(
84 Effect.gen(function* () {
85 const updates = yield* DesktopUpdates.DesktopUpdates;
86 const desktopState = yield* DesktopState.DesktopState;
87 yield* updates.configure;
88 return {
89 state: yield* updates.getState,
90 canInstallUpdates: yield* Ref.get(desktopState.canInstallUpdates),
91 };
92 }),
93 ).pipe(Effect.provide(makeHarness({ platform: "linux", packageType }).layer));
94​
95 const deb = yield* linuxState("deb\n");
96 assert.equal(deb.state.status, "idle");
97 assert.isTrue(deb.canInstallUpdates);
98​
99 const unmarked = yield* linuxState(undefined);
100 assert.equal(unmarked.state.status, "disabled");
101 assert.isFalse(unmarked.canInstallUpdates);
102 }),
103 );
104​
105 it.effect("keeps the disabled reason available after configuration and channel changes", () => {
106 const harness = makeHarness({ env: { T3CODE_DISABLE_AUTO_UPDATE: "true" } });
107 const reason = "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.";
108​
109 return Effect.scoped(
110 Effect.gen(function* () {
111 const updates = yield* DesktopUpdates.DesktopUpdates;
112 yield* updates.configure;
113​
114 const configured = yield* updates.getState;
115 assert.equal(configured.message, reason);
116​
117 const changed = yield* updates.setChannel("nightly");
118 assert.equal(changed.channel, "nightly");
119 assert.equal(changed.enabled, false);
120 assert.equal(changed.status, "disabled");
121 assert.equal(changed.message, reason);
122 assert.equal(harness.sentStates.at(-1)?.message, reason);
123 assert.equal(harness.checkCount(), 0);
124 }),
125 ).pipe(Effect.provide(harness.layer));
126 });
127​
128 it.effect("checks for newer releases after an update has been downloaded", () => {
129 const harness = makeHarness();
130​
131 return Effect.scoped(
132 Effect.gen(function* () {
133 const updates = yield* DesktopUpdates.DesktopUpdates;
134 yield* updates.configure;
135​
136 harness.emit("update-available", {
137 version: "1.2.4",
138 releaseNotes: "## What's changed\n- fix: queued update",
139 });
140 yield* flushCallbacks;
141 harness.emit("update-downloaded", { version: "1.2.4" });
142 yield* flushCallbacks;
143​
144 const result = yield* updates.check("poll");
145 assert.isTrue(result.checked);
146​
147 harness.emit("update-available", { version: "1.2.4" });
148 yield* flushCallbacks;
149​
150 const unchangedState = yield* updates.getState;
151 assert.equal(unchangedState.status, "downloaded");
152 assert.equal(unchangedState.downloadedVersion, "1.2.4");
153 assert.deepEqual(unchangedState.releaseNotes, [
154 { version: "1.2.4", items: ["fix: queued update"], totalItems: 1 },
155 ]);
156 assert.equal(unchangedState.omittedReleaseCount, 0);
157​
158 const nextResult = yield* updates.check("poll");
159 assert.isTrue(nextResult.checked);
160​
161 harness.emit("update-available", { version: "1.2.5" });
162 yield* flushCallbacks;
163​
164 const state = yield* updates.getState;
165 assert.equal(state.status, "available");
166 assert.equal(state.availableVersion, "1.2.5");
167 assert.isNull(state.downloadedVersion);
168 }),
169 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
170 });
171​
172 it.effect.each([
173 {
174 name: "shows no notes for a Stable release missing from the releases feed",
175 runningVersion: "1.2.3",
176 feedVersions: ["1.2.5-nightly.20261102.1", "1.2.5-nightly.20261101.1"],
177 expected: [],
178 },
179 {
180 name: "shows a Stable release's own notes from the releases feed",
181 runningVersion: "1.2.3",
182 feedVersions: ["1.2.5-nightly.20261102.1", "1.2.4", "1.2.4-nightly.20261030.1"],
183 expected: [{ version: "1.2.4", items: ["1.2.4 change"], totalItems: 1 }],
184 },
185 {
186 name: "shows a Stable release's notes when switching down from a newer Nightly",
187 runningVersion: "1.2.5-nightly.20261027.1",
188 feedVersions: ["1.2.5-nightly.20261102.1", "1.2.4"],
189 expected: [{ version: "1.2.4", items: ["1.2.4 change"], totalItems: 1 }],
190 },
191 ])("$name", ({ runningVersion, feedVersions, expected }) => {
192 const harness = makeHarness();
193​
194 return Effect.scoped(
195 Effect.gen(function* () {
196 const updates = yield* DesktopUpdates.DesktopUpdates;
197 yield* updates.configure;
198​
199 harness.emit(
200 "update-available",
201 stableUpdateInfo(
202 releaseFeed(...feedVersions),
203 "1.2.4",
204 runningVersion,
205 harness.fullChangelog(),
206 ),
207 );
208 yield* flushCallbacks;
209​
210 const state = yield* updates.getState;
211 assert.equal(state.availableVersion, "1.2.4");
212 assert.deepEqual(state.releaseNotes, expected);
213 }),
214 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
215 });
216​
217 it.effect("preserves a queued installer when the feed has no update", () => {
218 const harness = makeHarness();
219​
220 return Effect.scoped(
221 Effect.gen(function* () {
222 const updates = yield* DesktopUpdates.DesktopUpdates;
223 yield* updates.configure;
224​
225 harness.emit("update-available", {
226 version: "1.2.4",
227 releaseNotes: "## What's changed\n- fix: queued update",
228 });
229 yield* flushCallbacks;
230 harness.emit("update-downloaded", { version: "1.2.4" });
231 yield* flushCallbacks;
232​
233 yield* updates.check("poll");
234 harness.emit("update-not-available");
235 yield* flushCallbacks;
236​
237 const state = yield* updates.getState;
238 assert.equal(state.status, "downloaded");
239 assert.equal(state.availableVersion, "1.2.4");
240 assert.equal(state.downloadedVersion, "1.2.4");
241 assert.deepEqual(state.releaseNotes, [
242 { version: "1.2.4", items: ["fix: queued update"], totalItems: 1 },
243 ]);
244 assert.equal(state.omittedReleaseCount, 0);
245 assert.equal(state.downloadPercent, 100);
246 }),
247 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
248 });
249​
250 it.effect(
251 "rejects install while a refresh check is in progress and releases the reservation",
252 () =>
253 Effect.gen(function* () {
254 const checkStarted = yield* Deferred.make<void>();
255 const releaseCheck = yield* Deferred.make<void>();
256 const harness = makeHarness({
257 checkForUpdates: Deferred.succeed(checkStarted, undefined).pipe(
258 Effect.andThen(Deferred.await(releaseCheck)),
259 ),
260 });
261​
262 yield* Effect.scoped(
263 Effect.gen(function* () {
264 const updates = yield* DesktopUpdates.DesktopUpdates;
265 yield* updates.configure;
266 harness.emit("update-downloaded", { version: "1.2.4" });
267 yield* flushCallbacks;
268​
269 const checkFiber = yield* updates.check("manual").pipe(Effect.forkScoped);
270 yield* Deferred.await(checkStarted);
271​
272 const installResult = yield* updates.install;
273 assert.isFalse(installResult.accepted);
274​
275 yield* Deferred.succeed(releaseCheck, undefined);
276 const checkResult = yield* Fiber.join(checkFiber);
277 assert.isTrue(checkResult.checked);
278​
279 const followUpCheck = yield* updates.check("manual");
280 assert.isTrue(followUpCheck.checked);
281 assert.equal(harness.checkCount(), 2);
282 }),
283 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
284 }),
285 );
286​
287 it.effect("rejects refresh checks while install is in progress", () =>
288 Effect.gen(function* () {
289 const installStarted = yield* Deferred.make<void>();
290 const releaseInstall = yield* Deferred.make<void>();
291 const harness = makeHarness({
292 stopBackend: Deferred.succeed(installStarted, undefined).pipe(
293 Effect.andThen(Deferred.await(releaseInstall)),
294 ),
295 });
296​
297 yield* Effect.scoped(
298 Effect.gen(function* () {
299 const updates = yield* DesktopUpdates.DesktopUpdates;
300 yield* updates.configure;
301 harness.emit("update-downloaded", { version: "1.2.4" });
302 yield* flushCallbacks;
303​
304 const installFiber = yield* updates.install.pipe(Effect.forkScoped);
305 yield* Deferred.await(installStarted);
306​
307 const checkResult = yield* updates.check("manual");
308 assert.isFalse(checkResult.checked);
309 assert.equal(harness.checkCount(), 0);
310​
311 yield* Deferred.succeed(releaseInstall, undefined);
312 const installResult = yield* Fiber.join(installFiber);
313 assert.isTrue(installResult.accepted);
314 }),
315 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
316 }),
317 );
318​
319 it.effect("preserves a queued installer after a background updater error", () => {
320 const harness = makeHarness();
321​
322 return Effect.scoped(
323 Effect.gen(function* () {
324 const updates = yield* DesktopUpdates.DesktopUpdates;
325 yield* updates.configure;
326 harness.emit("update-downloaded", { version: "1.2.4" });
327 yield* flushCallbacks;
328​
329 harness.emit("error", new Error("background updater failure"));
330 yield* flushCallbacks;
331​
332 const state = yield* updates.getState;
333 assert.equal(state.status, "error");
334 assert.equal(state.downloadedVersion, "1.2.4");
335 assert.isNull(state.errorContext);
336​
337 const result = yield* updates.install;
338 assert.isTrue(result.accepted);
339 }),
340 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
341 });
342​
343 it.effect("logs the redacted cause of a rejected update check", () => {
344 const cause = Object.assign(
345 new Error("request failed for https://user:secret@example.com/update?token=secret"),
346 { code: "ERR_UPDATER_LATEST_VERSION_NOT_FOUND" },
347 );
348 const updaterError = new ElectronUpdater.ElectronUpdaterCheckForUpdatesError({
349 channel: null,
350 cause,
351 });
352 const harness = makeHarness({ checkForUpdates: Effect.fail(updaterError) });
353 const loggedAnnotations: Array<Record<string, unknown>> = [];
354 const logger = Logger.make(({ fiber }) => {
355 const annotations = fiber.getRef(References.CurrentLogAnnotations);
356 if (annotations.errorTag === "ElectronUpdaterCheckForUpdatesError") {
357 loggedAnnotations.push(annotations);
358 }
359 });
360​
361 return Effect.scoped(
362 Effect.gen(function* () {
363 const updates = yield* DesktopUpdates.DesktopUpdates;
364 yield* updates.configure;
365​
366 yield* updates.check("manual");
367​
368 const state = yield* updates.getState;
369 const loggedAnnotation = loggedAnnotations.at(-1);
370 assert.isDefined(loggedAnnotation);
371 assert.equal(loggedAnnotation.errorTag, "ElectronUpdaterCheckForUpdatesError");
372 assert.isNull(loggedAnnotation.channel);
373 assert.equal(
374 loggedAnnotation.cause,
375 "Error [ERR_UPDATER_LATEST_VERSION_NOT_FOUND]: request failed for [redacted URL]",
376 );
377 assert.notProperty(loggedAnnotation, "error");
378 assert.notInclude(Object.values(loggedAnnotation).map(String).join(" "), "secret");
379 assert.equal(
380 state.message,
381 "Electron updater failed to check for updates on channel default.",
382 );
383 assert.notInclude(state.message ?? "", "secret");
384 }),
385 ).pipe(
386 Effect.provide(
387 Layer.mergeAll(
388 TestClock.layer(),
389 harness.layer,
390 Logger.layer([logger], { mergeWithExisting: false }),
391 ),
392 ),
393 );
394 });
395​
396 it.effect("recovers download state after an unexpected setup failure", () => {
397 let disableDifferentialCalls = 0;
398 const harness = makeHarness({
399 setDisableDifferentialDownload: Effect.suspend(() => {
400 disableDifferentialCalls += 1;
401 return disableDifferentialCalls === 1
402 ? Effect.void
403 : Effect.die(new Error("download setup failed"));
404 }),
405 });
406​
407 return Effect.scoped(
408 Effect.gen(function* () {
409 const updates = yield* DesktopUpdates.DesktopUpdates;
410 yield* updates.configure;
411 harness.emit("update-available", { version: "1.2.4" });
412 yield* flushCallbacks;
413​
414 const result = yield* updates.download;
415 assert.isTrue(result.accepted);
416 assert.isFalse(result.completed);
417​
418 const failedState = yield* updates.getState;
419 assert.equal(failedState.status, "available");
420 assert.equal(failedState.errorContext, "download");
421 assert.equal(failedState.message, "Desktop update download action failed unexpectedly.");
422​
423 const changedState = yield* updates.setChannel("nightly");
424 assert.equal(changedState.channel, "nightly");
425 }),
426 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
427 });
428​
429 it.effect("shows why a download failed, not only the channel", () => {
430 const harness = makeHarness({
431 downloadUpdate: Effect.fail(
432 new ElectronUpdater.ElectronUpdaterDownloadUpdateError({
433 channel: "nightly",
434 cause: new Error("net::ERR_CONTENT_LENGTH_MISMATCH"),
435 }),
436 ),
437 });
438​
439 return Effect.scoped(
440 Effect.gen(function* () {
441 const updates = yield* DesktopUpdates.DesktopUpdates;
442 yield* updates.configure;
443 harness.emit("update-available", { version: "1.2.4" });
444 yield* flushCallbacks;
445​
446 const result = yield* updates.download;
447 assert.isFalse(result.completed);
448​
449 const state = yield* updates.getState;
450 assert.equal(state.errorContext, "download");
451 assert.include(state.message ?? "", "ERR_CONTENT_LENGTH_MISMATCH");
452 }),
453 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
454 });
455​
456 it.effect("restores download state and permits retry after interruption", () =>
457 Effect.gen(function* () {
458 const actionStarted = yield* Deferred.make<void>();
459 let disableDifferentialCalls = 0;
460 const harness = makeHarness({
461 setDisableDifferentialDownload: Effect.suspend(() => {
462 disableDifferentialCalls += 1;
463 if (disableDifferentialCalls === 1) {
464 return Effect.void;
465 }
466 if (disableDifferentialCalls === 2) {
467 return Deferred.succeed(actionStarted, undefined).pipe(Effect.andThen(Effect.never));
468 }
469 return Effect.void;
470 }),
471 });
472​
473 yield* Effect.scoped(
474 Effect.gen(function* () {
475 const updates = yield* DesktopUpdates.DesktopUpdates;
476 yield* updates.configure;
477 harness.emit("update-available", { version: "1.2.4" });
478 yield* flushCallbacks;
479​
480 const downloadFiber = yield* updates.download.pipe(Effect.forkScoped);
481 yield* Deferred.await(actionStarted);
482 yield* Fiber.interrupt(downloadFiber);
483​
484 const interruptedState = yield* updates.getState;
485 assert.equal(interruptedState.status, "available");
486 assert.isNull(interruptedState.message);
487​
488 const retry = yield* updates.download;
489 assert.isTrue(retry.accepted);
490 assert.isTrue(retry.completed);
491 }),
492 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
493 }),
494 );
495​
496 it.effect("clears quitting state after an unexpected install setup failure", () => {
497 const harness = makeHarness({
498 stopBackend: Effect.die(new Error("backend stop failed")),
499 });
500​
501 return Effect.scoped(
502 Effect.gen(function* () {
503 const desktopState = yield* DesktopState.DesktopState;
504 const updates = yield* DesktopUpdates.DesktopUpdates;
505 yield* updates.configure;
506 harness.emit("update-downloaded", { version: "1.2.4" });
507 yield* flushCallbacks;
508​
509 const result = yield* updates.install;
510 assert.isTrue(result.accepted);
511 assert.isFalse(result.completed);
512 assert.isFalse(yield* Ref.get(desktopState.quitting));
513​
514 const failedState = yield* updates.getState;
515 assert.equal(failedState.status, "downloaded");
516 assert.equal(failedState.errorContext, "install");
517 assert.equal(failedState.message, "Desktop update install action failed unexpectedly.");
518​
519 const changedState = yield* updates.setChannel("nightly");
520 assert.equal(changedState.channel, "nightly");
521 }),
522 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
523 });
524​
525 it.effect("marks the backend stop for an install as an update restart", () => {
526 let markersAtStop: ReadonlyArray<string> = [];
527 const harness = makeHarness({
528 stopBackend: Effect.sync(() => {
529 markersAtStop = [...harness.updateRestartMarkers];
530 }),
531 });
532​
533 return Effect.scoped(
534 Effect.gen(function* () {
535 const environment = yield* DesktopEnvironment.DesktopEnvironment;
536 const updates = yield* DesktopUpdates.DesktopUpdates;
537 yield* updates.configure;
538 harness.emit("update-downloaded", { version: "1.2.4" });
539 yield* flushCallbacks;
540​
541 assert.isTrue((yield* updates.install).accepted);
542 assert.deepEqual(markersAtStop, [
543 environment.path.join(environment.baseDir, "runtime", DESKTOP_UPDATE_RESTART_MARKER_FILE),
544 ]);
545 }),
546 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
547 });
548​
549 it.effect("records the version an install hands to the installer", () => {
550 let recordsAtStop: ReadonlyArray<string> = [];
551 const harness = makeHarness({
552 stopBackend: Effect.sync(() => {
553 recordsAtStop = [...harness.installRecords.values()];
554 }),
555 });
556​
557 return Effect.scoped(
558 Effect.gen(function* () {
559 const updates = yield* DesktopUpdates.DesktopUpdates;
560 yield* updates.configure;
561 harness.emit("update-downloaded", { version: "1.2.4" });
562 yield* flushCallbacks;
563​
564 assert.isTrue((yield* updates.install).accepted);
565 assert.deepEqual(
566 recordsAtStop.map((record) => JSON.parse(record)),
567 [{ fromVersion: "1.2.3", targetVersion: "1.2.4" }],
568 );
569 }),
570 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
571 });
572​
573 it.effect("flags an install that did not apply and keeps the flag through checks", () => {
574 const harness = makeHarness({
575 installRecord: JSON.stringify({ fromVersion: "1.2.3", targetVersion: "1.2.4" }),
576 });
577​
578 return Effect.scoped(
579 Effect.gen(function* () {
580 const updates = yield* DesktopUpdates.DesktopUpdates;
581 yield* updates.configure;
582 assert.equal((yield* updates.getState).notAppliedVersion, "1.2.4");
583 assert.isDefined(harness.previousInstallRecord());
584​
585 harness.emit("update-available", { version: "1.2.4" });
586 yield* flushCallbacks;
587 const state = yield* updates.getState;
588 assert.equal(state.status, "available");
589 assert.equal(state.notAppliedVersion, "1.2.4");
590 }),
591 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
592 });
593​
594 // regression: #19291 an install that did apply was still flagged as not applied
595 it.effect("does not flag an install that applied", () => {
596 const harness = makeHarness({
597 installRecord: JSON.stringify({ fromVersion: "1.2.2", targetVersion: "1.2.3" }),
598 });
599​
600 return Effect.scoped(
601 Effect.gen(function* () {
602 const updates = yield* DesktopUpdates.DesktopUpdates;
603 yield* updates.configure;
604 assert.isUndefined((yield* updates.getState).notAppliedVersion);
605 assert.isUndefined(harness.previousInstallRecord());
606 }),
607 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
608 });
609​
610 it.effect("drops the update restart marker when an install is interrupted", () =>
611 Effect.gen(function* () {
612 const stopping = yield* Deferred.make<void>();
613 const harness = makeHarness({
614 stopBackend: Deferred.succeed(stopping, undefined).pipe(Effect.andThen(Effect.never)),
615 });
616​
617 yield* Effect.scoped(
618 Effect.gen(function* () {
619 const updates = yield* DesktopUpdates.DesktopUpdates;
620 yield* updates.configure;
621 harness.emit("update-downloaded", { version: "1.2.4" });
622 yield* flushCallbacks;
623​
624 const installFiber = yield* updates.install.pipe(Effect.forkScoped);
625 yield* Deferred.await(stopping);
626 assert.equal(harness.updateRestartMarkers.size, 1);
627​
628 yield* Fiber.interrupt(installFiber);
629 assert.equal(harness.updateRestartMarkers.size, 0);
630 }),
631 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
632 }),
633 );
634​
635 it.effect("keeps windows and restarts backends when quitAndInstall fails", () => {
636 const harness = makeHarness({
637 quitAndInstall: Effect.fail(
638 new ElectronUpdater.ElectronUpdaterQuitAndInstallError({
639 channel: "latest",
640 isSilent: true,
641 isForceRunAfter: true,
642 cause: new Error("installer refused"),
643 }),
644 ),
645 });
646​
647 return Effect.scoped(
648 Effect.gen(function* () {
649 const desktopState = yield* DesktopState.DesktopState;
650 const updates = yield* DesktopUpdates.DesktopUpdates;
651 yield* updates.configure;
652 harness.emit("update-downloaded", { version: "1.2.4" });
653 yield* flushCallbacks;
654​
655 const result = yield* updates.install;
656 assert.isTrue(result.accepted);
657 assert.isFalse(yield* Ref.get(desktopState.quitting));
658 assert.deepEqual(harness.installSteps, [
659 "closeSshTunnels",
660 "quitAndInstall",
661 "startBackend",
662 ]);
663 assert.equal(harness.updateRestartMarkers.size, 0);
664 assert.equal(harness.installRecords.size, 0);
665 }),
666 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
667 });
668​
669 it.effect("keeps the disabled primary stopped when quitAndInstall fails", () => {
670 const harness = makeHarness({
671 backendDesiredRunning: false,
672 quitAndInstall: Effect.fail(
673 new ElectronUpdater.ElectronUpdaterQuitAndInstallError({
674 channel: "latest",
675 isSilent: true,
676 isForceRunAfter: true,
677 cause: new Error("installer refused"),
678 }),
679 ),
680 });
681​
682 return Effect.scoped(
683 Effect.gen(function* () {
684 const updates = yield* DesktopUpdates.DesktopUpdates;
685 const pool = yield* DesktopBackendPool.DesktopBackendPool;
686 yield* updates.configure;
687 harness.emit("update-downloaded", { version: "1.2.4" });
688 yield* flushCallbacks;
689​
690 const result = yield* updates.install;
691 assert.equal(result.state.errorContext, "install");
692 assert.deepEqual(harness.installSteps, ["closeSshTunnels", "quitAndInstall"]);
693 assert.isFalse((yield* (yield* pool.primary).snapshot).desiredRunning);
694 }),
695 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
696 });
697​
698 it.effect("restores only desired-running instances after an installer error event", () => {
699 const starts: string[] = [];
700 const stops: string[] = [];
701 const makeInstance = (id: DesktopBackendPool.BackendInstanceId, initiallyRunning: boolean) => {
702 let desiredRunning = initiallyRunning;
703 return {
704 id,
705 label: Effect.succeed(id),
706 currentConfig: Effect.succeedNone,
707 start: Effect.sync(() => {
708 starts.push(id);
709 desiredRunning = true;
710 }),
711 stop: () =>
712 Effect.sync(() => {
713 stops.push(id);
714 desiredRunning = false;
715 }),
716 snapshot: Effect.sync(() => ({
717 desiredRunning,
718 ready: false,
719 activePid: Option.none(),
720 restartAttempt: 0,
721 restartScheduled: false,
722 })),
723 waitForReady: () => Effect.succeed(true),
724 } satisfies DesktopBackendPool.DesktopBackendInstance;
725 };
726 const primary = makeInstance(DesktopBackendPool.PRIMARY_INSTANCE_ID, false);
727 const wsl = makeInstance(DesktopBackendPool.BackendInstanceId("wsl:default"), true);
728 const harness = makeHarness({ backendInstances: [primary, wsl] });
729​
730 return Effect.scoped(
731 Effect.gen(function* () {
732 const updates = yield* DesktopUpdates.DesktopUpdates;
733 yield* updates.configure;
734 harness.emit("update-downloaded", { version: "1.2.4" });
735 yield* flushCallbacks;
736​
737 yield* updates.install;
738 assert.sameMembers(stops, [primary.id, wsl.id]);
739 assert.isFalse((yield* wsl.snapshot).desiredRunning);
740 const { changes } = yield* updates.subscribe;
741 const recovered = yield* Stream.runHead(changes).pipe(Effect.forkChild);
742 yield* flushCallbacks;
743 harness.emit("error", new Error("native installer refused"));
744 assert.equal(Option.getOrThrow(yield* Fiber.join(recovered)).errorContext, "install");
745​
746 assert.deepEqual(starts, [wsl.id]);
747 assert.isFalse((yield* primary.snapshot).desiredRunning);
748 assert.isTrue((yield* wsl.snapshot).desiredRunning);
749 }),
750 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
751 });
752​
753 it.effect("holds the install reservation until failed-install recovery finishes", () => {
754 const recoveryStarted = Deferred.makeUnsafe<void>();
755 const releaseRecovery = Deferred.makeUnsafe<void>();
756 const harness = makeHarness({
757 quitAndInstall: Effect.fail(
758 new ElectronUpdater.ElectronUpdaterQuitAndInstallError({
759 channel: "latest",
760 isSilent: true,
761 isForceRunAfter: true,
762 cause: new Error("installer refused"),
763 }),
764 ),
765 startBackend: Deferred.succeed(recoveryStarted, undefined).pipe(
766 Effect.andThen(Deferred.await(releaseRecovery)),
767 ),
768 });
769​
770 return Effect.scoped(
771 Effect.gen(function* () {
772 const updates = yield* DesktopUpdates.DesktopUpdates;
773 yield* updates.configure;
774 harness.emit("update-downloaded", { version: "1.2.4" });
775 yield* flushCallbacks;
776​
777 const failedInstall = yield* updates.install.pipe(Effect.forkChild);
778 yield* Deferred.await(recoveryStarted);
779 assert.isFalse(yield* updates.isInstallActive);
780​
781 const overlappingInstall = yield* updates.install;
782 assert.isFalse(overlappingInstall.accepted);
783 assert.equal(harness.quitAndInstalls(), 1);
784 harness.emit("error", new Error("duplicate native installer error"));
785 yield* flushCallbacks;
786 assert.deepEqual(harness.installSteps, [
787 "closeSshTunnels",
788 "quitAndInstall",
789 "startBackend",
790 ]);
791​
792 yield* Deferred.succeed(releaseRecovery, undefined);
793 const failedResult = yield* Fiber.join(failedInstall);
794 assert.equal(failedResult.state.errorContext, "install");
795​
796 const retry = yield* updates.install;
797 assert.isTrue(retry.accepted);
798 assert.equal(harness.quitAndInstalls(), 2);
799 }),
800 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
801 });
802​
803 it.effect("rejects a prepared install when the downloaded version changed", () => {
804 const harness = makeHarness();
805​
806 return Effect.scoped(
807 Effect.gen(function* () {
808 const updates = yield* DesktopUpdates.DesktopUpdates;
809 yield* updates.configure;
810 harness.emit("update-downloaded", { version: "1.2.5" });
811 yield* flushCallbacks;
812​
813 const result = yield* updates.installPrepared("1.2.4");
814 assert.isFalse(result.accepted);
815 assert.equal(harness.quitAndInstalls(), 0);
816 }),
817 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
818 });
819​
820 it.effect("persists channel changes through the settings service", () => {
821 const harness = makeHarness();
822​
823 return Effect.scoped(
824 Effect.gen(function* () {
825 const settings = yield* DesktopAppSettings.DesktopAppSettings;
826 const updates = yield* DesktopUpdates.DesktopUpdates;
827 yield* updates.configure;
828​
829 const state = yield* updates.setChannel("nightly");
830 const persistedSettings = yield* settings.get;
831​
832 assert.equal(state.channel, "nightly");
833 assert.equal(persistedSettings.updateChannel, "nightly");
834 assert.equal(persistedSettings.updateChannelConfiguredByUser, true);
835 }),
836 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
837 });
838​
839 it.effect("ignores a finished download from a track it no longer follows", () => {
840 const harness = makeHarness();
841​
842 return Effect.scoped(
843 Effect.gen(function* () {
844 const updates = yield* DesktopUpdates.DesktopUpdates;
845 yield* updates.configure;
846 // A backed-out switch's download keeps reporting progress until it finishes.
847 harness.emit("download-progress", { percent: 40 });
848 yield* flushCallbacks;
849 harness.emit("update-downloaded", { version: "1.2.4-nightly.20261027.1" });
850 yield* flushCallbacks;
851​
852 const state = yield* updates.getState;
853 assert.equal(state.downloadedVersion, null);
854 assert.notEqual(state.status, "downloading");
855 }),
856 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
857 });
858​
859 it.effect("offers older releases only to checks that leave the running build's track", () => {
860 const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
861​
862 return Effect.scoped(
863 Effect.gen(function* () {
864 const updates = yield* DesktopUpdates.DesktopUpdates;
865 yield* updates.configure;
866 const before = harness.checkAllowedDowngrade.length;
867 yield* updates.setChannel("nightly");
868 yield* updates.setChannel("latest");
869 yield* updates.check("remote-update", { allowDowngrade: true });
870​
871 // Back on its own Stable track the build never needs an older release.
872 assert.deepEqual(harness.checkAllowedDowngrade.slice(before), [true, false, true]);
873 assert.isFalse(harness.allowDowngrade());
874 }),
875 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
876 });
877​
878 it.effect("re-checks a saved track that differs from the running build's track", () => {
879 const harness = makeHarness({
880 appVersion: "1.2.4-nightly.20261027.1",
881 beforeSetUpdateChannel: Effect.void,
882 });
883​
884 return Effect.scoped(
885 Effect.gen(function* () {
886 const updates = yield* DesktopUpdates.DesktopUpdates;
887 yield* updates.configure;
888 yield* updates.setChannel("latest");
889 const checks = harness.checkCount();
890​
891 yield* updates.setChannel("latest");
892​
893 assert.equal(harness.checkCount(), checks + 1);
894 }),
895 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
896 });
897​
898 it.effect("does not persist an unchanged update channel as a user preference", () => {
899 const harness = makeHarness();
900​
901 return Effect.scoped(
902 Effect.gen(function* () {
903 const settings = yield* DesktopAppSettings.DesktopAppSettings;
904 const updates = yield* DesktopUpdates.DesktopUpdates;
905 yield* updates.configure;
906​
907 const state = yield* updates.setChannel("latest");
908 const persistedSettings = yield* settings.get;
909​
910 assert.equal(state.channel, "latest");
911 assert.equal(persistedSettings.updateChannel, "latest");
912 assert.equal(persistedSettings.updateChannelConfiguredByUser, false);
913 }),
914 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
915 });
916​
917 it.effect("offers nothing below a track switch's checked release", () => {
918 const harness = makeHarness({
919 appVersion: "1.2.4-nightly.20261027.1",
920 beforeSetUpdateChannel: Effect.void,
921 });
922​
923 return Effect.scoped(
924 Effect.gen(function* () {
925 const updates = yield* DesktopUpdates.DesktopUpdates;
926 yield* updates.configure;
927 yield* updates.setChannel("latest", { minimumVersion: "1.2.3" });
928​
929 harness.emit("update-available", { version: "1.2.2" });
930 yield* flushCallbacks;
931 assert.isNull((yield* updates.getState).availableVersion);
932 harness.emit("update-downloaded", { version: "1.2.2" });
933 yield* flushCallbacks;
934 assert.isNull((yield* updates.getState).downloadedVersion);
935​
936 harness.emit("update-available", { version: "1.2.3" });
937 yield* flushCallbacks;
938 assert.equal((yield* updates.getState).availableVersion, "1.2.3");
939 }),
940 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
941 });
942​
943 it.effect("keeps the current track's offers when a track switch fails to save", () => {
944 const harness = makeHarness({
945 setUpdateChannelError: new DesktopAppSettings.DesktopSettingsWriteError({
946 operation: "replace-settings-file",
947 path: "desktop-settings.json",
948 cause: new Error("rename failed"),
949 }),
950 });
951​
952 return Effect.scoped(
953 Effect.gen(function* () {
954 const updates = yield* DesktopUpdates.DesktopUpdates;
955 yield* updates.configure;
956 const error = yield* updates
957 .setChannel("nightly", { minimumVersion: "1.2.5-nightly.20261028.1" })
958 .pipe(Effect.flip);
959 assert.equal(error._tag, "DesktopUpdateChannelPersistenceError");
960 assert.equal((yield* updates.getState).channel, "latest");
961​
962 harness.emit("update-available", { version: "1.2.4" });
963 yield* flushCallbacks;
964 assert.equal((yield* updates.getState).availableVersion, "1.2.4");
965 }),
966 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
967 });
968​
969 it.effect("keeps a saved Stable track across a restart without offering an older release", () => {
970 // A Nightly build whose switch to Stable did not finish before the app quit.
971 const harness = makeHarness({ appVersion: "1.2.4-nightly.20261027.1", savedChannel: "latest" });
972​
973 return Effect.scoped(
974 Effect.gen(function* () {
975 const updates = yield* DesktopUpdates.DesktopUpdates;
976 yield* updates.configure;
977 yield* updates.check("startup");
978​
979 assert.equal((yield* updates.getState).channel, "latest");
980 assert.deepEqual(harness.checkAllowedDowngrade, [false]);
981 // Semver ranks Stable 1.2.4 above this Nightly, but a Nightly built before the release's
982 // version bump can hold migrations 1.2.4 lacks. Crossing needs a guarded switch.
983 harness.emit("update-available", { version: "1.2.4" });
984 yield* flushCallbacks;
985 assert.isNull((yield* updates.getState).availableVersion);
986 }),
987 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
988 });
989​
990 it.effect("keeps a saved Nightly track across a restart without crossing on its own", () => {
991 // A Stable build whose switch to Nightly was refused before the app quit; its floor is gone.
992 const harness = makeHarness({ savedChannel: "nightly" });
993​
994 return Effect.scoped(
995 Effect.gen(function* () {
996 const updates = yield* DesktopUpdates.DesktopUpdates;
997 yield* updates.configure;
998 yield* updates.check("startup");
999 harness.emit("update-available", { version: "1.2.4-nightly.20261027.1" });
1000 yield* flushCallbacks;
1001​
1002 assert.equal((yield* updates.getState).channel, "nightly");
1003 assert.isNull((yield* updates.getState).availableVersion);
1004 assert.deepEqual(harness.checkAllowedDowngrade, [false]);
1005 }),
1006 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1007 });
1008​
1009 it.effect("never offers an older Nightly to a Nightly build's own checks", () => {
1010 const harness = makeHarness({ appVersion: "1.2.4-nightly.20261027.1" });
1011​
1012 return Effect.scoped(
1013 Effect.gen(function* () {
1014 const updates = yield* DesktopUpdates.DesktopUpdates;
1015 yield* updates.configure;
1016 yield* updates.check("poll");
1017​
1018 assert.equal((yield* updates.getState).channel, "nightly");
1019 assert.deepEqual(harness.checkAllowedDowngrade, [false]);
1020 }),
1021 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1022 });
1023​
1024 it.effect("waits out a background check instead of refusing a track change", () =>
1025 Effect.gen(function* () {
1026 const checkStarted = yield* Deferred.make<void>();
1027 const releaseCheck = yield* Deferred.make<void>();
1028 const harness = makeHarness({
1029 beforeSetUpdateChannel: Effect.void,
1030 checkForUpdates: Deferred.succeed(checkStarted, undefined).pipe(
1031 Effect.andThen(Deferred.await(releaseCheck)),
1032 ),
1033 });
1034​
1035 yield* Effect.scoped(
1036 Effect.gen(function* () {
1037 const updates = yield* DesktopUpdates.DesktopUpdates;
1038 yield* updates.configure;
1039 yield* updates.check("poll").pipe(Effect.forkScoped);
1040 yield* Deferred.await(checkStarted);
1041​
1042 const channelFiber = yield* updates.setChannel("nightly").pipe(Effect.forkScoped);
1043 yield* Deferred.succeed(releaseCheck, undefined);
1044 yield* TestClock.adjust(Duration.seconds(2));
1045 const state = yield* Fiber.join(channelFiber);
1046​
1047 assert.equal(state.channel, "nightly");
1048 }),
1049 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1050 }),
1051 );
1052​
1053 it.effect("rejects checks while an update channel change is being persisted", () =>
1054 Effect.gen(function* () {
1055 const channelChangeStarted = yield* Deferred.make<void>();
1056 const releaseChannelChange = yield* Deferred.make<void>();
1057 const harness = makeHarness({
1058 beforeSetUpdateChannel: Deferred.succeed(channelChangeStarted, undefined).pipe(
1059 Effect.andThen(Deferred.await(releaseChannelChange)),
1060 ),
1061 });
1062​
1063 yield* Effect.scoped(
1064 Effect.gen(function* () {
1065 const updates = yield* DesktopUpdates.DesktopUpdates;
1066 yield* updates.configure;
1067​
1068 const channelFiber = yield* updates.setChannel("nightly").pipe(Effect.forkScoped);
1069 yield* Deferred.await(channelChangeStarted);
1070​
1071 const checkResult = yield* updates.check("manual");
1072 assert.isFalse(checkResult.checked);
1073 assert.equal(harness.checkCount(), 0);
1074​
1075 yield* Deferred.succeed(releaseChannelChange, undefined);
1076 const state = yield* Fiber.join(channelFiber);
1077​
1078 assert.equal(state.channel, "nightly");
1079 assert.equal(harness.checkCount(), 1);
1080 }),
1081 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1082 }),
1083 );
1084});
1085​
1086describe("describeUpdateErrorCause", () => {
1087 it("removes URLs, credentials, response bodies, and headers from summaries", () => {
1088 const messages = [
1089 "Cannot download https://user:url-secret@example.com/update?token=query-secret, status 403",
1090 "Request failed: Bearer bearer-secret",
1091 "Request failed: Basic basic-secret",
1092 "Request failed: Authorization: Bearer header-secret",
1093 "Request failed: Cookie=session-secret",
1094 "Request failed: api_key=\"key-secret\" password='password-secret' access_token=token-secret",
1095 '404 Not Found\n{"body":"body-secret"}\nHeaders: cookie=header-secret',
1096 "Request failed\rHeaders: cookie=header-secret",
1097 ];
1098​
1099 for (const message of messages) {
1100 const summary = DesktopUpdates.describeUpdateErrorCause(new Error(message));
1101 assert.include(summary, "Error:");
1102 assert.notInclude(summary, "secret");
1103 assert.notInclude(summary, "https://");
1104 assert.notInclude(summary, "Headers:");
1106 assert.equal(
1107 DesktopUpdates.describeUpdateErrorCause("404 Not Found\nbody-secret"),
1108 "404 Not Found",
1109 );
1110 });
1111​
1112 it("bounds long messages, parallel failures, and cyclic causes", () => {
1113 const longError = new Error("x".repeat(10_000));
1114 const parallel = Cause.combine(Cause.fail(longError), Cause.die(longError));
1115 assert.isAtMost(DesktopUpdates.describeUpdateErrorCause(parallel).length, 1024);
1116​
1117 const cyclic = new Error("retry failed");
1118 cyclic.cause = cyclic;
1119 assert.include(DesktopUpdates.describeUpdateErrorCause(cyclic), "[truncated cause]");
1120 assert.isAtMost(DesktopUpdates.describeUpdateErrorCause(cyclic).length, 1024);
1121 });
1122​
1123 it("does not serialize arbitrary payloads or let unreadable errors break logging", () => {
1124 assert.equal(DesktopUpdates.describeUpdateErrorCause({ payload: "secret" }), "object");
1125 const unreadable = Object.defineProperty({}, "message", {
1126 get() {
1127 throw new Error("unreadable error");
1128 },
1129 });
1130 assert.equal(DesktopUpdates.describeUpdateErrorCause(unreadable), "UnknownError");
1131 });
1132});
1133​
1134describe("DesktopUpdates under a managed policy", () => {
1135 const message = "Example Corp manages T3 Code updates.";
1136 const managed = (
1137 policy: Partial<DesktopUpdatePolicy.UpdatePolicy>,
1138 ): DesktopUpdatePolicy.UpdatePolicy => ({
1139 ...DesktopUpdatePolicy.unmanagedUpdatePolicy,
1140 message,
1141 ...policy,
1142 });
1143​
1144 it.effect("never checks when updates are off", () => {
1145 const harness = makeHarness({ policy: managed({ mode: "off" }) });
1146​
1147 return Effect.scoped(
1148 Effect.gen(function* () {
1149 const updates = yield* DesktopUpdates.DesktopUpdates;
1150 yield* updates.configure;
1151 yield* TestClock.adjust("10 minutes");
1152​
1153 const state = yield* updates.getState;
1154 assert.equal(state.status, "disabled");
1155 assert.equal(state.message, message);
1156 assert.isFalse((yield* updates.check("menu")).checked);
1157 assert.deepEqual(yield* updates.disabledReason, Option.some(message));
1158 assert.equal(harness.checkCount(), 0);
1159 assert.equal(harness.listenerCount(), 0);
1160 }),
1161 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1162 });
1163​
1164 it.effect("updates from the administrator's feed", () => {
1165 const harness = makeHarness({
1166 // Any user can set the mock flag; it must not redirect a managed feed.
1167 env: { T3CODE_DESKTOP_MOCK_UPDATES: "true" },
1168 policy: managed({ feedUrl: "https://updates.example.com/t3code" }),
1169 });
1170​
1171 return Effect.scoped(
1172 Effect.gen(function* () {
1173 const updates = yield* DesktopUpdates.DesktopUpdates;
1174 yield* updates.configure;
1175 assert.equal((yield* updates.getState).status, "idle");
1176 assert.deepEqual(harness.feedUrls(), [
1177 { provider: "generic", url: "https://updates.example.com/t3code" },
1178 ]);
1179 }),
1180 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1181 });
1182​
1183 it.effect("refuses the nightly channel without nightly", () => {
1184 const harness = makeHarness({ policy: managed({ allowNightly: false }) });
1185​
1186 return Effect.scoped(
1187 Effect.gen(function* () {
1188 const updates = yield* DesktopUpdates.DesktopUpdates;
1189 yield* updates.configure;
1190 const error = yield* updates.setChannel("nightly").pipe(Effect.flip);
1191 assert.equal(error._tag, "DesktopUpdateChannelManagedError");
1192 assert.equal((yield* updates.getState).channel, "latest");
1193 }),
1194 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1195 });
1196​
1197 it.effect("does not report the channel as the only block when updates are off anyway", () => {
1198 const harness = makeHarness({
1199 appVersion: "1.2.3-nightly.20261028.1",
1200 env: { T3CODE_DISABLE_AUTO_UPDATE: "true" },
1201 policy: managed({ allowNightly: false, feedUrl: "https://updates.example.com/t3code" }),
1202 });
1203​
1204 return Effect.scoped(
1205 Effect.gen(function* () {
1206 const updates = yield* DesktopUpdates.DesktopUpdates;
1207 yield* updates.configure;
1208 const state = yield* updates.getState;
1209 assert.isFalse(state.enabled);
1210 assert.isUndefined(state.channelBlockedByPolicy);
1211 }),
1212 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1213 });
1214​
1215 it.effect("holds a nightly install until its user switches to stable", () => {
1216 const harness = makeHarness({
1217 appVersion: "1.2.3-nightly.20261028.1",
1218 // A managed app ignores the mock feed, so give it a real one.
1219 policy: managed({ allowNightly: false, feedUrl: "https://updates.example.com/t3code" }),
1220 });
1221​
1222 return Effect.scoped(
1223 Effect.gen(function* () {
1224 const updates = yield* DesktopUpdates.DesktopUpdates;
1225 yield* updates.configure;
1226 yield* TestClock.adjust("10 minutes");
1227​
1228 const held = yield* updates.getState;
1229 assert.equal(held.channel, "nightly");
1230 assert.equal(held.status, "disabled");
1231 assert.include(held.message ?? "", message);
1232 assert.isTrue(held.channelBlockedByPolicy);
1233 assert.isFalse((yield* updates.check("menu")).checked);
1234 assert.equal(harness.checkCount(), 0);
1235​
1236 const stable = yield* updates.setChannel("latest");
1237 assert.equal(stable.channel, "latest");
1238 assert.isTrue(stable.enabled);
1239 assert.isUndefined(stable.channelBlockedByPolicy);
1240 assert.equal(harness.checkCount(), 1);
1241 }),
1242 ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
1243 });
1244});