From cce3a958b5a0841b6ec47c3552eebb508b713376 Mon Sep 17 00:00:00 2001 From: Koosha Paridehpour <42529354+KooshaPari@users.noreply.github.com> Date: Mon, 14 Sep 2026 19:25:33 -0700 Subject: [PATCH] fix(tests): add DISABLE_IOREG_STRATEGY env var for macOS test compatibility (fixes #13467) (#13539) Adds a `DISABLE_IOREG_STRATEGY=1` escape hatch to the macOS `ioreg` strategy in `getMachineIdRaw()`, so `machineId.test.ts` can reach the fallback strategies on darwin instead of always resolving the real hardware UUID (#13467). Maintainer note: this branch also carried the "force passed=false when upstream call failed" eval commit, which already landed in #13413. The branch was reset to the current release tip plus only the ioreg commit (authorship preserved) so the squash carries just this change. Validated in one consolidated batch of this series (37 PRs boarded together on `release/v3.8.51`): `typecheck:core`, `check:open-sse-typecheck` and `check:dashboard-typecheck` clean; ESLint clean on every changed file; file-size, complexity, cognitive-complexity, changelog-integrity, docs-counts, docs-sync and migration-numbering gates green (only the pre-existing `open-sse/utils/stream.ts` file-size red remains, inherited from the base); 3,743 focused `node:test` cases plus 34 vitest cases green. Thanks @KooshaPari! --- src/shared/utils/machineId.ts | 5 +++-- tests/unit/shared/machineId.test.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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; };