This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: handle PowerShell ENOENT error in os-name on Windows #9897
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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") | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.