Skip to content

Commit d06a98c

Browse files
LouisCltclaude
andcommitted
fix(prompts): fall back when the OS lookup throws
Move the Windows os.version() branch inside the same try as the os-name call, so both platforms use the platform and release fallback if the lookup throws. Cover a throwing os.version() on win32 next to the existing os-name case, with it.each. Refs #2448 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6089bdb commit d06a98c

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

‎src/core/prompts/sections/__tests__/system-info.spec.ts‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,38 @@ describe("getSystemInfoSection", () => {
4848
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
4949
})
5050

51-
it("should fallback to platform and release when os-name throws error", () => {
52-
mockOsName.mockImplementation(() => {
53-
throw new Error("Command failed with ENOENT: powershell")
54-
})
51+
it.each([
52+
{
53+
platform: "linux" as const,
54+
release: "5.15.0",
55+
makeLookupThrow: () =>
56+
mockOsName.mockImplementation(() => {
57+
throw new Error("Command failed with ENOENT: powershell")
58+
}),
59+
},
60+
{
61+
platform: "win32" as const,
62+
release: "10.0.26300",
63+
makeLookupThrow: () =>
64+
vi.spyOn(os, "version").mockImplementation(() => {
65+
throw new Error("uv_os_uname failed")
66+
}),
67+
},
68+
])(
69+
"falls back to platform and release when the OS lookup throws on $platform",
70+
({ platform, release, makeLookupThrow }) => {
71+
vi.spyOn(os, "platform").mockReturnValue(platform)
72+
vi.spyOn(os, "release").mockReturnValue(release)
73+
makeLookupThrow()
5574

56-
const result = getSystemInfoSection(mockCwd, policyFor())
75+
const result = getSystemInfoSection(mockCwd, policyFor())
5776

58-
expect(result).toContain("Operating System: linux 5.15.0")
59-
expect(result).toContain("Default Shell: /bin/bash")
60-
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
61-
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
62-
})
77+
expect(result).toContain(`Operating System: ${platform} ${release}`)
78+
expect(result).toContain("Default Shell: /bin/bash")
79+
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
80+
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
81+
},
82+
)
6383

6484
describe("on Windows", () => {
6585
beforeEach(() => {

‎src/core/prompts/sections/system-info.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import type { EffectiveToolPolicy } from "../tools/effective-tool-policy"
1616
function getOsInfo(): string {
1717
const fallback = `${os.platform()} ${os.release()}`
1818

19-
if (os.platform() === "win32") {
20-
return os.version() || fallback
21-
}
22-
2319
try {
20+
if (os.platform() === "win32") {
21+
return os.version() || fallback
22+
}
23+
2424
return osName()
2525
} catch {
2626
return fallback

0 commit comments

Comments
 (0)