Skip to content

ci: guard the book's CLI command reference against subcommand drift - #803

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:guard/cli-command-reference
Aug 11, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:guard/cli-command-reference

Conversation

@vyncint

@vyncint vyncint commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The follow-up you offered on #794 — "Happy to take the drift guard as a
follow-up if you are up for it."

Why

#794 added the Command reference table because the book documented 11 of the
CLI's 15 subcommands; test, fmt, update and emit-ltoir appeared nowhere.
Nothing stops it falling behind again: adding a variant to the clap enum is a
one-line change, and no build compares the two.

scripts/check-cli-doc-coverage.sh compares the Commands enum in
crates/cargo-oxide/src/main.rs against the rows under ### Command reference,
in both directions. A missing row is the common case; a row for a command
that no longer exists is worse, because a reader trusts it and gets
unrecognized subcommand.

Design choices

Subcommands come from the enum, not from cargo oxide --help. The enum is
the definition, reading it needs no cargo and no build, and it keeps this guard
in the same source-only class as its siblings — a guard that needed a backend
build to answer a documentation question would not get run. I cross-checked the
parse against the built binary: both report the same 15 commands, zero
disagreement.

Not required to appear: anything carrying hide = true
(__materializer-provenance today) and clap's generated help, which is not in
the enum at all, so reading the enum excludes it without a special case.

Descriptions are out of scope. clap's short help is a variant's doc-comment
first line, while the table's cells deliberately add MyST backticks around names
like cuda-gdb and setup; comparing them literally would fail on correct
prose, and normalising invites the brittleness the guard exists to avoid.

A defect found while wiring it up

check-guards was running five of the seven guards. The crate-inventory
and toolchain-pin-parity jobs went into status-guard.yml in #793 and #790
without being added to the recipe, so just check could pass while
status-guard failed — precisely the drift #729 and #788 built that recipe to
prevent. That was my omission in those two PRs. All three are in now, and the
stale counts in its comment ("the status-guard pair", "two of the four") are
corrected. Every scripts/check-*.sh is now referenced by both the Justfile and
a workflow.

Verification

Clean tree:

OK: cuda-oxide-book/getting-started/installation.md documents all 15
`cargo oxide` subcommands (1 hidden one(s) correctly excluded).

Seven mutations, each failing and naming the cause:

mutation caught as
new visible subcommand added to the enum profile
row deleted from the table emit-ltoir
table lists a command that does not exist benchmark (no such subcommand)
table documents the hidden command __materializer-provenance (hidden from --help)
subcommand renamed (Doctor → Diagnose) diagnose
book section heading renamed parse self-test
enum Commands renamed parse self-test

The fourth case initially passed — my row pattern was [a-z][a-z0-9-]*, so a
__-prefixed name never matched and the hidden-command branch was unreachable
dead code. Widened to [a-z_][a-z0-9_-]*, with a comment on why the underscore
is deliberate.

just check-guards green end to end (exit 0, all eight legs), and
status-guard.yml parses as YAML with five jobs.

No Rust changed, so cargo fmt / clippy are untouched by this.

The follow-up offered on NVIDIA#794. That PR added a Command reference table
because the book documented 11 of the CLI's 15 subcommands; `test`, `fmt`,
`update` and `emit-ltoir` appeared nowhere. Nothing stops the table falling
behind again -- adding a variant to the clap enum is a one-line change and
no build compares the two.

`scripts/check-cli-doc-coverage.sh` compares the `Commands` enum in
`crates/cargo-oxide/src/main.rs` against the rows under `### Command
reference`, in both directions. A missing row is the common case; a row for
a command that no longer exists is worse, because a reader trusts it and
gets `unrecognized subcommand`.

Subcommands come from the enum rather than from `cargo oxide --help`: the
enum is the definition, reading it needs no cargo and no build, and that
keeps the guard in the same source-only class as its siblings. A guard that
needed a backend build to answer a documentation question would not get
run. The parse is cross-checked against the built binary -- both report the
same 15 commands, with no disagreement.

Deliberately not required to appear: anything carrying `hide = true`
(`__materializer-provenance` today) and clap's generated `help`, which is
not in the enum at all. Descriptions are out of scope, because clap's short
help is the doc-comment first line while the table's cells add MyST
backticks around names like `cuda-gdb`; comparing them literally would fail
on correct prose.

While wiring it up: `check-guards` was running five of the seven guards.
The crate-inventory and toolchain-parity jobs went into status-guard.yml in
NVIDIA#793 and NVIDIA#790 without being added to the recipe, so `just check` could pass
while status-guard failed -- exactly the drift NVIDIA#729 and NVIDIA#788 built that
recipe to prevent. My omission; all three are in now, and the stale counts
in its comment ("the status-guard pair", "two of the four") are fixed.

Verified: passes on the clean tree (15 documented, 1 hidden excluded), and
seven mutations each fail naming the cause -- new subcommand, deleted row,
invented row, a row for the hidden command, a rename, and both parse
self-tests. `just check-guards` is green end to end.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added QoL-improvement Quality-of-life improvement; not a correctness fix build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation labels Aug 11, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: the command table gets enforcement in both directions (missing row, phantom row), with loud parse self-tests and count floors so a restructured source fails instead of silently matching nothing. Also fixes real drift: just check-guards had quietly stopped running two of CI's guards.

Verified here:

  • re-derived the regex parse independently against main: 15 visible subcommands, 15 table rows, both directions match, hidden command excluded;
  • full eight-leg just check-guards green.

Merging. One follow-up worth a line: the variant regex skips tuple variants (none exist today); extending it closes the one silent hole.

@nihalpasham
nihalpasham merged commit b3db5a3 into NVIDIA:main Aug 11, 2026
41 checks passed
nihalpasham added a commit that referenced this pull request Aug 11, 2026
…805)

* ci: guard the book's CLI command reference against subcommand drift

The follow-up offered on #794. That PR added a Command reference table
because the book documented 11 of the CLI's 15 subcommands; `test`, `fmt`,
`update` and `emit-ltoir` appeared nowhere. Nothing stops the table falling
behind again -- adding a variant to the clap enum is a one-line change and
no build compares the two.

`scripts/check-cli-doc-coverage.sh` compares the `Commands` enum in
`crates/cargo-oxide/src/main.rs` against the rows under `### Command
reference`, in both directions. A missing row is the common case; a row for
a command that no longer exists is worse, because a reader trusts it and
gets `unrecognized subcommand`.

Subcommands come from the enum rather than from `cargo oxide --help`: the
enum is the definition, reading it needs no cargo and no build, and that
keeps the guard in the same source-only class as its siblings. A guard that
needed a backend build to answer a documentation question would not get
run. The parse is cross-checked against the built binary -- both report the
same 15 commands, with no disagreement.

Deliberately not required to appear: anything carrying `hide = true`
(`__materializer-provenance` today) and clap's generated `help`, which is
not in the enum at all. Descriptions are out of scope, because clap's short
help is the doc-comment first line while the table's cells add MyST
backticks around names like `cuda-gdb`; comparing them literally would fail
on correct prose.

While wiring it up: `check-guards` was running five of the seven guards.
The crate-inventory and toolchain-parity jobs went into status-guard.yml in
#793 and #790 without being added to the recipe, so `just check` could pass
while status-guard failed -- exactly the drift #729 and #788 built that
recipe to prevent. My omission; all three are in now, and the stale counts
in its comment ("the status-guard pair", "two of the four") are fixed.

Verified: passes on the clean tree (15 documented, 1 hidden excluded), and
seven mutations each fail naming the cause -- new subcommand, deleted row,
invented row, a row for the hidden command, a rename, and both parse
self-tests. `just check-guards` is green end to end.

Signed-off-by: Vyncint Ng <[email protected]>

* ci: cover the codegen backend's own workspace in both license guards

The second pass asked for in the #662 review: "a second pass over
`crates/rustc-codegen-cuda` (its own workspace, invisible to both
cargo-deny and this guard today)". Still true, and it had already cost a
row.

That crate carries its own `[workspace]` for the rustc-private dylibs, so
it is a third resolution alongside the root and the examples, and neither
existing guard reached it. The inventory guard read the root workspace
through `cargo metadata`, which stops at that boundary; the policy side ran
`cargo deny check` on the root and a script over the examples.

**Inventory, and a live omission.** `rustc_codegen_cuda` had no row in
dependency-licenses.csv at all -- the largest first-party crate in the
tree, missing from the inventory, while every other member carried a
`1st Party (workspace)` row. Nothing could have caught it. The guard now
unions the declared crates of both first-party workspaces, which takes it
from 41 to 55, and the missing row is added.

**Policy.** `cargo deny` now runs over that workspace too, in the same job
as the root run so the install is shared. This is narrower than it looks
and worth stating precisely: all 82 of its third-party crate *names* also
appear in the root graph, so nothing is unlicensed today. What differs is
versions -- 17 (name, version) pairs resolve there and nowhere else,
including `anyhow 1.0.100`, `libc 0.2.187` and `linkme 0.3.35` -- and
advisory and license verdicts are per version, so an advisory against one
of those 17 is invisible to the root run.

Verified:

  * the inventory guard passes with the row (55 crates) and, with the row
    removed again, fails naming exactly `rustc_codegen_cuda`;
  * banning `anyhow =1.0.100`, a backend-only version, leaves the root run
    at `bans ok` and makes the backend run fail with `error[banned]` --
    the new leg covers crates the root one cannot see;
  * `cargo deny --manifest-path crates/rustc-codegen-cuda/Cargo.toml
    --locked check` is clean on the current tree, so the policy half is
    prevention rather than a fix;
  * `just check-guards` green end to end, and both workflow files parse.

No `--config` on the new run: cargo-deny walks up from the manifest
directory to the repository-root deny.toml, the same resolution the
example-policy script already relies on.

Stacked on #803, which adds the CLI-reference guard to the same
`check-guards` recipe -- review only the second commit.

Signed-off-by: Vyncint Ng <[email protected]>

---------

Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 12, 2026
The follow-up noted on #803: "the variant regex skips tuple variants (none
exist today); extending it closes the one silent hole."

The pattern was `^ {4}([A-Z][A-Za-z0-9]*)\s*[{,]?\s*$`, which requires the
line to end after an optional `{` or `,`. A tuple variant carries its
fields on the same line -- `Profile(String),` -- so it matched nothing and
the subcommand was never required to appear in the book's table. Silent,
which is the bad direction for a guard: a missed variant does not fail, it
simply stops being checked.

It now accepts the identifier followed by `{`, `(`, `,` or end of line,
which covers all three variant shapes. The 4-space indent is what
separates variants from everything else in the block -- doc comments start
with `/`, attributes with `#`, a body's closing brace with `}`, and a
variant's own fields are indented deeper -- so nothing else in the enum
body can match, and the comment now records that reasoning.

Verified with ten mutation cases, all of #803's seven plus three for this
change:

  * a single-line tuple variant with no row is caught (`profile`);
  * a multi-line tuple variant is caught (`bisect`), so a reflowed field
    list does not reopen the hole;
  * a tuple variant carrying `hide = true` is still correctly excluded,
    which is the case a wider pattern could plausibly have broken.

The original seven are unchanged: new unit/struct variant, deleted row,
invented row, a row for the hidden command, a rename, and both parse
self-tests. The widened parse still agrees with the built binary -- 15
visible subcommands, 15 table rows, no disagreement -- and
`just check-guards` is green. Both inputs are bit-identical after the
mutation run.

Signed-off-by: Vyncint Ng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation QoL-improvement Quality-of-life improvement; not a correctness fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants