@devries-cameron20 / t3code Mirror · read-only / commits / a26428f833
Fork 0

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 23, 03:00 UTC

fix(desktop): a failed macOS test capture no longer blames the GNOME extension (#18857)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

luke committed Oct 18, 2026 at 21:04 UTC a26428f8337d5e130113c8ced63b0a870d023765
2 files changed +161 -14
apps/desktop/src/snapShot/DesktopSnapShot.test.ts
+81
@@ -498,6 +498,7 @@ const layerTest = (
498 DesktopEnvironment.DesktopEnvironment,
499 DesktopEnvironment.DesktopEnvironment.of({
500 platform,
501 + displayName: "T3 Code (Dev)",
502 stateDir: "/state",
503 linuxDesktopEntryName: "com.t3tools.T3Code.desktop",
504 appRoot: "/repo",
@@ -3961,6 +3962,10 @@ it.effect.each([false, true])(
3962 if (fails) {
3963 const error = yield* service.setup("test-mac-capture").pipe(Effect.flip);
3964 assert.equal(error.reason, "setup-failed");
3965 + assert.equal(
3966 + error.message,
3967 + 'Could not capture a test snapshot. Capturing the window failed. macOS grants Screen Recording and Accessibility to each app separately. In System Settings, open Privacy & Security and check that "T3 Code (Dev)" is allowed for both.',
3968 + );
3969 } else yield* service.setup("test-mac-capture");
3970 assert.equal(macCaptureMock.mock.calls.length, 1);
3971 assert.equal(macCaptureMock.mock.calls[0]?.[0], active);
@@ -3985,12 +3990,88 @@ it.effect.each([false, true])(
3990 },
3991 );
3992
3993 +const macTestCaptureLayer = layerTest("darwin", {
3994 + makeTempDirectoryScoped: () => Effect.succeed("/tmp/setup-test"),
3995 + readDirectory: () => Effect.succeed([]),
3996 +});
3997 +const macTestCaptureWindow = {
3998 + platform: "macos",
3999 + id: 42,
4000 + title: "Setup",
4001 + owner: { name: "T3 Code", processId: 123, path: "/Applications/T3 Code.app" },
4002 + bounds: { x: 0, y: 0, width: 800, height: 600 },
4003 +};
4004 +
4005 +it.effect("names the failed macOS window lookup without repeating what it printed", () => {
4006 + const script = 'ObjC.import("CoreGraphics"); function run() { return ""; }';
4007 + const stderr = "execution error: Error: Not authorized to send Apple events. (-1743)";
4008 + activeWindowMock
4009 + .mockReset()
4010 + .mockRejectedValue(
4011 + Object.assign(
4012 + new Error(`Command failed: /usr/bin/osascript -l JavaScript -e ${script}\n${stderr}`),
4013 + { cmd: `/usr/bin/osascript -l JavaScript -e ${script}`, code: 1, killed: false },
4014 + ),
4015 + );
4016 + macCaptureMock.mockReset();
4017 + return Effect.scoped(
4018 + Effect.gen(function* () {
4019 + const service = yield* DesktopSnapShot.make;
4020 + const error = yield* service.setup("test-mac-capture").pipe(Effect.flip);
4021 + assert.equal(
4022 + error.message,
4023 + 'Could not capture a test snapshot. Finding the front window failed: osascript exited with code 1. macOS grants Screen Recording and Accessibility to each app separately. In System Settings, open Privacy & Security and check that "T3 Code (Dev)" is allowed for both.',
4024 + );
4025 + assert.include(String(error.cause), stderr);
4026 + assert.equal(macCaptureMock.mock.calls.length, 0);
4027 + }),
4028 + ).pipe(Effect.provide(macTestCaptureLayer));
4029 +});
4030 +
4031 +it.effect("says when macOS has no window to test capture", () => {
4032 + activeWindowMock.mockReset().mockResolvedValue(undefined);
4033 + macCaptureMock.mockReset();
4034 + return Effect.scoped(
4035 + Effect.gen(function* () {
4036 + const service = yield* DesktopSnapShot.make;
4037 + const error = yield* service.setup("test-mac-capture").pipe(Effect.flip);
4038 + assert.equal(
4039 + error.message,
4040 + "Could not capture a test snapshot. No window is available to capture.",
4041 + );
4042 + assert.equal(macCaptureMock.mock.calls.length, 0);
4043 + }),
4044 + ).pipe(Effect.provide(macTestCaptureLayer));
4045 +});
4046 +
4047 +it.effect("says when the macOS test capture command timed out", () => {
4048 + activeWindowMock.mockReset().mockResolvedValue(macTestCaptureWindow);
4049 + macCaptureMock.mockReset().mockRejectedValue(
4050 + Object.assign(new Error("Command failed: /usr/sbin/screencapture -l 42 -o -x"), {
4051 + code: null,
4052 + killed: true,
4053 + signal: "SIGTERM",
4054 + }),
4055 + );
4056 + return Effect.scoped(
4057 + Effect.gen(function* () {
4058 + const service = yield* DesktopSnapShot.make;
4059 + const error = yield* service.setup("test-mac-capture").pipe(Effect.flip);
4060 + assert.equal(
4061 + error.message,
4062 + 'Could not capture a test snapshot. Capturing the window timed out. macOS grants Screen Recording and Accessibility to each app separately. In System Settings, open Privacy & Security and check that "T3 Code (Dev)" is allowed for both.',
4063 + );
4064 + }),
4065 + ).pipe(Effect.provide(macTestCaptureLayer));
4066 +});
4067 +
4068 it.effect("rejects macOS test capture on other platforms", () =>
4069 Effect.scoped(
4070 Effect.gen(function* () {
4071 const service = yield* DesktopSnapShot.make;
4072 const error = yield* service.setup("test-mac-capture").pipe(Effect.flip);
4073 assert.equal(error.reason, "unsupported-session");
4074 + assert.equal(error.message, "Test capture requires macOS.");
4075 }),
4076 ).pipe(Effect.provide(layerTest("win32"))),
4077 );
apps/desktop/src/snapShot/DesktopSnapShot.ts
+80 -14
@@ -30,6 +30,7 @@ import * as FileSystem from "effect/FileSystem";
30 import * as Layer from "effect/Layer";
31 import * as Option from "effect/Option";
32 import * as Path from "effect/Path";
33 +import * as Predicate from "effect/Predicate";
34 import * as Ref from "effect/Ref";
35 import * as Schema from "effect/Schema";
36 import * as Semaphore from "effect/Semaphore";
@@ -210,10 +211,36 @@ export class DesktopSnapShotSetupError extends Schema.TaggedError<DesktopSnapSho
211 Schema.Literals(["preview-config", "apply-config"]),
212 ]),
213 reason: Schema.Literals(["unsupported-session", "setup-failed", "shortcut-permissions"]),
214 + /** The part of the macOS test capture that failed, and how. */
215 + step: Schema.optional(Schema.Literals(["find-window", "capture-window"])),
216 + status: Schema.optional(Schema.Literals(["missing", "timed-out", "exited", "failed"])),
217 + exitCode: Schema.optional(Schema.Number),
218 + /** The running app, as macOS lists it under Privacy & Security. */
219 + appName: Schema.optional(Schema.String),
220 cause: Schema.optional(Schema.Defect()),
221 },
222 ) {
223 override get message(): string {
224 + if (this.action === "test-mac-capture") {
225 + if (this.reason === "unsupported-session") return "Test capture requires macOS.";
226 + const summary = "Could not capture a test snapshot.";
227 + if (this.step === undefined) return summary;
228 + if (this.status === "missing") return `${summary} No window is available to capture.`;
229 + const [task, command] =
230 + this.step === "find-window"
231 + ? ["Finding the front window", "osascript"]
232 + : ["Capturing the window", "screencapture"];
233 + const failure =
234 + this.status === "timed-out"
235 + ? `${task} timed out.`
236 + : this.status === "exited" && this.exitCode !== undefined
237 + ? `${task} failed: ${command} exited with code ${this.exitCode}.`
238 + : `${task} failed.`;
239 + // macOS can report both permissions as allowed while they belong to another install.
240 + return this.appName === undefined
241 + ? `${summary} ${failure}`
242 + : `${summary} ${failure} macOS grants Screen Recording and Accessibility to each app separately. In System Settings, open Privacy & Security and check that "${this.appName}" is allowed for both.`;
243 + }
244 if (this.action === "preview-config" || this.action === "apply-config") {
245 if (this.reason === "unsupported-session")
246 return "Config setup requires a Niri or Hyprland session.";
@@ -239,6 +266,18 @@ export class DesktopSnapShotSetupError extends Schema.TaggedError<DesktopSnapSho
266 }
267 }
268
269 +/**
270 + * How a macOS capture command ended, read from the child process error's own fields.
271 + * What the command printed stays in the error's `cause`.
272 + */
273 +function macCommandFailure(cause: unknown) {
274 + const failure = Predicate.isObject(cause) ? cause : {};
275 + if ("killed" in failure && failure.killed === true) return { status: "timed-out" } as const;
276 + return "code" in failure && typeof failure.code === "number"
277 + ? ({ status: "exited", exitCode: failure.code } as const)
278 + : ({ status: "failed" } as const);
279 +}
280 +
281 type SnapShotSystemAnimationSettings = Pick<
282 ReturnType<typeof Electron.systemPreferences.getAnimationSettings>,
283 "prefersReducedMotion" | "shouldRenderRichAnimation"
@@ -1327,23 +1366,50 @@ export const make = Effect.gen(function* () {
1366 return yield* new DesktopSnapShotSetupError({ action, reason: "unsupported-session" });
1367 yield* Effect.scoped(
1368 Effect.gen(function* () {
1330 - const directory = yield* fileSystem.makeTempDirectoryScoped({
1331 - prefix: "t3-snapshot-test-",
1332 - });
1333 - yield* Effect.tryPromise(async () => {
1334 - const active = await activeWindow("darwin");
1335 - if (!active) throw new Error("No window is available to test capture.");
1336 - await captureMacWindowSnapshot(
1337 - active,
1338 - path.join(directory, "test.png"),
1339 - snapShotThumbnailSize(active),
1369 + const directory = yield* fileSystem
1370 + .makeTempDirectoryScoped({ prefix: "t3-snapshot-test-" })
1371 + .pipe(
1372 + Effect.mapError(
1373 + (cause) => new DesktopSnapShotSetupError({ action, reason: "setup-failed", cause }),
1374 + ),
1375 );
1376 + const active = yield* Effect.tryPromise({
1377 + try: () => activeWindow("darwin"),
1378 + catch: (cause) =>
1379 + new DesktopSnapShotSetupError({
1380 + action,
1381 + reason: "setup-failed",
1382 + step: "find-window",
1383 + ...macCommandFailure(cause),
1384 + appName: environment.displayName,
1385 + cause,
1386 + }),
1387 + });
1388 + if (!active)
1389 + return yield* new DesktopSnapShotSetupError({
1390 + action,
1391 + reason: "setup-failed",
1392 + step: "find-window",
1393 + status: "missing",
1394 + });
1395 + yield* Effect.tryPromise({
1396 + try: () =>
1397 + captureMacWindowSnapshot(
1398 + active,
1399 + path.join(directory, "test.png"),
1400 + snapShotThumbnailSize(active),
1401 + ),
1402 + catch: (cause) =>
1403 + new DesktopSnapShotSetupError({
1404 + action,
1405 + reason: "setup-failed",
1406 + step: "capture-window",
1407 + ...macCommandFailure(cause),
1408 + appName: environment.displayName,
1409 + cause,
1410 + }),
1411 });
1412 }),
1343 - ).pipe(
1344 - Effect.mapError(
1345 - (cause) => new DesktopSnapShotSetupError({ action, reason: "setup-failed", cause }),
1346 - ),
1413 );
1414 return;
1415 } else if (action === "install-kde-helper" || action === "remove-kde-helper") {