fix(nu): create completion cache dir with mode 700 and fix home-dir lookup - #731
Conversation
…ookup Two fixes to the nu completion generator's cache-dir setup, both on the same lines touched by #727. 1. Permissions. Nushell's builtin `mkdir` has no mode flag, so the cache dir was created at the process umask (typically 755 / world-readable), unlike the bash/zsh/fish generators which use `mkdir -p -m 700`. Cached specs were therefore readable by other local users. Create the dir and then `^chmod 0700` it (guarded to non-Windows, where chmod doesn't apply). The chmod runs only when the dir is first created — behind a `path exists` check — so it stays off the completion hot path, matching the create-time-only semantics of `-m 700` in the other shells. 2. home-dir lookup. `$nu.home-path` was renamed to `$nu.home-dir` in nushell 0.110.0 (Jan 2026). Because `default` evaluates its argument eagerly, referencing the missing column made the completer error out on every invocation on current nushell — even when XDG_CACHE_HOME was set. Use optional access with a fallback: `$nu.home-dir? | default $nu.home-path?`, which resolves on both new and old nushell and no longer throws. Verified end-to-end on nushell 0.114.1: the generated completion sources cleanly, the cache dir is created as drwx------, and the spec file is written into it. Regenerated the nu snapshots. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 10 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (1)
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. Comment |
Greptile SummaryThis PR fixes two bugs in the Nushell completion cache-dir setup: the completer was broken on nushell ≥ 0.110 because
Confidence Score: 5/5Safe to merge — both fixes are targeted and correct, with no regressions introduced in the generated completion scripts. The two changes are minimal and address clearly identified, reproducible bugs. The home-dir fallback chain correctly handles both nushell < 0.110 and ≥ 0.110 via optional column access with no throw risk. The chmod is properly gated behind the creation check and the Windows guard. All three snapshot variants are updated consistently, and the PR author confirmed end-to-end testing on nushell 0.114.1. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "fix(nu): create completion cache dir wit..." | Re-trigger Greptile |
|
@coderabbitai review |
✅ Action performedReview finished.
|
### 🐛 Bug Fixes - **(cli)** avoid trailing semicolon in macro expression position by [@jdx](https://github.com/jdx) in [#729](#729) - **(completion)** write spec cache to private dir instead of world-writable tmp by [@jdx](https://github.com/jdx) in [#727](#727) - **(lib)** remove needless borrows in format args by [@jdx](https://github.com/jdx) in [#726](#726) - **(markdown)** preserve HTML in fenced code blocks by [@risu729](https://github.com/risu729) in [#720](#720) - **(nu)** create completion cache dir with mode 700 and fix home-dir lookup by [@jdx](https://github.com/jdx) in [#731](#731) ### 🔍 Other Changes - remove dtolnay/rust-toolchain action, use runner default rust by [@jdx](https://github.com/jdx) in [#724](#724) - regenerate aube-lock.yaml on renovate branches by [@jdx](https://github.com/jdx) in [#728](#728) - exclude aube-lock.yaml from prettier by [@jdx](https://github.com/jdx) in [#732](#732) ### 📦️ Dependency Updates - lock file maintenance by [@renovate[bot]](https://github.com/renovate[bot]) in [#723](#723)
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [usage](https://github.com/jdx/usage) | patch | `3.5.5` → `3.5.6` | 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.5.6`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#356---2026-07-20) [Compare Source](jdx/usage@v3.5.5...v3.5.6) ##### 🐛 Bug Fixes - **(cli)** avoid trailing semicolon in macro expression position by [@​jdx](https://github.com/jdx) in [#​729](jdx/usage#729) - **(completion)** write spec cache to private dir instead of world-writable tmp by [@​jdx](https://github.com/jdx) in [#​727](jdx/usage#727) - **(lib)** remove needless borrows in format args by [@​jdx](https://github.com/jdx) in [#​726](jdx/usage#726) - **(markdown)** preserve HTML in fenced code blocks by [@​risu729](https://github.com/risu729) in [#​720](jdx/usage#720) - **(nu)** create completion cache dir with mode 700 and fix home-dir lookup by [@​jdx](https://github.com/jdx) in [#​731](jdx/usage#731) ##### 🔍 Other Changes - remove dtolnay/rust-toolchain action, use runner default rust by [@​jdx](https://github.com/jdx) in [#​724](jdx/usage#724) - regenerate aube-lock.yaml on renovate branches by [@​jdx](https://github.com/jdx) in [#​728](jdx/usage#728) - exclude aube-lock.yaml from prettier by [@​jdx](https://github.com/jdx) in [#​732](jdx/usage#732) ##### 📦️ Dependency Updates - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​723](jdx/usage#723) </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 [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNzIuNiIsInVwZGF0ZWRJblZlciI6IjQzLjI3Mi42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6cGF0Y2giXX0=-->
Summary
Follow-up to #727, fixing two problems in the nu completion generator's cache-dir setup — both on the same lines that PR touched. Raised (in part) by Bugbot and Greptile on that PR.
1. Cache dir was world-readable (the reported gap)
Nushell's builtin
mkdirhas no mode flag, so the cache dir was created at the process umask — typically755, i.e. world-readable — whereas the bash/zsh/fish generators all usemkdir -p -m 700. The symlink-planting attack from #722 stays blocked (an attacker still can't write into~/.cache), but other local users could read the cached specs.Fix: create the dir, then
^chmod 0700it, guarded to non-Windows (where POSIX perms /chmoddon't apply):The
chmodruns only when the dir is first created (behind thepath existscheck), so it stays off the completion hot path — matching the create-time-only semantics of-m 700in the other three shells rather than forkingchmodon every Tab.2.
$nu.home-pathno longer exists → completer errors on every invocationWhile fixing the above I found the nu completion is currently broken on any recent nushell:
$nu.home-pathwas renamed to$nu.home-dirin nushell 0.110.0 (Jan 2026). Becausedefaultevaluates its argument eagerly, referencing the missing column throws — even whenXDG_CACHE_HOMEis set and the fallback isn't needed.Fix: optional access with a fallback that works on both new and old nushell:
Testing
Verified end-to-end on nushell 0.114.1:
XDG_CACHE_HOMEset and via the~/.cachefallback, the cache dir is created asdrwx------(700).chmod, no error.Also:
cargo test -p usage-lib --lib(257) passes,cargo clippyclean,cargo fmt --checkclean, nu snapshots regenerated. (nushell isn't installed in CI, so its integration tests skip — hence the manual end-to-end check above.)This PR was generated by Claude Code.
Note
Low Risk
Changes only the generated nu completion script strings and test snapshots; no runtime auth or data-path logic in the library itself.
Overview
Aligns nushell completion cache setup with bash/zsh/fish and fixes breakage on recent Nushell.
Generated completers now resolve the cache path with
$nu.home-dir?falling back to$nu.home-path?(optional chaining avoids errors whenXDG_CACHE_HOMEis set but the old$nu.home-pathcolumn is gone). They onlymkdirwhen the usage cache dir is missing, then run^chmod 0700on non-Windows so new dirs are not world-readable—matching the other shells’mkdir -m 700without chmod on every Tab.Insta snapshots for the nu generator are updated to match.
Reviewed by Cursor Bugbot for commit f54f4ad. Bugbot is set up for automated code reviews on this repo. Configure here.