fix(windows): correctly identify mise binary without extension#8496
fix(windows): correctly identify mise binary without extension#8496
Conversation
On Windows, mise expects argv[0] to resolve to a filename of mise.exe to consider itself as not running as a shim. However, under certain conditions (e.g. on the conda-forge Windows CI build environment), running mise --help or mise --version directly results in argv[0] resolving to just mise (without the .exe extension, or perhaps mise.bat if it gets wrapped in some instances). Because "mise" != "mise.exe", the condition bin_name != mise_bin evaluates to true, and mise mistakenly thinks it is running as a shim. When mise runs as a shim, it completely ignores CLI flags (like --help) and tries to execute the shimmed tool. Since no such tool is found or configured, it just silently exits with a non-zero exit code (exit(1)). This patch fixes the logic so that variations of mise on Windows (like mise without extension or mise.bat/mise.cmd) aren't considered shims.
Summary of ChangesHello, 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 resolves a critical issue on Windows where the Highlights
Changelog
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue on Windows where the mise binary could be misidentified as a shim if invoked without the .exe extension. The change correctly identifies mise, mise.exe, and mise.* as non-shim invocations on Windows. My review includes a suggestion to refactor the conditional logic to improve clarity and remove redundancy, making it more maintainable across different platforms.
src/env.rs
Outdated
| let mise_bin = "mise.exe"; | ||
| let bin_name = *MISE_BIN_NAME; | ||
| bin_name != mise_bin && !bin_name.starts_with("mise-") | ||
| bin_name != "mise" && bin_name != mise_bin && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.") |
There was a problem hiding this comment.
This logic is correct, but it introduces a small redundancy on Unix where mise_bin is "mise", leading to bin_name != "mise" && bin_name != "mise". This could be confusing for future readers.
For better clarity and to avoid this redundancy, consider refactoring the condition to be more explicit about the platform-specific checks. Here is a suggestion that achieves the same logic in a more readable way:
| bin_name != "mise" && bin_name != mise_bin && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.") | |
| !(bin_name == mise_bin || (cfg!(windows) && bin_name == "mise")) && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.") |
Greptile SummaryThis PR correctly fixes a Windows-specific bug in the Changes made:
Verification: Confidence Score: 5/5
Last reviewed commit: e782d54 |
| @@ -281,7 +281,10 @@ pub static IS_RUNNING_AS_SHIM: Lazy<bool> = Lazy::new(|| { | |||
| #[cfg(windows)] | |||
| let mise_bin = "mise.exe"; | |||
| let bin_name = *MISE_BIN_NAME; | |||
There was a problem hiding this comment.
I think we should only do this for windows and also probably clean this logic up since there's some unnecessary conditions
There was a problem hiding this comment.
Like the the gemini-code-assist suggestion above? Feel free to adapt the PR as you see fit (I'm not really experienced in Rust) :)
There was a problem hiding this comment.
Yes, jdx's feedback aligns with the idea of simplifying the shim detection logic. The current logic in the PR, while addressing the Windows-specific mise vs mise.exe issue, inadvertently introduces a new problem: it incorrectly identifies actual shims (like mise-node) as not being shims.
The most robust and straightforward way to determine if the current executable is a shim is to check if its name starts with mise-. This correctly identifies binaries like mise-node as shims, while correctly identifying mise, mise.exe, mise.bat, and mise.cmd as the main executable (not shims).
This approach also naturally handles the Windows-specific nuances without requiring explicit #[cfg(windows)] blocks within the IS_RUNNING_AS_SHIM calculation, thus cleaning up the logic as suggested.
I recommend replacing the entire Lazy::new block's content (lines 281-287 in the current PR) with the simplified logic below.
| let bin_name = *MISE_BIN_NAME; | |
| let bin_name = *MISE_BIN_NAME; | |
| bin_name.starts_with("mise-") |
## Summary - Fixes the same issue as #8496 with the cleanup requested by @jdx - On Windows, `argv[0]` can resolve to `mise` (without `.exe`), `mise.bat`, or `mise.cmd`, all of which were incorrectly identified as shims - Simplifies the `IS_RUNNING_AS_SHIM` logic by removing `#[cfg(unix)]`/`#[cfg(windows)]` blocks and using a single unified check - Extracts a shared `is_mise_binary()` helper used by both `IS_RUNNING_AS_SHIM` and `handle_shim()` to keep the logic in one place Credit to @salim-b for identifying and reporting the issue in #8496. Co-Authored-By: Salim B <git@salim.space> ## Test plan - Verify `mise --help` and `mise --version` work correctly on Windows when `argv[0]` is `mise` (without extension) - Verify shim behavior still works (e.g., `node` shim correctly identified as a shim) - Verify `mise-` prefixed subcommands are not treated as shims 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Small, localized change to binary-name detection; main risk is misclassifying edge-case executable names and altering shim behavior in those cases. > > **Overview** > Fixes Windows shim detection when `argv[0]` resolves to `mise` without an extension (or to `mise.bat`/`mise.cmd`), which previously caused real `mise` invocations to be treated as shims. > > This replaces the platform-specific comparison logic in `IS_RUNNING_AS_SHIM` with a shared `env::is_mise_binary()` helper and updates `handle_shim()` to use the same check, ensuring consistent behavior for `mise`, `mise.*`, and `mise-...` binaries. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 566183a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Salim B <git@salim.space> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, mise expects argv[0] to resolve to a filename of mise.exe to consider itself as not running as a shim. However, under certain conditions (e.g. on the conda-forge Windows CI build environment), running mise --help or mise --version directly results in argv[0] resolving to just mise (without the .exe extension, or perhaps mise.bat if it gets wrapped in some instances).
Because "mise" != "mise.exe", the condition bin_name != mise_bin evaluates to true, and mise mistakenly thinks it is running as a shim. When mise runs as a shim, it completely ignores CLI flags (like --help) and tries to execute the shimmed tool. Since no such tool is found or configured, it just silently exits with a non-zero exit code (exit(1)).
This PR fixes the logic so that variations of mise on Windows (like mise without extension or mise.bat/mise.cmd) aren't considered shims.