test(desktop): stabilize updater preference test against slow-disk race

The "skips startup and periodic checks when automatic updates are
disabled" case advanced fake timers without awaiting the async
preference load. On slow CI the in-flight readFile resolved after
afterEach() removed the temp dir, defaulted enabled back to true, and
fired a deferred background check into the next test's freshly-cleared
shared mock — making "persists the automatic update preference and stops
future background checks" flake with checkForUpdates called once.

Await updater:get-preferences (which awaits preferencesReady) before
advancing timers so the read settles against the existing file and no
background work outlives the test. Test-only change; production behavior
is unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
Naiyuan Qing
2026-07-14 16:56:13 +08:00
parent 2d13b26fcc
commit 49a49f837a

View File

@@ -160,6 +160,12 @@ describe("setupAutoUpdater", () => {
);
setupAutoUpdater(() => null);
// Let the async preference load settle before advancing timers; otherwise
// the in-flight readFile can resolve after afterEach() removes the temp
// dir, default back to enabled=true, and fire a background check into the
// next test's freshly-cleared mock (flake on slow CI).
await invokeIpc("updater:get-preferences");
await vi.advanceTimersByTimeAsync(60 * 60 * 1000 + 5_000);
expect(ctx.checkForUpdates).not.toHaveBeenCalled();