From 37559dae820de4f3fee3c83dccb7dd0840640cdf Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:58:06 +0100 Subject: [PATCH] pr_ready: run CI's clippy, CI's test features, Python tests and launcher rule pr_ready --quick passed #1895 while CI's clippy failed on an unused import in horizon-mods' tests: clippy on the touched crates and their dependents gives them other features than CI's workspace-wide run (Cargo unifies features over the packages it builds). - clippy: CI's two commands as they are. The whole workspace runs with the game's code mods, and the server build (horizon-client --no-default-features) runs when horizon-client is affected. Warm on the Mac mini, a change to hud.rs took 14-16 s against 17 s before, and food.rs 22-32 s against 14 s. Each worktree's first run costs about 3 min once. - tests stay on the touched crates, with the features CI's workspace run gives them: horizon-client's code mods, and horizon-mods' runtime, pack and index. - The Python tests always run, as in CI: some read the crates, the roadmap or the workflows. - The launcher steps run when CI's launcher job would (tools/ci/rust_changes.py's rule, which also covers the root manifests and the check itself). Co-Authored-By: Claude Opus 5.5 --- tests/test_pr_ready.py | 41 +++++++++++++++++++--------- tools/pr_ready.py | 61 +++++++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 36 deletions(-) diff --git a/tests/test_pr_ready.py b/tests/test_pr_ready.py index 0eab92fb0..87373cb31 100644 --- a/tests/test_pr_ready.py +++ b/tests/test_pr_ready.py @@ -9,7 +9,8 @@ PACKAGES = {"horizon-core": "crates/horizon-core", "horizon-client": "crates/hor "horizon-theme": "crates/horizon-theme", "xtask": "xtask"} LIBRARIES = set(PACKAGES) - {"xtask"} DEPENDENCIES = {"horizon-client": {"horizon-core"}} -MODS = " --features horizon-mods/runtime,horizon-mods/pack,horizon-client/mods" +MODS = " --features horizon-client/mods,horizon-mods/pack" +CLIPPY = pr_ready.CI_CLIPPY + " && " + pr_ready.CI_CLIPPY_SERVER def args(host="local", quick=False): @@ -35,6 +36,9 @@ class PrReadyTests(unittest.TestCase): self.assertFalse(pr_ready.workspace_rust("crates/horizon-client/README.md")) self.assertFalse(pr_ready.workspace_rust("launcher/src/main.rs")) self.assertTrue(pr_ready.launcher_rust("launcher/src/main.rs")) + # CI's launcher job also runs for the root workspace's manifests and for its own check. + self.assertTrue(pr_ready.launcher_rust("Cargo.lock")) + self.assertTrue(pr_ready.launcher_rust("tools/ci/rust_changes.py")) self.assertTrue(pr_ready.launcher_rust("crates/horizon-prepare/src/lib.rs")) self.assertTrue(pr_ready.launcher_rust("crates/horizon-theme/src/lib.rs")) self.assertTrue(pr_ready.launcher_rust("crates/horizon-telemetry/src/lib.rs")) @@ -46,10 +50,9 @@ class PrReadyTests(unittest.TestCase): with mock.patch.object(pr_ready, "affected_here", return_value=[]): steps = pr_ready.plan(args(quick=True), "origin/main", {"crates/horizon-client/src/game.rs"}, PACKAGES, LIBRARIES, DEPENDENCIES) by_name = {step.name: step for step in steps} - self.assertEqual(by_name["clippy"].command, - "cargo clippy -p horizon-client --all-targets --locked -- -D warnings") + self.assertEqual(by_name["clippy"].command, CLIPPY) self.assertEqual(by_name["tests: horizon-client"].command, - "cargo test --locked -p horizon-client --tests") + "cargo test --locked -p horizon-client --features horizon-client/mods --tests") self.assertEqual(by_name["doc tests"].command, "cargo test --locked -p horizon-client --doc") self.assertIsNone(by_name["doc tests"].status) @@ -58,12 +61,24 @@ class PrReadyTests(unittest.TestCase): with self.subTest(path=path), mock.patch.object(pr_ready, "affected_here", return_value=[]): steps = pr_ready.plan(args(quick=True), "origin/main", {path}, PACKAGES, LIBRARIES, DEPENDENCIES) by_name = {step.name: step for step in steps} - self.assertEqual(by_name["clippy"].command, - "cargo clippy --workspace" + MODS + " --all-targets --locked -- -D warnings") + self.assertEqual(by_name["clippy"].command, CLIPPY) self.assertEqual(by_name["tests: workspace"].command, "cargo test --locked --workspace" + MODS + " --tests") self.assertEqual(by_name["doc tests"].command, "cargo test --locked --workspace --doc") + def test_tests_get_the_features_ci_s_workspace_run_gives_them(self): + self.assertEqual(pr_ready.mod_features(["horizon-world"]), "") + self.assertEqual(pr_ready.mod_features(["horizon-client"]), " --features horizon-client/mods") + self.assertEqual(pr_ready.mod_features(["horizon-mods"]), + " --features horizon-mods/runtime,horizon-mods/pack,horizon-mods/index") + self.assertEqual(pr_ready.mod_features(None), MODS) + + def test_python_tests_always_run(self): + with mock.patch.object(pr_ready, "affected_here", return_value=[]): + steps = pr_ready.plan(args(quick=True), "origin/main", {"crates/horizon-core/src/lib.rs"}, + PACKAGES, LIBRARIES, DEPENDENCIES) + self.assertIsNone({step.name: step for step in steps}["Python tests"].status) + def test_non_rust_changes_skip_workspace_checks(self): for path in ("README.md", "tools/pr_ready.py", "launcher/src/main.rs"): with self.subTest(path=path), mock.patch.object(pr_ready, "affected_here", return_value=[]): @@ -77,7 +92,7 @@ class PrReadyTests(unittest.TestCase): steps = pr_ready.plan(args(), "origin/main", {"crates/horizon-core/src/lib.rs", "crates/horizon-client/examples/probe.rs"}, PACKAGES, LIBRARIES, DEPENDENCIES) for step in steps: - if step.name in ("clippy", "tests: horizon-client, horizon-core", "doc tests"): + if step.name in ("tests: horizon-client, horizon-core", "doc tests"): self.assertIn("-p horizon-client -p horizon-core", step.command) self.assertIsNone(step.status) @@ -94,15 +109,17 @@ class PrReadyTests(unittest.TestCase): by_name = {step.name: step for step in steps} self.assertEqual(by_name["doc tests"].command, "cargo test --locked -p horizon-core --doc") - def test_clippy_checks_transitive_consumers_but_tests_only_touched_crates(self): - packages = {name: f"crates/{name}" for name in ("core", "world", "client", "unrelated")} - dependencies = {"world": {"core"}, "client": {"world"}, "unrelated": set()} + def test_clippy_is_ci_s_and_the_server_build_when_the_game_is_affected(self): + packages = {name: f"crates/{name}" for name in ("core", "world", "horizon-client", "unrelated")} + dependencies = {"world": {"core"}, "horizon-client": {"world"}, "unrelated": set()} with mock.patch.object(pr_ready, "affected_here", return_value=[]): steps = pr_ready.plan(args(), "origin/main", {"crates/core/src/lib.rs"}, packages, set(packages), dependencies) + unrelated = pr_ready.plan(args(), "origin/main", {"crates/unrelated/src/lib.rs"}, + packages, set(packages), dependencies) + self.assertEqual({step.name: step for step in unrelated}["clippy"].command, pr_ready.CI_CLIPPY) by_name = {step.name: step for step in steps} - self.assertEqual(by_name["clippy"].command, - "cargo clippy -p client -p core -p world --all-targets --locked -- -D warnings") + self.assertEqual(by_name["clippy"].command, CLIPPY) self.assertEqual(by_name["tests: core"].command, "cargo test --locked -p core --tests") self.assertEqual(by_name["doc tests"].command, "cargo test --locked -p core --doc") diff --git a/tools/pr_ready.py b/tools/pr_ready.py index 5b1622e2e..89a529192 100755 --- a/tools/pr_ready.py +++ b/tools/pr_ready.py @@ -7,12 +7,13 @@ python3 tools/pr_ready.py --quick # without running the vanilla harnesses From the files the branch changes since its merge base with --base (committed or not) it decides what to run: -rustfmt, clippy with warnings denied and the tests of the touched crates; the launcher (its own workspace) the -same way when it, horizon-prepare or horizon-theme changed; crates/horizon-theme/tokens.css against horizon-theme; -Cargo.lock changing only with a Cargo.toml; the Python tests and the public-tree check; and the vanilla -harnesses the changes can affect, picked as CI's parity job picks them (tools/parity.py --changed). Harnesses run -where the vanilla data is (a prepared .local/ here, or the Mac mini); elsewhere they are listed for CI. -Clippy checks all targets of touched crates and their transitive workspace dependents, including examples. +rustfmt, and clippy with warnings denied exactly as CI's verify job runs it (the whole workspace with the game's code +mods, plus the server build when horizon-client is affected); the tests of the touched crates, with the features +CI's workspace-wide run gives them; the launcher (its own workspace) the same way when CI's launcher job would run +(tools/ci/rust_changes.py --launcher); crates/horizon-theme/tokens.css against horizon-theme; Cargo.lock changing +only with a Cargo.toml; the Python tests (always, as in CI) and the public-tree check; and the vanilla harnesses the +changes can affect, picked as CI's parity job picks them (tools/parity.py --changed). Harnesses run where the +vanilla data is (a prepared .local/ here, or the Mac mini); elsewhere they are listed for CI. Tests select library, binary and integration targets explicitly, followed by doc tests, so unrelated example executables are not built and linked again. @@ -43,6 +44,7 @@ if "PARITY_SHARED" not in os.environ and not (ROOT / ".local" / "minecraft").exi # A fleet worktree without vanilla data still knows each harness's dependencies. os.environ["PARITY_SHARED"] = str(FLEET_SHARED) from tools import parity, release_train # noqa: E402 +from tools.ci import rust_changes # noqa: E402 RBUILD = Path.home() / "fleet" / "rbuild" LINE_LIMIT = 500 @@ -82,9 +84,8 @@ def workspace_rust(path): def launcher_rust(path): - """Whether a change to path is built into the launcher (its own workspace).""" - return not is_doc(path) and any(path.startswith(p) for p in release_train.LAUNCHER_PATHS) and \ - path != "launcher/links.json" and not path.startswith("launcher/docs/") + """Whether a change to path is built into the launcher (its own workspace): CI's launcher job's own rule.""" + return rust_changes.needs_launcher([path]) def touched_crates(paths, packages): @@ -268,14 +269,25 @@ def parity_summary(output): return text +# CI's verify job (.github/workflows/ci.yml): clippy over the whole workspace with the game's code mods, and over the +# server build (the game without sound or controllers); tests with code mods and mod packaging. +CI_CLIPPY = "cargo clippy --workspace --all-targets --locked --features horizon-client/mods -- -D warnings" +CI_CLIPPY_SERVER = "cargo clippy -p horizon-client --all-targets --locked --no-default-features -- -D warnings" +CI_TEST_FEATURES = "horizon-client/mods,horizon-mods/pack" + + def mod_features(crates): - """Code mods are off by default (docs/mods.md): on wherever horizon-mods is checked, as in CI.""" - if crates is not None and "horizon-mods" not in crates: - return "" - features = ["horizon-mods/runtime", "horizon-mods/pack"] - if crates is None or "horizon-client" in crates: + """The features CI's workspace-wide test run gives these crates (code mods are off by default: docs/mods.md). + Cargo unifies features over the packages it builds, so a crate tested alone needs the ones the workspace would + have turned on for it: horizon-client's code mods, and horizon-mods' runtime, packaging and index.""" + if crates is None: + return f" --features {CI_TEST_FEATURES}" + features = [] + if "horizon-mods" in crates: + features += ["horizon-mods/runtime", "horizon-mods/pack", "horizon-mods/index"] + if "horizon-client" in crates: features.append("horizon-client/mods") - return f" --features {','.join(features)}" + return f" --features {','.join(features)}" if features else "" def plan(args, base, changed, crates_of, libraries, dependencies): @@ -283,16 +295,18 @@ def plan(args, base, changed, crates_of, libraries, dependencies): rust = any(workspace_rust(path) for path in changed) launcher = any(launcher_rust(path) for path in changed) # The Python tests also hold ROADMAP.md to roadmap/roadmap.toml (tests/test_roadmap.py). - python = any(path.endswith(".py") or path.startswith(("tests/", "tools/", "roadmap/")) or path == "ROADMAP.md" - for path in changed) crates = touched_crates(changed, crates_of) if rust else [] # An unrecognised Rust path must not silently skip validation. if rust and crates == []: crates = None selection = "--workspace" if crates is None else " ".join(f"-p {shlex.quote(c)}" for c in crates) + # CI's own clippy commands: a crate checked alone gets other features than in CI's workspace-wide run, and an + # unused import behind a feature passed here and failed in CI (#1895). Warm, the workspace run costs about what + # the touched crates and their dependents did (14-32 s against 14-17 s on the Mac mini, 2026-10-26). clippy_crates = dependent_crates(crates, dependencies) - clippy_selection = "--workspace" if clippy_crates is None else " ".join( - f"-p {shlex.quote(c)}" for c in clippy_crates) + clippy = CI_CLIPPY + if clippy_crates is None or "horizon-client" in clippy_crates: + clippy += f" && {CI_CLIPPY_SERVER}" test_skip = None if crates is None or crates else "no crate touched" doc_crates = sorted(libraries if crates is None else libraries.intersection(crates)) doc_selection = "--workspace" if crates is None else " ".join(f"-p {shlex.quote(c)}" for c in doc_crates) @@ -300,11 +314,10 @@ def plan(args, base, changed, crates_of, libraries, dependencies): steps = [ Step("Cargo.lock", where="git"), Step("Public tree", "python3 tools/check_public_tree.py", where="here"), - Step("Python tests", "python3 -m unittest discover -s tests", where="here", - skip=None if python else "no Python change", summary=unittest_passed), + # Always, as in CI: some read the crates, the roadmap or the workflows. + Step("Python tests", "python3 -m unittest discover -s tests", where="here", summary=unittest_passed), Step("rustfmt", "cargo fmt --all -- --check", skip=None if rust else no_rust), - Step("clippy", f"cargo clippy {clippy_selection}{mod_features(clippy_crates)} --all-targets --locked -- -D warnings", - skip=None if rust else no_rust), + Step("clippy", clippy, skip=None if rust else no_rust), Step("tests" + (": workspace" if crates is None else f": {', '.join(crates)}" if crates else ""), f"cargo test --locked {selection}{mod_features(crates)} --tests", skip=test_skip, summary=tests_passed), @@ -404,7 +417,7 @@ def run_windows(steps, verbose): elif step.name == "rustfmt": command = ["cargo", "fmt", "--all", "--", "--check"] elif step.name == "clippy": - command = ["cargo", "clippy", "--workspace", "--all-targets", "--locked", "--", "-D", "warnings"] + command = shlex.split(CI_CLIPPY) # the server build's clippy runs in CI (Linux) elif step.name.startswith("tests"): command = shlex.split(step.command) elif step.name == "tokens.css up to date":