Skip to content

Conversation

MrHIDEn
Copy link

@MrHIDEn MrHIDEn commented Aug 17, 2025

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. The ver command is only available in CMD, not in PowerShell, causing system detection to fail incorrectly.

Solution

Updated all instances of ssh.Run("ver", ...) to use ssh.Run("cmd /c ver 2>$null", ...) which:

  • Explicitly invokes CMD: Uses cmd /c to ensure the command runs in the Windows Command Prompt regardless of the default SSH shell
  • Suppresses error output: Redirects stderr to null with 2>$null to prevent error noise in logs
  • Maintains compatibility: Preserves the existing system detection logic while improving reliability

Changes Made

  • plugin.go: Updated 2 instances of Windows system detection calls
  • plugin_test.go: Updated 1 instance in test code to maintain consistency

Files Modified

plugin.go (lines 150, 295)
plugin_test.go (line 574)

Testing

  • All existing unit tests pass
  • System detection logic remains unchanged
  • Error handling behavior is preserved

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

    • Improved remote OS detection on Windows hosts to reduce noisy logs and make detection more reliable across mixed environments.
  • Tests

    • Updated a table-driven test to use the standardized argument struct format for consistency; no behavioral changes.

Copy link

coderabbitai bot commented Aug 17, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Updates 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

Cohort / File(s) Summary
Windows OS detection command
plugin.go, plugin_test.go
Replace remote OS detection command from "ver" to "cmd /c ver 2>$null" in detection paths (used in removeAllDestFile and per-host Exec). Tests adjusted to invoke the new command form. No other logic changed.
Test args struct alignment
path_windows_test.go
Table-driven test entry updated to provide input using an args struct literal (args{"C:\\Users\\appleboy\\test.txt"}) instead of a plain string; expected value and assertions unchanged.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I tapped my paw on the terminal pane,
Whispered "cmd /c ver" to hush the rain.
Tests snug in structs, paths neat and bright—
Quiet outputs now sleep through the night.
(_/)< 🐇
(•_•) Thump, thump—ready for flight.

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 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 11abda8 and 3a7e69a.

📒 Files selected for processing (3)
  • path_windows_test.go (1 hunks)
  • plugin.go (2 hunks)
  • plugin_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • plugin_test.go
  • path_windows_test.go
  • plugin.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 from ver to cmd /c ver 2>$null. This ensures that the ver 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 includes 2>$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 to plugin_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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As with line 150, this command string is duplicated. Using a shared constant would improve code clarity and maintainability.

@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This command string is also present in plugin.go. To ensure consistency between tests and implementation, it's best to define this as an exported constant in plugin.go and reuse it here.

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.
@MrHIDEn MrHIDEn force-pushed the Fix-remote-system-detection-v2 branch from 11abda8 to 3a7e69a Compare August 17, 2025 15:16
@@ -15,7 +15,7 @@ func TestGetRealPath(t *testing.T) {
}{
{
"Test Windows Path",
"C:\\Users\\appleboy\\test.txt",
args{"C:\\Users\\appleboy\\test.txt"},
Copy link
Author

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.

Copy link

@coderabbitai coderabbitai bot left a 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 command

Good 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 explicit

Updating 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 here

Mirror 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 reordering

Minor 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.

📥 Commits

Reviewing files that changed from the base of the PR and between dd5217c and 11abda8.

📒 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)
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant