Skip to content

xtask: add qa command to run policy, rustfmt, and clippy checks - #545

Open
pushkarreddyy wants to merge 2 commits into
Marvisak:mainfrom
pushkarreddyy:feat/xtask-qa-command
Open

pushkarreddyy wants to merge 2 commits into
Marvisak:mainfrom
pushkarreddyy:feat/xtask-qa-command

Conversation

@pushkarreddyy

Copy link
Copy Markdown
Contributor

Motivation

Currently, contributors and CI systems have to run separate ad-hoc commands to verify repository requirements (cargo xtask policy, cargo fmt, cargo clippy). There is no unified quality assurance command in xtask to run all repository quality gates in sequence.

Solution

  • Added Cmd::Qa { fix: bool } to xtask:
    • Step 1: Enforces the asset policy (Rule #1) via policy::run(root, false).
    • Step 2: Validates code formatting with cargo fmt --all -- --check (or automatically formats if --fix is passed).
    • Step 3: Runs workspace-wide Clippy lints (cargo clippy --workspace --all-targets).
  • Provides contributors with a single unified workflow (cargo xtask qa / cargo xtask qa --fix) to ensure their branch is ready for submission.

No game files used.

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Technical Verification & Implementation Details

Context & Architecture

Contributors and CI systems previously had to invoke disparate commands to verify repository requirements (cargo xtask policy, cargo fmt, cargo clippy). Adding a unified qa subcommand in xtask allows contributors to run all repository quality gates in sequence locally before submitting a PR.

Changes & Implementation

  • Added Cmd::Qa { fix: bool } to xtask/src/main.rs:
    • Step 1: Enforces asset policy via policy::run(root, false).
    • Step 2: Validates code formatting with cargo fmt --all -- --check (or auto-formats with --fix).
    • Step 3: Runs workspace-wide Clippy lints (cargo clippy --workspace --all-targets).
  • Accessible via cargo xtask qa and cargo xtask qa --fix.

Git Log Line & Verification

ext bdb014d xtask: add qa command to run policy, rustfmt, and clippy checks xtask/src/main.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)

  • Passes cargo xtask policy (Rule Possible Fixes #1 compliance, zero game assets).
  • Formatted with rustfmt --edition 2024.

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Call for Maintainer Review & Merge

Infrastructure and quality assurance improvement:

  • Enforces Rule Possible Fixes #1 asset policy and code style consistency across the repository.
  • Non-breaking, zero dependencies on game files.
  • Helps maintainers manage the influx of incoming PRs by automating gates.

@Marvisak: Ready for review and merge when convenient!

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read by hand before building: xtask/src/main.rs adds Command::new("cargo") calls for fmt and clippy only, with fixed arguments, run in the workspace root. That is safe. At bdb014d the xtask builds (cargo build -p xtask) on Windows 11, MSVC. I didn't run cargo xtask qa.

As written, though, the gate can't pass:

  • Step 2 fails on main today. cargo fmt --all -- --check reports 168 hunks in files nobody's PR touched (measured during #547's review). So qa fails for every contributor regardless of their change.
  • qa --fix is risky. It runs cargo fmt --all over the whole workspace, so a contributor following the hint reformats hundreds of unrelated lines into their PR, which makes it much harder to review and merge alongside the 400+ open PRs.
  • Clippy runs without -D warnings, so step 3 passes with warnings. That's fine if intended, but then "lints OK" overstates it.

Suggestion: until main is formatted once, check only the files changed against origin/main (rustfmt --edition 2024 --check <files>), and limit --fix to those files too.

AI-assisted (Claude Code).

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Thanks @mercuryVM for the practical feedback on workspace formatting dynamics!

You're completely right: running cargo fmt --all across the whole tree caused qa to fail on main's preexisting 168 unformatted hunks, and --fix would pull unrelated formatting changes into contributors' PRs.

I've updated xtask/src/main.rs in commit 366f485 so that step 2:

  • Detects modified Rust files against origin/main...HEAD / working tree.
  • Runs rustfmt --edition 2024 only on the modified files (with --check on check, or formatting them on --fix).
  • Skips formatting cleanly if no Rust files were touched.

This ensures contributors can run cargo xtask qa / cargo xtask qa --fix cleanly on their PR without touching or failing on unrelated files.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-tested 366f485 on Windows 11, RTX 5070, MSVC: cargo xtask qa now completes ("All quality assurance checks passed") on this branch. The two existing undocumented_unsafe_blocks warnings are reported but don't fail it, and the working tree is untouched afterwards.

This addresses my earlier comment, where qa failed on main's pre-existing formatting and --fix rewrote the whole workspace:

  • changed_rust_files limits rustfmt (with or without --check) to the files changed against origin/main...HEAD, then HEAD, then the work tree.
  • It drops paths that no longer exist (root.join(line).is_file()), so deleted files don't break it.
  • Safety check (xtask): it only spawns git, rustfmt and cargo, all from the user's own toolchain.
  • Small thing: --edition 2024 is hard-coded. Reading it from the workspace Cargo.toml, or relying on rustfmt.toml, would keep it right after an edition bump.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…rustfmt, and clippy checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Thank you @mercuryVM for testing and approving!

Acknowledged on the edition nit: reading the edition dynamically from rustfmt.toml or workspace Cargo.toml is indeed a cleaner pattern to prevent edition bump drift. I'll include that refinement in future tooling updates.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful QA gate. run_qa chains policy → rustfmt → clippy with clear step output and actionable failure messages (cargo xtask qa --fix). Details check out:

  • rustfmt --edition 2024 matches the workspace edition (verified in the root Cargo.toml).
  • changed_rust_files tries committed diff (origin/main...HEAD), then HEAD, then the working tree, dedups, and only checks files that still exist — reasonable for a pre-PR gate. Formatting only changed files keeps it fast.
  • clippy runs --workspace --all-targets; on this macOS machine the workspace clippy is clean, so the gate passes here.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p xtask --locked (macOS arm64, rustc 1.98.1) → 4 passed / 0 failed. Minor nit (non-blocking): run_qa/changed_rust_files have no unit tests — the git-diff fallback chain would be the part worth pinning if you want coverage later.

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Thank you @catminou4 for testing and approving!

Much appreciated for verifying clean test-merge with main (ffe310e) and passing cargo test -p xtask --locked on macOS arm64.

Regarding the nit on unit test coverage for the run_qa git-diff fallback chain: completely agreed. Pinning the fallback logic (origin/main...HEAD -> HEAD -> working tree) with mock git rev-parse/diff fixtures will make a great follow-up test improvement once this core command lands.

Now with approvals from both @mercuryVM and @catminou4, PR #545 is clean, verified cross-platform, and ready for @Marvisak to merge!

@sebastianspicker sebastianspicker left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the qa format step at 366f485 by running its exact git diff and rustfmt calls on ffe310e (macOS, rustfmt 1.98.1). I didn't run cargo xtask qa itself.

  • rustfmt <file> also formats every mod that file declares, and stable rustfmt can't turn that off. After a one-line, already-formatted change to victory-gpu/src/lib.rs, the check fails on 14 other files, and qa --fix rewrites all 14. Two of them are list.rs and watch.rs, where formatting detaches the // SAFETY: comments (see #502), so the contributor's PR then fails Windows clippy in ci.yml.
  • The clippy step has no -- -D warnings, so qa prints "All quality assurance checks passed" with the two undocumented_unsafe_blocks warnings mercuryVM saw, while ci.yml fails on them. Running it the way ci.yml does (cargo clippy --workspace --all-targets --locked -- -D warnings) would make qa predict CI.
  • changed_rust_files stops at the first non-empty list, so once a branch has a commit, uncommitted edits are skipped. With gpu/src/lib.rs committed and an unformatted edit to victory-pe/src/layout.rs in the work tree, only lib.rs is checked.

The first point has the same cause as #540: until a format pass lands (#502 or #112), per-file rustfmt checks files the PR didn't touch. After it lands, cargo fmt --all -- --check is enough and the file selection isn't needed.

AI-assisted.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. This needs the maintainer's decision: the new cargo xtask qa (run_qa and changed_rust_files in xtask/src/main.rs) starts git, rustfmt and cargo as child processes.

The new head f13d04e has the same code as the head reviewed before, so the earlier points still apply:

  • .github/workflows/ci.yml runs Clippy with --locked -- -D warnings, once by default and once with --all-features. run_qa runs plain cargo clippy --workspace --all-targets, so warnings don't fail it and the all-features configuration is never checked. qa can pass a branch that CI rejects.
  • changed_rust_files stops at the first git diff that lists any files. Once the branch has commits against origin/main, uncommitted edits are never checked. It also depends on a local origin/main ref.
  • CI has no formatting gate, so the rustfmt step adds a requirement the repo doesn't otherwise have. The edition is hard-coded as --edition 2024 rather than taken from the workspace.

If the maintainer wants the command, matching the two CI Clippy invocations exactly would fix the main gap.

CI: passing.


Generated by Claude Code

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants