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 // Linux must register the renderer schemes so the generated .desktop
353 // entry advertises MimeType=x-scheme-handler/t3code; for OAuth deep links.
354 assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [
355 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
356 ]);
357 for (const config of [mac, linux, win]) {
358 assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
359 assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS);
360 }
361 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
362 );
363
364 it.effect("preserves both Linux icon resize failures with structural context", () => {
365 const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> = [];
366
367 return Effect.gen(function* () {
368 const error = yield* stageLinuxIconSize("source.png", "target.png", 512, false).pipe(
369 Effect.provide(iconResizeSpawnerLayer(commands, [1, 2])),
370 Effect.flip,
371 );
372
373 assert.instanceOf(error, LinuxIconResizeError);
374 assert.equal(error.operation, "resize");
375 assert.equal(error.iconSize, 512);
376 assert.equal(error.primaryTool, "magick");
377 assert.equal(error.fallbackTool, "convert");
378 assert.include(error.message, "512x512");
379 assert.include(error.message, "`magick`");
380 assert.include(error.message, "`convert`");
381 assert.notInclude(error.message, "non-zero exit code");
382
383 assert.instanceOf(error.cause, AggregateError);
384 const aggregateCause = error.cause as AggregateError;
385 assert.lengthOf(aggregateCause.errors, 2);
386 assert.strictEqual(aggregateCause.cause, aggregateCause.errors[0]);
387 assert.instanceOf(aggregateCause.errors[0], BuildCommandFailedError);
388 assert.instanceOf(aggregateCause.errors[1], BuildCommandFailedError);
389 const primaryError = aggregateCause.errors[0] as BuildCommandFailedError;
390 const fallbackError = aggregateCause.errors[1] as BuildCommandFailedError;
391 assert.equal(primaryError.command, "magick linux icon 512x512");
392 assert.equal(primaryError.exitCode, 1);
393 assert.include(primaryError.message, "magick linux icon");
394 assert.equal(fallbackError.command, "convert linux icon 512x512");
395 assert.equal(fallbackError.exitCode, 2);
396 assert.include(fallbackError.message, "convert linux icon");
397 assert.deepStrictEqual(
398 commands.map(({ command }) => command),
399 ["magick", "convert"],
400 );
401 });
402 });
403
404 it("derives macOS passkey signing configuration from the Clerk publishable key", () => {
405 const configuration = resolveMacPasskeySigningConfiguration({
406 T3CODE_APPLE_TEAM_ID: "abc1234567",
407 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
408 T3CODE_CLERK_PUBLISHABLE_KEY: `pk_test_${btoa("example.clerk.accounts.dev$")}`,
409 });
410
411 assert.deepStrictEqual(configuration, {
412 appId: "com.t3tools.t3code",
413 teamId: "ABC1234567",
414 rpDomains: ["example.clerk.accounts.dev"],
415 provisioningProfilePath: "/tmp/t3code.provisionprofile",
416 });
417 });
418
419 it("normalizes explicit macOS passkey RP domains and renders required entitlements", () => {
420 const configuration = resolveMacPasskeySigningConfiguration({
421 T3CODE_APPLE_TEAM_ID: "ABC1234567",
422 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
423 T3CODE_CLERK_PASSKEY_RP_DOMAINS:
424 " Clerk.Example.com,example.clerk.accounts.dev,clerk.example.com ",
425 });
426 const entitlements = renderMacPasskeyEntitlements(configuration);
427
428 assert.deepStrictEqual(configuration.rpDomains, [
429 "clerk.example.com",
430 "example.clerk.accounts.dev",
431 ]);
432 assert.include(entitlements, "<string>ABC1234567.com.t3tools.t3code</string>");
433 assert.include(entitlements, "<string>webcredentials:clerk.example.com</string>");
434 assert.include(entitlements, "<string>webcredentials:example.clerk.accounts.dev</string>");
435 assert.include(entitlements, "<key>com.apple.security.cs.allow-jit</key>");
436 });
437
438 it("rejects incomplete macOS passkey signing configuration", () => {
439 const captureError = (env: Readonly<Record<string, string | undefined>>) => {
440 try {
441 resolveMacPasskeySigningConfiguration(env);
442 } catch (error) {
443 return error;
444 }
445 return assert.fail("Expected passkey signing configuration to fail.");
446 };
447
448 const missingProfileError = captureError({
449 T3CODE_APPLE_TEAM_ID: "ABC1234567",
450 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev",
451 });
452 assert.instanceOf(missingProfileError, MissingMacPasskeyProvisioningProfileError);
453 assert.equal(
454 missingProfileError.message,
455 "T3CODE_MACOS_PROVISIONING_PROFILE must point to an Associated Domains provisioning profile.",
456 );
457
458 const unsafeDomain =
459 "https://domain-user:domain-secret@example.clerk.accounts.dev/path?token=query-secret";
460 const invalidDomainError = captureError({
461 T3CODE_APPLE_TEAM_ID: "ABC1234567",
462 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
463 T3CODE_CLERK_PASSKEY_RP_DOMAINS: unsafeDomain,
464 });
465 assert.instanceOf(invalidDomainError, InvalidMacPasskeyRpDomainError);
466 assert.equal(invalidDomainError.reason, "scheme-not-allowed");
467 assert.equal(invalidDomainError.inputLength, unsafeDomain.length);
468 assert.equal(invalidDomainError.message, "Invalid passkey RP domain (scheme-not-allowed).");
469 assert.notProperty(invalidDomainError, "domain");
470 assert.notProperty(invalidDomainError, "cause");
471 const serializedInvalidDomainError = JSON.stringify(invalidDomainError);
472 assert.notInclude(serializedInvalidDomainError, unsafeDomain);
473 assert.notInclude(serializedInvalidDomainError, "domain-user");
474 assert.notInclude(serializedInvalidDomainError, "domain-secret");
475 assert.notInclude(serializedInvalidDomainError, "query-secret");
476 assert.throws(
477 () =>
478 resolveMacPasskeySigningConfiguration({
479 T3CODE_APPLE_TEAM_ID: "ABC1234567",
480 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
481 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev:8443",
482 }),
483 /Invalid passkey RP domain/u,
484 );
485 const invalidPublishableKeyError = captureError({
486 T3CODE_APPLE_TEAM_ID: "ABC1234567",
487 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
488 T3CODE_CLERK_PUBLISHABLE_KEY: "pk_test_%",
489 });
490 assert.instanceOf(invalidPublishableKeyError, InvalidMacPasskeyPublishableKeyError);
491 assert.ok(invalidPublishableKeyError.cause);
492 assert.equal(invalidPublishableKeyError.message, "T3CODE_CLERK_PUBLISHABLE_KEY is invalid.");
493 assert.notProperty(invalidPublishableKeyError, "publishableKey");
494 assert.notInclude(invalidPublishableKeyError.message, "pk_test_%");
495 });
496
497 it("preserves known passkey signing configuration errors at the build boundary", () => {
498 const decodingCause = new Error("publishable-key-decode-failed");
499 const knownError = new InvalidMacPasskeyPublishableKeyError({ cause: decodingCause });
500 const error = MacPasskeySigningConfigurationResolutionError.fromCause(knownError);
501
502 assert.strictEqual(error, knownError);
503 assert.instanceOf(error, InvalidMacPasskeyPublishableKeyError);
504 assert.strictEqual(error.cause, decodingCause);
505 assert.isTrue(isMacPasskeySigningConfigurationError(error));
506 });
507
508 it("wraps unknown passkey signing configuration defects without copying cause text", () => {
509 const secret = "pk_test_do-not-retain";
510 const cause = new Error(secret);
511 const error = MacPasskeySigningConfigurationResolutionError.fromCause(cause);
512
513 assert.instanceOf(error, MacPasskeySigningConfigurationResolutionError);
514 assert.strictEqual(error.cause, cause);
515 assert.equal(error.message, "Failed to resolve macOS passkey signing configuration.");
516 assert.notInclude(error.message, secret);
517 });
518
519 it.effect("adds passkey entitlements and both renderer protocols to signed macOS builds", () =>
520 Effect.gen(function* () {
521 const config = yield* createBuildConfig("mac", "dmg", "1.2.3", true, false, undefined, {
522 entitlementsPath: "/tmp/entitlements.mac.plist",
523 provisioningProfilePath: "/tmp/t3code.provisionprofile",
524 });
525
526 const mac = config.mac as Record<string, unknown>;
527 assert.equal(config.appId, "com.t3tools.t3code");
528 assert.equal(mac.entitlements, "/tmp/entitlements.mac.plist");
529 assert.equal(mac.provisioningProfile, "/tmp/t3code.provisionprofile");
530 assert.deepStrictEqual(mac.protocols, [
531 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
532 ]);
533 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
534 );
535
536 it.effect("keeps executable resource editing enabled for unsigned Windows builds", () =>
537 Effect.gen(function* () {
538 const config = yield* createBuildConfig(
539 "win",
540 "nsis",
541 "1.2.3",
542 false,
543 false,
544 undefined,
545 undefined,
546 );
547
548 const win = config.win as Record<string, unknown>;
549 assert.equal(win.icon, "icon.ico");
550 assert.equal(win.signAndEditExecutable, true);
551 assert.notProperty(win, "azureSignOptions");
552 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
553 );
554
555 it("stages the resource monitor as an external executable resource", () => {
556 assert.deepStrictEqual(DESKTOP_EXTRA_RESOURCES, [
557 {
558 from: "apps/desktop/prod-resources/resource-monitor",
559 to: "resource-monitor",
560 },
561 ]);
562 assert.deepStrictEqual(resolveResourceMonitorRustTargets("mac", "universal"), [
563 "aarch64-apple-darwin",
564 "x86_64-apple-darwin",
565 ]);
566 assert.deepStrictEqual(resolveResourceMonitorRustTargets("linux", "x64"), [
567 "x86_64-unknown-linux-gnu",
568 ]);
569 assert.deepStrictEqual(resolveResourceMonitorRustTargets("win", "arm64"), [
570 "aarch64-pc-windows-msvc",
571 ]);
572 assert.equal(resourceMonitorExecutableName("mac"), "t3-resource-monitor");
573 assert.equal(resourceMonitorExecutableName("win"), "t3-resource-monitor.exe");
574 });
575 it("promotes target fff binaries to direct staged dependencies", () => {
576 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
577 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
578 });
579 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "universal", "0.9.4"), {
580 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
581 "@ff-labs/fff-bin-darwin-x64": "0.9.4",
582 });
583 assert.deepStrictEqual(resolveFffNativeDependencies("win", "x64", "0.9.4"), {
584 "@ff-labs/fff-bin-win32-x64": "0.9.4",
585 });
586 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "x64", "0.9.4"), {
587 "@ff-labs/fff-bin-linux-x64-gnu": "0.9.4",
588 "@ff-labs/fff-bin-linux-x64-musl": "0.9.4",
589 });
590 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "arm64", "0.9.4"), {
591 "@ff-labs/fff-bin-linux-arm64-gnu": "0.9.4",
592 "@ff-labs/fff-bin-linux-arm64-musl": "0.9.4",
593 });
594 });
595
596 it("resolves target Clerk passkey native artifacts", () => {
597 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("mac", "universal"), [
598 {
599 packageName: "@clerk/electron-passkeys-darwin-arm64",
600 binaryFileName: "electron-passkeys.darwin-arm64.node",
601 },
602 {
603 packageName: "@clerk/electron-passkeys-darwin-x64",
604 binaryFileName: "electron-passkeys.darwin-x64.node",
605 },
606 ]);
607 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("win", "x64"), [
608 {
609 packageName: "@clerk/electron-passkeys-win32-x64-msvc",
610 binaryFileName: "electron-passkeys.win32-x64-msvc.node",
611 },
612 ]);
613 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("linux", "x64"), []);
614 });
615
616 it("falls back to the default mock update port when the configured port is blank", () => {
617 assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
618 assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
619 });
620
621 it("derives the electron-builder package manager user agent from packageManager", () => {
622 assert.equal(resolvePackageManagerUserAgent("pnpm@11.10.0"), "pnpm/11.10.0");
623 assert.equal(resolvePackageManagerUserAgent(" yarn@4.9.2 "), "yarn/4.9.2");
624 assert.equal(resolvePackageManagerUserAgent("pnpm"), "pnpm");
625 });
626
627 it.effect("normalizes mock update server ports from env-style strings", () =>
628 Effect.gen(function* () {
629 assert.equal(yield* resolveMockUpdateServerPort(undefined), undefined);
630 assert.equal(yield* resolveMockUpdateServerPort(""), undefined);
631 assert.equal(yield* resolveMockUpdateServerPort(" "), undefined);
632 assert.equal(yield* resolveMockUpdateServerPort("4123"), 4123);
633 }),
634 );
635
636 it.effect("rejects non-numeric or out-of-range mock update ports", () =>
637 Effect.gen(function* () {
638 const invalidPorts = ["abc", "12.5", "0", "65536"];
639 for (const port of invalidPorts) {
640 const exit = yield* Effect.exit(resolveMockUpdateServerPort(port));
641 assert.equal(exit._tag, "Failure");
642 }
643 }),
644 );
645
646 it("classifies invalid configured ports with the decoder's number grammar", () => {
647 const cause = new Error("invalid configured port");
648
649 assert.equal(
650 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).reason,
651 "not-numeric",
652 );
653 assert.equal(
654 InvalidMockUpdateServerPortError.fromConfigValue("12.5", cause).reason,
655 "not-integer",
656 );
657 assert.equal(
658 InvalidMockUpdateServerPortError.fromConfigValue("65536", cause).reason,
659 "out-of-range",
660 );
661 assert.strictEqual(
662 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).cause,
663 cause,
664 );
665 });
666
667 it.effect("resolves default platform and architecture from host references", () =>
668 Effect.gen(function* () {
669 const resolved = yield* resolveBuildOptions({
670 platform: Option.none(),
671 target: Option.none(),
672 arch: Option.none(),
673 buildVersion: Option.none(),
674 outputDir: Option.none(),
675 skipBuild: Option.none(),
676 keepStage: Option.none(),
677 signed: Option.none(),
678 verbose: Option.none(),
679 mockUpdates: Option.none(),
680 mockUpdateServerPort: Option.none(),
681 wslPrebuild: Option.none(),
682 }).pipe(
683 Effect.provide(
684 Layer.mergeAll(
685 Layer.succeed(HostProcessPlatform, "win32"),
686 Layer.succeed(HostProcessArchitecture, "x64"),
687 ConfigProvider.layer(
688 ConfigProvider.fromEnv({
689 env: {
690 PROCESSOR_ARCHITECTURE: "AMD64",
691 PROCESSOR_ARCHITEW6432: "ARM64",
692 },
693 }),
694 ),
695 ),
696 ),
697 );
698
699 assert.equal(resolved.platform, "win");
700 assert.equal(resolved.target, "nsis");
701 assert.equal(resolved.arch, "arm64");
702 }),
703 );
704
705 it.effect("rejects universal builds on Linux and Windows before staging binaries", () =>
706 Effect.gen(function* () {
707 for (const platform of ["linux", "win"] as const) {
708 const error = yield* Effect.flip(
709 resolveBuildOptions({
710 platform: Option.some(platform),
711 target: Option.none(),
712 arch: Option.some("universal"),
713 buildVersion: Option.none(),
714 outputDir: Option.none(),
715 skipBuild: Option.none(),
716 keepStage: Option.none(),
717 signed: Option.none(),
718 verbose: Option.none(),
719 mockUpdates: Option.none(),
720 mockUpdateServerPort: Option.none(),
721 wslPrebuild: Option.none(),
722 }),
723 );
724
725 assert.instanceOf(error, UnsupportedDesktopBuildArchitectureError);
726 assert.deepStrictEqual(error.supportedArchitectures, ["x64", "arm64"]);
727 }
728 }),
729 );
730
731 it.effect("preserves explicit false boolean flags over true env defaults", () =>
732 Effect.gen(function* () {
733 const resolved = yield* resolveBuildOptions({
734 platform: Option.some("mac"),
735 target: Option.none(),
736 arch: Option.some("arm64"),
737 buildVersion: Option.none(),
738 outputDir: Option.some("release-test"),
739 skipBuild: Option.some(false),
740 keepStage: Option.some(false),
741 signed: Option.some(false),
742 verbose: Option.some(false),
743 mockUpdates: Option.some(false),
744 mockUpdateServerPort: Option.none(),
745 wslPrebuild: Option.none(),
746 }).pipe(
747 Effect.provide(
748 ConfigProvider.layer(
749 ConfigProvider.fromEnv({
750 env: {
751 T3CODE_DESKTOP_SKIP_BUILD: "true",
752 T3CODE_DESKTOP_KEEP_STAGE: "true",
753 T3CODE_DESKTOP_SIGNED: "true",
754 T3CODE_DESKTOP_VERBOSE: "true",
755 T3CODE_DESKTOP_MOCK_UPDATES: "true",
756 },
757 }),
758 ),
759 ),
760 );
761
762 assert.equal(resolved.skipBuild, false);
763 assert.equal(resolved.keepStage, false);
764 assert.equal(resolved.signed, false);
765 assert.equal(resolved.verbose, false);
766 assert.equal(resolved.mockUpdates, false);
767 }),
768 );
769});