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

build-desktop-artifact.test.ts

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