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

build-desktop-artifact.test.ts

855 lines31.4 KB

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