-
-
Notifications
You must be signed in to change notification settings - Fork 35
Fix: Update remote system detection command for Windows compatibility #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughUpdates tests and plugin logic: switch Windows detection command to "cmd /c ver 2>$null" in plugin and tests; adjust one Windows path test to pass input via an args struct literal. No production control flow or exported APIs changed. Changes
Sequence Diagram(s)sequenceDiagram
participant U as Caller
participant P as Plugin (Exec / removeAllDestFile)
participant S as SSH
participant H as Remote Host
U->>P: Execute operation
P->>S: Run "cmd /c ver 2>$null"
S->>H: Execute command
H-->>S: Exit status
S-->>P: Result (success/failure)
alt Windows detected (success)
P->>H: Run Windows-specific commands
else Unix (failure)
P->>H: Run Unix-specific commands
end
P-->>U: Return result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @MrHIDEn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a compatibility issue where Windows system detection failed on servers configured with PowerShell as the default SSH shell. The core change involves modifying the command used for system detection to explicitly invoke the ver
command via cmd /c
, ensuring it runs correctly in all Windows SSH environments. This change significantly improves the reliability of system type detection on Windows servers, preventing incorrect failures and enhancing overall compatibility.
Highlights
- Improved Windows System Detection: The
ssh.Run
command for detecting Windows systems has been updated fromver
tocmd /c ver 2>$null
. This ensures that thever
command is executed within the Windows Command Prompt environment, regardless of whether PowerShell is the default SSH shell, resolving issues where system detection previously failed. - Suppressed Error Output: The updated command
cmd /c ver 2>$null
includes2>$null
to redirect standard error output to null. This suppresses any potential error messages or noise in logs that might arise from the command execution, leading to cleaner output. - Consistency in Test Code: The same fix applied to
plugin.go
has also been consistently applied toplugin_test.go
. This ensures that the test environment accurately reflects the production changes and maintains consistency across the codebase.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses the Windows system detection issue by using cmd /c ver
to ensure compatibility with different SSH shell configurations. The change is applied consistently across the codebase and tests.
My main feedback is to refactor the duplicated command string "cmd /c ver 2>$null"
into a shared constant. This will improve maintainability and ensure that any future changes to the detection command are applied everywhere. I've left specific comments on the affected lines.
I also noticed a small fix in path_windows_test.go
that wasn't mentioned in the description. While the fix is correct, it's generally best practice to keep pull requests focused on a single logical change to maintain a clean history.
@@ -147,7 +147,7 @@ func (p *Plugin) removeAllDestFile() error { | |||
}, | |||
} | |||
|
|||
_, _, _, err := ssh.Run("ver", p.Config.CommandTimeout) | |||
_, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command string "cmd /c ver 2>$null"
is also used on line 295 and in plugin_test.go
. To improve maintainability and avoid magic strings, consider defining it as an exported constant at the package level. This makes the command's purpose clearer and centralizes it for future changes.
For example, you could add:
const WindowsDetectCmd = "cmd /c ver 2>$null"
Then, you can use WindowsDetectCmd
in all three locations.
@@ -292,7 +292,7 @@ func (p *Plugin) Exec() error { | |||
} | |||
|
|||
systemType := "unix" | |||
_, _, _, err := ssh.Run("ver", p.Config.CommandTimeout) | |||
_, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -571,7 +571,7 @@ func TestRemoveDestFile(t *testing.T) { | |||
DestFile: "/etc/resolv.conf", | |||
} | |||
|
|||
_, _, _, err := ssh.Run("ver", plugin.Config.CommandTimeout) | |||
_, _, _, err := ssh.Run("cmd /c ver 2>$null", plugin.Config.CommandTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed test case structure where string was passed directly instead of being wrapped in args struct, which caused build failure.
The current Windows system detection uses a simple `ver` command which fails on Windows servers where PowerShell is configured as the default SSH shell. The `ver` command is only available in CMD, not in PowerShell, causing system detection to fail incorrectly.
11abda8
to
3a7e69a
Compare
@@ -15,7 +15,7 @@ func TestGetRealPath(t *testing.T) { | |||
}{ | |||
{ | |||
"Test Windows Path", | |||
"C:\\Users\\appleboy\\test.txt", | |||
args{"C:\\Users\\appleboy\\test.txt"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: resolve compilation error in path_windows_test.go
Fixed test case structure where string was passed directly instead of
being wrapped in args struct, which caused build failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
plugin_test.go (1)
574-578
: Keep test and implementation in sync by centralizing the detection commandGood update. To avoid future drift between tests and implementation, consider referencing a single helper (or const) for the Windows-detection command. This also makes later tweaks (e.g., swapping to cmd.exe) one-line changes.
Apply this diff here:
- _, _, _, err := ssh.Run("cmd /c ver 2>$null", plugin.Config.CommandTimeout) + _, _, _, err := ssh.Run(windowsDetectCmd(), plugin.Config.CommandTimeout)And add this helper in production code (see suggested change in plugin.go comments) so both places use the same source of truth.
plugin.go (2)
150-154
: Solid fix for PowerShell default shell; de-duplicate and make the command explicitUpdating to run via cmd solves the PowerShell default-shell issue. Two suggestions:
- Extract the detection command into a helper to avoid duplication and test drift.
- Use cmd.exe explicitly for robustness.
Apply this diff here:
- _, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout) + _, _, _, err := ssh.Run(windowsDetectCmd(), p.Config.CommandTimeout)And similarly in the other call site (see below). Then add this helper (outside the shown range):
// windowsDetectCmd returns the cross-shell Windows detection command. // Explicitly invoke cmd.exe so it works when the default shell is PowerShell. func windowsDetectCmd() string { return "cmd.exe /c ver 2>$null" }Note: The 2>$null redirection is PowerShell-friendly. Under pure cmd, it may create or touch a file named "$null". If that side-effect is a concern, we can discuss alternatives, but this keeps your current behavior while improving reliability.
295-298
: Apply the same centralization hereMirror the previous suggestion to keep a single source of truth for the detection command.
Apply this diff:
- _, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout) + _, _, _, err := ssh.Run(windowsDetectCmd(), p.Config.CommandTimeout)path_windows_test.go (1)
17-20
: Use keyed struct literal for clarity and resilience to field reorderingMinor test readability nit: prefer keyed fields in table-driven tests.
Apply this diff:
- "Test Windows Path", - args{"C:\\Users\\appleboy\\test.txt"}, - "/C/Users/appleboy/test.txt", + "Test Windows Path", + args{path: "C:\\Users\\appleboy\\test.txt"}, + "/C/Users/appleboy/test.txt",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
path_windows_test.go
(1 hunks)plugin.go
(2 hunks)plugin_test.go
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
plugin_test.go (1)
plugin.go (1)
Config
(27-52)
@@ -147,7 +147,7 @@ func (p *Plugin) removeAllDestFile() error { | |||
}, | |||
} | |||
|
|||
_, _, _, err := ssh.Run("ver", p.Config.CommandTimeout) | |||
_, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execute Windows version command through CMD explicitly
This ensures compatibility when PowerShell is the default SSH shell,
as 'ver' command only exists in CMD, not PowerShell
Problem
The current Windows system detection uses a simple
ver
command which fails on Windows servers where PowerShell is configured as the default SSH shell. Thever
command is only available in CMD, not in PowerShell, causing system detection to fail incorrectly.Solution
Updated all instances of
ssh.Run("ver", ...)
to usessh.Run("cmd /c ver 2>$null", ...)
which:cmd /c
to ensure the command runs in the Windows Command Prompt regardless of the default SSH shell2>$null
to prevent error noise in logsChanges Made
Files Modified
Testing
Impact
This change improves compatibility with Windows servers that use PowerShell as the default SSH shell, ensuring reliable system type detection across different Windows SSH configurations.
Summary by CodeRabbit
Bug Fixes
Tests