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

build-desktop-artifact.test.ts

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