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