@devries-cameron20 / t3code Mirror · read-only / commits / 1152e9171a
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 22, 14:30 UTC

fix(desktop): run the packaged bundle self-check on macOS artifacts (#25900)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Theo Browne <me@theo.li>

Stephen Benjamin committed Oct 27, 2026 at 07:38 UTC 1152e9171a9ce6ede20e0cc1f16ed0dbe103da9b
2 files changed +115 -1
scripts/build-desktop-artifact.test.ts
+75 -1
@@ -3,7 +3,7 @@ import * as NodeCrypto from "node:crypto";
3 import * as NodePath from "node:path";
4
5 import * as NodeServices from "@effect/platform-node/NodeServices";
6 -import { extractFile } from "@electron/asar";
6 +import { createPackageWithOptions, extractFile } from "@electron/asar";
7 import { assert, it } from "@effect/vitest";
8 import * as ConfigProvider from "effect/ConfigProvider";
9 import * as Deferred from "effect/Deferred";
@@ -45,7 +45,9 @@ import {
45 ancestorNodeModulesPaths,
46 copyDirectoryPreservingSymlinks,
47 LinuxBrowserSecretHostError,
48 + MacPackagedAppMissingError,
49 stageBrowserSecret,
50 + validateMacPackagedPayload,
51 validateWindowsPackagedPayload,
52 verifyPackagedBundleIsSelfContained,
53 WindowsPrimaryNativeProbeError,
@@ -211,6 +213,26 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
213 } as const;
214 });
215
216 +const makeMacPayloadFixture = Effect.fn("test.makeMacPayloadFixture")(function* (input: {
217 + readonly serverEntrySource?: string;
218 +}) {
219 + const fs = yield* FileSystem.FileSystem;
220 + const path = yield* Path.Path;
221 + const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-mac-payload-test-" });
222 + const sourceDir = path.join(tempDir, "app-source");
223 + const serverEntryPath = path.join(sourceDir, "apps/server/dist/bin.mjs");
224 + yield* fs.makeDirectory(path.dirname(serverEntryPath), { recursive: true });
225 + yield* fs.writeFileString(serverEntryPath, input.serverEntrySource ?? "console.log('server');\n");
226 +
227 + const stageDistDir = path.join(tempDir, "dist");
228 + const resourcesDir = path.join(stageDistDir, "mac-arm64/T3 Code.app/Contents/Resources");
229 + yield* fs.makeDirectory(resourcesDir, { recursive: true });
230 + yield* Effect.promise(() =>
231 + createPackageWithOptions(sourceDir, path.join(resourcesDir, "app.asar"), {}),
232 + );
233 + return { stageDistDir } as const;
234 +});
235 +
236 it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
237 it.effect("rejects overlapping builds from another process until restoration finishes", () =>
238 Effect.gen(function* () {
@@ -1283,6 +1305,58 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
1305 ),
1306 );
1307
1308 + it.effect("rejects a macOS app whose packaged server bundle cannot resolve", () =>
1309 + Effect.scoped(
1310 + Effect.gen(function* () {
1311 + const fixture = yield* makeMacPayloadFixture({
1312 + serverEntrySource: 'import "t3code-deliberately-missing-package";\n',
1313 + });
1314 + const error = yield* validateMacPackagedPayload({
1315 + stageDistDir: fixture.stageDistDir,
1316 + }).pipe(Effect.flip);
1317 +
1318 + assert.instanceOf(error, BundleNotSelfContainedError);
1319 + assert.include(error.output, "t3code-deliberately-missing-package");
1320 + }),
1321 + ),
1322 + );
1323 +
1324 + it.effect("accepts a macOS app whose packaged server bundle resolves", () =>
1325 + Effect.scoped(
1326 + Effect.gen(function* () {
1327 + const fixture = yield* makeMacPayloadFixture({});
1328 + yield* validateMacPackagedPayload({ stageDistDir: fixture.stageDistDir });
1329 + }),
1330 + ),
1331 + );
1332 +
1333 + it.effect("rejects a macOS stage without a packaged app", () =>
1334 + Effect.scoped(
1335 + Effect.gen(function* () {
1336 + const fs = yield* FileSystem.FileSystem;
1337 + const stageDistDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-mac-payload-test-" });
1338 + const error = yield* validateMacPackagedPayload({ stageDistDir }).pipe(Effect.flip);
1339 +
1340 + assert.instanceOf(error, MacPackagedAppMissingError);
1341 + }),
1342 + ),
1343 + );
1344 +
1345 + it.effect("rejects a macOS app without app.asar", () =>
1346 + Effect.scoped(
1347 + Effect.gen(function* () {
1348 + const fs = yield* FileSystem.FileSystem;
1349 + const stageDistDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-mac-payload-test-" });
1350 + yield* fs.makeDirectory(`${stageDistDir}/mac-arm64/T3 Code.app/Contents/Resources`, {
1351 + recursive: true,
1352 + });
1353 + const error = yield* validateMacPackagedPayload({ stageDistDir }).pipe(Effect.flip);
1354 +
1355 + assert.instanceOf(error, BundleNotSelfContainedError);
1356 + }),
1357 + ),
1358 + );
1359 +
1360 it.effect("leaves the bundle self-check of a cross-built payload to the verify job", () =>
1361 Effect.scoped(
1362 Effect.gen(function* () {
scripts/build-desktop-artifact.ts
+40
@@ -3521,6 +3521,42 @@ export const validateWindowsPackagedPayload = Effect.fn(
3521 return { packagedAppDir, fileCount, unpackedFiles } as const;
3522 });
3523
3524 +export class MacPackagedAppMissingError extends Schema.TaggedError<MacPackagedAppMissingError>()(
3525 + "MacPackagedAppMissingError",
3526 + { stageDistDir: Schema.String },
3527 +) {
3528 + override get message(): string {
3529 + return `Expected electron-builder to leave a packaged .app with Contents/Resources/app.asar under ${this.stageDistDir}/mac*.`;
3530 + }
3531 +}
3532 +
3533 +export const validateMacPackagedPayload = Effect.fn("desktopArtifact.validateMacPackagedPayload")(
3534 + function* (input: { readonly stageDistDir: string; readonly verbose?: boolean }) {
3535 + const fs = yield* FileSystem.FileSystem;
3536 + const path = yield* Path.Path;
3537 + const asarPaths: string[] = [];
3538 + for (const entry of yield* fs.readDirectory(input.stageDistDir)) {
3539 + if (!entry.startsWith("mac")) continue;
3540 + const outputDir = path.join(input.stageDistDir, entry);
3541 + const apps = yield* fs.readDirectory(outputDir).pipe(Effect.orElseSucceed(() => []));
3542 + for (const app of apps) {
3543 + if (app.endsWith(".app")) {
3544 + asarPaths.push(path.join(outputDir, app, "Contents/Resources/app.asar"));
3545 + }
3546 + }
3547 + }
3548 + if (asarPaths.length === 0) {
3549 + return yield* new MacPackagedAppMissingError({ stageDistDir: input.stageDistDir });
3550 + }
3551 + for (const asarPath of asarPaths) {
3552 + yield* verifyPackagedBundleIsSelfContained({ asarPath, verbose: input.verbose ?? false });
3553 + }
3554 + yield* Effect.log(
3555 + `[desktop-artifact] Validated macOS payload (${String(asarPaths.length)} app bundle(s)).`,
3556 + );
3557 + },
3558 +);
3559 +
3560 const buildDesktopArtifactUnlocked = Effect.fn("buildDesktopArtifactUnlocked")(function* (
3561 options: ResolvedBuildOptions,
3562 ) {
@@ -4016,6 +4052,10 @@ const buildDesktopArtifactUnlocked = Effect.fn("buildDesktopArtifactUnlocked")(f
4052 verbose: options.verbose,
4053 });
4054 }
4055 + // x64 builds on arm64 runners; the arm64 check covers the shared JS bundle.
4056 + if (options.platform === "mac" && options.arch === "arm64" && hostPlatform === "darwin") {
4057 + yield* validateMacPackagedPayload({ stageDistDir, verbose: options.verbose });
4058 + }
4059
4060 const stageEntries = yield* fs.readDirectory(stageDistDir);
4061 yield* fs.makeDirectory(options.outputDir, { recursive: true });