Skip to content

Commit b2f2220

Browse files
committed
fix: preserve non-darwin runtime os strings
1 parent fb4923c commit b2f2220

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/infra/os-summary.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,19 @@ describe("resolveOsRuntimeName", () => {
116116
expect(resolveOsRuntimeName()).toBe("macos 26.5.1");
117117
});
118118

119-
it("keeps non-darwin runtime names on os metadata", () => {
119+
it("keeps non-darwin runtime names on os.type metadata", () => {
120120
vi.spyOn(os, "platform").mockReturnValue("linux");
121+
vi.spyOn(os, "type").mockReturnValue("Linux");
121122
vi.spyOn(os, "release").mockReturnValue("6.8.0");
122123

123-
expect(resolveOsRuntimeName()).toBe("linux 6.8.0");
124+
expect(resolveOsRuntimeName()).toBe("Linux 6.8.0");
125+
});
126+
127+
it("keeps Windows runtime names on os.type metadata", () => {
128+
vi.spyOn(os, "platform").mockReturnValue("win32");
129+
vi.spyOn(os, "type").mockReturnValue("Windows_NT");
130+
vi.spyOn(os, "release").mockReturnValue("10.0.26100");
131+
132+
expect(resolveOsRuntimeName()).toBe("Windows_NT 10.0.26100");
124133
});
125134
});

src/infra/os-summary.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function macosVersion(): string {
2323
export function resolveOsRuntimeName(): string {
2424
const platform = os.platform();
2525
const release = os.release();
26-
const cacheKey = `${platform}\0${release}`;
26+
const type = os.type();
27+
const cacheKey = `${platform}\0${type}\0${release}`;
2728
const cached = cachedOsRuntimeNameByKey.get(cacheKey);
2829
if (cached) {
2930
return cached;
@@ -32,10 +33,7 @@ export function resolveOsRuntimeName(): string {
3233
if (platform === "darwin") {
3334
return `macos ${macosVersion()}`;
3435
}
35-
if (platform === "win32") {
36-
return `windows ${release}`;
37-
}
38-
return `${platform} ${release}`;
36+
return `${type} ${release}`;
3937
})();
4038
cachedOsRuntimeNameByKey.set(cacheKey, runtimeName);
4139
return runtimeName;
@@ -53,7 +51,15 @@ export function resolveOsSummary(): OsSummary {
5351
if (cached) {
5452
return cached;
5553
}
56-
const label = `${resolveOsRuntimeName()} (${arch})`;
54+
const label = (() => {
55+
if (platform === "darwin") {
56+
return `macos ${macosVersion()} (${arch})`;
57+
}
58+
if (platform === "win32") {
59+
return `windows ${release} (${arch})`;
60+
}
61+
return `${platform} ${release} (${arch})`;
62+
})();
5763
const summary = { platform, arch, release, label };
5864
cachedOsSummaryByKey.set(cacheKey, summary);
5965
return summary;

0 commit comments

Comments
 (0)