Skip to content

fix: detect WSL on non-English Windows locales - #85

Closed
Variiuz wants to merge 2 commits into
codacy:masterfrom
Variiuz:master
Closed

fix: detect WSL on non-English Windows locales#85
Variiuz wants to merge 2 commits into
codacy:masterfrom
Variiuz:master

Conversation

@Variiuz

@Variiuz Variiuz commented Jul 13, 2026

Copy link
Copy Markdown

Problem

On Windows, local Codacy CLI analysis via MCP fails with:

"CLI on Windows is not supported without WSL."

…even when WSL is installed and working.

Root cause: WSL detection parses wsl --status output for the English string
"Default Distribution". On localized Windows installs the label differs, e.g.:

  • de-DE: Standard-Distribution: Ubuntu
  • fr-FR: Distribution par défaut: Ubuntu
  • cs-CZ: Výchozí distribuce: Debian

So hasWSL is always false and the MCP uses WinCodacyCli, which rejects all operations.

Fix

Treat a successful wsl --status exit as proof WSL is available, instead of
matching a locale-specific label.

Alternative Fix

Alternative fix would be to use regex:

const hasWSL = /:\s*\S+/m.test(stdout); // "Something: Ubuntu"

Test plan

  • Windows + English locale + WSL: codacy_cli_analyze works
  • Windows + German locale + WSL: codacy_cli_analyze works
  • Windows without WSL: still returns "CLI on Windows is not supported without WSL."

Copilot AI review requested due to automatic review settings July 13, 2026 20:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 refactors the WSL availability check on Windows by introducing a helper function isWslAvailable that runs wsl --status instead of parsing localized stdout strings. Feedback suggests improving this check by using wsl -l -q to ensure that at least one Linux distribution is actually installed and registered, preventing potential failures when executing commands via WSL.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/cli/index.ts
@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect WSL detection on Windows systems using non-English locales by switching from parsing localized wsl --status output to using command success/failure as the signal for WSL availability. This ensures the MCP uses WinWSLCodacyCli only when WSL truly isn’t available, rather than failing due to locale-dependent labels.

Changes:

  • Add isWslAvailable() helper that treats a successful wsl --status execution as proof WSL is available.
  • Replace string-based WSL detection (stdout.includes('Default Distribution')) with the new helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR successfully addresses WSL detection issues on non-English Windows locales by switching from output string parsing to checking command execution status. While Codacy indicates the code is up to standards, the transition to wsl --status introduces a potential functional gap: the command may return a successful exit code even if no WSL distributions are installed. This could result in the CLI incorrectly selecting the WSL-based implementation over the standard Windows implementation. Furthermore, there are no automated tests included to verify the new detection logic or the factory's fallback behavior, and the implementation lacks a timeout mechanism to handle cases where the WSL subsystem might hang.

About this PR

  • The implementation relies on the exit code of wsl --status. While this solves the localization issue, it removes the specific check for a 'Default Distribution' presence; if wsl --status returns success without a distribution configured, it might lead to downstream failures in WinWSLCodacyCli.
  • The PR does not include automated tests (unit or integration) to verify the new detection logic or the factory selection logic.

Test suggestions

  • isWslAvailable returns true when 'wsl --status' succeeds
  • isWslAvailable returns false when 'wsl --status' fails or is not found
  • Cli.createInstance selects WinWSLCodacyCli when WSL is detected
  • Cli.createInstance selects WinCodacyCli when WSL detection fails
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. isWslAvailable returns true when 'wsl --status' succeeds
2. isWslAvailable returns false when 'wsl --status' fails or is not found
3. Cli.createInstance selects WinWSLCodacyCli when WSL is detected
4. Cli.createInstance selects WinCodacyCli when WSL detection fails

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread src/cli/index.ts Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@joanasteodoro

Copy link
Copy Markdown
Contributor

Hi! We are going to release a version soon where you no longer need to worry about WSL detection! Our new CLI makes everything easier :)

@Variiuz

Variiuz commented Jul 30, 2026

Copy link
Copy Markdown
Author

Hi! We are going to release a version soon where you no longer need to worry about WSL detection! Our new CLI makes everything easier :)

Alrighty, then this can be ignored 🙏

@Variiuz Variiuz closed this Jul 30, 2026
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.

3 participants