Skip to content

Commit 6a0d688

Browse files
committed
fix(macos): derive macOS version from Darwin kernel in fallback path
When sw_vers -productVersion is unavailable (CI, containers), derive the macOS version from the Darwin kernel major version using the known mapping (Darwin 12-24 = macOS major - 9). Darwin 25+ (macOS 26 Tahoe) no longer follows this formula, so return the raw kernel version. Fixes #95145
1 parent 934e825 commit 6a0d688

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/infra/os-summary.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ const cachedOsSummaryByKey = new Map<string, OsSummary>();
1515
function macosVersion(): string {
1616
const res = spawnSync("sw_vers", ["-productVersion"], { encoding: "utf-8" });
1717
const out = normalizeOptionalString(res.stdout) ?? "";
18-
return out || os.release();
18+
if (out) return out;
19+
// Fallback: derive macOS version from Darwin kernel (os.release()).
20+
// Darwin 12-24 → macOS (major - 9), e.g. Darwin 24 = macOS 15
21+
// Darwin 25+ → formula broke (macOS 26 Tahoe uses Darwin 25, not 16)
22+
const release = os.release();
23+
const major = parseInt(release.split(".")[0], 10);
24+
if (!isNaN(major) && major >= 12 && major <= 24) {
25+
return `${major - 9}.0`;
26+
}
27+
// Darwin 25+ or unknown: return raw version labeled clearly (#95145)
28+
return release;
1929
}
2030

2131
/** Resolves a compact OS label for diagnostics, logs, and environment summaries. */

src/infra/system-presence.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ function initSelfPresence() {
6969
encoding: "utf-8",
7070
});
7171
const out = normalizeOptionalString(res.stdout) ?? "";
72-
return out.length > 0 ? out : os.release();
72+
if (out) return out;
73+
const release = os.release();
74+
const major = parseInt(release.split(".")[0], 10);
75+
if (!isNaN(major) && major >= 12 && major <= 24) {
76+
return `${major - 9}.0`;
77+
}
78+
return release;
7379
};
7480
const platform = (() => {
7581
const p = os.platform();

0 commit comments

Comments
 (0)