fix(init): pre-commit hook runs cargo fmt --check on staged Rust (REQ-210, #438)#505
Merged
Conversation
…-210, #438) `rivet init --hooks` installed a pre-commit hook that ran only `rivet validate` — no formatting gate. A misformatted-Rust diff is the most common first-push CI failure, and AI agents kept hitting it: commit "passes" locally, then CI's `cargo fmt --check` job goes red (#438). The fmt-checking hook that lives in THIS repo was installed by the dev-only scripts/install-hooks.sh, which `rivet init --hooks` does not use — so every project adopting hooks the shipped way got no formatting gate. cmd_init_hooks now writes a pre-commit hook that runs `cargo fmt --all -- --check` before `rivet validate`, guarded so it stays language-agnostic: the fmt step runs only when `command -v cargo` succeeds AND the commit stages at least one `.rs` file (`git diff --cached … | grep -q '\.rs$'`). Non-Rust rivet projects and cargo-less machines skip it silently and are never blocked. Mirrors scripts/install-hooks.sh. Convenience only; CI is the real gate (REQ-051) and `--no-verify` still bypasses it. Confirmed with a temp-repo `rivet init --hooks` (generated hook contains the fmt step + both guards, passes `bash -n`, preserves the validate step); cargo test -p rivet-cli --test cli_commands (127 passed, 0 failed — the full suite); cargo fmt --check + cargo clippy -p rivet-cli --all-targets -- -D warnings (exit 0); rivet validate PASS. Implements: REQ-210 Refs: REQ-051 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📐 Rivet artifact delta
Graphgraph LR
REQ_210["REQ-210"]:::added
classDef added fill:#d4edda,stroke:#28a745,color:#155724
classDef removed fill:#f8d7da,stroke:#dc3545,color:#721c24
classDef modified fill:#fff3cd,stroke:#ffc107,color:#856404
classDef overflow fill:#e2e3e5,stroke:#6c757d,color:#495057,stroke-dasharray: 3 3
Added
Posted by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (#438)
rivet init --hooksinstalls a pre-commit hook that runs onlyrivet validate— there is no formatting gate. A misformatted-Rust diff is the single most common first-push CI failure, and AI agents kept hitting it: the commit "passes" locally (validate is clean), then CI'scargo fmt --checkjob goes red.The fmt-checking pre-commit hook that this repo actually uses was installed by the dev-only
scripts/install-hooks.sh— whichrivet init --hooksdoes not use. So every project that adopts hooks the shipped way gets no formatting gate. (The original issue framed it as the Claude Code hook missing fmt; the accurate root cause is the shippedcmd_init_hookstemplate.)Fix
cmd_init_hooks(rivet-cli/src/main.rs) now writes a pre-commit hook that runscargo fmt --all -- --checkbefore the existingrivet validatestep — guarded to stay language-agnostic:The fmt step runs only when cargo is on PATH and the commit stages at least one
.rsfile, so non-Rust rivet projects (and cargo-less machines) skip it silently and are never blocked. Mirrors the proven logic inscripts/install-hooks.sh. Convenience only — CI remains the real gate (REQ-051) and--no-verifystill bypasses it.Verification (acceptance, REQ-210)
rivet init --hooks→ generated.git/hooks/pre-commitcontains the fmt step + the.rsguard + thecommand -v cargoguard, preserves therivet validate --format jsonstep, and passesbash -n.cargo test -p rivet-cli --test cli_commands— 127 passed, 0 failed (the full CLI suite, per the REQ-209 lesson).cargo fmt --check+cargo clippy -p rivet-cli --all-targets -- -D warnings— exit 0.rivet validate— PASS.REQ-210 filed and flipped to
implementedin the same commit (repo convention, cf. REQ-208).Closes #438.
🤖 Generated with Claude Code