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

build-desktop-artifact.test.ts

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