import * as NodeServices from "@effect/platform-node/NodeServices";import { assert, it } from "@effect/vitest";import * as ConfigProvider from "effect/ConfigProvider";import * as FileSystem from "effect/FileSystem";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import * as Option from "effect/Option";import * as Path from "effect/Path";import * as Sink from "effect/Sink";import * as Stream from "effect/Stream";import { ChildProcessSpawner } from "effect/unstable/process"; import { BundleNotSelfContainedError, BuildCommandFailedError, DesktopDmgBackgroundSourceMissingError, createStageWorkspaceConfig, createStagePatchedDependencies, createBuildConfig, DESKTOP_ELECTRON_LANGUAGES, DESKTOP_FILE_EXCLUSIONS, DESKTOP_EXTRA_RESOURCES, InvalidMacPasskeyRpDomainError, InvalidMacPasskeyPublishableKeyError, InvalidMockUpdateServerPortError, UnsupportedDesktopBuildArchitectureError, isMacPasskeySigningConfigurationError, LinuxIconResizeError, MacPasskeySigningConfigurationResolutionError, MissingMacPasskeyProvisioningProfileError, packWindowsServerAsar, renderMacPasskeyEntitlements, resolveClerkPasskeyNativeArtifacts, resolveMacPasskeySigningConfiguration, resolveDesktopRuntimeDependencies, resolveFffNativeDependencies, resolveBuildOptions, resolveDesktopBuildIconAssets, resolveDesktopProductName, resolveDesktopUpdateChannel, resolveDesktopWebAssetBrand, resolveResourceMonitorRustTargets, resourceMonitorExecutableName, resolveGitHubPublishConfig, resolveMockUpdateServerPort, resolveMockUpdateServerUrl, resolvePackageManagerUserAgent, stageLinuxIconSize, stageDesktopDmgBackground, STAGE_INSTALL_ARGS, ancestorNodeModulesPaths, copyDirectoryPreservingSymlinks, validateWindowsPackagedPayload, WindowsPrimaryNativeProbeError, WindowsPackagedPayloadValidationError, WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT, WINDOWS_SERVER_ASAR_IGNORE_GLOBS, WINDOWS_SERVER_EXTRA_RESOURCES, WINDOWS_SERVER_ASAR_RESOURCE, WINDOWS_SERVER_ASAR_UNPACK_GLOB, WINDOWS_SERVER_RESOURCE_SOURCE_DIR,} from "./build-desktop-artifact.ts";import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess"; function mockProcess(exitCode: number) { return ChildProcessSpawner.makeHandle({ pid: ChildProcessSpawner.ProcessId(1), exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)), isRunning: Effect.succeed(false), kill: () => Effect.void, unref: Effect.succeed(Effect.void), stdin: Sink.drain, stdout: Stream.empty, stderr: Stream.empty, all: Stream.empty, getInputFd: () => Sink.drain, getOutputFd: () => Stream.empty, });} function iconResizeSpawnerLayer( commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>, exitCodes: ReadonlyArray<number>,) { let commandIndex = 0; return Layer.succeed( ChildProcessSpawner.ChildProcessSpawner, ChildProcessSpawner.make((command) => { const childProcess = command as unknown as { readonly command: string; readonly args: ReadonlyArray<string>; }; commands.push({ command: childProcess.command, args: childProcess.args, }); return Effect.succeed(mockProcess(exitCodes[commandIndex++] ?? 0)); }), );} const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(function* (input: { readonly copyUnpackedNatives: boolean; readonly serverEntrySource?: string;}) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-windows-payload-test-", }); const sourceDir = path.join(tempDir, "server-source"); const serverEntryPath = path.join(sourceDir, "apps/server/dist/bin.mjs"); const nativePath = path.join(sourceDir, "node_modules/native/addon.node"); yield* fs.makeDirectory(path.dirname(serverEntryPath), { recursive: true }); yield* fs.makeDirectory(path.dirname(nativePath), { recursive: true }); yield* fs.writeFileString(serverEntryPath, input.serverEntrySource ?? "console.log('server');\n"); yield* fs.writeFileString(nativePath, "native-binary"); const generatedAsarPath = path.join(tempDir, WINDOWS_SERVER_ASAR_RESOURCE); yield* packWindowsServerAsar({ sourceDir, asarPath: generatedAsarPath }); const stageDistDir = path.join(tempDir, "dist"); const packagedAppDir = path.join(stageDistDir, "win-unpacked"); const resourcesDir = path.join(packagedAppDir, "resources"); yield* fs.makeDirectory(path.join(resourcesDir, "resource-monitor"), { recursive: true }); yield* fs.copyFile(generatedAsarPath, path.join(resourcesDir, WINDOWS_SERVER_ASAR_RESOURCE)); if (input.copyUnpackedNatives) { yield* fs.copy( `${generatedAsarPath}.unpacked`, path.join(resourcesDir, `${WINDOWS_SERVER_ASAR_RESOURCE}.unpacked`), ); } yield* fs.writeFileString( path.join(resourcesDir, "resource-monitor/t3-resource-monitor.exe"), "monitor", ); const appExecutableName = "t3code.exe"; yield* fs.writeFileString(path.join(packagedAppDir, appExecutableName), "electron"); yield* fs.writeFileString(path.join(packagedAppDir, "chrome_crashpad_handler.exe"), "crashpad"); return { stageDistDir, packagedAppDir, sourceDir, generatedAsarPath, appExecutableName, } as const;}); it.layer(NodeServices.layer)("build-desktop-artifact", (it) => { it("resolves the dedicated nightly updater channel from nightly versions", () => { assert.equal(resolveDesktopUpdateChannel("0.0.17-nightly.20260413.42"), "nightly"); assert.equal(resolveDesktopUpdateChannel("0.0.17"), "latest"); }); it("switches desktop packaging product names to nightly for nightly builds", () => { assert.equal(resolveDesktopProductName("0.0.17"), "T3 Code (Alpha)"); assert.equal(resolveDesktopProductName("0.0.17-nightly.20260413.42"), "T3 Code (Nightly)"); }); it("switches desktop packaging icons to the nightly artwork for nightly versions", () => { assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17"), { macIconPng: BRAND_ASSET_PATHS.productionMacIconPng, linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng, windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco, }); assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17-nightly.20260413.42"), { macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng, linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng, windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco, }); }); it("switches the bundled splash and favicon branding for nightly versions", () => { assert.equal(resolveDesktopWebAssetBrand("0.0.17"), "production"); assert.equal(resolveDesktopWebAssetBrand("0.0.17-nightly.20260413.42"), "nightly"); }); it.effect("resolves GitHub desktop publish config from Effect config", () => Effect.gen(function* () { const latestConfig = yield* resolveGitHubPublishConfig("latest").pipe( Effect.provide( ConfigProvider.layer( ConfigProvider.fromEnv({ env: { T3CODE_DESKTOP_UPDATE_REPOSITORY: "pingdotgg/t3code", }, }), ), ), ); const nightlyConfig = yield* resolveGitHubPublishConfig("nightly").pipe( Effect.provide( ConfigProvider.layer( ConfigProvider.fromEnv({ env: { GITHUB_REPOSITORY: "pingdotgg/t3code", }, }), ), ), ); assert.deepStrictEqual(latestConfig, { provider: "github", owner: "pingdotgg", repo: "t3code", releaseType: "release", }); assert.deepStrictEqual(nightlyConfig, { provider: "github", owner: "pingdotgg", repo: "t3code", releaseType: "prerelease", channel: "nightly", }); }), ); it("omits bundled workspace packages from staged desktop dependencies", () => { assert.deepStrictEqual( resolveDesktopRuntimeDependencies( { "@effect/platform-node": "catalog:", "@t3tools/contracts": "workspace:*", "@t3tools/shared": "workspace:*", "@t3tools/ssh": "workspace:*", "@t3tools/tailscale": "workspace:*", effect: "catalog:", electron: "41.5.0", }, { "@effect/platform-node": "4.0.0-beta.59", effect: "4.0.0-beta.59", }, ), { "@effect/platform-node": "4.0.0-beta.59", effect: "4.0.0-beta.59", }, ); }); it("carries only staged dependency patch metadata into staged desktop installs", () => { assert.deepStrictEqual( createStagePatchedDependencies( { "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch", "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch", "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch", "alchemy@2.0.0-beta.49": "patches/alchemy@2.0.0-beta.49.patch", "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, { "@ff-labs/fff-node": "0.9.4", "@pierre/diffs": "1.1.20", effect: "4.0.0-beta.73", }, ), { "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch", "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch", "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, ); assert.deepStrictEqual( createStagePatchedDependencies( { "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch", }, { effect: "4.0.0-beta.73" }, ), {}, ); }); it("installs optional native dependencies for the target desktop architecture", () => { assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "x64" }), { supportedArchitectures: { os: ["darwin"], cpu: ["x64"], }, }); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "linux", arch: "x64" }), { supportedArchitectures: { os: ["linux"], cpu: ["x64"], libc: ["glibc"], }, }); // The Windows app stage only serves the desktop main process; the server // sidecar stage is the one that needs Linux natives (below). assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "x64" }), { supportedArchitectures: { os: ["win32"], cpu: ["x64"], }, }); // The server sidecar stage bundles the same-architecture WSL (Linux, // glibc) backend, so its install must fetch Linux native optional deps // (e.g. ffi-rs) too — and must be hoisted so the tree survives asar // packing and runtime extraction without symlinks. assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "win", arch: "x64", linuxServerBackend: true }), { supportedArchitectures: { os: ["win32", "linux"], cpu: ["x64"], libc: ["glibc"], }, nodeLinker: "hoisted", }, ); assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "win", arch: "arm64", linuxServerBackend: true }), { supportedArchitectures: { os: ["win32", "linux"], cpu: ["arm64"], libc: ["glibc"], }, nodeLinker: "hoisted", }, ); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), { supportedArchitectures: { os: ["darwin"], cpu: ["arm64", "x64"], }, }); }); it("stages pnpm 11 allowBuilds and patchedDependencies in the workspace yaml", () => { assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "linux", arch: "x64", allowBuilds: { electron: true, "node-pty": true, "browser-tabs-lock": false, }, patchedDependencies: { "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, overrides: { effect: "4.0.0-beta.73", }, }), { supportedArchitectures: { os: ["linux"], cpu: ["x64"], libc: ["glibc"], }, allowBuilds: { electron: true, "node-pty": true, "browser-tabs-lock": false, }, patchedDependencies: { "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, overrides: { effect: "4.0.0-beta.73", }, }, ); // Empty maps must not be written — pnpm would still require reviewed // packages if allowBuilds is present but incomplete, and omitting empty // patchedDependencies keeps the stage yaml minimal. assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "mac", arch: "arm64", allowBuilds: {}, patchedDependencies: {}, overrides: {}, }), { supportedArchitectures: { os: ["darwin"], cpu: ["arm64"], }, }, ); }); it("limits Electron locales and excludes the unused Claude SDK executable", () => { assert.deepStrictEqual(DESKTOP_ELECTRON_LANGUAGES, ["en-US"]); assert.deepStrictEqual(DESKTOP_FILE_EXCLUSIONS, [ "!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*", "!apps/desktop/prod-resources/windows-server", "!apps/desktop/prod-resources/windows-server/**/*", ]); assert.equal(WINDOWS_SERVER_RESOURCE_SOURCE_DIR, "apps/desktop/prod-resources/windows-server"); assert.deepStrictEqual(WINDOWS_SERVER_EXTRA_RESOURCES, [ { from: "apps/desktop/prod-resources/windows-server", to: ".", filter: ["server.asar", "server.asar.unpacked/**/*"], }, ]); }); it.effect("applies platform-specific packaging to the build config", () => Effect.gen(function* () { const mac = yield* createBuildConfig( "mac", "dmg", "1.2.3", false, false, undefined, undefined, ); const linux = yield* createBuildConfig( "linux", "AppImage", "1.2.3", false, false, undefined, undefined, ); const win = yield* createBuildConfig( "win", "nsis", "1.2.3", false, false, undefined, undefined, ); // All platforms keep app.asar fully packed; Windows ships the server // tree as the hand-packed server.asar sidecar in extraResources instead // of unpacking thousands of loose files at install time. assert.notProperty(mac, "asarUnpack"); assert.notProperty(linux, "asarUnpack"); assert.notProperty(win, "asarUnpack"); assert.deepStrictEqual(win.extraResources, [ { from: "apps/desktop/prod-resources/resource-monitor", to: "resource-monitor", }, ...WINDOWS_SERVER_EXTRA_RESOURCES, ]); assert.deepStrictEqual(win.nsis, { differentialPackage: true }); // Native binaries and helper executables cannot load from inside an // asar; everything else stays packed. The Claude SDK platform packages // and .bin shims never ship. assert.equal( WINDOWS_SERVER_ASAR_UNPACK_GLOB, "{**/*.node,**/*.dll,**/*.exe,**/*.so,**/*.so.*,**/*.dylib}", ); assert.deepStrictEqual(WINDOWS_SERVER_ASAR_IGNORE_GLOBS, [ "**/node_modules/@anthropic-ai/claude-agent-sdk-*", "**/node_modules/@anthropic-ai/claude-agent-sdk-*/**", "**/node_modules/.bin", "**/node_modules/.bin/**", ]); assert.deepStrictEqual(mac.dmg, { title: "T3 Code (Alpha) 1.2.3 Installer", background: "dmg/dmg-background-latest.png", window: { width: 540, height: 412 }, contents: [ { x: 130, y: 220, type: "file" }, { x: 410, y: 220, type: "link", path: "/Applications" }, ], iconSize: 80, iconTextSize: 12, }); // Linux must register the renderer schemes so the generated .desktop // entry advertises MimeType=x-scheme-handler/t3code; for OAuth deep links. assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [ { name: "T3 Code", schemes: ["t3code", "t3code-dev"] }, ]); for (const config of [mac, linux, win]) { assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES); assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS); } }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))), ); it.effect("validates every ASAR-unpacked native in the packaged Windows payload", () => Effect.scoped( Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true }); const result = yield* validateWindowsPackagedPayload({ stageDistDir: fixture.stageDistDir, appExecutableName: fixture.appExecutableName, targetArch: "x64",Lines 1–500 of 1337. Load more
import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, it } from "@effect/vitest"; import * as ConfigProvider from "effect/ConfigProvider"; import * as FileSystem from "effect/FileSystem"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Sink from "effect/Sink"; import * as Stream from "effect/Stream"; import { ChildProcessSpawner } from "effect/unstable/process"; import { BundleNotSelfContainedError, BuildCommandFailedError, DesktopDmgBackgroundSourceMissingError, createStageWorkspaceConfig, createStagePatchedDependencies, createBuildConfig, DESKTOP_ELECTRON_LANGUAGES, DESKTOP_FILE_EXCLUSIONS, DESKTOP_EXTRA_RESOURCES, InvalidMacPasskeyRpDomainError, InvalidMacPasskeyPublishableKeyError, InvalidMockUpdateServerPortError, UnsupportedDesktopBuildArchitectureError, isMacPasskeySigningConfigurationError, LinuxIconResizeError, MacPasskeySigningConfigurationResolutionError, MissingMacPasskeyProvisioningProfileError, packWindowsServerAsar, renderMacPasskeyEntitlements, resolveClerkPasskeyNativeArtifacts, resolveMacPasskeySigningConfiguration, resolveDesktopRuntimeDependencies, resolveFffNativeDependencies, resolveBuildOptions, resolveDesktopBuildIconAssets, resolveDesktopProductName, resolveDesktopUpdateChannel, resolveDesktopWebAssetBrand, resolveResourceMonitorRustTargets, resourceMonitorExecutableName, resolveGitHubPublishConfig, resolveMockUpdateServerPort, resolveMockUpdateServerUrl, resolvePackageManagerUserAgent, stageLinuxIconSize, stageDesktopDmgBackground, STAGE_INSTALL_ARGS, ancestorNodeModulesPaths, copyDirectoryPreservingSymlinks, validateWindowsPackagedPayload, WindowsPrimaryNativeProbeError, WindowsPackagedPayloadValidationError, WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT, WINDOWS_SERVER_ASAR_IGNORE_GLOBS, WINDOWS_SERVER_EXTRA_RESOURCES, WINDOWS_SERVER_ASAR_RESOURCE, WINDOWS_SERVER_ASAR_UNPACK_GLOB, WINDOWS_SERVER_RESOURCE_SOURCE_DIR, } from "./build-desktop-artifact.ts"; import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts"; import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess"; function mockProcess(exitCode: number) { return ChildProcessSpawner.makeHandle({ pid: ChildProcessSpawner.ProcessId(1), exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)), isRunning: Effect.succeed(false), kill: () => Effect.void, unref: Effect.succeed(Effect.void), stdin: Sink.drain, stdout: Stream.empty, stderr: Stream.empty, all: Stream.empty, getInputFd: () => Sink.drain, getOutputFd: () => Stream.empty, }); } function iconResizeSpawnerLayer( commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>, exitCodes: ReadonlyArray<number>, ) { let commandIndex = 0; return Layer.succeed( ChildProcessSpawner.ChildProcessSpawner, ChildProcessSpawner.make((command) => { const childProcess = command as unknown as { readonly command: string; readonly args: ReadonlyArray<string>; }; commands.push({ command: childProcess.command, args: childProcess.args, }); return Effect.succeed(mockProcess(exitCodes[commandIndex++] ?? 0)); }), ); } const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(function* (input: { readonly copyUnpackedNatives: boolean; readonly serverEntrySource?: string; }) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-windows-payload-test-", }); const sourceDir = path.join(tempDir, "server-source"); const serverEntryPath = path.join(sourceDir, "apps/server/dist/bin.mjs"); const nativePath = path.join(sourceDir, "node_modules/native/addon.node"); yield* fs.makeDirectory(path.dirname(serverEntryPath), { recursive: true }); yield* fs.makeDirectory(path.dirname(nativePath), { recursive: true }); yield* fs.writeFileString(serverEntryPath, input.serverEntrySource ?? "console.log('server');\n"); yield* fs.writeFileString(nativePath, "native-binary"); const generatedAsarPath = path.join(tempDir, WINDOWS_SERVER_ASAR_RESOURCE); yield* packWindowsServerAsar({ sourceDir, asarPath: generatedAsarPath }); const stageDistDir = path.join(tempDir, "dist"); const packagedAppDir = path.join(stageDistDir, "win-unpacked"); const resourcesDir = path.join(packagedAppDir, "resources"); yield* fs.makeDirectory(path.join(resourcesDir, "resource-monitor"), { recursive: true }); yield* fs.copyFile(generatedAsarPath, path.join(resourcesDir, WINDOWS_SERVER_ASAR_RESOURCE)); if (input.copyUnpackedNatives) { yield* fs.copy( `${generatedAsarPath}.unpacked`, path.join(resourcesDir, `${WINDOWS_SERVER_ASAR_RESOURCE}.unpacked`), ); } yield* fs.writeFileString( path.join(resourcesDir, "resource-monitor/t3-resource-monitor.exe"), "monitor", ); const appExecutableName = "t3code.exe"; yield* fs.writeFileString(path.join(packagedAppDir, appExecutableName), "electron"); yield* fs.writeFileString(path.join(packagedAppDir, "chrome_crashpad_handler.exe"), "crashpad"); return { stageDistDir, packagedAppDir, sourceDir, generatedAsarPath, appExecutableName, } as const; }); it.layer(NodeServices.layer)("build-desktop-artifact", (it) => { it("resolves the dedicated nightly updater channel from nightly versions", () => { assert.equal(resolveDesktopUpdateChannel("0.0.17-nightly.20260413.42"), "nightly"); assert.equal(resolveDesktopUpdateChannel("0.0.17"), "latest"); }); it("switches desktop packaging product names to nightly for nightly builds", () => { assert.equal(resolveDesktopProductName("0.0.17"), "T3 Code (Alpha)"); assert.equal(resolveDesktopProductName("0.0.17-nightly.20260413.42"), "T3 Code (Nightly)"); }); it("switches desktop packaging icons to the nightly artwork for nightly versions", () => { assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17"), { macIconPng: BRAND_ASSET_PATHS.productionMacIconPng, linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng, windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco, }); assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17-nightly.20260413.42"), { macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng, linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng, windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco, }); }); it("switches the bundled splash and favicon branding for nightly versions", () => { assert.equal(resolveDesktopWebAssetBrand("0.0.17"), "production"); assert.equal(resolveDesktopWebAssetBrand("0.0.17-nightly.20260413.42"), "nightly"); }); it.effect("resolves GitHub desktop publish config from Effect config", () => Effect.gen(function* () { const latestConfig = yield* resolveGitHubPublishConfig("latest").pipe( Effect.provide( ConfigProvider.layer( ConfigProvider.fromEnv({ env: { T3CODE_DESKTOP_UPDATE_REPOSITORY: "pingdotgg/t3code", }, }), ), ), ); const nightlyConfig = yield* resolveGitHubPublishConfig("nightly").pipe( Effect.provide( ConfigProvider.layer( ConfigProvider.fromEnv({ env: { GITHUB_REPOSITORY: "pingdotgg/t3code", }, }), ), ), ); assert.deepStrictEqual(latestConfig, { provider: "github", owner: "pingdotgg", repo: "t3code", releaseType: "release", }); assert.deepStrictEqual(nightlyConfig, { provider: "github", owner: "pingdotgg", repo: "t3code", releaseType: "prerelease", channel: "nightly", }); }), ); it("omits bundled workspace packages from staged desktop dependencies", () => { assert.deepStrictEqual( resolveDesktopRuntimeDependencies( { "@effect/platform-node": "catalog:", "@t3tools/contracts": "workspace:*", "@t3tools/shared": "workspace:*", "@t3tools/ssh": "workspace:*", "@t3tools/tailscale": "workspace:*", effect: "catalog:", electron: "41.5.0", }, { "@effect/platform-node": "4.0.0-beta.59", effect: "4.0.0-beta.59", }, ), { "@effect/platform-node": "4.0.0-beta.59", effect: "4.0.0-beta.59", }, ); }); it("carries only staged dependency patch metadata into staged desktop installs", () => { assert.deepStrictEqual( createStagePatchedDependencies( { "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch", "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch", "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch", "alchemy@2.0.0-beta.49": "patches/alchemy@2.0.0-beta.49.patch", "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, { "@ff-labs/fff-node": "0.9.4", "@pierre/diffs": "1.1.20", effect: "4.0.0-beta.73", }, ), { "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch", "@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch", "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, ); assert.deepStrictEqual( createStagePatchedDependencies( { "@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch", }, { effect: "4.0.0-beta.73" }, ), {}, ); }); it("installs optional native dependencies for the target desktop architecture", () => { assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "x64" }), { supportedArchitectures: { os: ["darwin"], cpu: ["x64"], }, }); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "linux", arch: "x64" }), { supportedArchitectures: { os: ["linux"], cpu: ["x64"], libc: ["glibc"], }, }); // The Windows app stage only serves the desktop main process; the server // sidecar stage is the one that needs Linux natives (below). assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "x64" }), { supportedArchitectures: { os: ["win32"], cpu: ["x64"], }, }); // The server sidecar stage bundles the same-architecture WSL (Linux, // glibc) backend, so its install must fetch Linux native optional deps // (e.g. ffi-rs) too — and must be hoisted so the tree survives asar // packing and runtime extraction without symlinks. assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "win", arch: "x64", linuxServerBackend: true }), { supportedArchitectures: { os: ["win32", "linux"], cpu: ["x64"], libc: ["glibc"], }, nodeLinker: "hoisted", }, ); assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "win", arch: "arm64", linuxServerBackend: true }), { supportedArchitectures: { os: ["win32", "linux"], cpu: ["arm64"], libc: ["glibc"], }, nodeLinker: "hoisted", }, ); assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), { supportedArchitectures: { os: ["darwin"], cpu: ["arm64", "x64"], }, }); }); it("stages pnpm 11 allowBuilds and patchedDependencies in the workspace yaml", () => { assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "linux", arch: "x64", allowBuilds: { electron: true, "node-pty": true, "browser-tabs-lock": false, }, patchedDependencies: { "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, overrides: { effect: "4.0.0-beta.73", }, }), { supportedArchitectures: { os: ["linux"], cpu: ["x64"], libc: ["glibc"], }, allowBuilds: { electron: true, "node-pty": true, "browser-tabs-lock": false, }, patchedDependencies: { "effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch", }, overrides: { effect: "4.0.0-beta.73", }, }, ); // Empty maps must not be written — pnpm would still require reviewed // packages if allowBuilds is present but incomplete, and omitting empty // patchedDependencies keeps the stage yaml minimal. assert.deepStrictEqual( createStageWorkspaceConfig({ platform: "mac", arch: "arm64", allowBuilds: {}, patchedDependencies: {}, overrides: {}, }), { supportedArchitectures: { os: ["darwin"], cpu: ["arm64"], }, }, ); }); it("limits Electron locales and excludes the unused Claude SDK executable", () => { assert.deepStrictEqual(DESKTOP_ELECTRON_LANGUAGES, ["en-US"]); assert.deepStrictEqual(DESKTOP_FILE_EXCLUSIONS, [ "!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*", "!apps/desktop/prod-resources/windows-server", "!apps/desktop/prod-resources/windows-server/**/*", ]); assert.equal(WINDOWS_SERVER_RESOURCE_SOURCE_DIR, "apps/desktop/prod-resources/windows-server"); assert.deepStrictEqual(WINDOWS_SERVER_EXTRA_RESOURCES, [ { from: "apps/desktop/prod-resources/windows-server", to: ".", filter: ["server.asar", "server.asar.unpacked/**/*"], }, ]); }); it.effect("applies platform-specific packaging to the build config", () => Effect.gen(function* () { const mac = yield* createBuildConfig( "mac", "dmg", "1.2.3", false, false, undefined, undefined, ); const linux = yield* createBuildConfig( "linux", "AppImage", "1.2.3", false, false, undefined, undefined, ); const win = yield* createBuildConfig( "win", "nsis", "1.2.3", false, false, undefined, undefined, ); // All platforms keep app.asar fully packed; Windows ships the server // tree as the hand-packed server.asar sidecar in extraResources instead // of unpacking thousands of loose files at install time. assert.notProperty(mac, "asarUnpack"); assert.notProperty(linux, "asarUnpack"); assert.notProperty(win, "asarUnpack"); assert.deepStrictEqual(win.extraResources, [ { from: "apps/desktop/prod-resources/resource-monitor", to: "resource-monitor", }, ...WINDOWS_SERVER_EXTRA_RESOURCES, ]); assert.deepStrictEqual(win.nsis, { differentialPackage: true }); // Native binaries and helper executables cannot load from inside an // asar; everything else stays packed. The Claude SDK platform packages // and .bin shims never ship. assert.equal( WINDOWS_SERVER_ASAR_UNPACK_GLOB, "{**/*.node,**/*.dll,**/*.exe,**/*.so,**/*.so.*,**/*.dylib}", ); assert.deepStrictEqual(WINDOWS_SERVER_ASAR_IGNORE_GLOBS, [ "**/node_modules/@anthropic-ai/claude-agent-sdk-*", "**/node_modules/@anthropic-ai/claude-agent-sdk-*/**", "**/node_modules/.bin", "**/node_modules/.bin/**", ]); assert.deepStrictEqual(mac.dmg, { title: "T3 Code (Alpha) 1.2.3 Installer", background: "dmg/dmg-background-latest.png", window: { width: 540, height: 412 }, contents: [ { x: 130, y: 220, type: "file" }, { x: 410, y: 220, type: "link", path: "/Applications" }, ], iconSize: 80, iconTextSize: 12, }); // Linux must register the renderer schemes so the generated .desktop // entry advertises MimeType=x-scheme-handler/t3code; for OAuth deep links. assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [ { name: "T3 Code", schemes: ["t3code", "t3code-dev"] }, ]); for (const config of [mac, linux, win]) { assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES); assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS); } }).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))), ); it.effect("validates every ASAR-unpacked native in the packaged Windows payload", () => Effect.scoped( Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true }); const result = yield* validateWindowsPackagedPayload({ stageDistDir: fixture.stageDistDir, appExecutableName: fixture.appExecutableName, targetArch: "x64",