diff --git a/changelog.d/fixes/10244-cliproxy-installer-windows-platform-detection.md b/changelog.d/fixes/10244-cliproxy-installer-windows-platform-detection.md new file mode 100644 index 0000000000..bdc134b990 --- /dev/null +++ b/changelog.d/fixes/10244-cliproxy-installer-windows-platform-detection.md @@ -0,0 +1 @@ +- **fix(cliproxy):** read platform/arch at runtime via `os.platform()`/`os.arch()` in `binaryManager` so the embedded installer selects the Windows/ARM assets even when the release bundle is built on a Linux runner (fixes #10244) \ No newline at end of file diff --git a/src/lib/versionManager/binaryManager.ts b/src/lib/versionManager/binaryManager.ts index eec36ab3cb..c77ac0a79f 100644 --- a/src/lib/versionManager/binaryManager.ts +++ b/src/lib/versionManager/binaryManager.ts @@ -16,7 +16,7 @@ type Platform = "linux" | "darwin" | "windows" | "freebsd"; type Arch = "amd64" | "arm64"; function detectPlatform(): Platform { - const p = process.platform; + const p = os.platform(); if (p === "linux") return "linux"; if (p === "darwin") return "darwin"; if (p === "win32") return "windows"; @@ -24,7 +24,7 @@ function detectPlatform(): Platform { } function detectArch(): Arch { - const a = process.arch; + const a = os.arch(); if (a === "x64") return "amd64"; if (a === "arm64") return "arm64"; return "amd64"; diff --git a/tests/unit/binaryManager.test.ts b/tests/unit/binaryManager.test.ts index dd0acba78b..188bcc3348 100644 --- a/tests/unit/binaryManager.test.ts +++ b/tests/unit/binaryManager.test.ts @@ -1,4 +1,4 @@ -import { describe, it, afterEach, after } from "node:test"; +import { describe, it, afterEach, after, mock } from "node:test"; import assert from "node:assert/strict"; import path from "node:path"; import fs from "node:fs"; @@ -63,6 +63,22 @@ describe("binaryManager", () => { assert.ok(["linux", "darwin", "windows"].includes(platform)); assert.ok(["amd64", "arm64"].includes(arch)); }); + + it("should read platform/arch at runtime from os (anti build-folding guard) (#10244)", () => { + // Regression guard for #10244/#10293: detectPlatform/detectArch must read + // os.platform()/os.arch() at call time, NOT the build-machine foldable + // process.platform/process.arch constants. Turbopack `next build` running + // on Linux constant-folds `process.platform` and prunes every Windows/arm64 + // branch from the published npm artifact. Simulate a Windows arm64 host via + // the runtime os.* functions; the Windows/arm64 branch must be reachable. + mock.method(os, "platform", () => "win32"); + mock.method(os, "arch", () => "arm64"); + assert.deepEqual(mod.getTargetPlatform(), { platform: "windows", arch: "arm64" }); + assert.equal( + mod.getAssetName(), + "CLIProxyAPI_{version}_windows_arm64.zip" + ); + }); }); describe("getCurrentBinaryPath", () => {