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

build-desktop-artifact.test.ts

1,337 lines48.9 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 Effect from "effect/Effect";
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 BundleNotSelfContainedError,
15 BuildCommandFailedError,
16 DesktopDmgBackgroundSourceMissingError,
17 createStageWorkspaceConfig,
18 createStagePatchedDependencies,
19 createBuildConfig,
20 DESKTOP_ELECTRON_LANGUAGES,
21 DESKTOP_FILE_EXCLUSIONS,
22 DESKTOP_EXTRA_RESOURCES,
23 InvalidMacPasskeyRpDomainError,
24 InvalidMacPasskeyPublishableKeyError,
25 InvalidMockUpdateServerPortError,
26 UnsupportedDesktopBuildArchitectureError,
27 isMacPasskeySigningConfigurationError,
28 LinuxIconResizeError,
29 MacPasskeySigningConfigurationResolutionError,
30 MissingMacPasskeyProvisioningProfileError,
31 packWindowsServerAsar,
32 renderMacPasskeyEntitlements,
33 resolveClerkPasskeyNativeArtifacts,
34 resolveMacPasskeySigningConfiguration,
35 resolveDesktopRuntimeDependencies,
36 resolveFffNativeDependencies,
37 resolveBuildOptions,
38 resolveDesktopBuildIconAssets,
39 resolveDesktopProductName,
40 resolveDesktopUpdateChannel,
41 resolveDesktopWebAssetBrand,
42 resolveResourceMonitorRustTargets,
43 resourceMonitorExecutableName,
44 resolveGitHubPublishConfig,
45 resolveMockUpdateServerPort,
46 resolveMockUpdateServerUrl,
47 resolvePackageManagerUserAgent,
48 stageLinuxIconSize,
49 stageDesktopDmgBackground,
50 STAGE_INSTALL_ARGS,
51 ancestorNodeModulesPaths,
52 copyDirectoryPreservingSymlinks,
53 validateWindowsPackagedPayload,
54 WindowsPrimaryNativeProbeError,
55 WindowsPackagedPayloadValidationError,
56 WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT,
57 WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
58 WINDOWS_SERVER_EXTRA_RESOURCES,
59 WINDOWS_SERVER_ASAR_RESOURCE,
60 WINDOWS_SERVER_ASAR_UNPACK_GLOB,
61 WINDOWS_SERVER_RESOURCE_SOURCE_DIR,
62} from "./build-desktop-artifact.ts";
63import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
64import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
65​
66function mockProcess(exitCode: number) {
67 return ChildProcessSpawner.makeHandle({
68 pid: ChildProcessSpawner.ProcessId(1),
69 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
70 isRunning: Effect.succeed(false),
71 kill: () => Effect.void,
72 unref: Effect.succeed(Effect.void),
73 stdin: Sink.drain,
74 stdout: Stream.empty,
75 stderr: Stream.empty,
76 all: Stream.empty,
77 getInputFd: () => Sink.drain,
78 getOutputFd: () => Stream.empty,
79 });
81​
82function iconResizeSpawnerLayer(
83 commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>,
84 exitCodes: ReadonlyArray<number>,
85) {
86 let commandIndex = 0;
87 return Layer.succeed(
88 ChildProcessSpawner.ChildProcessSpawner,
89 ChildProcessSpawner.make((command) => {
90 const childProcess = command as unknown as {
91 readonly command: string;
92 readonly args: ReadonlyArray<string>;
93 };
94 commands.push({
95 command: childProcess.command,
96 args: childProcess.args,
97 });
98 return Effect.succeed(mockProcess(exitCodes[commandIndex++] ?? 0));
99 }),
100 );
102​
103const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(function* (input: {
104 readonly copyUnpackedNatives: boolean;
105 readonly serverEntrySource?: string;
106}) {
107 const fs = yield* FileSystem.FileSystem;
108 const path = yield* Path.Path;
109 const tempDir = yield* fs.makeTempDirectoryScoped({
110 prefix: "t3-windows-payload-test-",
111 });
112 const sourceDir = path.join(tempDir, "server-source");
113 const serverEntryPath = path.join(sourceDir, "apps/server/dist/bin.mjs");
114 const nativePath = path.join(sourceDir, "node_modules/native/addon.node");
115 yield* fs.makeDirectory(path.dirname(serverEntryPath), { recursive: true });
116 yield* fs.makeDirectory(path.dirname(nativePath), { recursive: true });
117 yield* fs.writeFileString(serverEntryPath, input.serverEntrySource ?? "console.log('server');\n");
118 yield* fs.writeFileString(nativePath, "native-binary");
119​
120 const generatedAsarPath = path.join(tempDir, WINDOWS_SERVER_ASAR_RESOURCE);
121 yield* packWindowsServerAsar({ sourceDir, asarPath: generatedAsarPath });
122​
123 const stageDistDir = path.join(tempDir, "dist");
124 const packagedAppDir = path.join(stageDistDir, "win-unpacked");
125 const resourcesDir = path.join(packagedAppDir, "resources");
126 yield* fs.makeDirectory(path.join(resourcesDir, "resource-monitor"), { recursive: true });
127 yield* fs.copyFile(generatedAsarPath, path.join(resourcesDir, WINDOWS_SERVER_ASAR_RESOURCE));
128 if (input.copyUnpackedNatives) {
129 yield* fs.copy(
130 `${generatedAsarPath}.unpacked`,
131 path.join(resourcesDir, `${WINDOWS_SERVER_ASAR_RESOURCE}.unpacked`),
132 );
133 }
134 yield* fs.writeFileString(
135 path.join(resourcesDir, "resource-monitor/t3-resource-monitor.exe"),
136 "monitor",
137 );
138 const appExecutableName = "t3code.exe";
139 yield* fs.writeFileString(path.join(packagedAppDir, appExecutableName), "electron");
140 yield* fs.writeFileString(path.join(packagedAppDir, "chrome_crashpad_handler.exe"), "crashpad");
141​
142 return {
143 stageDistDir,
144 packagedAppDir,
145 sourceDir,
146 generatedAsarPath,
147 appExecutableName,
148 } as const;
149});
150​
151it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
152 it("resolves the dedicated nightly updater channel from nightly versions", () => {
153 assert.equal(resolveDesktopUpdateChannel("0.0.17-nightly.20260413.42"), "nightly");
154 assert.equal(resolveDesktopUpdateChannel("0.0.17"), "latest");
155 });
156​
157 it("switches desktop packaging product names to nightly for nightly builds", () => {
158 assert.equal(resolveDesktopProductName("0.0.17"), "T3 Code (Alpha)");
159 assert.equal(resolveDesktopProductName("0.0.17-nightly.20260413.42"), "T3 Code (Nightly)");
160 });
161​
162 it("switches desktop packaging icons to the nightly artwork for nightly versions", () => {
163 assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17"), {
164 macIconPng: BRAND_ASSET_PATHS.productionMacIconPng,
165 linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng,
166 windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco,
167 });
168​
169 assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17-nightly.20260413.42"), {
170 macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng,
171 linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng,
172 windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco,
173 });
174 });
175​
176 it("switches the bundled splash and favicon branding for nightly versions", () => {
177 assert.equal(resolveDesktopWebAssetBrand("0.0.17"), "production");
178 assert.equal(resolveDesktopWebAssetBrand("0.0.17-nightly.20260413.42"), "nightly");
179 });
180​
181 it.effect("resolves GitHub desktop publish config from Effect config", () =>
182 Effect.gen(function* () {
183 const latestConfig = yield* resolveGitHubPublishConfig("latest").pipe(
184 Effect.provide(
185 ConfigProvider.layer(
186 ConfigProvider.fromEnv({
187 env: {
188 T3CODE_DESKTOP_UPDATE_REPOSITORY: "pingdotgg/t3code",
189 },
190 }),
191 ),
192 ),
193 );
194 const nightlyConfig = yield* resolveGitHubPublishConfig("nightly").pipe(
195 Effect.provide(
196 ConfigProvider.layer(
197 ConfigProvider.fromEnv({
198 env: {
199 GITHUB_REPOSITORY: "pingdotgg/t3code",
200 },
201 }),
202 ),
203 ),
204 );
205​
206 assert.deepStrictEqual(latestConfig, {
207 provider: "github",
208 owner: "pingdotgg",
209 repo: "t3code",
210 releaseType: "release",
211 });
212 assert.deepStrictEqual(nightlyConfig, {
213 provider: "github",
214 owner: "pingdotgg",
215 repo: "t3code",
216 releaseType: "prerelease",
217 channel: "nightly",
218 });
219 }),
220 );
221​
222 it("omits bundled workspace packages from staged desktop dependencies", () => {
223 assert.deepStrictEqual(
224 resolveDesktopRuntimeDependencies(
225 {
226 "@effect/platform-node": "catalog:",
227 "@t3tools/contracts": "workspace:*",
228 "@t3tools/shared": "workspace:*",
229 "@t3tools/ssh": "workspace:*",
230 "@t3tools/tailscale": "workspace:*",
231 effect: "catalog:",
232 electron: "41.5.0",
233 },
234 {
235 "@effect/platform-node": "4.0.0-beta.59",
236 effect: "4.0.0-beta.59",
237 },
238 ),
239 {
240 "@effect/platform-node": "4.0.0-beta.59",
241 effect: "4.0.0-beta.59",
242 },
243 );
244 });
245​
246 it("carries only staged dependency patch metadata into staged desktop installs", () => {
247 assert.deepStrictEqual(
248 createStagePatchedDependencies(
249 {
250 "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch",
251 "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
252 "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
253 "alchemy@2.0.0-beta.49": "patches/alchemy@2.0.0-beta.49.patch",
254 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
255 },
256 {
257 "@ff-labs/fff-node": "0.9.4",
258 "@pierre/diffs": "1.1.20",
259 effect: "4.0.0-beta.73",
260 },
261 ),
262 {
263 "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
264 "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
265 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
266 },
267 );
268​
269 assert.deepStrictEqual(
270 createStagePatchedDependencies(
271 {
272 "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch",
273 },
274 { effect: "4.0.0-beta.73" },
275 ),
276 {},
277 );
278 });
279​
280 it("installs optional native dependencies for the target desktop architecture", () => {
281 assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]);
282 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "x64" }), {
283 supportedArchitectures: {
284 os: ["darwin"],
285 cpu: ["x64"],
286 },
287 });
288 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "linux", arch: "x64" }), {
289 supportedArchitectures: {
290 os: ["linux"],
291 cpu: ["x64"],
292 libc: ["glibc"],
293 },
294 });
295 // The Windows app stage only serves the desktop main process; the server
296 // sidecar stage is the one that needs Linux natives (below).
297 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "x64" }), {
298 supportedArchitectures: {
299 os: ["win32"],
300 cpu: ["x64"],
301 },
302 });
303 // The server sidecar stage bundles the same-architecture WSL (Linux,
304 // glibc) backend, so its install must fetch Linux native optional deps
305 // (e.g. ffi-rs) too — and must be hoisted so the tree survives asar
306 // packing and runtime extraction without symlinks.
307 assert.deepStrictEqual(
308 createStageWorkspaceConfig({ platform: "win", arch: "x64", linuxServerBackend: true }),
309 {
310 supportedArchitectures: {
311 os: ["win32", "linux"],
312 cpu: ["x64"],
313 libc: ["glibc"],
314 },
315 nodeLinker: "hoisted",
316 },
317 );
318 assert.deepStrictEqual(
319 createStageWorkspaceConfig({ platform: "win", arch: "arm64", linuxServerBackend: true }),
320 {
321 supportedArchitectures: {
322 os: ["win32", "linux"],
323 cpu: ["arm64"],
324 libc: ["glibc"],
325 },
326 nodeLinker: "hoisted",
327 },
328 );
329 assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), {
330 supportedArchitectures: {
331 os: ["darwin"],
332 cpu: ["arm64", "x64"],
333 },
334 });
335 });
336​
337 it("stages pnpm 11 allowBuilds and patchedDependencies in the workspace yaml", () => {
338 assert.deepStrictEqual(
339 createStageWorkspaceConfig({
340 platform: "linux",
341 arch: "x64",
342 allowBuilds: {
343 electron: true,
344 "node-pty": true,
345 "browser-tabs-lock": false,
346 },
347 patchedDependencies: {
348 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
349 },
350 overrides: {
351 effect: "4.0.0-beta.73",
352 },
353 }),
354 {
355 supportedArchitectures: {
356 os: ["linux"],
357 cpu: ["x64"],
358 libc: ["glibc"],
359 },
360 allowBuilds: {
361 electron: true,
362 "node-pty": true,
363 "browser-tabs-lock": false,
364 },
365 patchedDependencies: {
366 "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
367 },
368 overrides: {
369 effect: "4.0.0-beta.73",
370 },
371 },
372 );
373​
374 // Empty maps must not be written — pnpm would still require reviewed
375 // packages if allowBuilds is present but incomplete, and omitting empty
376 // patchedDependencies keeps the stage yaml minimal.
377 assert.deepStrictEqual(
378 createStageWorkspaceConfig({
379 platform: "mac",
380 arch: "arm64",
381 allowBuilds: {},
382 patchedDependencies: {},
383 overrides: {},
384 }),
385 {
386 supportedArchitectures: {
387 os: ["darwin"],
388 cpu: ["arm64"],
389 },
390 },
391 );
392 });
393​
394 it("limits Electron locales and excludes the unused Claude SDK executable", () => {
395 assert.deepStrictEqual(DESKTOP_ELECTRON_LANGUAGES, ["en-US"]);
396 assert.deepStrictEqual(DESKTOP_FILE_EXCLUSIONS, [
397 "!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*",
398 "!apps/desktop/prod-resources/windows-server",
399 "!apps/desktop/prod-resources/windows-server/**/*",
400 ]);
401 assert.equal(WINDOWS_SERVER_RESOURCE_SOURCE_DIR, "apps/desktop/prod-resources/windows-server");
402 assert.deepStrictEqual(WINDOWS_SERVER_EXTRA_RESOURCES, [
403 {
404 from: "apps/desktop/prod-resources/windows-server",
405 to: ".",
406 filter: ["server.asar", "server.asar.unpacked/**/*"],
407 },
408 ]);
409 });
410​
411 it.effect("applies platform-specific packaging to the build config", () =>
412 Effect.gen(function* () {
413 const mac = yield* createBuildConfig(
414 "mac",
415 "dmg",
416 "1.2.3",
417 false,
418 false,
419 undefined,
420 undefined,
421 );
422 const linux = yield* createBuildConfig(
423 "linux",
424 "AppImage",
425 "1.2.3",
426 false,
427 false,
428 undefined,
429 undefined,
430 );
431 const win = yield* createBuildConfig(
432 "win",
433 "nsis",
434 "1.2.3",
435 false,
436 false,
437 undefined,
438 undefined,
439 );
440​
441 // All platforms keep app.asar fully packed; Windows ships the server
442 // tree as the hand-packed server.asar sidecar in extraResources instead
443 // of unpacking thousands of loose files at install time.
444 assert.notProperty(mac, "asarUnpack");
445 assert.notProperty(linux, "asarUnpack");
446 assert.notProperty(win, "asarUnpack");
447 assert.deepStrictEqual(win.extraResources, [
448 {
449 from: "apps/desktop/prod-resources/resource-monitor",
450 to: "resource-monitor",
451 },
452 ...WINDOWS_SERVER_EXTRA_RESOURCES,
453 ]);
454 assert.deepStrictEqual(win.nsis, { differentialPackage: true });
455 // Native binaries and helper executables cannot load from inside an
456 // asar; everything else stays packed. The Claude SDK platform packages
457 // and .bin shims never ship.
458 assert.equal(
459 WINDOWS_SERVER_ASAR_UNPACK_GLOB,
460 "{**/*.node,**/*.dll,**/*.exe,**/*.so,**/*.so.*,**/*.dylib}",
461 );
462 assert.deepStrictEqual(WINDOWS_SERVER_ASAR_IGNORE_GLOBS, [
463 "**/node_modules/@anthropic-ai/claude-agent-sdk-*",
464 "**/node_modules/@anthropic-ai/claude-agent-sdk-*/**",
465 "**/node_modules/.bin",
466 "**/node_modules/.bin/**",
467 ]);
468 assert.deepStrictEqual(mac.dmg, {
469 title: "T3 Code (Alpha) 1.2.3 Installer",
470 background: "dmg/dmg-background-latest.png",
471 window: { width: 540, height: 412 },
472 contents: [
473 { x: 130, y: 220, type: "file" },
474 { x: 410, y: 220, type: "link", path: "/Applications" },
475 ],
476 iconSize: 80,
477 iconTextSize: 12,
478 });
479 // Linux must register the renderer schemes so the generated .desktop
480 // entry advertises MimeType=x-scheme-handler/t3code; for OAuth deep links.
481 assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [
482 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
483 ]);
484 for (const config of [mac, linux, win]) {
485 assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
486 assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS);
487 }
488 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
489 );
490​
491 it.effect("validates every ASAR-unpacked native in the packaged Windows payload", () =>
492 Effect.scoped(
493 Effect.gen(function* () {
494 const fs = yield* FileSystem.FileSystem;
495 const path = yield* Path.Path;
496 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
497 const result = yield* validateWindowsPackagedPayload({
498 stageDistDir: fixture.stageDistDir,
499 appExecutableName: fixture.appExecutableName,
500 targetArch: "x64",
501 });
502​
503 const secondAsarPath = path.join(path.dirname(fixture.generatedAsarPath), "second.asar");
504 yield* packWindowsServerAsar({
505 sourceDir: fixture.sourceDir,
506 asarPath: secondAsarPath,
507 });
508 const [firstAsar, secondAsar] = yield* Effect.all([
509 fs.readFile(fixture.generatedAsarPath),
510 fs.readFile(secondAsarPath),
511 ]);
512​
513 assert.equal(result.packagedAppDir, fixture.packagedAppDir);
514 assert.deepStrictEqual(result.unpackedFiles, ["node_modules/native/addon.node"]);
515 assert.isBelow(result.fileCount, WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT);
516 assert.deepStrictEqual(secondAsar, firstAsar);
517 }),
518 ),
519 );
520​
521 it.effect("probes fff through the packaged Windows primary instead of helper executables", () => {
522 const commands: Array<{
523 readonly command: string;
524 readonly args: ReadonlyArray<string>;
525 readonly options: {
526 readonly cwd?: string;
527 readonly env?: Readonly<Record<string, string | undefined>>;
528 };
529 }> = [];
530 const spawnerLayer = Layer.succeed(
531 ChildProcessSpawner.ChildProcessSpawner,
532 ChildProcessSpawner.make((command) => {
533 commands.push(command as unknown as (typeof commands)[number]);
534 return Effect.succeed(mockProcess(0));
535 }),
536 );
537​
538 return Effect.scoped(
539 Effect.gen(function* () {
540 const path = yield* Path.Path;
541 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
542 yield* validateWindowsPackagedPayload({
543 stageDistDir: fixture.stageDistDir,
544 appExecutableName: fixture.appExecutableName,
545 targetArch: "x64",
546 });
547​
548 const primaryProbe = commands.find(
549 (command) => command.options.env?.ELECTRON_RUN_AS_NODE === "1",
550 );
551 if (primaryProbe === undefined) return assert.fail("Windows primary probe was not spawned");
552​
553 assert.equal(
554 primaryProbe.command,
555 path.join(fixture.packagedAppDir, fixture.appExecutableName),
556 );
557 assert.deepStrictEqual(primaryProbe.args.slice(0, 3), [
558 "--no-global-search-paths",
559 "--input-type=module",
560 "--eval",
561 ]);
562 assert.include(primaryProbe.args[3], "FileFinder.create");
563 assert.equal(
564 primaryProbe.args[4],
565 path.join(
566 fixture.packagedAppDir,
567 "resources/server.asar/node_modules/@ff-labs/fff-node/dist/src/index.js",
568 ),
569 );
570 assert.equal(primaryProbe.options.cwd, fixture.packagedAppDir);
571 assert.equal(primaryProbe.options.env?.NODE_PATH, "");
572 }),
573 ).pipe(
574 Effect.provide(
575 Layer.mergeAll(
576 spawnerLayer,
577 Layer.succeed(HostProcessPlatform, "win32"),
578 Layer.succeed(HostProcessArchitecture, "x64"),
579 ),
580 ),
581 );
582 });
583​
584 it.effect("skips the primary native probe for cross-architecture Windows payloads", () => {
585 const commands: Array<{
586 readonly command: string;
587 readonly options: {
588 readonly env?: Readonly<Record<string, string | undefined>>;
589 };
590 }> = [];
591 const spawnerLayer = Layer.succeed(
592 ChildProcessSpawner.ChildProcessSpawner,
593 ChildProcessSpawner.make((command) => {
594 commands.push(command as unknown as (typeof commands)[number]);
595 return Effect.succeed(mockProcess(0));
596 }),
597 );
598​
599 return Effect.scoped(
600 Effect.gen(function* () {
601 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
602 yield* validateWindowsPackagedPayload({
603 stageDistDir: fixture.stageDistDir,
604 appExecutableName: fixture.appExecutableName,
605 targetArch: "arm64",
606 });
607​
608 assert.isFalse(
609 commands.some((command) => command.options.env?.ELECTRON_RUN_AS_NODE === "1"),
610 );
611 assert.isTrue(
612 commands.some(
613 (command) =>
614 command.command === process.execPath && command.options.env?.NODE_PATH === "",
615 ),
616 );
617 }),
618 ).pipe(
619 Effect.provide(
620 Layer.mergeAll(
621 spawnerLayer,
622 Layer.succeed(HostProcessPlatform, "win32"),
623 Layer.succeed(HostProcessArchitecture, "x64"),
624 ),
625 ),
626 );
627 });
628​
629 it.effect("rejects a cross-architecture Windows payload without its primary executable", () =>
630 Effect.scoped(
631 Effect.gen(function* () {
632 const fs = yield* FileSystem.FileSystem;
633 const path = yield* Path.Path;
634 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
635 const executablePath = path.join(fixture.packagedAppDir, fixture.appExecutableName);
636 yield* fs.remove(executablePath);
637​
638 const error = yield* validateWindowsPackagedPayload({
639 stageDistDir: fixture.stageDistDir,
640 appExecutableName: fixture.appExecutableName,
641 targetArch: "arm64",
642 }).pipe(Effect.flip);
643​
644 assert.instanceOf(error, WindowsPrimaryNativeProbeError);
645 assert.equal(error.executablePath, executablePath);
646 }),
647 ).pipe(
648 Effect.provide(
649 Layer.mergeAll(
650 Layer.succeed(HostProcessPlatform, "win32"),
651 Layer.succeed(HostProcessArchitecture, "x64"),
652 ),
653 ),
654 ),
655 );
656​
657 it.effect("rejects a packaged sidecar whose ASAR-unpacked native is missing", () =>
658 Effect.scoped(
659 Effect.gen(function* () {
660 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: false });
661 const error = yield* validateWindowsPackagedPayload({
662 stageDistDir: fixture.stageDistDir,
663 appExecutableName: fixture.appExecutableName,
664 targetArch: "x64",
665 }).pipe(Effect.flip);
666​
667 assert.instanceOf(error, WindowsPackagedPayloadValidationError);
668 assert.equal(error.reason, "unpacked-native-missing");
669 assert.deepStrictEqual(error.missingFiles, [
670 "server.asar.unpacked/node_modules/native/addon.node",
671 ]);
672 }),
673 ),
674 );
675​
676 it.effect("rejects directories in place of packaged executable files", () =>
677 Effect.scoped(
678 Effect.gen(function* () {
679 const fs = yield* FileSystem.FileSystem;
680 const path = yield* Path.Path;
681 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
682 const nativePath = path.join(
683 fixture.packagedAppDir,
684 "resources/server.asar.unpacked/node_modules/native/addon.node",
685 );
686 yield* fs.remove(nativePath);
687 yield* fs.makeDirectory(nativePath);
688​
689 const nativeError = yield* validateWindowsPackagedPayload({
690 stageDistDir: fixture.stageDistDir,
691 appExecutableName: fixture.appExecutableName,
692 targetArch: "x64",
693 }).pipe(Effect.flip);
694 assert.instanceOf(nativeError, WindowsPackagedPayloadValidationError);
695 assert.equal(nativeError.reason, "unpacked-native-missing");
696 assert.deepStrictEqual(nativeError.missingFiles, [
697 "server.asar.unpacked/node_modules/native/addon.node",
698 ]);
699​
700 yield* fs.remove(nativePath, { recursive: true });
701 yield* fs.writeFileString(nativePath, "native-binary");
702 const resourceMonitorPath = path.join(
703 fixture.packagedAppDir,
704 "resources/resource-monitor/t3-resource-monitor.exe",
705 );
706 yield* fs.remove(resourceMonitorPath);
707 yield* fs.makeDirectory(resourceMonitorPath);
708​
709 const resourceMonitorError = yield* validateWindowsPackagedPayload({
710 stageDistDir: fixture.stageDistDir,
711 appExecutableName: fixture.appExecutableName,
712 targetArch: "x64",
713 }).pipe(Effect.flip);
714 assert.instanceOf(resourceMonitorError, WindowsPackagedPayloadValidationError);
715 assert.equal(resourceMonitorError.reason, "resource-monitor-missing");
716 assert.deepStrictEqual(resourceMonitorError.missingFiles, [
717 "resource-monitor/t3-resource-monitor.exe",
718 ]);
719 }),
720 ),
721 );
722​
723 it.effect("rejects a Windows payload that regresses above the file-count budget", () =>
724 Effect.scoped(
725 Effect.gen(function* () {
726 const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
727 const error = yield* validateWindowsPackagedPayload({
728 stageDistDir: fixture.stageDistDir,
729 appExecutableName: fixture.appExecutableName,
730 targetArch: "x64",
731 fileLimit: 2,
732 }).pipe(Effect.flip);
733​
734 assert.instanceOf(error, WindowsPackagedPayloadValidationError);
735 assert.equal(error.reason, "file-limit-exceeded");
736 assert.isAbove(error.fileCount ?? 0, 2);
737 }),
738 ),
739 );
740​
741 it.effect("rejects a sidecar whose extracted server bundle cannot resolve", () =>
742 Effect.scoped(
743 Effect.gen(function* () {
744 const fixture = yield* makeWindowsPayloadFixture({
745 copyUnpackedNatives: true,
746 serverEntrySource: 'import "t3code-deliberately-missing-package";\n',
747 });
748 const error = yield* validateWindowsPackagedPayload({
749 stageDistDir: fixture.stageDistDir,
750 appExecutableName: fixture.appExecutableName,
751 targetArch: "x64",
752 }).pipe(Effect.flip);
753​
754 assert.instanceOf(error, BundleNotSelfContainedError);
755 assert.include(error.output, "t3code-deliberately-missing-package");
756 }),
757 ),
758 );
759​
760 it.effect("preserves both Linux icon resize failures with structural context", () => {
761 const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> = [];
762​
763 return Effect.gen(function* () {
764 const error = yield* stageLinuxIconSize("source.png", "target.png", 512, false).pipe(
765 Effect.provide(iconResizeSpawnerLayer(commands, [1, 2])),
766 Effect.flip,
767 );
768​
769 assert.instanceOf(error, LinuxIconResizeError);
770 assert.equal(error.operation, "resize");
771 assert.equal(error.iconSize, 512);
772 assert.equal(error.primaryTool, "magick");
773 assert.equal(error.fallbackTool, "convert");
774 assert.include(error.message, "512x512");
775 assert.include(error.message, "`magick`");
776 assert.include(error.message, "`convert`");
777 assert.notInclude(error.message, "non-zero exit code");
778​
779 assert.instanceOf(error.cause, AggregateError);
780 const aggregateCause = error.cause as AggregateError;
781 assert.lengthOf(aggregateCause.errors, 2);
782 assert.strictEqual(aggregateCause.cause, aggregateCause.errors[0]);
783 assert.instanceOf(aggregateCause.errors[0], BuildCommandFailedError);
784 assert.instanceOf(aggregateCause.errors[1], BuildCommandFailedError);
785 const primaryError = aggregateCause.errors[0] as BuildCommandFailedError;
786 const fallbackError = aggregateCause.errors[1] as BuildCommandFailedError;
787 assert.equal(primaryError.command, "magick linux icon 512x512");
788 assert.equal(primaryError.exitCode, 1);
789 assert.include(primaryError.message, "magick linux icon");
790 assert.equal(fallbackError.command, "convert linux icon 512x512");
791 assert.equal(fallbackError.exitCode, 2);
792 assert.include(fallbackError.message, "convert linux icon");
793 assert.deepStrictEqual(
794 commands.map(({ command }) => command),
795 ["magick", "convert"],
796 );
797 });
798 });
799​
800 it.effect("rasterizes staged DMG backgrounds at standard and Retina sizes", () =>
801 Effect.scoped(
802 Effect.gen(function* () {
803 const fs = yield* FileSystem.FileSystem;
804 const path = yield* Path.Path;
805 const stageResourcesDir = yield* fs.makeTempDirectoryScoped({
806 prefix: "t3code-dmg-background-",
807 });
808 const dmgDir = path.join(stageResourcesDir, "dmg");
809 yield* fs.makeDirectory(dmgDir, { recursive: true });
810 const sourcePath = path.join(dmgDir, "dmg-background-nightly.svg");
811 yield* fs.writeFileString(sourcePath, '<svg xmlns="http://www.w3.org/2000/svg"/>');
812 const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> =
813 [];
814​
815 yield* stageDesktopDmgBackground(stageResourcesDir, "nightly", false).pipe(
816 Effect.provide(iconResizeSpawnerLayer(commands, [0, 0])),
817 );
818​
819 assert.deepStrictEqual(
820 commands.map((command) => [command.command, ...command.args]),
821 [
822 [
823 "sips",
824 "-s",
825 "format",
826 "png",
827 "-z",
828 "380",
829 "540",
830 sourcePath,
831 "--out",
832 path.join(dmgDir, "dmg-background-nightly.png"),
833 ],
834 [
835 "sips",
836 "-s",
837 "format",
838 "png",
839 "-z",
840 "760",
841 "1080",
842 sourcePath,
843 "--out",
844 path.join(dmgDir, "dmg-background-nightly@2x.png"),
845 ],
846 ],
847 );
848 }),
849 ),
850 );
851​
852 it.effect("fails clearly when the selected DMG background source is missing", () =>
853 Effect.scoped(
854 Effect.gen(function* () {
855 const fs = yield* FileSystem.FileSystem;
856 const stageResourcesDir = yield* fs.makeTempDirectoryScoped({
857 prefix: "t3code-dmg-background-missing-",
858 });
859​
860 const error = yield* stageDesktopDmgBackground(stageResourcesDir, "latest", false).pipe(
861 Effect.flip,
862 );
863​
864 assert.instanceOf(error, DesktopDmgBackgroundSourceMissingError);
865 assert.equal(error.channel, "latest");
866 assert.include(error.sourcePath, "dmg-background-latest.svg");
867 }),
868 ),
869 );
870​
871 it("derives macOS passkey signing configuration from the Clerk publishable key", () => {
872 const configuration = resolveMacPasskeySigningConfiguration({
873 T3CODE_APPLE_TEAM_ID: "abc1234567",
874 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
875 T3CODE_CLERK_PUBLISHABLE_KEY: `pk_test_${btoa("example.clerk.accounts.dev$")}`,
876 });
877​
878 assert.deepStrictEqual(configuration, {
879 appId: "com.t3tools.t3code",
880 teamId: "ABC1234567",
881 rpDomains: ["example.clerk.accounts.dev"],
882 provisioningProfilePath: "/tmp/t3code.provisionprofile",
883 });
884 });
885​
886 it("normalizes explicit macOS passkey RP domains and renders required entitlements", () => {
887 const configuration = resolveMacPasskeySigningConfiguration({
888 T3CODE_APPLE_TEAM_ID: "ABC1234567",
889 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
890 T3CODE_CLERK_PASSKEY_RP_DOMAINS:
891 " Clerk.Example.com,example.clerk.accounts.dev,clerk.example.com ",
892 });
893 const entitlements = renderMacPasskeyEntitlements(configuration);
894​
895 assert.deepStrictEqual(configuration.rpDomains, [
896 "clerk.example.com",
897 "example.clerk.accounts.dev",
898 ]);
899 assert.include(entitlements, "<string>ABC1234567.com.t3tools.t3code</string>");
900 assert.include(entitlements, "<string>webcredentials:clerk.example.com</string>");
901 assert.include(entitlements, "<string>webcredentials:example.clerk.accounts.dev</string>");
902 assert.include(entitlements, "<key>com.apple.security.cs.allow-jit</key>");
903 });
904​
905 it("rejects incomplete macOS passkey signing configuration", () => {
906 const captureError = (env: Readonly<Record<string, string | undefined>>) => {
907 try {
908 resolveMacPasskeySigningConfiguration(env);
909 } catch (error) {
910 return error;
911 }
912 return assert.fail("Expected passkey signing configuration to fail.");
913 };
914​
915 const missingProfileError = captureError({
916 T3CODE_APPLE_TEAM_ID: "ABC1234567",
917 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev",
918 });
919 assert.instanceOf(missingProfileError, MissingMacPasskeyProvisioningProfileError);
920 assert.equal(
921 missingProfileError.message,
922 "T3CODE_MACOS_PROVISIONING_PROFILE must point to an Associated Domains provisioning profile.",
923 );
924​
925 const unsafeDomain =
926 "https://domain-user:domain-secret@example.clerk.accounts.dev/path?token=query-secret";
927 const invalidDomainError = captureError({
928 T3CODE_APPLE_TEAM_ID: "ABC1234567",
929 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
930 T3CODE_CLERK_PASSKEY_RP_DOMAINS: unsafeDomain,
931 });
932 assert.instanceOf(invalidDomainError, InvalidMacPasskeyRpDomainError);
933 assert.equal(invalidDomainError.reason, "scheme-not-allowed");
934 assert.equal(invalidDomainError.inputLength, unsafeDomain.length);
935 assert.equal(invalidDomainError.message, "Invalid passkey RP domain (scheme-not-allowed).");
936 assert.notProperty(invalidDomainError, "domain");
937 assert.notProperty(invalidDomainError, "cause");
938 const serializedInvalidDomainError = JSON.stringify(invalidDomainError);
939 assert.notInclude(serializedInvalidDomainError, unsafeDomain);
940 assert.notInclude(serializedInvalidDomainError, "domain-user");
941 assert.notInclude(serializedInvalidDomainError, "domain-secret");
942 assert.notInclude(serializedInvalidDomainError, "query-secret");
943 assert.throws(
944 () =>
945 resolveMacPasskeySigningConfiguration({
946 T3CODE_APPLE_TEAM_ID: "ABC1234567",
947 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
948 T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev:8443",
949 }),
950 /Invalid passkey RP domain/u,
951 );
952 const invalidPublishableKeyError = captureError({
953 T3CODE_APPLE_TEAM_ID: "ABC1234567",
954 T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
955 T3CODE_CLERK_PUBLISHABLE_KEY: "pk_test_%",
956 });
957 assert.instanceOf(invalidPublishableKeyError, InvalidMacPasskeyPublishableKeyError);
958 assert.ok(invalidPublishableKeyError.cause);
959 assert.equal(invalidPublishableKeyError.message, "T3CODE_CLERK_PUBLISHABLE_KEY is invalid.");
960 assert.notProperty(invalidPublishableKeyError, "publishableKey");
961 assert.notInclude(invalidPublishableKeyError.message, "pk_test_%");
962 });
963​
964 it("preserves known passkey signing configuration errors at the build boundary", () => {
965 const decodingCause = new Error("publishable-key-decode-failed");
966 const knownError = new InvalidMacPasskeyPublishableKeyError({ cause: decodingCause });
967 const error = MacPasskeySigningConfigurationResolutionError.fromCause(knownError);
968​
969 assert.strictEqual(error, knownError);
970 assert.instanceOf(error, InvalidMacPasskeyPublishableKeyError);
971 assert.strictEqual(error.cause, decodingCause);
972 assert.isTrue(isMacPasskeySigningConfigurationError(error));
973 });
974​
975 it("wraps unknown passkey signing configuration defects without copying cause text", () => {
976 const secret = "pk_test_do-not-retain";
977 const cause = new Error(secret);
978 const error = MacPasskeySigningConfigurationResolutionError.fromCause(cause);
979​
980 assert.instanceOf(error, MacPasskeySigningConfigurationResolutionError);
981 assert.strictEqual(error.cause, cause);
982 assert.equal(error.message, "Failed to resolve macOS passkey signing configuration.");
983 assert.notInclude(error.message, secret);
984 });
985​
986 it.effect("adds passkey entitlements and both renderer protocols to signed macOS builds", () =>
987 Effect.gen(function* () {
988 const config = yield* createBuildConfig("mac", "dmg", "1.2.3", true, false, undefined, {
989 entitlementsPath: "/tmp/entitlements.mac.plist",
990 provisioningProfilePath: "/tmp/t3code.provisionprofile",
991 });
992​
993 const mac = config.mac as Record<string, unknown>;
994 assert.equal(config.appId, "com.t3tools.t3code");
995 assert.equal(mac.entitlements, "/tmp/entitlements.mac.plist");
996 assert.equal(mac.provisioningProfile, "/tmp/t3code.provisionprofile");
997 assert.deepStrictEqual(mac.protocols, [
998 { name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
999 ]);
1000 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
1001 );
1002​
1003 it.effect("uses the nightly DMG background for nightly macOS builds", () =>
1004 Effect.gen(function* () {
1005 const config = yield* createBuildConfig(
1006 "mac",
1007 "dmg",
1008 "1.2.3-nightly.20260815.1",
1009 false,
1010 false,
1011 undefined,
1012 undefined,
1013 );
1014​
1015 assert.equal(
1016 (config.dmg as Record<string, unknown>).background,
1017 "dmg/dmg-background-nightly.png",
1018 );
1019 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
1020 );
1021​
1022 it.effect("keeps executable resource editing enabled for unsigned Windows builds", () =>
1023 Effect.gen(function* () {
1024 const config = yield* createBuildConfig(
1025 "win",
1026 "nsis",
1027 "1.2.3",
1028 false,
1029 false,
1030 undefined,
1031 undefined,
1032 );
1033​
1034 const win = config.win as Record<string, unknown>;
1035 assert.equal(win.icon, "icon.ico");
1036 assert.equal(win.signAndEditExecutable, true);
1037 assert.notProperty(win, "azureSignOptions");
1038 }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
1039 );
1040​
1041 it("stages the resource monitor as an external executable resource", () => {
1042 assert.deepStrictEqual(DESKTOP_EXTRA_RESOURCES, [
1044 from: "apps/desktop/prod-resources/resource-monitor",
1045 to: "resource-monitor",
1046 },
1047 ]);
1048 assert.deepStrictEqual(resolveResourceMonitorRustTargets("mac", "universal"), [
1049 "aarch64-apple-darwin",
1050 "x86_64-apple-darwin",
1051 ]);
1052 assert.deepStrictEqual(resolveResourceMonitorRustTargets("linux", "x64"), [
1053 "x86_64-unknown-linux-gnu",
1054 ]);
1055 assert.deepStrictEqual(resolveResourceMonitorRustTargets("win", "arm64"), [
1056 "aarch64-pc-windows-msvc",
1057 ]);
1058 assert.equal(resourceMonitorExecutableName("mac"), "t3-resource-monitor");
1059 assert.equal(resourceMonitorExecutableName("win"), "t3-resource-monitor.exe");
1060 });
1061 it("promotes target fff binaries to direct staged dependencies", () => {
1062 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
1063 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
1064 });
1065 assert.deepStrictEqual(resolveFffNativeDependencies("mac", "universal", "0.9.4"), {
1066 "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
1067 "@ff-labs/fff-bin-darwin-x64": "0.9.4",
1068 });
1069 assert.deepStrictEqual(resolveFffNativeDependencies("win", "x64", "0.9.4"), {
1070 "@ff-labs/fff-bin-win32-x64": "0.9.4",
1071 });
1072 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "x64", "0.9.4"), {
1073 "@ff-labs/fff-bin-linux-x64-gnu": "0.9.4",
1074 "@ff-labs/fff-bin-linux-x64-musl": "0.9.4",
1075 });
1076 assert.deepStrictEqual(resolveFffNativeDependencies("linux", "arm64", "0.9.4"), {
1077 "@ff-labs/fff-bin-linux-arm64-gnu": "0.9.4",
1078 "@ff-labs/fff-bin-linux-arm64-musl": "0.9.4",
1079 });
1080 });
1081​
1082 it("resolves target Clerk passkey native artifacts", () => {
1083 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("mac", "universal"), [
1085 packageName: "@clerk/electron-passkeys-darwin-arm64",
1086 binaryFileName: "electron-passkeys.darwin-arm64.node",
1087 },
1089 packageName: "@clerk/electron-passkeys-darwin-x64",
1090 binaryFileName: "electron-passkeys.darwin-x64.node",
1091 },
1092 ]);
1093 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("win", "x64"), [
1095 packageName: "@clerk/electron-passkeys-win32-x64-msvc",
1096 binaryFileName: "electron-passkeys.win32-x64-msvc.node",
1097 },
1098 ]);
1099 assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("linux", "x64"), []);
1100 });
1101​
1102 it("falls back to the default mock update port when the configured port is blank", () => {
1103 assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
1104 assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
1105 });
1106​
1107 it("derives the electron-builder package manager user agent from packageManager", () => {
1108 assert.equal(resolvePackageManagerUserAgent("pnpm@11.10.0"), "pnpm/11.10.0");
1109 assert.equal(resolvePackageManagerUserAgent(" yarn@4.9.2 "), "yarn/4.9.2");
1110 assert.equal(resolvePackageManagerUserAgent("pnpm"), "pnpm");
1111 });
1112​
1113 it.effect("normalizes mock update server ports from env-style strings", () =>
1114 Effect.gen(function* () {
1115 assert.equal(yield* resolveMockUpdateServerPort(undefined), undefined);
1116 assert.equal(yield* resolveMockUpdateServerPort(""), undefined);
1117 assert.equal(yield* resolveMockUpdateServerPort(" "), undefined);
1118 assert.equal(yield* resolveMockUpdateServerPort("4123"), 4123);
1119 }),
1120 );
1121​
1122 it.effect("rejects non-numeric or out-of-range mock update ports", () =>
1123 Effect.gen(function* () {
1124 const invalidPorts = ["abc", "12.5", "0", "65536"];
1125 for (const port of invalidPorts) {
1126 const exit = yield* Effect.exit(resolveMockUpdateServerPort(port));
1127 assert.equal(exit._tag, "Failure");
1129 }),
1130 );
1131​
1132 it("classifies invalid configured ports with the decoder's number grammar", () => {
1133 const cause = new Error("invalid configured port");
1134​
1135 assert.equal(
1136 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).reason,
1137 "not-numeric",
1138 );
1139 assert.equal(
1140 InvalidMockUpdateServerPortError.fromConfigValue("12.5", cause).reason,
1141 "not-integer",
1142 );
1143 assert.equal(
1144 InvalidMockUpdateServerPortError.fromConfigValue("65536", cause).reason,
1145 "out-of-range",
1146 );
1147 assert.strictEqual(
1148 InvalidMockUpdateServerPortError.fromConfigValue("0x10", cause).cause,
1149 cause,
1150 );
1151 });
1152​
1153 it.effect("resolves default platform and architecture from host references", () =>
1154 Effect.gen(function* () {
1155 const resolved = yield* resolveBuildOptions({
1156 platform: Option.none(),
1157 target: Option.none(),
1158 arch: Option.none(),
1159 buildVersion: Option.none(),
1160 outputDir: Option.none(),
1161 skipBuild: Option.none(),
1162 keepStage: Option.none(),
1163 signed: Option.none(),
1164 verbose: Option.none(),
1165 mockUpdates: Option.none(),
1166 mockUpdateServerPort: Option.none(),
1167 wslPrebuild: Option.none(),
1168 }).pipe(
1169 Effect.provide(
1170 Layer.mergeAll(
1171 Layer.succeed(HostProcessPlatform, "win32"),
1172 Layer.succeed(HostProcessArchitecture, "x64"),
1173 ConfigProvider.layer(
1174 ConfigProvider.fromEnv({
1175 env: {
1176 PROCESSOR_ARCHITECTURE: "AMD64",
1177 PROCESSOR_ARCHITEW6432: "ARM64",
1178 },
1179 }),
1180 ),
1181 ),
1182 ),
1183 );
1184​
1185 assert.equal(resolved.platform, "win");
1186 assert.equal(resolved.target, "nsis");
1187 assert.equal(resolved.arch, "arm64");
1188 }),
1189 );
1190​
1191 it.effect("rejects universal builds on Linux and Windows before staging binaries", () =>
1192 Effect.gen(function* () {
1193 for (const platform of ["linux", "win"] as const) {
1194 const error = yield* Effect.flip(
1195 resolveBuildOptions({
1196 platform: Option.some(platform),
1197 target: Option.none(),
1198 arch: Option.some("universal"),
1199 buildVersion: Option.none(),
1200 outputDir: Option.none(),
1201 skipBuild: Option.none(),
1202 keepStage: Option.none(),
1203 signed: Option.none(),
1204 verbose: Option.none(),
1205 mockUpdates: Option.none(),
1206 mockUpdateServerPort: Option.none(),
1207 wslPrebuild: Option.none(),
1208 }),
1209 );
1210​
1211 assert.instanceOf(error, UnsupportedDesktopBuildArchitectureError);
1212 assert.deepStrictEqual(error.supportedArchitectures, ["x64", "arm64"]);
1214 }),
1215 );
1216​
1217 it.effect("preserves explicit false boolean flags over true env defaults", () =>
1218 Effect.gen(function* () {
1219 const resolved = yield* resolveBuildOptions({
1220 platform: Option.some("mac"),
1221 target: Option.none(),
1222 arch: Option.some("arm64"),
1223 buildVersion: Option.none(),
1224 outputDir: Option.some("release-test"),
1225 skipBuild: Option.some(false),
1226 keepStage: Option.some(false),
1227 signed: Option.some(false),
1228 verbose: Option.some(false),
1229 mockUpdates: Option.some(false),
1230 mockUpdateServerPort: Option.none(),
1231 wslPrebuild: Option.none(),
1232 }).pipe(
1233 Effect.provide(
1234 ConfigProvider.layer(
1235 ConfigProvider.fromEnv({
1236 env: {
1237 T3CODE_DESKTOP_SKIP_BUILD: "true",
1238 T3CODE_DESKTOP_KEEP_STAGE: "true",
1239 T3CODE_DESKTOP_SIGNED: "true",
1240 T3CODE_DESKTOP_VERBOSE: "true",
1241 T3CODE_DESKTOP_MOCK_UPDATES: "true",
1242 },
1243 }),
1244 ),
1245 ),
1246 );
1247​
1248 assert.equal(resolved.skipBuild, false);
1249 assert.equal(resolved.keepStage, false);
1250 assert.equal(resolved.signed, false);
1251 assert.equal(resolved.verbose, false);
1252 assert.equal(resolved.mockUpdates, false);
1253 }),
1254 );
1255});
1256​
1257// The self-containment check runs the packaged tree in a scratch directory. Its
1258// own node_modules holds the sidecar externals and must be ignored, but any
1259// node_modules *above* it would let Node's parent walk satisfy an import that is
1260// missing from the package, so the probe refuses to run in that case.
1261it("lists ancestor node_modules, nearest first, excluding the start directory", () => {
1262 assert.deepStrictEqual(ancestorNodeModulesPaths("C:\\tmp\\probe\\app", "\\"), [
1263 "C:\\tmp\\probe\\node_modules",
1264 "C:\\tmp\\node_modules",
1265 "C:\\node_modules",
1266 ]);
1267});
1268​
1269it("includes the filesystem root for posix paths", () => {
1270 assert.deepStrictEqual(ancestorNodeModulesPaths("/tmp/probe", "/"), [
1271 "/tmp/node_modules",
1272 "/node_modules",
1273 ]);
1274});
1275​
1276// A UNC root must keep its \\server\share prefix. Rebuilding it from segments
1277// produced relative paths, which fs.exists resolves against the build cwd, so
1278// the guard checked directories that do not exist and silently passed.
1279it("keeps the prefix of a UNC path instead of going relative", () => {
1280 const paths = ancestorNodeModulesPaths("\\\\server\\share\\tmp\\app", "\\");
1281 for (const candidate of paths) {
1282 assert.ok(candidate.startsWith("\\\\server\\share"), candidate);
1284 assert.deepStrictEqual(paths[0], "\\\\server\\share\\tmp\\node_modules");
1285});
1286​
1287it.effect("rebases packaged links into the isolated tree", () =>
1288 Effect.gen(function* () {
1289 const fs = yield* FileSystem.FileSystem;
1290 const path = yield* Path.Path;
1291 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-copy-symlinks-" });
1292 const source = path.join(root, "source");
1293 const destination = path.join(root, "destination");
1294 const packageDir = path.join(source, "node_modules/.pnpm/example@1/node_modules/example");
1295 const relativePackageLink = path.join(source, "node_modules/example-relative");
1296 const absolutePackageLink = path.join(source, "node_modules/example-absolute");
1297​
1298 yield* fs.makeDirectory(packageDir, { recursive: true });
1299 yield* fs.writeFileString(path.join(packageDir, "index.js"), "module.exports = true;\n");
1300 yield* fs.symlink(
1301 path.join(".pnpm", "example@1", "node_modules", "example"),
1302 relativePackageLink,
1303 );
1304 yield* fs.symlink(packageDir, absolutePackageLink);
1305​
1306 yield* copyDirectoryPreservingSymlinks(source, destination);
1307​
1308 const copiedPackage = path.join(
1309 destination,
1310 "node_modules/.pnpm/example@1/node_modules/example",
1311 );
1312 const resolvedCopiedPackage = yield* fs.realPath(copiedPackage);
1313 assert.equal(
1314 yield* fs.readLink(path.join(destination, "node_modules/example-relative")),
1315 copiedPackage,
1316 );
1317 assert.equal(
1318 yield* fs.readLink(path.join(destination, "node_modules/example-absolute")),
1319 copiedPackage,
1320 );
1321 assert.equal(
1322 yield* fs.realPath(path.join(destination, "node_modules/example-relative")),
1323 resolvedCopiedPackage,
1324 );
1325 assert.equal(
1326 yield* fs.realPath(path.join(destination, "node_modules/example-absolute")),
1327 resolvedCopiedPackage,
1328 );
1329 }).pipe(Effect.provide(NodeServices.layer)),
1331​
1332it("ignores trailing separators", () => {
1333 assert.deepStrictEqual(
1334 ancestorNodeModulesPaths("C:\\tmp\\probe\\app\\", "\\"),
1335 ancestorNodeModulesPaths("C:\\tmp\\probe\\app", "\\"),
1336 );
1337});