Skip to content

fix: use CARGO_BIN_EXE_usage if set#568

Merged
jdx merged 2 commits intojdx:mainfrom
kybe236:main
Mar 30, 2026
Merged

fix: use CARGO_BIN_EXE_usage if set#568
jdx merged 2 commits intojdx:mainfrom
kybe236:main

Conversation

@kybe236
Copy link
Copy Markdown
Contributor

@kybe236 kybe236 commented Mar 29, 2026

Use CARGO_BIN_EXE_usage if set

This ensures the tests can locate the binary even if the build directory includes a target triple.
It requires the binary to be built beforehand, which is already the case in Nixpkgs (hence this PR/patch).
Not sure how to determine the correct path if the binary hasn't been built yet.

Mainly made this commit to make the tests pass in Nixpkgs:
NixOS/nixpkgs#504792

See:

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.04%. Comparing base (2eee02e) to head (e4768f5).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #568   +/-   ##
=======================================
  Coverage   79.04%   79.04%           
=======================================
  Files          48       48           
  Lines        7235     7235           
  Branches     7235     7235           
=======================================
  Hits         5719     5719           
  Misses       1141     1141           
  Partials      375      375           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@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 updates the build_usage_binary function in the shell completion integration tests to check for the CARGO_BIN_EXE_usage environment variable. A review comment suggests enhancing this check by filtering out empty strings to avoid potential panics when the path is used later.

Comment thread cli/tests/shell_completions_integration.rs Outdated
@kybe236 kybe236 changed the title use CARGO_BIN_EXE_usage if set fix: use CARGO_BIN_EXE_usage if set Mar 29, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 29, 2026

Greptile Summary

This PR adds a small but meaningful fix to build_usage_binary() in the shell-completions integration test: before falling back to running cargo build, it checks the CARGO_BIN_EXE_usage environment variable and, if set and non-empty, returns that path directly.

Why this matters:

  • Cargo already sets CARGO_BIN_EXE_<name> at runtime for integration tests, so in normal cargo test runs this also eliminates a redundant rebuild.
  • In Nixpkgs (and similar sandboxed build systems), the binary is pre-built and lives at a path that may include a target triple; CARGO_BIN_EXE_usage is the standard Cargo mechanism to expose that path to tests.

Key observations:

  • The filter(|s| !s.is_empty()) guard is a good defensive touch.
  • All four shell-specific test functions call usage_bin.parent().unwrap() to build a PATH prefix. This is fine for absolute paths (which both Cargo and Nixpkgs produce), but would silently add "" (i.e., the CWD) to PATH for a bare binary name — a low-risk but easy-to-tighten edge case.

Confidence Score: 5/5

Safe to merge — the change is minimal, well-scoped, and the only remaining feedback is a low-priority style suggestion.

No P0 or P1 issues. The logic is correct: runtime env-var lookup with an empty-string guard, followed by an early return. The single P2 note about parent() on a bare filename is an edge case that won't occur with either Cargo or Nixpkgs paths.

No files require special attention.

Important Files Changed

Filename Overview
cli/tests/shell_completions_integration.rs Added early return in build_usage_binary() to honour CARGO_BIN_EXE_usage env var when set, allowing Nixpkgs (and normal Cargo test runs) to skip the redundant cargo build step and correctly locate binaries built with a target-triple in the path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[build_usage_binary called] --> B{CARGO_BIN_EXE_usage set\nand non-empty?}
    B -- Yes --> C[Return PathBuf from env var\ne.g. /nix/store/.../bin/usage]
    B -- No --> D[Locate CARGO_MANIFEST_DIR\nfind workspace root]
    D --> E[Run: cargo build --bin usage]
    E --> F{Build successful?}
    F -- No --> G[panic! with stderr]
    F -- Yes --> H[Return workspace_root/target/debug/usage]
    C --> I[Tests use binary path\nfor shell completion tests]
    H --> I
Loading

Reviews (2): Last reviewed commit: "[autofix.ci] apply automated fixes" | Re-trigger Greptile

Comment thread cli/tests/shell_completions_integration.rs Outdated
@jdx jdx merged commit 62936a2 into jdx:main Mar 30, 2026
8 checks passed
jdx pushed a commit that referenced this pull request Apr 22, 2026
### 🐛 Bug Fixes

- **(zsh)** escape values without descriptions by
[@david-hamilton-glean](https://github.com/david-hamilton-glean) in
[#597](#597)
- use CARGO_BIN_EXE_usage if set by
[@kybe236](https://github.com/kybe236) in
[#568](#568)

### 📚 Documentation

- add releases nav and aube lock by [@jdx](https://github.com/jdx) in
[#593](#593)
- add linux optional packages to aube lock by
[@jdx](https://github.com/jdx) in
[#594](#594)

### 📦️ Dependency Updates

- pin dtolnay/rust-toolchain action to 631a55b by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#562](#562)
- update codecov/codecov-action digest to 75cd116 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#563](#563)
- update pnpm/action-setup digest to b906aff by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#566](#566)
- update jdx/mise-action digest to 5228313 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#565](#565)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#569](#569)
- update dtolnay/rust-toolchain digest to 29eef33 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#571](#571)
- update swatinem/rust-cache digest to e18b497 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#572](#572)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#574](#574)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#575](#575)
- update taiki-e/upload-rust-binary-action digest to 10c1cf6 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#576](#576)
- update rust crate ctor to 0.9 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#577](#577)
- update actions/configure-pages action to v6 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#579](#579)
- update rust crate indexmap to v2.14.0 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#578](#578)
- update codecov/codecov-action action to v6 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#581](#581)
- update actions/deploy-pages action to v5 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#580](#580)
- update pnpm/action-setup action to v5 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#583](#583)
- update jdx/mise-action action to v4 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#582](#582)
- update pnpm/action-setup action to v6 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#584](#584)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#585](#585)
- update rust crate clap to v4.6.1 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#586](#586)
- update rust crate ctor to 0.10 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#587](#587)
- update actions/upload-pages-artifact action to v5 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#588](#588)
- update rust crate assert_cmd to v2.2.1 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#589](#589)
- update taiki-e/upload-rust-binary-action digest to f0d45ae by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#590](#590)
- update dependency eslint to v10.2.1 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#591](#591)
- update pnpm/action-setup digest to 078e9d4 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#592](#592)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#595](#595)

### New Contributors

- @david-hamilton-glean made their first contribution in
[#597](#597)
- @kybe236 made their first contribution in
[#568](#568)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Apr 22, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [usage](https://github.com/jdx/usage) | patch | `3.2.0` → `3.2.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/usage (usage)</summary>

### [`v3.2.1`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#321---2026-04-22)

[Compare Source](jdx/usage@v3.2.0...v3.2.1)

##### 🐛 Bug Fixes

- **(zsh)** escape values without descriptions by [@&#8203;david-hamilton-glean](https://github.com/david-hamilton-glean) in [#&#8203;597](jdx/usage#597)
- use CARGO\_BIN\_EXE\_usage if set by [@&#8203;kybe236](https://github.com/kybe236) in [#&#8203;568](jdx/usage#568)

##### 📚 Documentation

- add releases nav and aube lock by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;593](jdx/usage#593)
- add linux optional packages to aube lock by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;594](jdx/usage#594)

##### 📦️ Dependency Updates

- pin dtolnay/rust-toolchain action to [`631a55b`](jdx/usage@631a55b) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;562](jdx/usage#562)
- update codecov/codecov-action digest to [`75cd116`](jdx/usage@75cd116) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;563](jdx/usage#563)
- update pnpm/action-setup digest to [`b906aff`](jdx/usage@b906aff) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;566](jdx/usage#566)
- update jdx/mise-action digest to [`5228313`](jdx/usage@5228313) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;565](jdx/usage#565)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;569](jdx/usage#569)
- update dtolnay/rust-toolchain digest to [`29eef33`](jdx/usage@29eef33) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;571](jdx/usage#571)
- update swatinem/rust-cache digest to [`e18b497`](jdx/usage@e18b497) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;572](jdx/usage#572)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;574](jdx/usage#574)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;575](jdx/usage#575)
- update taiki-e/upload-rust-binary-action digest to [`10c1cf6`](jdx/usage@10c1cf6) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;576](jdx/usage#576)
- update rust crate ctor to 0.9 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;577](jdx/usage#577)
- update actions/configure-pages action to v6 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;579](jdx/usage#579)
- update rust crate indexmap to v2.14.0 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;578](jdx/usage#578)
- update codecov/codecov-action action to v6 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;581](jdx/usage#581)
- update actions/deploy-pages action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;580](jdx/usage#580)
- update pnpm/action-setup action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;583](jdx/usage#583)
- update jdx/mise-action action to v4 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;582](jdx/usage#582)
- update pnpm/action-setup action to v6 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;584](jdx/usage#584)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;585](jdx/usage#585)
- update rust crate clap to v4.6.1 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;586](jdx/usage#586)
- update rust crate ctor to 0.10 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;587](jdx/usage#587)
- update actions/upload-pages-artifact action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;588](jdx/usage#588)
- update rust crate assert\_cmd to v2.2.1 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;589](jdx/usage#589)
- update taiki-e/upload-rust-binary-action digest to [`f0d45ae`](jdx/usage@f0d45ae) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;590](jdx/usage#590)
- update dependency eslint to v10.2.1 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;591](jdx/usage#591)
- update pnpm/action-setup digest to [`078e9d4`](jdx/usage@078e9d4) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;592](jdx/usage#592)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;595](jdx/usage#595)

##### New Contributors

- [@&#8203;david-hamilton-glean](https://github.com/david-hamilton-glean) made their first contribution in [#&#8203;597](jdx/usage#597)
- [@&#8203;kybe236](https://github.com/kybe236) made their first contribution in [#&#8203;568](jdx/usage#568)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMzYuMiIsInVwZGF0ZWRJblZlciI6IjQzLjEzNi4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6cGF0Y2giXX0=-->
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.

2 participants