Skip to content

fix: gate cmd switch escaping to MSYS#58

Merged
zkochan merged 1 commit into
mainfrom
fix-qodo-msys-wsl-cmd-shim
Jun 15, 2026
Merged

fix: gate cmd switch escaping to MSYS#58
zkochan merged 1 commit into
mainfrom
fix-qodo-msys-wsl-cmd-shim

Conversation

@zkochan

@zkochan zkochan commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary:

  • preserve POSIX basedir in sh shims while keeping a Windows basedir for native executables
  • use //C for cmd shims only under MSYS-like shells, and keep /C for WSL and other shells

Tests:

  • pnpm test

Written by an agent (Codex, GPT-5).

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows environment detection and command-line argument handling for MSYS/Cygwin compatibility.
    • Enhanced path conversion logic in shell scripts for better Windows and POSIX environment handling.
  • Refactor

    • Optimized shell script generation structure for clearer environment-specific behavior separation.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@zkochan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 54 minutes and 38 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba997eb9-a348-4f1e-9d06-58f306ee4128

📥 Commits

Reviewing files that changed from the base of the PR and between 001f86b and 4a16c7c.

📒 Files selected for processing (3)
  • src/index.ts
  • test/e2e.test.js.snapshot
  • test/test.js.snapshot
📝 Walkthrough

Walkthrough

Refactors generateShShim in src/index.ts to track basedir_win and an msys flag separately from basedir, introduces isCmdRuntime detection, adds a generateExecBlock helper, and conditionally wraps cmd-runtime exec dispatch in an MSYS branch that applies escapeMsysCmdSwitches. All affected shell shim snapshots are updated accordingly.

Changes

MSYS-aware sh shim generation

Layer / File(s) Summary
New generator variables: shTarget_win and isCmdRuntime
src/index.ts
Adds shTarget_win for the Windows-form target path and isCmdRuntime boolean to identify cmd/cmd.exe runtime shims inside generateShShim.
Generated shell: msys flag and uname -a branch rewrite
src/index.ts
Rewrites the generated shell script's MSYS/CYGWIN/MINGW detection block to initialize msys, assign basedir_win via cygpath (instead of rewriting basedir), and set msys="true".
Generated shell: conditional MSYS exec dispatch and indentShellBlock
src/index.ts
Introduces generateExecBlock helper and wraps cmd-runtime shims in if [ -n "$msys" ] to apply escapeMsysCmdSwitches on MSYS; adds indentShellBlock to format nested shell blocks.
Snapshot updates for all sh shim variants
test/test.js.snapshot
Updates bat.shim, all env.shim variants, sh.shim variants, exe.shim variants, env.args.shim, and from.env.s.shim to reflect the new msys initialization, basedir_win via cygpath, and (for bat.shim) the //C vs /C conditional dispatch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • pnpm/cmd-shim#55: Directly overlaps with this PR's escapeMsysCmdSwitches integration and MSYS-conditional exec logic inside generateShShim.
  • pnpm/cmd-shim#56: Modifies generateShShim to introduce basedir_win and Windows-target path variables through uname -a platform detection, the same mechanism refactored here.
  • pnpm/cmd-shim#53: Changes generateShShim exec/dispatch semantics in the generated sh binstubs, which is the same code area reorganized in this PR.

Poem

🐇 Hop, hop through the Cygwin path,
basedir_win now avoids the wrath!
msys flag raised, the switch goes //C,
No more mangled args — we're finally free.
With indented blocks all neat and trim,
This bunny ships shims on every whim! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: gate cmd switch escaping to MSYS' directly describes the main objective: conditional cmd switch escaping based on MSYS environment.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-qodo-msys-wsl-cmd-shim

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Gate cmd /C switch escaping to MSYS shells in sh shims
🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

Walkthroughs

Description
• Preserve POSIX basedir while maintaining a Windows basedir for native executables.
• Only apply MSYS //C escaping for cmd shims under MSYS/Cygwin/Mingw shells.
• Update shim snapshot expectations for the new MSYS-gated execution logic.
Diagram
graph TD
  A["generateShShim()"] --> B{"uname indicates MSYS?"}
  B -->|"yes"| C["set basedir_win via cygpath + msys=true"] --> D{"cmd runtime?"}
  B -->|"no"| E["keep basedir (POSIX) + basedir_win"] --> D
  D -->|"yes"| F["exec with escaped switches (//C)"]
  D -->|"no"| G["exec with original args (/C etc.)"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Detect MSYS via environment variables (e.g., MSYSTEM) instead of uname
  • ➕ Potentially faster and less error-prone than parsing uname output
  • ➕ Avoids edge cases where uname strings differ across distributions
  • ➖ Not all MSYS-like environments reliably export the same variables
  • ➖ May reduce portability compared to uname-based detection already used
2. Always use //C for cmd shims on any non-Windows sh shell
  • ➕ Simplifies logic (no runtime MSYS gating)
  • ➕ Eliminates MSYS path-translation failure mode unconditionally
  • ➖ Risk of breaking WSL/other shells where /C is expected/standard
  • ➖ Harder to reason about correctness outside MSYS-specific behavior

Recommendation: Keep the PR’s runtime MSYS gating approach: it addresses the MSYS argument translation bug while preserving expected behavior on WSL and other shells. uname-based detection is consistent with existing shim platform branching and avoids relying on environment-variable conventions.

Grey Divider

File Changes

Bug fix (1)
index.ts Gate MSYS cmd switch escaping and preserve POSIX basedir in sh shims +42/-30

Gate MSYS cmd switch escaping and preserve POSIX basedir in sh shims

• Refactors sh shim exec generation to compute cmd-runtime status once and to assemble execution blocks via a helper. Introduces an 'msys' runtime flag in the emitted shell script, preserves POSIX 'basedir' while computing 'basedir_win' via 'cygpath', and conditionally applies 'escapeMsysCmdSwitches()' only when running under MSYS-like shells.

src/index.ts


Tests (1)
test.js.snapshot Update snapshots for MSYS-gated cmd shim execution +70/-39

Update snapshots for MSYS-gated cmd shim execution

• Updates expected shim output to include the new 'msys' variable initialization and the conditional exec blocks that use '//C' only under MSYS and '/C' otherwise.

test/test.js.snapshot


Grey Divider

Qodo Logo

@zkochan zkochan force-pushed the fix-qodo-msys-wsl-cmd-shim branch from 001f86b to 4a16c7c Compare June 15, 2026 00:06
@zkochan zkochan merged commit df84013 into main Jun 15, 2026
4 of 7 checks passed
@zkochan zkochan deleted the fix-qodo-msys-wsl-cmd-shim branch June 15, 2026 00:08
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