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

build-desktop-artifact.test.ts

669 lines24.6 KB

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