The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
fix(desktop): retry a timed-out Windows update signature check once (#21273)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor Vogel committed
Oct 19, 2026 at 23:55 UTC
369826946a4271f3ba3aa447ce37a7cd2f3fb8d4
2 files changed
+125
apps/desktop/src/electron/ElectronUpdater.test.ts
+84
@@ -1,5 +1,6 @@
1
import { assert, describe, it } from "@effect/vitest";
2
import * as Effect from "effect/Effect";
3
+import type { VerifyUpdateCodeSignature } from "electron-updater";
4
import { beforeEach, vi } from "vite-plus/test";
5
6
const { autoUpdaterMock } = vi.hoisted(() => ({
@@ -13,6 +14,8 @@ const { autoUpdaterMock } = vi.hoisted(() => ({
14
fullChangelog: false,
15
checkForUpdates: vi.fn(() => Promise.resolve(null)),
16
downloadUpdate: vi.fn(() => Promise.resolve([])),
17
+ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
18
+ verifyUpdateCodeSignature: undefined as VerifyUpdateCodeSignature | undefined,
19
on: vi.fn(),
20
quitAndInstall: vi.fn(),
21
removeListener: vi.fn(),
@@ -43,6 +46,7 @@ describe("ElectronUpdater", () => {
46
autoUpdaterMock.quitAndInstall.mockClear();
47
autoUpdaterMock.removeListener.mockClear();
48
autoUpdaterMock.setFeedURL.mockClear();
49
+ autoUpdaterMock.verifyUpdateCodeSignature = undefined;
50
});
51
52
it.effect("scopes updater event listeners", () =>
@@ -136,4 +140,84 @@ describe("ElectronUpdater", () => {
140
assert.deepEqual(autoUpdaterMock.quitAndInstall.mock.calls, [[true, false]]);
141
}).pipe(Effect.provide(ElectronUpdater.layer)),
142
);
143
+
144
+ describe("Windows update signature check", () => {
145
+ const publisherNames = ["T3 Tools Inc"];
146
+ const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe";
147
+ // execFile marks the error killed when the verifier exceeds its 20-second timeout.
148
+ const timedOut = () =>
149
+ Object.assign(new Error("Command failed: powershell.exe"), { killed: true });
150
+
151
+ const downloadVerifyingSignature = () => {
152
+ autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => {
153
+ const rejection = await autoUpdaterMock.verifyUpdateCodeSignature!(
154
+ publisherNames,
155
+ installerPath,
156
+ );
157
+ // NSIS accepts only null as a successful signature check.
158
+ if (rejection !== null) throw new Error(`Invalid signature: ${rejection}`);
159
+ return [];
160
+ });
161
+ return Effect.flatMap(ElectronUpdater.ElectronUpdater, (updater) => updater.downloadUpdate);
162
+ };
163
+
164
+ it.effect("retries a timed-out signature check with the same verifier and installer", () =>
165
+ Effect.gen(function* () {
166
+ const verify = vi
167
+ .fn<VerifyUpdateCodeSignature>()
168
+ .mockRejectedValueOnce(timedOut())
169
+ .mockResolvedValueOnce(null);
170
+ autoUpdaterMock.verifyUpdateCodeSignature = verify;
171
+
172
+ yield* downloadVerifyingSignature();
173
+
174
+ assert.deepEqual(verify.mock.calls, [
175
+ [publisherNames, installerPath],
176
+ [publisherNames, installerPath],
177
+ ]);
178
+ }).pipe(Effect.provide(ElectronUpdater.layer)),
179
+ );
180
+
181
+ it.effect("fails on invalid signatures, other errors and two timeouts on each download", () =>
182
+ Effect.gen(function* () {
183
+ const cases = [
184
+ { outcome: () => Promise.resolve("Invalid publisher"), calls: 1 },
185
+ { outcome: () => Promise.reject(new Error("Cannot execute PowerShell")), calls: 1 },
186
+ { outcome: () => Promise.reject(timedOut()), calls: 2 },
187
+ ];
188
+ for (const { outcome, calls } of cases) {
189
+ const verify = vi.fn<VerifyUpdateCodeSignature>(outcome);
190
+ autoUpdaterMock.verifyUpdateCodeSignature = verify;
191
+
192
+ // Reusing the installed verifier must neither stack retries nor exhaust future retries.
193
+ for (let download = 1; download <= 2; download++) {
194
+ const error = yield* downloadVerifyingSignature().pipe(Effect.flip);
195
+ assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError);
196
+ assert.equal(verify.mock.calls.length, calls * download);
197
+ }
198
+ }
199
+ }).pipe(Effect.provide(ElectronUpdater.layer)),
200
+ );
201
+
202
+ it.effect("rejects a retry when the upstream capability probe skips verification", () =>
203
+ Effect.gen(function* () {
204
+ const verify = vi
205
+ .fn<VerifyUpdateCodeSignature>()
206
+ .mockRejectedValueOnce(timedOut())
207
+ .mockImplementationOnce(async () => {
208
+ // Upstream resolves null even though its failed capability probe skips verification.
209
+ autoUpdaterMock.logger.warn(
210
+ "Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.",
211
+ );
212
+ return null;
213
+ });
214
+ autoUpdaterMock.verifyUpdateCodeSignature = verify;
215
+
216
+ const error = yield* downloadVerifyingSignature().pipe(Effect.flip);
217
+
218
+ assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError);
219
+ assert.equal(verify.mock.calls.length, 2);
220
+ }).pipe(Effect.provide(ElectronUpdater.layer)),
221
+ );
222
+ });
223
});
apps/desktop/src/electron/ElectronUpdater.ts
+41
@@ -5,6 +5,7 @@ import * as Schema from "effect/Schema";
5
import * as Scope from "effect/Scope";
6
7
import { autoUpdater } from "electron-updater";
8
+import type { NsisUpdater, VerifyUpdateCodeSignature } from "electron-updater";
9
10
type AutoUpdater = typeof autoUpdater;
11
@@ -80,6 +81,45 @@ export class ElectronUpdater extends Context.Service<
81
}
82
>()("@t3tools/desktop/electron/ElectronUpdater") {}
83
84
+const signatureChecksWithRetry = new WeakSet<VerifyUpdateCodeSignature>();
85
+
86
+const retrySignatureCheckAfterTimeout = () => {
87
+ // Only the Windows NSIS updater exposes this hook; its PowerShell check times out after 20 s.
88
+ const updater = autoUpdater as AutoUpdater &
89
+ Partial<Pick<NsisUpdater, "verifyUpdateCodeSignature">>;
90
+ const verify = updater.verifyUpdateCodeSignature;
91
+ if (verify === undefined || signatureChecksWithRetry.has(verify)) return;
92
+
93
+ const verifyWithRetry: VerifyUpdateCodeSignature = async (publisherNames, path) => {
94
+ try {
95
+ return await verify(publisherNames, path);
96
+ } catch (error) {
97
+ if (!(error instanceof Error && "killed" in error && error.killed === true)) throw error;
98
+ }
99
+
100
+ const logger = updater.logger;
101
+ let skipped = false;
102
+ updater.logger = {
103
+ info: (message) => logger?.info(message),
104
+ warn: (message) => {
105
+ // A failed capability probe makes electron-updater warn and return null without checking.
106
+ skipped ||= String(message).includes("Ignoring signature validation");
107
+ logger?.warn(message);
108
+ },
109
+ error: (message) => logger?.error(message),
110
+ debug: (message) => logger?.debug?.(message),
111
+ };
112
+ try {
113
+ const result = await verify(publisherNames, path);
114
+ return skipped ? "Signature validation was skipped after a timed-out check." : result;
115
+ } finally {
116
+ updater.logger = logger;
117
+ }
118
+ };
119
+ signatureChecksWithRetry.add(verifyWithRetry);
120
+ updater.verifyUpdateCodeSignature = verifyWithRetry;
121
+};
122
+
123
/** @public Service construction is part of the canonical Effect module API. */
124
export const make = ElectronUpdater.of({
125
setFeedURL: (options) =>
@@ -131,6 +171,7 @@ export const make = ElectronUpdater.of({
171
}).pipe(Effect.asVoid);
172
}),
173
downloadUpdate: Effect.suspend(() => {
174
+ retrySignatureCheckAfterTimeout();
175
const channel = autoUpdater.channel;
176
return Effect.tryPromise({
177
try: () => autoUpdater.downloadUpdate(),