Repository navigation
cargo-oxide: hold the fmt gate and cargo oxide fmt to one scope list - #1050
NgoQuocViet2001 wants to merge 2 commits into
Conversation
The gate and the command mirrored each other by convention only, which is how NVIDIA#1047 happened: the gate grew a fourth scope, the command kept three, and a contributor could format everything locally and still fail CI. Lift the fixed scopes into FIXED_FMT_SCOPES and drive format_all from it, so there is one list rather than a hand-unrolled copy of it, and add a test that reads .github/workflows/fmt.yml and compares the two sets. It takes the directory from each whole-directory `cargo fmt` step (the following working-directory:, or the workspace root when there is none), so a scope added to either side without the other fails the check: left: [".", "crates/cuda-host", "crates/cuda-macros/tests/device-only", ...] right: [".", "crates/cuda-macros/tests/device-only", ...] The examples walk is checked the same way: FMT_EXAMPLES_DIR now names the directory the Context builds and the test asserts the gate globs it, so the constant cannot drift from either. Closes NVIDIA#1048
nihalpasham
left a comment
There was a problem hiding this comment.
Verified against the tree: the parity test parses the real fmt.yml and matches its scope set, and the branch correctly builds on #1047 (your base already has it). This closes #1048 via its option 1.
Two small changes needed to merge, both in commands.rs:
- The doc comment moved:
FIXED_FMT_SCOPESwas inserted right afterformat_all's doc block, so the whole function doc (including the check-mode sentence) now documents the const, andpub fn format_allhas no rustdoc. Keep the scope-list prose on the const and move the function doc back onto the function. - One more hardcoded scope:
resolve_passive_contextstill builds its examples dir by hand. Derive it fromFMT_EXAMPLES_DIRso there's truly one list:
- let examples_dir = codegen_crate.join("examples");
+ let examples_dir = workspace_root.join(FMT_EXAMPLES_DIR);With both applied, cargo test -p cargo-oxide --all-targets passes 178 including your new parity test, and clippy -D warnings plus fmt stay clean; we ran all three on your branch with the changes in place.
To land it:
- Push the two changes, or tick "Allow edits by maintainers" and we'll push the validated commit.
Worth a separate issue so it doesn't get lost, not needed here: also assert every working-directory: in fmt.yml maps to a known scope, so a future step written with a different run spelling still trips the test.
…ples dir Two review fixes from @nihalpasham: - Inserting FIXED_FMT_SCOPES right after format_all's doc block left the whole function doc, check-mode sentence included, documenting the const instead, and pub fn format_all with no rustdoc at all. The scope-list prose stays on the const; the function doc goes back on the function. - resolve_passive_context still built its examples dir by hand, so the path existed in two places despite the point of the change being one list. Derive it from FMT_EXAMPLES_DIR. The remaining codegen_crate.join("examples") is inside workspace_clean_removes_root_backend_and_example_targets, which builds a synthetic temp tree rather than resolving the real scope, so it is left alone.
|
Both applied, pushed. Doc placement. You're right, and it was worse than misplaced prose: Second hardcoded scope. Fixed — One I deliberately left: Verification. On the follow-up: agreed that asserting every |
|
Closing this PR because the production scope refactor is useful, but its parity gate can still report success when CI does not enforce the same scope.
The test scans lines and substrings, so its happy path repeats the same assumption instead of proving PR-reachable, failure-propagating enforcement. Under the acceptance criteria shared in Discord, fixes need to address the root cause across the full path and include negative and unaffected controls. A replacement should use one executable scope source or structural, fail-closed validation with these mutations. That is a redesign rather than a small maintainer correction. The constant and production refactor can still inform a narrower replacement. |
Closes #1048, taking the first of the two options there — the check that compares the gate's scopes against the command's — since the second needs a cached backend binary the fmt job does not have.
What changed
format_allhand-unrolled its three fixed scopes as three blocks. They are now one list:and
format_alliterates it. TheCargo.tomlexistence check that guarded only the device-only fixture now guards every scope, which is what the fixture's block was doing anyway.fmt_gate_and_cargo_oxide_fmt_cover_the_same_scopesreads.github/workflows/fmt.ymland takes the directory from each whole-directorycargo fmtstep — theworking-directory:that follows it, or the workspace root when there is none — then compares that set againstFIXED_FMT_SCOPES.The examples walk is held the same way:
FMT_EXAMPLES_DIRnow names the directoryresolve_contextbuildsexamples_dirfrom, and the test asserts the gate globs{FMT_EXAMPLES_DIR}/**/Cargo.toml. So the constant is load-bearing rather than a second copy of the path.The test also asserts every listed scope really has a
Cargo.toml, so a rename cannot leave the command silently formatting nothing while the gate still checks it.Test plan
cargo test -p cargo-oxide— 178 passed, 0 failed (177 pre-existing + 1 new).cargo clippy -p cargo-oxide --all-targets— 0 warnings.cargo fmt --all -- --check— clean.cargo oxide fmtmisses three scopes the fmt gate checks #1047 drift by adding a fourthworking-directory:step tofmt.ymland leaving the command alone. The check fails with the diff spelled out:Scope
Deliberately text-level rather than a YAML dependency: the shape it has to recognise is "a step running
cargo fmt --all -- --check, optionally with aworking-directory:", which is what the gate writes today and what a new scope would be written as. If the gate ever moves to a matrix or a composite action this needs revisiting, and the assertion message says which two places disagree so that is a visible failure rather than a silent pass.