Skip to content

fix windows PATHEXT resolution for .cmd/.bat wrappers#269

Open
F0rty-Tw0 wants to merge 34 commits intortk-ai:masterfrom
F0rty-Tw0:bug/212/cant-resolve-cmd-bat-wrappers
Open

fix windows PATHEXT resolution for .cmd/.bat wrappers#269
F0rty-Tw0 wants to merge 34 commits intortk-ai:masterfrom
F0rty-Tw0:bug/212/cant-resolve-cmd-bat-wrappers

Conversation

@F0rty-Tw0
Copy link

What changed

  • Added which crate to resolve binary paths with proper PATH+PATHEXT handling before spawning
  • New resolve_binary(), resolved_command(), and tool_exists() helpers in src/utils.rs
  • Replaced Command::new(...) with resolved_command(...) across all 16+ command modules (vitest, eslint, tsc, pnpm, playwright, prisma, next, pip, pytest, ruff, golangci-lint, etc.)
  • Removed duplicate which_command() / tool_exists() helpers from individual modules (pip_cmd.rs, pytest_cmd.rs, ccusage.rs)
  • Added 213 lines of tests including Windows-specific .CMD/.BAT wrapper resolution
  • Added troubleshooting guide for Windows "program not found" errors
  • Translated French comments to English in utils.rs

Impact on existing code

  • Every command module that spawns an external tool now goes through resolved_command() instead of raw Command::new(). On non-Windows this resolves to the same binary path, so behavior is unchanged. On Windows, .CMD/.BAT/.PS1 shims installed by npm/pnpm are now found correctly.
  • The which crate adds three small transitive dependencies (env_home, winsafe, rustix — rustix was already present).
  • Modules that had their own which_command() helpers (pip, pytest, ccusage) now use the shared tool_exists() from utils, removing ~40 lines of duplicated code.

Test plan

  • On Windows: run rtk vitest run, rtk lint src/, rtk tsc with Node.js tools installed via pnpm/npm — should no longer fail with "program not found"
  • On macOS/Linux: run cargo test --all to confirm no regressions
  • Verify resolve_binary("cargo") returns a valid path in CI across all platforms

Closes #212

@pszymkowiak
Copy link
Collaborator

Hi, this PR has conflicts with master. Could you rebase on current master? Thanks!

F0rty-Tw0 added 28 commits March 2, 2026 10:35
- Add `which` and `env_home` packages to dependencies.
- Update `Cargo.lock` with new package versions.
- Introduce `resolve_binary` to find binaries on PATH, honoring PATHEXT.
- Implement `resolved_command` for creating commands with proper binary resolution.
- Add `tool_exists` function to check for tool availability on PATH.

This change improves command execution reliability on Windows systems.
Use `resolved_command` for executing `wget` to improve command resolution and error handling.
Use `resolved_command` utility to create the command for `wc`, improving command resolution consistency across platforms.
- Update command resolution to use `resolved_command` for better compatibility.
- Simplify tool existence check by using `tool_exists` function.
Use `resolved_command` to check for the `tree` command instead of using `Command::new("which")`. This simplifies the command resolution process and ensures consistency across the codebase.
Updated the command execution to use `resolved_command` for better compatibility and resolution of command paths.
- Updated command execution to use `resolved_command` for better resolution of command paths.
- Removed the `which_command` function as it is no longer needed.
- Updated `create_prisma_command` to use `resolved_command` for better tool resolution.
- Removed unnecessary checks for `prisma` existence.
Refactor command execution to use `resolved_command` for better compatibility and error handling.

- Updated `run_list`, `run_outdated`, `run_install`, and `run_passthrough` functions to utilize `resolved_command`.
- Update command initialization to use `resolved_command` for better package manager detection.
- Update command execution to use `resolved_command` for better consistency.
- Remove the obsolete `which_command` function.
Updated function documentation to provide English descriptions for better understanding and consistency across the codebase.
Refactor the `create_prisma_command` function to use the imported `Command` type directly for improved clarity and consistency.
- Updated the command execution logic to use `resolved_command` for better resolution of command paths.
- Simplified the existence check for the `next` tool.
- Update Python linter command execution to use `resolved_command`, which honors PATHEXT on Windows for `.CMD/.BAT` wrappers.
Refactor the command execution in `run` function to use `resolved_command` for better consistency and error handling.

- Updated `rg_cmd` to use `resolved_command("rg")`.
- Updated fallback to use `resolved_command("grep")`.
- Update command execution to use `resolved_command` for consistency across formatters.
Updated the command initialization to use `resolved_command` for better consistency across the codebase.
Updated the `curl_cmd` to utilize `resolved_command` for command execution, enhancing consistency across command wrappers.
Updated the command execution to use `resolved_command` for better handling of command paths and execution context.
Refactor `kubectl` command invocations to use `resolved_command` for improved command resolution.
Refactor command execution to utilize `resolved_command` for better handling of command paths and existence checks.
- Documented the fix for spawning .CMD/.BAT/.PS1 wrappers on Windows.
- Explained the root cause and solution for the issue.
- Listed affected command modules and added testing details.
Add section addressing "program not found" errors for Node.js tools on Windows.
Explain root cause related to PATHEXT and provide solutions for upgrading and verifying installation.

* Introduced `resolved_command()` for better command resolution.
* Added workaround for users on older versions.
- Bump version in `Cargo.toml`, `CHANGELOG.md`, and documentation files.
- Ensure consistency across project files for the new release.
@F0rty-Tw0 F0rty-Tw0 force-pushed the bug/212/cant-resolve-cmd-bat-wrappers branch from de135a4 to a5eea5a Compare March 2, 2026 09:40
- Correct `rtk` version in README from `0.22.3` to `0.22.2`.
- Improve formatting of tables and sections for clarity.
- Add troubleshooting steps for common installation issues.
- Clarify the distinction between `Rust Token Killer` and `Rust Type Kit`.
- Update installation instructions and verification steps.
- Ensure consistency in command examples and outputs.
… support

New upstream mypy_cmd.rs (0.23.0) used Command::new("mypy"),
Command::new("python3"), and a custom which_command() helper — all
of which fail on Windows .CMD/.BAT wrappers. Migrate to
resolved_command() and tool_exists() from utils.rs.
Restore CHANGELOG.md, CLAUDE.md, README.md, ARCHITECTURE.md,
docs/TROUBLESHOOTING.md, and .gitignore to upstream/master state.
This PR should only contain the PATHEXT resolution code changes.
Added `.omc` to the `.gitignore` file to prevent tracking of this file in the repository.
@F0rty-Tw0
Copy link
Author

Hi, this PR has conflicts with master. Could you rebase on current master? Thanks!

Should be done, plus updated the new commands with the utils.

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.

bug: RTK can't resolve .CMD/.BAT wrappers on Windows (PATHEXT not honored)

2 participants