Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as ConfigProvider from "effect/ConfigProvider";
4import * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6import * as Option from "effect/Option";
7import * as Sink from "effect/Sink";
8import * as Stream from "effect/Stream";
9import { ChildProcessSpawner } from "effect/unstable/process";
10
11import {
12 BuildCommandFailedError,
13 createStageWorkspaceConfig,
14 createStagePatchedDependencies,
15 createBuildConfig,
16 DEB_DEPENDENCIES,
17 DESKTOP_ELECTRON_LANGUAGES,
18 DESKTOP_FILE_EXCLUSIONS,
19 DESKTOP_EXTRA_RESOURCES,
20 DESKTOP_LINUX_MAINTAINER,
21 InvalidMacPasskeyRpDomainError,
22 InvalidMacPasskeyPublishableKeyError,
23 InvalidMockUpdateServerPortError,
24 UnsupportedDesktopBuildArchitectureError,
25 isMacPasskeySigningConfigurationError,
26 LinuxIconResizeError,
27 MacPasskeySigningConfigurationResolutionError,
28 MissingMacPasskeyProvisioningProfileError,
29 renderMacPasskeyEntitlements,
30 resolveClerkPasskeyNativeArtifacts,
31 resolveMacPasskeySigningConfiguration,
32 resolveDesktopRuntimeDependencies,
33 resolveFffNativeDependencies,
34 resolveBuildOptions,
35 resolveDesktopBuildIconAssets,
36 resolveDesktopProductName,
37 resolveDesktopUpdateChannel,
38 resolveDesktopWebAssetBrand,
39 resolveLinuxTargets,
40 resolveResourceMonitorRustTargets,
41 RPM_DEPENDENCIES,
42 resourceMonitorExecutableName,
43 resolveGitHubPublishConfig,
44 resolveMockUpdateServerPort,
45 resolveMockUpdateServerUrl,
46 resolvePackageManagerUserAgent,
47 stageLinuxIconSize,
48 STAGE_INSTALL_ARGS,
49 WINDOWS_ASAR_UNPACK,
50} from "./build-desktop-artifact.ts";
51import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
52import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
53
54function mockProcess(exitCode: number) {
55 return ChildProcessSpawner.makeHandle({
56 pid: ChildProcessSpawner.ProcessId(1),
57 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
58 isRunning: Effect.succeed(false),
59 kill: () => Effect.void,
60 unref: Effect.succeed(Effect.void),
61 stdin: Sink.drain,
62 stdout: Stream.empty,
63 stderr: Stream.empty,
64 all: Stream.empty,
65 getInputFd: () => Sink.drain,
66 getOutputFd: () => Stream.empty,
67 });
68}
69
70function iconResizeSpawnerLayer(
71 commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>,
72 exitCodes: ReadonlyArray<number>,
73) {
74 let commandIndex = 0;
75 return Layer.succeed(
76 ChildProcessSpawner.ChildProcessSpawner,
77 ChildProcessSpawner.make((command) => {
78 const childProcess = command as unknown as {
79 readonly command: string;
80 readonly args: ReadonlyArray<string>;
81 };
82 commands.push({
83 command: childProcess.command,
84 args: childProcess.args,
85 });
86 return Effect.succeed(mockProcess(exitCodes[commandIndex++] ?? 0));
87 }),
88 );
89}
90
91it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
92 it("resolves the dedicated nightly updater channel from nightly versions", () => {
93 assert.equal(resolveDesktopUpdateChannel("0.0.17-nightly.20260413.42"), "nightly");
94 assert.equal(resolveDesktopUpdateChannel("0.0.17"), "latest");
95 });
96
97 it("switches desktop packaging product names to nightly for nightly builds", () => {
98 assert.equal(resolveDesktopProductName("0.0.17"), "T3 Code (Alpha)");
99 assert.equal(resolveDesktopProductName("0.0.17-nightly.20260413.42"), "T3 Code (Nightly)");
100 });
101
102 it("switches desktop packaging icons to the nightly artwork for nightly versions", () => {
103 assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17"), {
104 macIconPng: BRAND_ASSET_PATHS.productionMacIconPng,
105 linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng,
106 windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco,
107 });
108
109 assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17-nightly.20260413.42"), {
110 macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng,
111 linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng,
112 windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco,
113 });
114 });
115
116 it("switches the bundled splash and favicon branding for nightly versions", () => {
117 assert.equal(resolveDesktopWebAssetBrand("0.0.17"), "production");
118 assert.equal(resolveDesktopWebAssetBrand("0.0.17-nightly.20260413.42"), "nightly");
119 });
120
121 it.effect("resolves GitHub desktop publish config from Effect config", () =>
122 Effect.gen(function* () {
123 const latestConfig = yield* resolveGitHubPublishConfig("latest").pipe(
124 Effect.provide(
125 ConfigProvider.layer(
126 ConfigProvider.fromEnv({
127 env: {
128 T3CODE_DESKTOP_UPDATE_REPOSITORY: "pingdotgg/t3code",
129 },
130 }),
131 ),
132 ),
133 );
134 const nightlyConfig = yield* resolveGitHubPublishConfig("nightly").pipe(
135 Effect.provide(
136 ConfigProvider.layer(
137 ConfigProvider.fromEnv({
138 env: {
139 GITHUB_REPOSITORY: "pingdotgg/t3code",
140 },
141 }),
142 ),
143 ),
144 );
145
146 assert.deepStrictEqual(latestConfig, {
147 provider: "github",
148 owner: "pingdotgg",
149 repo: "t3code",
150 releaseType: "release",
151 });
152 assert.deepStrictEqual(nightlyConfig, {
153 provider: "github",
154 owner: "pingdotgg",
155 repo: "t3code",
156 releaseType: "prerelease",
157 channel: "nightly",
158 });
159 }),
160 );
161
162 it("omits bundled workspace packages from staged desktop dependencies", () => {
163 assert.deepStrictEqual(
164 resolveDesktopRuntimeDependencies(
165 {
166 "@effect/platform-node": "catalog:",
167 "@t3tools/contracts": "workspace:*",
168 "@t3tools/shared": "workspace:*",
169 "@t3tools/ssh": "workspace:*",
170 "@t3tools/tailscale": "workspace:*",
171 effect: "catalog:",
172 electron: "41.5.0",
173 },
174 {
175 "@effect/platform-node": "4.0.0-beta.59",
176 effect: "4.0.0-beta.59",
177 },
178 ),
179 {
180 "@effect/platform-node": "4.0.0-beta.59",
181 effect: "4.0.0-beta.59",
182 },
183 );
184 });
185
186 it("carries only staged dependency patch metadata into staged desktop installs", () => {
187 assert.deepStrictEqual(
188 createStagePatchedDependencies(
189 {
190 "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch",
191 "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
192 "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
193 "alchemy@2.0.0-beta.49": "patches/alchemy@2.0.0-beta.49.patch",
194 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
195 },
196 {
197 "@ff-labs/fff-node": "0.9.4",
198 "@pierre/diffs": "1.1.20",
199 effect: "4.0.0-beta.73",
200 },
201 ),
202 {
203 "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
204 "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
205 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
206 },
207 );
208
209 assert.deepStrictEqual(
210 createStagePatchedDependencies(
211 {
212 "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch",
213 },
214 { effect: "4.0.0-beta.73" },
215 ),
216 {},
217 );
218 });
219
220 it("installs optional native dependencies for the target desktop architecture", () => {
221 assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]);
222 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "x64" }), {
223 supportedArchitectures: {
224 os: ["darwin"],
225 cpu: ["x64"],
226 },
227 });
228 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "linux", arch: "x64" }), {
229 supportedArchitectures: {
230 os: ["linux"],
231 cpu: ["x64"],
232 libc: ["glibc"],
233 },
234 });
235 // Windows artifacts also bundle the same-architecture WSL (Linux, glibc) backend, so the
236 // staged install must fetch its native optional deps (e.g. ffi-rs) too.
237 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "x64" }), {
238 supportedArchitectures: {
239 os: ["win32", "linux"],
240 cpu: ["x64"],
241 libc: ["glibc"],
242 },
243 });
244 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "arm64" }), {
245 supportedArchitectures: {
246 os: ["win32", "linux"],
247 cpu: ["arm64"],
248 libc: ["glibc"],
249 },
250 });
251 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), {
252 supportedArchitectures: {
253 os: ["darwin"],
254 cpu: ["arm64", "x64"],
255 },
256 });
257 });
258
259 it("stages pnpm 11 allowBuilds and patchedDependencies in the workspace yaml", () => {
260 assert.deepStrictEqual(
261 createStageWorkspaceConfig({
262 platform: "linux",
263 arch: "x64",
264 allowBuilds: {
265 electron: true,
266 "node-pty": true,
267 "browser-tabs-lock": false,
268 },
269 patchedDependencies: {
270 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
271 },
272 overrides: {
273 effect: "4.0.0-beta.73",
274 },
275 }),
276 {
277 supportedArchitectures: {
278 os: ["linux"],
279 cpu: ["x64"],
280 libc: ["glibc"],
281 },
282 allowBuilds: {
283 electron: true,
284 "node-pty": true,
285 "browser-tabs-lock": false,
286 },
287 patchedDependencies: {
288 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
289 },
290 overrides: {
291 effect: "4.0.0-beta.73",
292 },
293 },
294 );
295
296 // Empty maps must not be written — pnpm would still require reviewed
297 // packages if allowBuilds is present but incomplete, and omitting empty
298 // patchedDependencies keeps the stage yaml minimal.
299 assert.deepStrictEqual(
300 createStageWorkspaceConfig({
301 platform: "mac",
302 arch: "arm64",
303 allowBuilds: {},
304 patchedDependencies: {},
305 overrides: {},
306 }),
307 {
308 supportedArchitectures: {
309 os: ["darwin"],
310 cpu: ["arm64"],
311 },
312 },
313 );
314 });
315
316 it("limits Electron locales and excludes the unused Claude SDK executable", () => {
317 assert.deepStrictEqual(DESKTOP_ELECTRON_LANGUAGES, ["en-US"]);
318 assert.deepStrictEqual(DESKTOP_FILE_EXCLUSIONS, [
319 "!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*",
320 ]);
321 });
322
323 it.effect("applies platform-specific packaging to the build config", () =>
324 Effect.gen(function* () {
325 const mac = yield* createBuildConfig(
326 "mac",
327 "dmg",
328 "1.2.3",
329 false,
330 false,
331 undefined,
332 undefined,
333 );
334 const linux = yield* createBuildConfig(
335 "linux",
336 "AppImage",
337 "1.2.3",
338 false,
339 false,
340 undefined,
341 undefined,
342 );
343 const win = yield* createBuildConfig(
344 "win",
345 "nsis",
346 "1.2.3",
347 false,
348 false,
349 undefined,
350 undefined,
351 );
352
353 assert.notProperty(mac, "asarUnpack");
354 assert.notProperty(linux, "asarUnpack");
355 assert.deepStrictEqual(win.asarUnpack, WINDOWS_ASAR_UNPACK);
356 // Linux must register the renderer schemes so the generated .desktop
357 // entry advertises MimeType=x-scheme-handler/t3code; for OAuth deep links.
358 assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [
359 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
360 ]);
361 for (const config of [mac, linux, win]) {
362 assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
363 assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS);
364 }
365 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
366 );
367
368 it("splits a comma-separated Linux target into one target per package", () => {
369 assert.deepStrictEqual(resolveLinuxTargets("AppImage"), ["AppImage"]);
370 assert.deepStrictEqual(resolveLinuxTargets("AppImage,deb"), ["AppImage", "deb"]);
371 assert.deepStrictEqual(resolveLinuxTargets(" AppImage , deb , rpm "), [
372 "AppImage",
373 "deb",
374 "rpm",
375 ]);
376 });
377
378 it.effect("packages a .deb alongside the AppImage from a single Linux build", () =>
379 Effect.gen(function* () {
380 const appImageOnly = yield* createBuildConfig(
381 "linux",
382 "AppImage",
383 "1.2.3",
384 false,
385 false,
386 undefined,
387 undefined,
388 );
389 const both = yield* createBuildConfig(
390 "linux",
391 "AppImage,deb",
392 "1.2.3",
393 false,
394 false,
395 undefined,
396 undefined,
397 );
398 const rpmOnly = yield* createBuildConfig(
399 "linux",
400 "rpm",
401 "1.2.3",
402 false,
403 false,
404 undefined,
405 undefined,
406 );
407
408 assert.deepStrictEqual((both.linux as Record<string, unknown>).target, ["AppImage", "deb"]);
409 // fpm derives the maintainer from `author` otherwise, which carries no
410 // email address and fails the deb and rpm builds.
411 assert.equal((both.linux as Record<string, unknown>).maintainer, DESKTOP_LINUX_MAINTAINER);
412 assert.match(DESKTOP_LINUX_MAINTAINER, /^.+ <[^@\s]+@[^@\s]+>$/u);
413
414 // Package-format sections only appear for the formats actually built.
415 assert.deepStrictEqual((both.deb as Record<string, unknown>).depends, [...DEB_DEPENDENCIES]);
416 assert.notProperty(both, "rpm");
417 assert.deepStrictEqual((rpmOnly.rpm as Record<string, unknown>).depends, [
418 ...RPM_DEPENDENCIES,
419 ]);
420 assert.notProperty(rpmOnly, "deb");
421 assert.notProperty(appImageOnly, "deb");
422 assert.notProperty(appImageOnly, "rpm");
423 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
424 );
425
426 it.effect("preserves both Linux icon resize failures with structural context", () => {
427 const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> = [];
428
429 return Effect.gen(function* () {
430 const error = yield* stageLinuxIconSize("source.png", "target.png", 512, false).pipe(
431 Effect.provide(iconResizeSpawnerLayer(commands, [1, 2])),
432 Effect.flip,
433 );
434
435 assert.instanceOf(error, LinuxIconResizeError);
436 assert.equal(error.operation, "resize");
437 assert.equal(error.iconSize, 512);
438 assert.equal(error.primaryTool, "magick");
439 assert.equal(error.fallbackTool, "convert");
440 assert.include(error.message, "512x512");
441 assert.include(error.message, "`magick`");
442 assert.include(error.message, "`convert`");
443 assert.notInclude(error.message, "non-zero exit code");
444
445 assert.instanceOf(error.cause, AggregateError);
446 const aggregateCause = error.cause as AggregateError;
447 assert.lengthOf(aggregateCause.errors, 2);
448 assert.strictEqual(aggregateCause.cause, aggregateCause.errors[0]);
449 assert.instanceOf(aggregateCause.errors[0], BuildCommandFailedError);
450 assert.instanceOf(aggregateCause.errors[1], BuildCommandFailedError);
451 const primaryError = aggregateCause.errors[0] as BuildCommandFailedError;
452 const fallbackError = aggregateCause.errors[1] as BuildCommandFailedError;
453 assert.equal(primaryError.command, "magick linux icon 512x512");
454 assert.equal(primaryError.exitCode, 1);
455 assert.include(primaryError.message, "magick linux icon");
456 assert.equal(fallbackError.command, "convert linux icon 512x512");
457 assert.equal(fallbackError.exitCode, 2);
458 assert.include(fallbackError.message, "convert linux icon");
459 assert.deepStrictEqual(
460 commands.map(({ command }) => command),
461 ["magick", "convert"],
462 );
463 });
464 });
465
466 it("derives macOS passkey signing configuration from the Clerk publishable key", () => {
467 const configuration = resolveMacPasskeySigningConfiguration({
468 T3CODE_APPLE_TEAM_ID: "abc1234567",
469 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
470 T3CODE_CLERK_PUBLISHABLE_KEY: `pk_test_${btoa("example.clerk.accounts.dev$")}`,
471 });
472
473 assert.deepStrictEqual(configuration, {
474 appId: "com.t3tools.t3code",
475 teamId: "ABC1234567",
476 rpDomains: ["example.clerk.accounts.dev"],
477 provisioningProfilePath: "/tmp/t3code.provisionprofile",
478 });
479 });
480
481 it("normalizes explicit macOS passkey RP domains and renders required entitlements", () => {
482 const configuration = resolveMacPasskeySigningConfiguration({
483 T3CODE_APPLE_TEAM_ID: "ABC1234567",
484 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
485 T3CODE_CLERK_PASSKEY_RP_DOMAINS:
486 " Clerk.Example.com,example.clerk.accounts.dev,clerk.example.com ",
487 });
488 const entitlements = renderMacPasskeyEntitlements(configuration);
489
490 assert.deepStrictEqual(configuration.rpDomains, [
491 "clerk.example.com",
492 "example.clerk.accounts.dev",
493 ]);
494 assert.include(entitlements, "<string>ABC1234567.com.t3tools.t3code</string>");
495 assert.include(entitlements, "<string>webcredentials:clerk.example.com</string>");
496 assert.include(entitlements, "<string>webcredentials:example.clerk.accounts.dev</string>");
497 assert.include(entitlements, "<key>com.apple.security.cs.allow-jit</key>");
498 });
499
500 it("rejects incomplete macOS passkey signing configuration", () => {
501 const captureError = (env: Readonly<Record<string, string | undefined>>) => {
502 try {
503 resolveMacPasskeySigningConfiguration(env);
504 } catch (error) {
505 return error;
506 }
507 return assert.fail("Expected passkey signing configuration to fail.");
508 };
509
510 const missingProfileError = captureError({
511 T3CODE_APPLE_TEAM_ID: "ABC1234567",
512 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev",
513 });
514 assert.instanceOf(missingProfileError, MissingMacPasskeyProvisioningProfileError);
515 assert.equal(
516 missingProfileError.message,
517 "T3CODE_MACOS_PROVISIONING_PROFILE must point to an Associated Domains provisioning profile.",
518 );
519
520 const unsafeDomain =
521 "https://domain-user:domain-secret@example.clerk.accounts.dev/path?token=query-secret";
522 const invalidDomainError = captureError({
523 T3CODE_APPLE_TEAM_ID: "ABC1234567",
524 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
525 T3CODE_CLERK_PASSKEY_RP_DOMAINS: unsafeDomain,
526 });
527 assert.instanceOf(invalidDomainError, InvalidMacPasskeyRpDomainError);
528 assert.equal(invalidDomainError.reason, "scheme-not-allowed");
529 assert.equal(invalidDomainError.inputLength, unsafeDomain.length);
530 assert.equal(invalidDomainError.message, "Invalid passkey RP domain (scheme-not-allowed).");
531 assert.notProperty(invalidDomainError, "domain");
532 assert.notProperty(invalidDomainError, "cause");
533 const serializedInvalidDomainError = JSON.stringify(invalidDomainError);
534 assert.notInclude(serializedInvalidDomainError, unsafeDomain);
535 assert.notInclude(serializedInvalidDomainError, "domain-user");
536 assert.notInclude(serializedInvalidDomainError, "domain-secret");
537 assert.notInclude(serializedInvalidDomainError, "query-secret");
538 assert.throws(
539 () =>
540 resolveMacPasskeySigningConfiguration({
541 T3CODE_APPLE_TEAM_ID: "ABC1234567",
542 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
543 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev:8443",
544 }),
545 /Invalid passkey RP domain/u,
546 );
547 const invalidPublishableKeyError = captureError({
548 T3CODE_APPLE_TEAM_ID: "ABC1234567",
549 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
550 T3CODE_CLERK_PUBLISHABLE_KEY: "pk_test_%",
551 });
552 assert.instanceOf(invalidPublishableKeyError, InvalidMacPasskeyPublishableKeyError);
553 assert.ok(invalidPublishableKeyError.cause);
554 assert.equal(invalidPublishableKeyError.message, "T3CODE_CLERK_PUBLISHABLE_KEY is invalid.");
555 assert.notProperty(invalidPublishableKeyError, "publishableKey");
556 assert.notInclude(invalidPublishableKeyError.message, "pk_test_%");
557 });
558
559 it("preserves known passkey signing configuration errors at the build boundary", () => {
560 const decodingCause = new Error("publishable-key-decode-failed");
561 const knownError = new InvalidMacPasskeyPublishableKeyError({ cause: decodingCause });
562 const error = MacPasskeySigningConfigurationResolutionError.fromCause(knownError);
563
564 assert.strictEqual(error, knownError);
565 assert.instanceOf(error, InvalidMacPasskeyPublishableKeyError);
566 assert.strictEqual(error.cause, decodingCause);
567 assert.isTrue(isMacPasskeySigningConfigurationError(error));
568 });
569
570 it("wraps unknown passkey signing configuration defects without copying cause text", () => {
571 const secret = "pk_test_do-not-retain";
572 const cause = new Error(secret);
573 const error = MacPasskeySigningConfigurationResolutionError.fromCause(cause);
574
575 assert.instanceOf(error, MacPasskeySigningConfigurationResolutionError);
576 assert.strictEqual(error.cause, cause);
577 assert.equal(error.message, "Failed to resolve macOS passkey signing configuration.");
578 assert.notInclude(error.message, secret);
579 });
580
581 it.effect("adds passkey entitlements and both renderer protocols to signed macOS builds", () =>
582 Effect.gen(function* () {
583 const config = yield* createBuildConfig("mac", "dmg", "1.2.3", true, false, undefined, {
584 entitlementsPath: "/tmp/entitlements.mac.plist",
585 provisioningProfilePath: "/tmp/t3code.provisionprofile",
586 });
587
588 const mac = config.mac as Record<string, unknown>;
589 assert.equal(config.appId, "com.t3tools.t3code");
590 assert.equal(mac.entitlements, "/tmp/entitlements.mac.plist");
591 assert.equal(mac.provisioningProfile, "/tmp/t3code.provisionprofile");
592 assert.deepStrictEqual(mac.protocols, [
593 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
594 ]);
595 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
596 );
597
598 it.effect("keeps executable resource editing enabled for unsigned Windows builds", () =>
599 Effect.gen(function* () {
600 const config = yield* createBuildConfig(
601 "win",
602 "nsis",
603 "1.2.3",
604 false,
605 false,
606 undefined,
607 undefined,
608 );
609
610 const win = config.win as Record<string, unknown>;
611 assert.equal(win.icon, "icon.ico");
612 assert.equal(win.signAndEditExecutable, true);
613 assert.notProperty(win, "azureSignOptions");
614 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
615 );
616
617 it("stages the resource monitor as an external executable resource", () => {
618 assert.deepStrictEqual(DESKTOP_EXTRA_RESOURCES, [
619 {
620 from: "apps/desktop/prod-resources/resource-monitor",
621 to: "resource-monitor",
622 },
623 ]);
624 assert.deepStrictEqual(resolveResourceMonitorRustTargets("mac", "universal"), [
625 "aarch64-apple-darwin",
626 "x86_64-apple-darwin",
627 ]);
628 assert.deepStrictEqual(resolveResourceMonitorRustTargets("linux", "x64"), [
629 "x86_64-unknown-linux-gnu",
630 ]);
631 assert.deepStrictEqual(resolveResourceMonitorRustTargets("win", "arm64"), [
632 "aarch64-pc-windows-msvc",
633 ]);
634 assert.equal(resourceMonitorExecutableName("mac"), "t3-resource-monitor");
635 assert.equal(resourceMonitorExecutableName("win"), "t3-resource-monitor.exe");
636 });
637 it("promotes target fff binaries to direct staged dependencies", () => {
638 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
639 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
640 });
641 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "universal", "0.9.4"), {
642 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
643 "@ff-labs/fff-bin-darwin-x64": "0.9.4",
644 });
645 assert.deepStrictEqual(resolveFffNativeDependencies("win", "x64", "0.9.4"), {
646 "@ff-labs/fff-bin-win32-x64": "0.9.4",
647 });
648 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "x64", "0.9.4"), {
649 "@ff-labs/fff-bin-linux-x64-gnu": "0.9.4",
650 "@ff-labs/fff-bin-linux-x64-musl": "0.9.4",
651 });
652 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "arm64", "0.9.4"), {
653 "@ff-labs/fff-bin-linux-arm64-gnu": "0.9.4",
654 "@ff-labs/fff-bin-linux-arm64-musl": "0.9.4",
655 });
656 });
657
658 it("resolves target Clerk passkey native artifacts", () => {
659 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("mac", "universal"), [
660 {
661 packageName: "@clerk/electron-passkeys-darwin-arm64",
662 binaryFileName: "electron-passkeys.darwin-arm64.node",
663 },
664 {
665 packageName: "@clerk/electron-passkeys-darwin-x64",
666 binaryFileName: "electron-passkeys.darwin-x64.node",
667 },
668 ]);
669 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("win", "x64"), [
670 {
671 packageName: "@clerk/electron-passkeys-win32-x64-msvc",
672 binaryFileName: "electron-passkeys.win32-x64-msvc.node",
673 },
674 ]);
675 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("linux", "x64"), []);
676 });
677
678 it("falls back to the default mock update port when the configured port is blank", () => {
679 assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
680 assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
681 });
682
683 it("derives the electron-builder package manager user agent from packageManager", () => {
684 assert.equal(resolvePackageManagerUserAgent("pnpm@11.10.0"), "pnpm/11.10.0");
685 assert.equal(resolvePackageManagerUserAgent(" yarn@4.9.2 "), "yarn/4.9.2");
686 assert.equal(resolvePackageManagerUserAgent("pnpm"), "pnpm");
687 });
688
689 it.effect("normalizes mock update server ports from env-style strings", () =>
690 Effect.gen(function* () {
691 assert.equal(yield* resolveMockUpdateServerPort(undefined), undefined);
692 assert.equal(yield* resolveMockUpdateServerPort(""), undefined);
693 assert.equal(yield* resolveMockUpdateServerPort(" "), undefined);
694 assert.equal(yield* resolveMockUpdateServerPort("4123"), 4123);
695 }),
696 );
697
698 it.effect("rejects non-numeric or out-of-range mock update ports", () =>
699 Effect.gen(function* () {
700 const invalidPorts = ["abc", "12.5", "0", "65536"];
701 for (const port of invalidPorts) {
702 const exit = yield* Effect.exit(resolveMockUpdateServerPort(port));
703 assert.equal(exit._tag, "Failure");
704 }
705 }),
706 );
707
708 it("classifies invalid configured ports with the decoder's number grammar", () => {
709 const cause = new Error("invalid configured port");
710
711 assert.equal(
712 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).reason,
713 "not-numeric",
714 );
715 assert.equal(
716 InvalidMockUpdateServerPortError.fromConfigValue("12.5", cause).reason,
717 "not-integer",
718 );
719 assert.equal(
720 InvalidMockUpdateServerPortError.fromConfigValue("65536", cause).reason,
721 "out-of-range",
722 );
723 assert.strictEqual(
724 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).cause,
725 cause,
726 );
727 });
728
729 it.effect("resolves default platform and architecture from host references", () =>
730 Effect.gen(function* () {
731 const resolved = yield* resolveBuildOptions({
732 platform: Option.none(),
733 target: Option.none(),
734 arch: Option.none(),
735 buildVersion: Option.none(),
736 outputDir: Option.none(),
737 skipBuild: Option.none(),
738 keepStage: Option.none(),
739 signed: Option.none(),
740 verbose: Option.none(),
741 mockUpdates: Option.none(),
742 mockUpdateServerPort: Option.none(),
743 wslPrebuild: Option.none(),
744 }).pipe(
745 Effect.provide(
746 Layer.mergeAll(
747 Layer.succeed(HostProcessPlatform, "win32"),
748 Layer.succeed(HostProcessArchitecture, "x64"),
749 ConfigProvider.layer(
750 ConfigProvider.fromEnv({
751 env: {
752 PROCESSOR_ARCHITECTURE: "AMD64",
753 PROCESSOR_ARCHITEW6432: "ARM64",
754 },
755 }),
756 ),
757 ),
758 ),
759 );
760
761 assert.equal(resolved.platform, "win");
762 assert.equal(resolved.target, "nsis");
763 assert.equal(resolved.arch, "arm64");
764 }),
765 );
766
767 it.effect("rejects universal builds on Linux and Windows before staging binaries", () =>
768 Effect.gen(function* () {
769 for (const platform of ["linux", "win"] as const) {
770 const error = yield* Effect.flip(
771 resolveBuildOptions({
772 platform: Option.some(platform),
773 target: Option.none(),
774 arch: Option.some("universal"),
775 buildVersion: Option.none(),
776 outputDir: Option.none(),
777 skipBuild: Option.none(),
778 keepStage: Option.none(),
779 signed: Option.none(),
780 verbose: Option.none(),
781 mockUpdates: Option.none(),
782 mockUpdateServerPort: Option.none(),
783 wslPrebuild: Option.none(),
784 }),
785 );
786
787 assert.instanceOf(error, UnsupportedDesktopBuildArchitectureError);
788 assert.deepStrictEqual(error.supportedArchitectures, ["x64", "arm64"]);
789 }
790 }),
791 );
792
793 it.effect("preserves explicit false boolean flags over true env defaults", () =>
794 Effect.gen(function* () {
795 const resolved = yield* resolveBuildOptions({
796 platform: Option.some("mac"),
797 target: Option.none(),
798 arch: Option.some("arm64"),
799 buildVersion: Option.none(),
800 outputDir: Option.some("release-test"),
801 skipBuild: Option.some(false),
802 keepStage: Option.some(false),
803 signed: Option.some(false),
804 verbose: Option.some(false),
805 mockUpdates: Option.some(false),
806 mockUpdateServerPort: Option.none(),
807 wslPrebuild: Option.none(),
808 }).pipe(
809 Effect.provide(
810 ConfigProvider.layer(
811 ConfigProvider.fromEnv({
812 env: {
813 T3CODE_DESKTOP_SKIP_BUILD: "true",
814 T3CODE_DESKTOP_KEEP_STAGE: "true",
815 T3CODE_DESKTOP_SIGNED: "true",
816 T3CODE_DESKTOP_VERBOSE: "true",
817 T3CODE_DESKTOP_MOCK_UPDATES: "true",
818 },
819 }),
820 ),
821 ),
822 );
823
824 assert.equal(resolved.skipBuild, false);
825 assert.equal(resolved.keepStage, false);
826 assert.equal(resolved.signed, false);
827 assert.equal(resolved.verbose, false);
828 assert.equal(resolved.mockUpdates, false);
829 }),
830 );
831});