Skip to content

ci: the example-policy guard's parse self-test cannot detect the rot it guards - #1044

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/example-policy-scope-selftest
Aug 19, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/example-policy-scope-selftest

Conversation

@vyncint

@vyncint vyncint commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

check-example-license-policy.sh collapses every example lock file into groups keyed by their third-party (name, version, source) triples and runs cargo-deny once per distinct group. The comment above its second self-test states the hazard exactly:

# Mirrors the inventory guard: if the lock-file regexes silently rotted, the
# groups would quietly collapse and a single run would vouch for everything.

That test cannot see it. seen incremented once per [[package]] string split, before any regex ran, so it counted blocks rather than parses. Simulating a rot of ^name over the real tree:

healthy          locks=217  seen=13871  groups=31
regexes rotted   locks=217  seen=13871  groups=1      <- both floors pass

Every triple fails to match, every lock parses as having zero third-party crates, all 217 collapse into the single empty group, and the guard runs cargo-deny once, over one example, and exits 0 — vouching for everything, which is the outcome the comment says it prevents. Verified for ^name, ^version and ^source independently; each rots to the same result.

Three changes

  1. seen becomes parsed, counted only after name and version match. Every locked package carries both, so the tally now goes to zero on a rot instead of staying at 13871. Its floor is scaled to the locks found rather than fixed, so it cannot go stale as the tree grows.

  2. A per-lock assertion is the actual detector. Every example reaches crates.io through cuda-core/cuda-device/cuda-host, so a lock resolving no third-party crate means the parse failed. Measured range across the tree is 46 to 142 per lock, so the margin is wide — and a rot takes every lock to zero.

  3. The len(locks) < 20 floor is replaced by a cross-check against an independent enumeration. A count cannot tell a narrowed glob from a smaller tree — [a-m]* still finds 137 of 217 locks and clears any floor loose enough to survive ordinary growth — whereas every example directory with a Cargo.toml has a Cargo.lock beside it (215 of each today), so comparing the two sets names exactly what the glob stopped reaching.

Mutations

Each fails with a specific message where the old code passed silently:

mutation result
rot ^name parse self-test failed: no third-party crates in .../abi_hmm/Cargo.lock
rot ^version same
rot ^source same
glob → [a-m]* found no Cargo.lock for 78 example(s), so deny.toml cannot be enforced over them: ne_bytes_transmute, nested_index_assignment, …

Scope note

The scope sentence is also corrected: it described 187 lock files (186 examples plus one nested sub-workspace) collapsing to 26 runs. Today's tree is 217 locks — 215 examples plus two nested sub-workspaces, cutile_inter_kernel/simt and interop_cubin_identity/device — collapsing to the 31 runs the script itself announces.

The # Measured when this guard was written: line above it is a timestamped measurement and is left exactly as written.

Verification

The guard passes unchanged on today's tree: 31 representatives, every one reporting advisories ok, bans ok, licenses ok, sources ok, exit 0. All counts re-measured against f1e62fe2.

…it guards

`check-example-license-policy.sh` collapses every example lock file into
groups keyed by their third-party `(name, version, source)` triples and runs
cargo-deny once per distinct group. The comment above its second self-test
states the hazard exactly:

    # Mirrors the inventory guard: if the lock-file regexes silently rotted,
    # the groups would quietly collapse and a single run would vouch for
    # everything.

That test cannot see it. `seen` incremented once per `[[package]]` string
split, before any regex ran, so it counts blocks rather than parses.
Simulating a rot of `^name` over the real tree:

    healthy          locks=217  seen=13871  groups=31
    regexes rotted   locks=217  seen=13871  groups=1      <- both floors pass

Every triple fails to match, every lock parses as having zero third-party
crates, all 217 collapse into the single empty group, and the guard runs
cargo-deny once, over one example, and exits 0 -- vouching for everything,
which is the outcome the comment says it prevents. Verified for `^name`,
`^version` and `^source` independently; each rots to the same outcome.

Three changes:

- `seen` becomes `parsed`, counted only after `name` and `version` match.
  Every locked package carries both, so the tally now goes to zero on a rot
  instead of staying at 13871. Its floor is scaled to the locks found rather
  than fixed, so it cannot go stale as the tree grows.

- A per-lock assertion is the actual detector: every example reaches
  crates.io through cuda-core/cuda-device/cuda-host, so a lock resolving no
  third-party crate at all means the parse failed. Measured range across the
  tree is 46 to 142 per lock, so the margin is wide, and a rot takes every
  lock to zero.

- The `len(locks) < 20` floor is replaced by a cross-check against an
  independent enumeration. A count cannot tell a narrowed glob from a smaller
  tree -- `[a-m]*` still finds 137 of 217 locks and clears any floor loose
  enough to survive ordinary growth -- whereas every example directory with a
  Cargo.toml has a Cargo.lock beside it (215 of each today), so comparing the
  two sets names exactly what the glob stopped reaching.

Four mutations, each failing with a specific message where the old code
passed silently: rotting `^name`, `^version` or `^source` each reports
`no third-party crates in .../abi_hmm/Cargo.lock`, and narrowing the glob to
`[a-m]*` reports `found no Cargo.lock for 78 example(s)` and names five.

The scope sentence is also corrected: it described 187 lock files (186
examples plus one nested sub-workspace) collapsing to 26 runs. Today's tree
is 217 locks -- 215 examples plus two nested sub-workspaces,
cutile_inter_kernel/simt and interop_cubin_identity/device -- collapsing to
the 31 runs the script itself announces. The "measured when this guard was
written" line above it is a timestamped measurement and is left as written.

Verified: the guard passes unchanged on today's tree, 31 representatives, all
reporting `advisories ok, bans ok, licenses ok, sources ok`.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup labels Aug 19, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Verified the hardened self-test both ways: clean tree passes (31 grouped cargo-deny runs), and with a deliberately dead name pattern the guard now fails on the first lock with parse self-test failed: no third-party crates in crates/rustc-codegen-cuda/examples/abi_hmm/Cargo.lock. The old count-before-parse check stayed green under the same breakage, which is the hole this closes.
  • The glob-vs-disk cross-check naming missed examples beats the fixed "at least 20" floor. No changes needed.

@nihalpasham
nihalpasham merged commit ea4658f into NVIDIA:main Aug 19, 2026
49 checks passed
nihalpasham added a commit that referenced this pull request Aug 20, 2026
…ed in a day (#1055)

* ci: four tooling comments keep tree sizes by hand, and all four drifted in a day

#1032 added one example, `redux_f32`, and eight catalog entries. That single
merge falsified numbers in four places:

| site | said | now |
|---|--:|--:|
| `check-example-license-policy.sh` (x3) | 217 locks | 218 |
| `check-example-license-policy.sh` (x2) | 215 examples | 216 |
| `check-example-license-policy.sh` | 13871 packages, floor 2170 | 13934, 2180 |
| `cargo-deny.yml` | 31 runs instead of 217 | ... of 218 |
| `Justfile` | 986 catalog entries | 1010 |
| `examples-compile.yml` | 210 example crates | 216 |

Six of those transcriptions are mine, from #1043 and #1044, written the day
before. Refreshing them buys one day. The counts are not load-bearing in any
of the four -- each is there to make a structural point -- so state the
structure and let the code report the numbers:

- The license-policy guard already announced its representative count. It now
  announces the lock count beside it, so the grouping ratio is observable
  output rather than a comment to keep in step:

      Checking deny.toml over 31 representative example workspaces,
      grouped from 218 example lock files.

- Its scope comment and its enumeration cross-check now say "one lock per
  example directory, plus one per nested sub-workspace" instead of naming
  today's totals.

- The parsed-package floor is computed as ten per lock, so the comment says
  that rather than quoting the current product.

- `cargo-deny.yml` says one run per distinct dependency set instead of one per
  lock file, and points at the script's own output.

- The `Justfile` comment's point was that the generated path dominates, which
  35 generated op modules against 7 hand-written makes without an entry count.
  Module counts are structural and have not moved through any of these merges.

- `examples-compile.yml`'s number only justified a timeout, so "every example
  crate" does the same job.

One number is kept and re-labelled rather than removed: the `[a-m]*` glob
illustration in the cross-check comment now reads "measured once ... 137 of
the 217 locks then present", matching the timestamped-measurement idiom the
same file already uses two paragraphs above. The argument needs a concrete
ratio; making it explicitly historical stops it being a live claim.

Verified: the guard passes unchanged -- 31 representatives grouped from 218
lock files, `deny.toml holds over every example workspace outside
POLICY_EXEMPT_EXAMPLES`, exit 0. `bash -n` clean, `just --list` parses, all
eleven workflows parse, and dialect-nvvm really does hold 35 generated and 7
hand-written op modules.

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

* ci: correct the floor-margin claim and tighten the rewritten tooling comments

---------

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

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants