From d12c3b37da8207c300d690a6e83543f62c1547f6 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza Date: Fri, 7 Aug 2026 18:07:42 -0300 Subject: [PATCH] fix: resolve two macOS-only test/script failures in unit suite (#8577) bin/restore-policies.sh used readarray (bash 4+), which fails on macOS bash 3.2. Replace with a compatible while-read loop. machineId.test.ts disableWindowsRegistryStrategy() did not neutralize the macOS ioreg strategy, so mocked os.hostname() was never reached on macOS and both ladder tests failed. Stub execSync for ioreg commands so the fallback chain reaches os.hostname() as intended. Production src/shared/utils/machineId.ts is correct and unchanged. Co-authored-by: diegosouzapw --- bin/restore-policies.sh | 3 ++- changelog.d/fixes/8577-fix.plan.md | 2 ++ tests/unit/shared/machineId.test.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fixes/8577-fix.plan.md diff --git a/bin/restore-policies.sh b/bin/restore-policies.sh index de1c2608aa..4472fb601f 100755 --- a/bin/restore-policies.sh +++ b/bin/restore-policies.sh @@ -39,7 +39,8 @@ snap="$(ops_find_snapshot "$ID")" # Policy definition tables present in BOTH the snapshot and the live DB. GLOB # keeps `_` literal; we drop usage counters / logs so accounting isn't rewound. -readarray -t tables < <( +tables=() +while IFS= read -r t; do tables+=("$t"); done < <( sqlite3 "$snap/storage.sqlite" \ "SELECT name FROM sqlite_master WHERE type='table' AND name GLOB 'api_key*' \ AND name NOT GLOB '*counter*' AND name NOT GLOB '*_log*' ORDER BY name;" diff --git a/changelog.d/fixes/8577-fix.plan.md b/changelog.d/fixes/8577-fix.plan.md new file mode 100644 index 0000000000..2b7b175101 --- /dev/null +++ b/changelog.d/fixes/8577-fix.plan.md @@ -0,0 +1,2 @@ +- fix(tests): make machineId tests macOS-compatible by stubbing ioreg in test helper (#8577) +- fix(scripts): replace bash 4+ readarray with compatible while-read loop in restore-policies.sh (#8577) diff --git a/tests/unit/shared/machineId.test.ts b/tests/unit/shared/machineId.test.ts index 46bc5441ae..cde9b9a4f6 100644 --- a/tests/unit/shared/machineId.test.ts +++ b/tests/unit/shared/machineId.test.ts @@ -38,6 +38,14 @@ function disableWindowsRegistryStrategy(): () => void { return origReadFileSync(filePath, encoding); }; + const origExecSync = childProcess.execSync; + childProcess.execSync = ((cmd: Parameters[0], opts: Parameters[1]) => { + if (String(cmd ?? "").includes("ioreg")) { + throw new Error("ENOENT: mocked ioreg not available"); + } + return origExecSync(cmd, opts); + }) as typeof childProcess.execSync; + return () => { if (origSysRoot !== undefined) { process.env.SystemRoot = origSysRoot; @@ -50,6 +58,7 @@ function disableWindowsRegistryStrategy(): () => void { delete process.env.windir; } fs.readFileSync = origReadFileSync; + childProcess.execSync = origExecSync; }; }