Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

build-desktop-artifact.test.ts

764 lines27.7 KB

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