Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2
3import { getDefaultBuildArch, resolveHostProcessArch } from "./build-target-arch.ts";
4
5describe("build-target-arch", () => {
6 it("prefers arm64 for Windows-on-Arm hosts running x64 emulation", () => {
7 // Windows-on-Arm can run an x64 Node process under emulation while still
8 // exposing the real host CPU via PROCESSOR_ARCHITEW6432.
9 const hostArch = resolveHostProcessArch("win32", "x64", {
10 PROCESSOR_ARCHITECTURE: "AMD64", // The currently running Node process is x64.
11 PROCESSOR_ARCHITEW6432: "ARM64", // Windows exposes the real host CPU here when x64 runs under ARM emulation.
12 });
13
14 assert.equal(hostArch, "arm64");
15 });
16
17 it("falls back to x64 for native x64 Windows hosts", () => {
18 const hostArch = resolveHostProcessArch("win32", "x64", {
19 PROCESSOR_ARCHITECTURE: "AMD64", // Both the process and the Windows host are native x64.
20 });
21
22 assert.equal(hostArch, "x64");
23 });
24
25 it("keeps arm64 when the current process is already native arm64", () => {
26 const hostArch = resolveHostProcessArch("win32", "arm64", {});
27
28 assert.equal(hostArch, "arm64");
29 });
30
31 it("uses the resolved host arch when selecting the default Windows build arch", () => {
32 // This mirrors the packaging script's default-path behavior: the current
33 // process is x64, but the machine itself is ARM64, so the default build
34 // target should be win-arm64 rather than win-x64.
35 const arch = getDefaultBuildArch(
36 "win",
37 "x64",
38 {
39 PROCESSOR_ARCHITECTURE: "AMD64", // The currently running Node process is x64.
40 PROCESSOR_ARCHITEW6432: "ARM64", // The process is x64, but the actual Windows host is ARM64.
41 },
42 { archChoices: ["x64", "arm64"] },
43 );
44
45 assert.equal(arch, "arm64");
46 });
47
48 it("does not apply Windows host env heuristics for non-Windows targets", () => {
49 const arch = getDefaultBuildArch(
50 "linux",
51 "x64",
52 {
53 PROCESSOR_ARCHITECTURE: "AMD64",
54 PROCESSOR_ARCHITEW6432: "ARM64",
55 },
56 { archChoices: ["x64", "arm64"] },
57 );
58
59 assert.equal(arch, "x64");
60 });
61});