diff --git a/.github/justfile b/.github/justfile index 714a195bcb8..613419b213e 100644 --- a/.github/justfile +++ b/.github/justfile @@ -26,6 +26,7 @@ test: python3 sh/rs/package-rename.test.py python3 sh/rs/select.test.py python3 sh/js/workspace.test.py + python3 sh/rs/test-lints.test.py sh/go/publish-wrapper.test.sh bash .claude/hooks/direnv.test.sh python3 sh/rs/uring.test.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a0aa9c68e22..afcb74d4949 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -20,11 +20,8 @@ concurrency: cancel-in-progress: true jobs: - # `check` and `test` are separate jobs because they share almost no build - # artifacts: clippy emits rmeta without codegen, while nextest codegens and - # links every test binary. Running them in sequence meant paying both in - # series for no reuse, so they run concurrently and the job takes the slower - # of the two rather than their sum. + # Test enforces default-feature clippy while compiling its binaries. Check + # runs the other lints, docs, and distinct feature/target builds in parallel. check: name: Check # Skip the actual work on close/merge: this run exists only to cancel the diff --git a/quest/m0/ci/README.md b/quest/m0/ci/README.md index b5e61ba9c38..4674b0d3472 100644 --- a/quest/m0/ci/README.md +++ b/quest/m0/ci/README.md @@ -57,7 +57,6 @@ Measure each change against the numbers above and record the result in its PR. - [Require platform gates](/quest/m0/ci/platform-queue.md) - activate the consolidated platform checks in the main and release rulesets after the workflow lands - [mbx on R2](/quest/m0/ci/mbx-r2.md) - Rust builds on every OS read an R2 cache that only `main` writes, escaping the 10 GB Actions cache - [Nix cache](/quest/m0/ci/nix-cache.md) - `nix.moq.dev` on R2 replaces Cachix for CI and releases -- [Clippy in Test](/quest/m0/ci/clippy-test.md) - Test's clippy-driver compile denies warnings, so Check stops repeating the default Clippy pass - [Nightly finishes](/quest/m0/ci/nightly-split.md) - every Nightly step runs within its timeout - [FFI artifact reuse](/quest/m0/ci/ffi-reuse.md) - identical FFI release builds are built once and shared across the language packages - [Feature permutations](/quest/m0/ci/features.md) - PR feature checks and test builds compile only what they run, measured first diff --git a/quest/m0/ci/clippy-test.md b/quest/m0/ci/clippy-test.md deleted file mode 100644 index 42d1ef07454..00000000000 --- a/quest/m0/ci/clippy-test.md +++ /dev/null @@ -1,16 +0,0 @@ -# [S] Test enforces Clippy so Check stops repeating it - -## Goal - -The Clippy lints that gate a merge are enforced once, during the compile that -Test already does, and Check no longer runs a second default-feature Clippy -pass. Docs and the distinct feature and target checks still run in Check, in -parallel. - -## Plan - -Test already compiles through clippy-driver, but warnings do not fail it, and -Check's separate pass cost nearly five minutes on the default suite in one -sampled run. Deny warnings in Test's compile. Verify the two passes cover the -same targets and lints before removing Check's; any target only Check lints -(benches, examples) stays. diff --git a/rs/justfile b/rs/justfile index 43a5e513aec..0e6c82a82ce 100644 --- a/rs/justfile +++ b/rs/justfile @@ -30,22 +30,20 @@ default: [positional-arguments] check *args: cargo clippy --locked --all-targets "$@" -- -D warnings - just rs _lint "$@" + just rs lint "$@" -# `check` with clippy replaced by the `test` build, whose clippy-driver reports -# the same findings. `build.warnings` turns them into errors without entering -# cargo's fingerprint, so a later plain `test` reuses the artifacts. 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: - CARGO_BUILD_WARNINGS=deny RUSTC_WORKSPACE_WRAPPER={{ require("clippy-driver") }} bash sh/rs/nextest.sh cargo nextest run --locked --all-targets --no-tests=pass "$@" - just rs _lint "$@" + just rs test --no-tests=pass "$@" + just rs lint "$@" # Everything `check` verifies besides clippy. [positional-arguments] -_lint *args: +lint *args: python3 sh/rs/stats-docs.py cargo fmt --all --check # quinn-udp keeps quinn's formatting; cargo fmt skips it (see moq-sock's lib.rs). @@ -67,6 +65,10 @@ fix *args: check-changed $LIST: sh/rs/select.sh check "$LIST" +# Like `lint`, with the feature and target checks for the selected crates. +lint-changed $LIST: + sh/rs/select.sh lint "$LIST" + # Like `check-test`, but only the crates in a changed-file list plus their dependents. check-test-changed $LIST: sh/rs/select.sh check-test "$LIST" @@ -250,14 +252,14 @@ media-features: # 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 reports lint findings from the same compile, as warnings: `check-test` -# is the gate. It is part of cargo's fingerprint, and RUSTFLAGS would split the -# artifact cache, which is why neither is set any other way. +# wrapper enforces lint findings from the same compile, including benches and +# examples. `build.warnings` denies warnings without changing cargo's artifact +# fingerprint, unlike RUSTFLAGS. -# Run the test suite, reporting clippy findings from the same compile. +# Run the test suite and enforce clippy findings from the same compile. [positional-arguments] test *args: - RUSTC_WORKSPACE_WRAPPER="$(command -v clippy-driver || true)" bash sh/rs/nextest.sh cargo nextest run --locked --all-targets "$@" + CARGO_BUILD_WARNINGS=deny RUSTC_WORKSPACE_WRAPPER={{ require("clippy-driver") }} bash sh/rs/nextest.sh cargo nextest run --locked --all-targets "$@" # Exercise the ignored hardware tests for every GPU vendor on this Linux host. gpu: diff --git a/rs/moq-video/src/capture/mod.rs b/rs/moq-video/src/capture/mod.rs index 83443ba3f0c..38c066d558c 100644 --- a/rs/moq-video/src/capture/mod.rs +++ b/rs/moq-video/src/capture/mod.rs @@ -374,12 +374,12 @@ impl Stream { /// A test-driven capture device: fixtures push frames at explicit acquisition /// instants or device timestamps, standing in for a camera behind a [`Stream`]. -#[cfg(test)] +#[cfg(all(test, feature = "openh264"))] pub(crate) struct Synthetic { chan: Arc, } -#[cfg(test)] +#[cfg(all(test, feature = "openh264"))] impl Synthetic { /// Open a synthetic device with the given geometry, returning it and the stream reading it. pub(crate) fn open(size: crate::Size, framerate: Rate) -> (Self, Stream) { diff --git a/sh/dispatch-query.test.py b/sh/dispatch-query.test.py index 621de375248..de28e22813c 100644 --- a/sh/dispatch-query.test.py +++ b/sh/dispatch-query.test.py @@ -175,6 +175,29 @@ def test_platform_is_only_a_query(self): self.assertEqual(result.returncode, 2) self.assertEqual(result.stdout, "") + def test_ci_check_leaves_default_rust_lints_to_test(self): + for tool in ("bun", "python3", "cargo", "wasm-bindgen", "jq", "shellcheck", + "shfmt", "taplo", "nixfmt", "actionlint", "quest", "nix"): + path = self.bin / tool + path.write_text("#!/bin/sh\nexit 0\n") + path.chmod(0o755) + just = self.bin / "just" + just.write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$*" >>"$CALLS"\n') + just.chmod(0o755) + self.env.update(MOQ_DEV_SHELL="1", CALLS=str(self.root / "calls")) + self.change("rs/moq-clock/src/lib.rs") + self.env["PATH"] += f":{os.environ['PATH']}" + for script in ("markdown.sh", "shell.sh"): + path = self.repo / "sh" / script + path.write_text("#!/bin/sh\nexit 0\n") + path.chmod(0o755) + result = subprocess.run(["bash", "sh/dispatch.sh", "ci-check", "origin/main"], + cwd=self.repo, env=self.env, text=True, capture_output=True) + self.assertEqual(result.returncode, 0, result.stderr) + calls = (self.root / "calls").read_text().splitlines() + self.assertTrue(any(call.startswith("rs lint-changed ") for call in calls), calls) + self.assertFalse(any(call.startswith("rs check-changed ") for call in calls), calls) + def benchmark(): # Sweep path count and both job selections. No timing threshold: hosted setup diff --git a/sh/dispatch.sh b/sh/dispatch.sh index a632297589e..6bcc101ae48 100755 --- a/sh/dispatch.sh +++ b/sh/dispatch.sh @@ -228,9 +228,9 @@ for module in "${selected[@]}"; do check:js) just js check-changed "$js_list" ;; check:workers) just js workers ;; check:moq_sh) just infra moq-sh test ;; - # `check` lints Rust through its test build, so the crates compile once; - # `ci-check` uses clippy, which is quicker when the tests run elsewhere. - check:rs) if [[ "$action" == check ]]; then just rs check-test-changed "$rs_list"; else just rs check-changed "$rs_list"; fi ;; + # Test enforces default-feature clippy through its compile. Check keeps + # the other lints and distinct feature/target builds. + check:rs) if [[ "$action" == check ]]; then just rs check-test-changed "$rs_list"; else just rs lint-changed "$rs_list"; fi ;; check:bench) cargo check --locked --package moq-relay --package moq-bench --features moq-relay/io-uring ;; check:quest) quest check ;; check:drill) just test drill-sensitivity --apply-only ;; diff --git a/sh/rs/select.sh b/sh/rs/select.sh index a637f29e4a3..13a53ee7d1e 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash -# Run `just rs check|check-test|fix|test` on the crates a diff touches, plus +# Run `just rs check|check-test|lint|fix|test` on the crates a diff touches, plus # their dependents. `platform` is the Windows and macOS compile. # -# Usage: sh/rs/select.sh check|check-test|fix|test|platform|uring LISTFILE|--all +# Usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|uring LISTFILE|--all # # LISTFILE holds the changed paths, one per line. `--all` is the whole # workspace, as is a change to anything every crate is built or tested by. set -euo pipefail -usage="usage: sh/rs/select.sh check|check-test|fix|test|platform|uring LISTFILE|--all" +usage="usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|uring LISTFILE|--all" action=${1:?$usage} list=${2:?$usage} @@ -101,7 +101,7 @@ if [[ -f "$list" ]] && grep -qx 'sh/rs/net-features.sh' "$list"; then net_script case "$packages" in "") - if [[ "$action" == check* && -n "$media_script$net_script" ]]; then + if [[ ("$action" == check* || "$action" == lint) && -n "$media_script$net_script" ]]; then if [[ -n "$media_script" ]]; then just rs media-features; fi if [[ -n "$net_script" ]]; then just rs net-features; fi else @@ -126,7 +126,7 @@ case "$action" in uring) if wants '(moq-uring|moq-relay)'; then just rs uring; fi ;; - check | check-test) + check | check-test | lint) just rs "$action" "${flags[@]}" # Workspace feature unification hides a broken moq-tokio feature set # whenever any dependent enables a transport. @@ -139,8 +139,8 @@ case "$action" in if wants '(moq-wasm|moq-mux|moq-ffi|moq-clock)'; then just rs wasm; fi # Device code behind the off-by-default `capture` feature. check-test # lints it through the test build, as for the default features. - if wants '(moq-video|moq-audio)'; then - if [[ "$action" == check-test ]]; then CARGO_BUILD_WARNINGS=deny just rs capture-test; else just rs capture; fi + if [[ "$action" != lint ]] && wants '(moq-video|moq-audio)'; then + if [[ "$action" == check-test ]]; then just rs capture-test; else just rs capture; fi fi # moq-cli's media tasks are behind `play`; only check-test runs tests. if [[ "$action" == check-test ]] && wants moq-cli; then just rs play; fi diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 7898e109161..573d39509ab 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -20,8 +20,9 @@ def test_nextest_launcher_selects_workspace(self): just.chmod(0o755) changed = scratch / "changed" changed.write_text("sh/rs/nextest.sh\n") - env = dict(os.environ, PATH=f"{scratch}:{os.environ['PATH']}", SELECT_CALLS=str(calls)) - for action in ("check", "check-test", "test"): + env = dict(os.environ, PATH=f"{scratch}:{os.environ['PATH']}", SELECT_CALLS=str(calls), + BASH_ENV=os.devnull) + for action in ("check", "check-test", "lint", "test"): with self.subTest(action=action): calls.write_text("") subprocess.run( @@ -32,6 +33,11 @@ def test_nextest_launcher_selects_workspace(self): f"rs {action} --workspace --exclude moq-net-fuzz", calls.read_text().splitlines(), ) + if action == "lint": + selected = calls.read_text().splitlines() + for recipe in ("tokio-features", "wasm", "uring-check", "media-features"): + self.assertIn(f"rs {recipe}", selected) + self.assertNotIn("rs capture", selected) if __name__ == "__main__": diff --git a/sh/rs/test-lints.test.py b/sh/rs/test-lints.test.py new file mode 100644 index 00000000000..81d5085f5b5 --- /dev/null +++ b/sh/rs/test-lints.test.py @@ -0,0 +1,48 @@ +"""A test build must reject Clippy findings without a separate lint compile.""" + +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] + + +class TestLints(unittest.TestCase): + def test_clippy_warning_fails_test_build(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + (root / "rs").mkdir() + (root / "sh" / "rs").mkdir(parents=True) + (root / "src").mkdir() + (root / "justfile").write_text("mod rs\n") + shutil.copy(ROOT / "rs" / "justfile", root / "rs" / "justfile") + shutil.copy(ROOT / "sh" / "rs" / "nextest.sh", root / "sh" / "rs" / "nextest.sh") + (root / "Cargo.toml").write_text( + '[package]\nname = "test-lint-gate"\nversion = "0.0.0"\nedition = "2024"\n' + ) + (root / "src" / "lib.rs").write_text( + 'pub fn empty(values: &[u8]) -> bool { values.len() == 0 }\n' + '#[test]\nfn runs() { assert!(empty(&[])); }\n' + ) + toolchain = Path(shutil.which("clippy-driver")).parent + env = dict(os.environ, CARGO_TARGET_DIR=str(root / "target"), + PATH=f"{toolchain}:{os.environ['PATH']}") + subprocess.run(["cargo", "generate-lockfile", "--offline"], cwd=root, + env=env, check=True, capture_output=True) + result = subprocess.run(["just", "rs", "test"], cwd=root, env=env, + text=True, capture_output=True) + self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("clippy::len_zero", result.stderr) + source = root / "src" / "lib.rs" + source.write_text(source.read_text().replace("values.len() == 0", "values.is_empty()")) + result = subprocess.run(["just", "rs", "test"], cwd=root, env=env, + text=True, capture_output=True) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + +if __name__ == "__main__": + unittest.main()