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

build-desktop-artifact.test.ts

663 lines24.3 KB

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