Skip to content

ci: match tuple variants in the CLI command-reference guard - #807

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/cli-guard-tuple-variants
Aug 12, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/cli-guard-tuple-variants

Conversation

@vyncint

@vyncint vyncint commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The follow-up you noted on #803 — "the variant regex skips tuple variants (none
exist today); extending it closes the one silent hole."

The hole

The pattern was:

VARIANT = re.compile(r"^ {4}([A-Z][A-Za-z0-9]*)\s*[{,]?\s*$")

It 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 that 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 just quietly stops being checked.

The fix

The identifier may now be followed by {, (, , or end of line, covering all
three variant shapes:

Clean,            unit    -> ends after the comma (or at EOF)
Run {             struct  -> body follows on deeper-indented lines
Profile(String),  tuple   -> fields follow on the same line

Widening is safe because 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. The comment now records that reasoning,
since it is the load-bearing assumption.

Verification — ten mutation cases

Three new ones for this change:

mutation result
single-line tuple variant, no row caught (profile)
multi-line tuple variant, no row caught (bisect) — a reflowed field list does not reopen the hole
tuple variant carrying hide = true correctly excluded — the case a wider pattern could plausibly have broken

And #803's original seven, all still caught with no regression: new unit/struct
variant, deleted row, invented row, a row for the hidden command, a rename, and
both parse self-tests.

Also re-ran the checks you verified independently on #803:

  • widened parse still agrees with the built binary — 15 visible subcommands,
    15 table rows, zero disagreement;
  • just check-guards green end to end;
  • both inputs bit-identical after the mutation run (git diff clean).

One script, one regex, one comment. No behaviour change today, since the enum has
no tuple variants — this is the hole closing before something falls in it.

The follow-up noted on NVIDIA#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 NVIDIA#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]>
@nihalpasham nihalpasham added 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 labels Aug 12, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: the follow-up named in the #803 merge note. The variant regex now catches tuple, inline-struct, and trailing-comment forms instead of silently skipping them.

Verified here:

  • re-ran the guard's parse loop against the real Commands enum: identical 15 visible + 1 hidden under old and new regex, so no behavior change today;
  • synthetic probes: single-line tuple, multi-line tuple, inline struct, trailing comment all caught by the new regex and all silently missed by the old; a hide = true tuple routes to hidden; zero false positives on doc comments, attributes, and closers.

Landing once CI is green.

@nihalpasham
nihalpasham merged commit 4c0be88 into NVIDIA:main Aug 12, 2026
41 checks passed
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