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