diff --git a/src/shared/utils/machineId.ts b/src/shared/utils/machineId.ts index db0dfad80e..1b4837aad4 100644 --- a/src/shared/utils/machineId.ts +++ b/src/shared/utils/machineId.ts @@ -57,9 +57,10 @@ function getMachineIdRaw(): string { } // Strategy 2: macOS — ioreg IOPlatformUUID + // Skip when DISABLE_IOREG_STRATEGY=1 so tests can reach Strategy 4/5 on darwin. try { - if (process.platform !== "darwin") { - throw new Error("Not macOS"); + if (process.platform !== "darwin" || process.env.DISABLE_IOREG_STRATEGY === "1") { + throw new Error("Not macOS or ioreg disabled"); } const output = execSync("ioreg -rd1 -c IOPlatformExpertDevice", { encoding: "utf8", diff --git a/tests/unit/shared/machineId.test.ts b/tests/unit/shared/machineId.test.ts index cde9b9a4f6..97cc7b7b05 100644 --- a/tests/unit/shared/machineId.test.ts +++ b/tests/unit/shared/machineId.test.ts @@ -30,6 +30,10 @@ function disableWindowsRegistryStrategy(): () => void { process.env.SystemRoot = "Z:\\NonExistent"; process.env.windir = "Z:\\NonExistent"; + // Also disable macOS ioreg strategy so Strategy 4/5 can be reached on darwin. + const origDisableIoreg = process.env.DISABLE_IOREG_STRATEGY; + process.env.DISABLE_IOREG_STRATEGY = "1"; + const origReadFileSync = fs.readFileSync; fs.readFileSync = (filePath: string, encoding: string) => { if (filePath === "/etc/machine-id" || filePath === "/var/lib/dbus/machine-id") { @@ -57,6 +61,11 @@ function disableWindowsRegistryStrategy(): () => void { } else { delete process.env.windir; } + if (origDisableIoreg !== undefined) { + process.env.DISABLE_IOREG_STRATEGY = origDisableIoreg; + } else { + delete process.env.DISABLE_IOREG_STRATEGY; + } fs.readFileSync = origReadFileSync; childProcess.execSync = origExecSync; };