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