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!
This commit is contained in:
Koosha Paridehpour
2026-09-14 19:25:33 -07:00
committed by GitHub
parent 222fe4314e
commit cce3a958b5
2 changed files with 12 additions and 2 deletions

View File

@@ -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",

View File

@@ -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;
};