mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-07 02:58:15 +00:00
fix: handle PowerShell ENOENT error in os-name on Windows (#9897)
Co-authored-by: Roo Code <roomote@roocode.com>
This commit is contained in:
parent
43f7ce025f
commit
d7d3f4099b
2 changed files with 78 additions and 1 deletions
66
src/core/prompts/sections/__tests__/system-info.spec.ts
Normal file
66
src/core/prompts/sections/__tests__/system-info.spec.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import os from "os"
|
||||
|
||||
// Mock the modules - must be hoisted before imports
|
||||
vi.mock("os-name", () => ({
|
||||
default: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock("../../../../utils/shell", () => ({
|
||||
getShell: vi.fn(() => "/bin/bash"),
|
||||
}))
|
||||
|
||||
import { getSystemInfoSection } from "../system-info"
|
||||
import osName from "os-name"
|
||||
|
||||
const mockOsName = osName as unknown as ReturnType<typeof vi.fn>
|
||||
|
||||
describe("getSystemInfoSection", () => {
|
||||
const mockCwd = "/test/workspace"
|
||||
const mockHomeDir = "/home/user"
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(os, "homedir").mockReturnValue(mockHomeDir)
|
||||
vi.spyOn(os, "platform").mockReturnValue("linux" as any)
|
||||
vi.spyOn(os, "release").mockReturnValue("5.15.0")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it("should return system info with os-name when available", () => {
|
||||
mockOsName.mockReturnValue("Ubuntu 22.04")
|
||||
|
||||
const result = getSystemInfoSection(mockCwd)
|
||||
|
||||
expect(result).toContain("Operating System: Ubuntu 22.04")
|
||||
expect(result).toContain("Default Shell: /bin/bash")
|
||||
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
|
||||
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
|
||||
})
|
||||
|
||||
it("should fallback to platform and release when os-name throws error", () => {
|
||||
mockOsName.mockImplementation(() => {
|
||||
throw new Error("Command failed with ENOENT: powershell")
|
||||
})
|
||||
|
||||
const result = getSystemInfoSection(mockCwd)
|
||||
|
||||
expect(result).toContain("Operating System: linux 5.15.0")
|
||||
expect(result).toContain("Default Shell: /bin/bash")
|
||||
expect(result).toContain(`Home Directory: ${mockHomeDir}`)
|
||||
expect(result).toContain(`Current Workspace Directory: ${mockCwd}`)
|
||||
})
|
||||
|
||||
it("should handle Windows platform in fallback", () => {
|
||||
mockOsName.mockImplementation(() => {
|
||||
throw new Error("Command failed with ENOENT: powershell")
|
||||
})
|
||||
vi.spyOn(os, "platform").mockReturnValue("win32" as any)
|
||||
vi.spyOn(os, "release").mockReturnValue("10.0.19043")
|
||||
|
||||
const result = getSystemInfoSection(mockCwd)
|
||||
|
||||
expect(result).toContain("Operating System: win32 10.0.19043")
|
||||
})
|
||||
})
|
||||
|
|
@ -4,11 +4,22 @@ import osName from "os-name"
|
|||
import { getShell } from "../../../utils/shell"
|
||||
|
||||
export function getSystemInfoSection(cwd: string): string {
|
||||
// Try to get detailed OS name, fall back to basic info if it fails
|
||||
let osInfo: string
|
||||
try {
|
||||
osInfo = osName()
|
||||
} catch (error) {
|
||||
// Fallback when os-name fails (e.g., PowerShell not available on Windows)
|
||||
const platform = os.platform()
|
||||
const release = os.release()
|
||||
osInfo = `${platform} ${release}`
|
||||
}
|
||||
|
||||
let details = `====
|
||||
|
||||
SYSTEM INFORMATION
|
||||
|
||||
Operating System: ${osName()}
|
||||
Operating System: ${osInfo}
|
||||
Default Shell: ${getShell()}
|
||||
Home Directory: ${os.homedir().toPosix()}
|
||||
Current Workspace Directory: ${cwd.toPosix()}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue