Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit d7d3f40

Browse files
roomote[bot]roomote
andauthored
fix: handle PowerShell ENOENT error in os-name on Windows (#9897)
Co-authored-by: Roo Code <roomote@roocode.com>
1 parent 43f7ce0 commit d7d3f40

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os from "os"
2+
3+
// Mock the modules - must be hoisted before imports
4+
vi.mock("os-name", () => ({
5+
default: vi.fn(),
6+
}))
7+
8+
vi.mock("../../../../utils/shell", () => ({
9+
getShell: vi.fn(() => "/bin/bash"),
10+
}))
11+
12+
import { getSystemInfoSection } from "../system-info"
13+
import osName from "os-name"
14+
15+
const mockOsName = osName as unknown as ReturnType<typeof vi.fn>
16+
17+
describe("getSystemInfoSection", () => {
18+
const mockCwd = "/test/workspace"
19+
const mockHomeDir = "/home/user"
20+
21+
beforeEach(() => {
22+
vi.spyOn(os, "homedir").mockReturnValue(mockHomeDir)
23+
vi.spyOn(os, "platform").mockReturnValue("linux" as any)
24+
vi.spyOn(os, "release").mockReturnValue("5.15.0")
25+
})
26+
27+
afterEach(() => {
28+
vi.clearAllMocks()
29+
})
30+
31+
it("should return system info with os-name when available", () => {
32+
mockOsName.mockReturnValue("Ubuntu 22.04")
33+
34+
const result = getSystemInfoSection(mockCwd)
35+
36+
expect(result).toContain("Operating System: Ubuntu 22.04")
37+
expect(result).toContain("Default Shell: /bin/bash")
38+
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
39+
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
40+
})
41+
42+
it("should fallback to platform and release when os-name throws error", () => {
43+
mockOsName.mockImplementation(() => {
44+
throw new Error("Command failed with ENOENT: powershell")
45+
})
46+
47+
const result = getSystemInfoSection(mockCwd)
48+
49+
expect(result).toContain("Operating System: linux 5.15.0")
50+
expect(result).toContain("Default Shell: /bin/bash")
51+
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
52+
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
53+
})
54+
55+
it("should handle Windows platform in fallback", () => {
56+
mockOsName.mockImplementation(() => {
57+
throw new Error("Command failed with ENOENT: powershell")
58+
})
59+
vi.spyOn(os, "platform").mockReturnValue("win32" as any)
60+
vi.spyOn(os, "release").mockReturnValue("10.0.19043")
61+
62+
const result = getSystemInfoSection(mockCwd)
63+
64+
expect(result).toContain("Operating System: win32 10.0.19043")
65+
})
66+
})

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ import osName from "os-name"
44
import { getShell } from "../../../utils/shell"
55

66
export function getSystemInfoSection(cwd: string): string {
7+
// Try to get detailed OS name, fall back to basic info if it fails
8+
let osInfo: string
9+
try {
10+
osInfo = osName()
11+
} catch (error) {
12+
// Fallback when os-name fails (e.g., PowerShell not available on Windows)
13+
const platform = os.platform()
14+
const release = os.release()
15+
osInfo = `${platform} ${release}`
16+
}
17+
718
let details = `====
819
920
SYSTEM INFORMATION
1021
11-
Operating System: ${osName()}
22+
Operating System: ${osInfo}
1223
Default Shell: ${getShell()}
1324
Home Directory: ${os.homedir().toPosix()}
1425
Current Workspace Directory: ${cwd.toPosix()}

0 commit comments

Comments
 (0)