From 1f0b3a54f6f42331b63200493096399e3e16dd25 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 15:30:39 -0800 Subject: [PATCH 1/4] ci(rs): lint benches and examples in the PR gate The moq-pattern matching bench's varint match had overlapping ranges (`..64`, `..16384`), which `cargo clippy --all-targets` rejects as `match_overlapping_arm`. The gate's clippy runs through the `--tests` nextest build, which never compiles bench or example targets, so only Nightly could see it. Make the varint ranges disjoint, and have the gate's test build (sh/rs/select.sh `test` and `just rs check-test`) also compile `--benches --examples` so clippy-driver lints them; nextest's default filter still leaves the benches unrun. Co-Authored-By: Claude Opus 5.5 --- .config/nextest.toml | 4 ++-- rs/justfile | 15 +++++++++------ rs/moq-pattern/benches/matching.rs | 4 ++-- sh/rs/select.sh | 7 +++++-- sh/rs/select.test.py | 7 +++++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 49d5913fe55..88350511582 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -19,8 +19,8 @@ slow-timeout = { period = "30s", terminate-after = 2 } # race until proven otherwise (see Root Cause First in AGENTS.md). retries = 0 -# PR recipes build library, binary, and integration-test targets. Nightly keeps -# the exhaustive target compile, but executes benches through cargo bench smokes. +# The PR gate compiles benches to lint them, but never runs them here; Nightly +# executes them through cargo bench smokes. default-filter = "not kind(bench)" # Limit ring concurrency within one invocation. Unit-test workers use small diff --git a/rs/justfile b/rs/justfile index 8fafe882020..525780f5f39 100644 --- a/rs/justfile +++ b/rs/justfile @@ -32,13 +32,14 @@ check *args: bash sh/local.sh cargo clippy --locked --all-targets "$@" -- -D warnings just rs lint "$@" -# `check` with clippy enforced by the `test` build. A selection can hold -# nothing testable. +# `check` with clippy enforced by the `test` build, which also compiles the +# benches and examples so they are linted too. A selection can hold nothing +# testable. # Compile, lint, and test in one build, plus everything else `check` verifies. [positional-arguments] check-test *args: - just rs test --no-tests=pass "$@" + just rs test --no-tests=pass --benches --examples "$@" just rs lint "$@" # Everything `check` verifies besides clippy. @@ -293,9 +294,11 @@ media-features *args: # nextest kills a wedged test (`.config/nextest.toml` sets the timeout), but # skips doctests; `just rs doctest` covers those. clippy-driver as the workspace # wrapper enforces lint findings from the same compile. `--tests` builds library, -# binary, and integration-test targets, including binary-only crates; benches and -# examples compile and lint in Nightly's `features`. `build.warnings` denies -# warnings without changing cargo's artifact fingerprint, unlike RUSTFLAGS. +# binary, and integration-test targets, including binary-only crates. The gate +# (`check-test`, sh/rs/select.sh's `test`) adds `--benches --examples` so their +# lints fail the PR rather than Nightly; nextest's default filter leaves the +# benches unrun. `build.warnings` denies warnings without changing cargo's +# artifact fingerprint, unlike RUSTFLAGS. # Run library, binary, and integration tests, enforcing clippy from the same compile. [positional-arguments] diff --git a/rs/moq-pattern/benches/matching.rs b/rs/moq-pattern/benches/matching.rs index 2b2f605bb39..5677acf620d 100644 --- a/rs/moq-pattern/benches/matching.rs +++ b/rs/moq-pattern/benches/matching.rs @@ -151,8 +151,8 @@ const MAX_MESSAGE: usize = u16::MAX as usize; /// A QUIC varint's size, as `AUTH_OK` writes counts and lengths. fn varint(value: usize) -> usize { match value { - ..64 => 1, - ..16384 => 2, + 0..64 => 1, + 64..16384 => 2, _ => 4, } } diff --git a/sh/rs/select.sh b/sh/rs/select.sh index 1d50728277c..a957fab7c18 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -50,8 +50,8 @@ select_packages() { local seeds benches edges selected # A crate's `benches/` builds only its own bench targets, which no other crate can - # depend on and the test build never compiles, so it selects that crate alone - # (for its lint) rather than every dependent's tests. + # depend on, so it selects that crate alone (for its lint) rather than every + # dependent's tests. benches=$(sed -n 's|^rs/\([^/]*\)/benches/.*|\1|p' "$list") # A target can also sit outside its crate, as moq-cli's interop examples # under test/interop/clients/rust/ do, so a change in the directory of a @@ -176,6 +176,9 @@ case "$action" in # A selection can hold nothing testable, and # nextest exits 4 on that; the whole workspace finding none really is wrong. [[ "$packages" == ALL ]] || flags+=(--no-tests=pass) + # Benches and examples join the build only to be linted; nextest's + # default filter leaves the benches unrun. + flags+=(--benches --examples) # CI keeps Cargo's per-crate build timings, which check.yml uploads. timings=() [[ "${GITHUB_ACTIONS:-}" != true ]] || timings=(--timings) diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 3d7e59ee5f6..2c0224ebd1d 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -53,7 +53,7 @@ def test_nextest_launcher_selects_workspace(self): for github_actions in (False, True): for action in ("check", "check-test", "lint", "test"): with self.subTest(action=action, github_actions=github_actions): - suffix = f" --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" + suffix = f" --benches --examples --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" suffix += " moq-relay/io-uring" if LINUX and action == "test" else "" suffix += " --timings" if github_actions and action == "test" else "" self.assertIn( @@ -263,7 +263,10 @@ def test_valid_metadata_selects_dependents_without_errors(self): self.assertEqual(result.stderr, "") self.assertEqual( self.calls.read_text().splitlines(), - ["rs test --package path+file:///rs/dependent#1.0.0 --package path+file:///rs/seed#1.0.0 --no-tests=pass"], + [ + "rs test --package path+file:///rs/dependent#1.0.0 --package path+file:///rs/seed#1.0.0" + " --no-tests=pass --benches --examples" + ], ) def test_malformed_metadata_stops_before_running_tests(self): From b45ec9d76183037d20499a553bebaaf0ab4140ba Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 15:57:04 -0800 Subject: [PATCH 2/4] test(rs): wrap the selector's workspace expectation under 120 columns Co-Authored-By: Claude Opus 5.5 --- sh/rs/select.test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 2c0224ebd1d..5986451538e 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -53,7 +53,8 @@ def test_nextest_launcher_selects_workspace(self): for github_actions in (False, True): for action in ("check", "check-test", "lint", "test"): with self.subTest(action=action, github_actions=github_actions): - suffix = f" --benches --examples --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" + suffix = " --benches --examples" if action == "test" else "" + suffix += f" --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" suffix += " moq-relay/io-uring" if LINUX and action == "test" else "" suffix += " --timings" if github_actions and action == "test" else "" self.assertIn( From 415e69bd0188e5b2d60206b08301960d39f39661 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 16:28:56 -0800 Subject: [PATCH 3/4] ci(rs): enable bench and example required-features in the gate Cargo skips a bench or example whose `required-features` are off without a word, so `--benches --examples` still left moq-quic's benches, moq-stats' `producer_tick`, and on a bench-only change moq-net's `fuzz` and moq-relay's `session` benches unlinted. sh/rs/select.sh's `test` action now reads the built crates' target `required-features` from `cargo metadata` and turns them on in the one test build, beside the device picks. They are all additive. `just rs check-test` drops `--benches --examples`: it forwards the same args to `cargo doc`, which has no `--benches`, so it could not carry the features, and nothing in CI runs it. Co-Authored-By: Claude Opus 5.5 --- rs/justfile | 15 +++++++-------- sh/rs/select.sh | 23 ++++++++++++++++++++++ sh/rs/select.test.py | 46 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/rs/justfile b/rs/justfile index 525780f5f39..f75b16a56c0 100644 --- a/rs/justfile +++ b/rs/justfile @@ -32,14 +32,13 @@ check *args: bash sh/local.sh cargo clippy --locked --all-targets "$@" -- -D warnings just rs lint "$@" -# `check` with clippy enforced by the `test` build, which also compiles the -# benches and examples so they are linted too. A selection can hold nothing -# testable. +# `check` with clippy enforced by the `test` build. A selection can hold +# nothing testable. # Compile, lint, and test in one build, plus everything else `check` verifies. [positional-arguments] check-test *args: - just rs test --no-tests=pass --benches --examples "$@" + just rs test --no-tests=pass "$@" just rs lint "$@" # Everything `check` verifies besides clippy. @@ -295,10 +294,10 @@ media-features *args: # skips doctests; `just rs doctest` covers those. clippy-driver as the workspace # wrapper enforces lint findings from the same compile. `--tests` builds library, # binary, and integration-test targets, including binary-only crates. The gate -# (`check-test`, sh/rs/select.sh's `test`) adds `--benches --examples` so their -# lints fail the PR rather than Nightly; nextest's default filter leaves the -# benches unrun. `build.warnings` denies warnings without changing cargo's -# artifact fingerprint, unlike RUSTFLAGS. +# (sh/rs/select.sh's `test`) adds `--benches --examples` and the features those +# targets require, so their lints fail the PR rather than Nightly; nextest's +# default filter leaves the benches unrun. `build.warnings` denies warnings +# without changing cargo's artifact fingerprint, unlike RUSTFLAGS. # Run library, binary, and integration tests, enforcing clippy from the same compile. [positional-arguments] diff --git a/sh/rs/select.sh b/sh/rs/select.sh index a957fab7c18..94b6f26aa41 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -187,8 +187,11 @@ case "$action" in # features only add code, so every test still runs. Cargo rejects a # feature of a package outside the selection, hence the explicit picks. features=() + # The crates the build holds, for their targets' features below. + building=$names if wants '(moq-video|moq-audio)'; then [[ "$packages" == ALL ]] || flags+=(--package moq-video --package moq-audio) + building+=" moq-video moq-audio" features+=(moq-video/capture moq-audio/capture moq-audio/playback) fi if wants moq-cli; then features+=(moq-cli/play moq-cli/openh264); fi @@ -197,6 +200,26 @@ case "$action" in # The relay's io_uring listener, Linux-only. A moq-uring change selects # the relay too, as its dependent. if [[ "$(uname -s)" == Linux ]] && wants moq-relay; then features+=(moq-relay/io-uring); fi + # Cargo skips a bench or example whose `required-features` are off without + # a word, and a bench-only change selects its crate alone, so no dependent + # turns them on. Turn on every one the built crates' targets name. All of + # them are additive and build wherever the gate runs; moq-uring's targets + # compile to nothing off Linux. + required=$( + set -e + cargo metadata --locked --format-version 1 --no-deps | jq -r --arg names "$building" --arg all "$packages" ' + ($names | split(" ") | map(select(. != ""))) as $want + | .packages[] + | select(if $all == "ALL" then (.name | endswith("-fuzz") | not) else (.name as $n | $want | index($n) != null) end) + | .name as $name + | .targets[] + | select(.kind // [] | any(. == "bench" or . == "example")) + | (.["required-features"] // [])[] + | "\($name)/\(.)"' | sort -u | tr '\n' ' ' + ) + for feature in $required; do + [[ " ${features[*]-} " == *" $feature "* ]] || features+=("$feature") + done if ((${#features[@]})); then flags+=(--features "${features[*]}"); fi just rs test "${flags[@]}" ${timings[@]+"${timings[@]}"} ;; diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 5986451538e..32a2757f778 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -15,6 +15,29 @@ LINUX = os.uname().sysname == "Linux" +def target_features(): + """Every bench and example `required-features`, as `crate/feature`, for the workspace.""" + metadata = json.loads( + subprocess.run( + ["cargo", "metadata", "--locked", "--format-version", "1", "--no-deps"], + cwd=ROOT, + check=True, + capture_output=True, + text=True, + ).stdout + ) + return sorted( + { + f"{package['name']}/{feature}" + for package in metadata["packages"] + if not package["name"].endswith("-fuzz") + for target in package["targets"] + if {"bench", "example"} & set(target["kind"]) + for feature in target.get("required-features", []) + } + ) + + def dispatch_scope(): """The rs module's impact pattern, as sh/dispatch.sh registers it.""" return re.search(r"^module rs '([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) @@ -50,12 +73,12 @@ def selected(self, *paths, action="lint", github_actions=False): return calls.read_text().splitlines() if calls.exists() else [] def test_nextest_launcher_selects_workspace(self): + features = [*DEVICE_FEATURES.split(), "moq-tokio/webrtc", *(["moq-relay/io-uring"] if LINUX else [])] + features += [feature for feature in target_features() if feature not in features] for github_actions in (False, True): for action in ("check", "check-test", "lint", "test"): with self.subTest(action=action, github_actions=github_actions): - suffix = " --benches --examples" if action == "test" else "" - suffix += f" --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" - suffix += " moq-relay/io-uring" if LINUX and action == "test" else "" + suffix = f" --benches --examples --features {' '.join(features)}" if action == "test" else "" suffix += " --timings" if github_actions and action == "test" else "" self.assertIn( f"rs {action} --workspace {FUZZ_EXCLUDES}{suffix}", @@ -118,7 +141,8 @@ def test_device_features_join_the_one_test_build(self): with self.subTest(path=path): calls = self.selected(path, action="test") self.assertEqual(len(calls), 1, calls) - self.assertTrue(calls[0].endswith(f" --features {features}"), calls) + # The targets' required features follow the device ones. + self.assertIn(f" --features {features}", calls[0]) # moq-tokio's WebRTC module is off by default too. calls = self.selected("rs/moq-tokio/src/webrtc.rs", action="test") self.assertEqual(len(calls), 1, calls) @@ -193,6 +217,20 @@ def test_a_bench_selects_only_its_crate(self): calls = self.selected(bench, action=action) self.assertTrue(any("#moq-stats@" in call or "/rs/moq-stats#" in call for call in calls), calls) self.assertFalse(any("moq-relay" in call or "moq-cli" in call for call in calls), calls) + + def test_a_bench_alone_enables_its_required_features(self): + # Alone in the selection, no dependent turns these on, and cargo would + # skip the targets without a word. + for bench, feature in ( + ("rs/moq-stats/benches/producer_tick.rs", "moq-stats/bench"), + ("rs/moq-net/benches/codec.rs", "moq-net/fuzz"), + ("rs/moq-relay/benches/session.rs", "moq-relay/test-support"), + ("rs/moq-quic/benches/wire.rs", "moq-quic/fuzz"), + ): + with self.subTest(bench=bench): + (call,) = [call for call in self.selected(bench, action="test") if call.startswith("rs test ")] + self.assertIn(" --benches --examples ", call) + self.assertIn(feature, call.split(" --features ", 1)[1].split()) calls = self.selected(bench, "rs/moq-stats/src/lib.rs", action="test") self.assertTrue(any("/rs/moq-relay#" in call for call in calls), calls) From 1a135b069e77392cff4889b6a1dc97561b4e96fd Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 17:14:42 -0800 Subject: [PATCH 4/4] test(rs): keep the bench test's dependent check on its moq-stats bench Co-Authored-By: Claude Opus 5.5 --- sh/rs/select.test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 32a2757f778..b0a3bf0311d 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -217,6 +217,8 @@ def test_a_bench_selects_only_its_crate(self): calls = self.selected(bench, action=action) self.assertTrue(any("#moq-stats@" in call or "/rs/moq-stats#" in call for call in calls), calls) self.assertFalse(any("moq-relay" in call or "moq-cli" in call for call in calls), calls) + calls = self.selected(bench, "rs/moq-stats/src/lib.rs", action="test") + self.assertTrue(any("/rs/moq-relay#" in call for call in calls), calls) def test_a_bench_alone_enables_its_required_features(self): # Alone in the selection, no dependent turns these on, and cargo would @@ -231,8 +233,6 @@ def test_a_bench_alone_enables_its_required_features(self): (call,) = [call for call in self.selected(bench, action="test") if call.startswith("rs test ")] self.assertIn(" --benches --examples ", call) self.assertIn(feature, call.split(" --features ", 1)[1].split()) - calls = self.selected(bench, "rs/moq-stats/src/lib.rs", action="test") - self.assertTrue(any("/rs/moq-relay#" in call for call in calls), calls) class MetadataTest(unittest.TestCase):