Skip to content

fix(pre-commit): rustfmt a virtual workspace root - #363

Merged
thedavidmeister merged 1 commit into
mainfrom
2026-08-25-rustfmt-virtual-workspace
Aug 25, 2026
Merged

fix(pre-commit): rustfmt a virtual workspace root#363
thedavidmeister merged 1 commit into
mainfrom
2026-08-25-rustfmt-virtual-workspace

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What is broken

2455992d changed the rustfmt-conditional hook to format each manifest via --manifest-path, so a crate one level below the repo root gets formatted instead of cargo erroring on a manifest-less root.

That broke the other layout. A virtual workspace root — [workspace] with members and no [package] — has no targets of its own, so cargo-fmt fmt --manifest-path Cargo.toml exits 1 with:

Failed to find targets
This utility formats all bin and lib files of the current crate using rustfmt.
Usage: cargo fmt [OPTIONS] [-- <rustfmt_options>...]

The */Cargo.toml arm does not save it when the members live deeper, e.g. crates/*/Cargo.toml.

Impact

rainlanguage/rain.metadata — root Cargo.toml is [workspace] over crates/bindings, crates/cli, crates/metaboard — is red on rainix-rs / static / rs-static on every PR and on main, with no formatting problem at all: clippy passes in that same job before the hook runs.

That repo's ci-gate reads the lane, so release / release on main fails with ci-gate: refusing to publish <sha> — rainix-rs (.github/workflows/rainix-rs.yaml) concluded failure. The repo cannot publish until this hook is fixed.

The fix

--all formats the workspace members rather than the root package's own targets. That is what the hook wants in both layouts, and it is a no-op for a single-package manifest.

QA

  • Discriminating tests: n/a - this repo has no harness that executes a git-hooks.nix hook body, so there is no test that could fail on base. The hook is verified by running its exact command line against a virtual-workspace repo, below. A hook-execution harness is a larger change than this one-flag fix and belongs in its own issue.
  • Mutations applied: cargo-fmt fmt --all --manifest-path "$manifest" -> drop --all (the base as of 2455992) -> exits 1 with Failed to find targets against rain.metadata's virtual root; restored -> exits 0. Run in rain.metadata's dev shell at 45ca96c: cargo-fmt fmt --all --manifest-path Cargo.toml --check gives rc=0, cargo-fmt fmt --manifest-path Cargo.toml --check gives rc=1 and Failed to find targets. The same tree passes cargo fmt --all --check at rc=0 across five separate merge commits, so the lane's red X was never a formatting diff.
  • Oracle: cargo-fmt's documented behaviour (--all formats all workspace packages; a manifest with no [package] has no targets to find), plus the CI job log for rainix-rs / static / rs-static on rain.metadata main at 45ca96c (run 32862493917), which shows every other pre-commit hook passing and rustfmt-conditional alone exiting 1 on Failed to find targets.
  • Category check: Refs no issue - found from rain.metadata's red lane rather than filed. The regression is one behaviour, the hook's exit status on a virtual workspace root, covered by the mutation above; the nested-crate case 2455992 added is preserved, since --all on a member manifest formats that member.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved automatic Rust formatting to include all workspace members.
    • Enhanced formatting guidance for projects using virtual manifests.

2455992 moved the hook to per-manifest --manifest-path so a crate one
level below the repo root gets formatted. That broke every repo whose
root manifest is a virtual workspace: cargo-fmt finds no targets for a
manifest with no [package] and exits 1 with "Failed to find targets".

rain.metadata is red on rs-static for this reason, on PRs and on main,
and its ci-gate refuses to publish while rainix-rs is failing.

--all formats the workspace members instead of the root package's own
targets, which is what the hook wants in both layouts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f0091fa0-999c-4d43-a509-9c77996901b3

📥 Commits

Reviewing files that changed from the base of the PR and between 60ec0d8 and 9677110.

📒 Files selected for processing (1)
  • flake.nix

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The rustfmt-conditional hook now runs cargo-fmt fmt --all for each manifest. The comment explains that this supports virtual Cargo manifests by formatting their workspace members.

Changes

Workspace Rust formatting

Layer / File(s) Summary
Update rustfmt-conditional workspace formatting
flake.nix
The hook now formats all workspace members with cargo-fmt fmt --all --manifest-path "$manifest". The comment documents the virtual manifest behavior.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 96771

This localized change updates formatting for virtual workspaces while preserving single-package behavior; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: findolor

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: fixing rustfmt behavior for virtual workspace roots in the pre-commit hook.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-08-25-rustfmt-virtual-workspace

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.

@thedavidmeister
thedavidmeister merged commit dbcd9d3 into main Aug 25, 2026
17 checks passed
@github-actions

Copy link
Copy Markdown

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

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