Files
horizon-airdef/tests/test_ci_rust_changes.py
T
Ludovic Marie dbbe3a45d9 CI: check the launcher's workspace on every push to main and on pull requests that touch it
verify's cargo runs never build launcher/ (its own workspace), so #2059 and the
registry ratings commit each passed alone and left main's launcher failing to
compile (E0061). The new launcher job runs its rustfmt, clippy -D warnings and lib
tests when a pull request changes the launcher, a crate it builds or the root
manifests, and on every push to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 16:29:09 +01:00

65 lines
2.8 KiB
Python

import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from tools.ci.rust_changes import changed_paths, needs_launcher, needs_rust
class RustChangesTests(unittest.TestCase):
def test_only_content_changes_skip_rust(self):
self.assertFalse(needs_rust([]))
self.assertFalse(needs_rust([
"website/src/index.html", "website/src/main.ts", "docs/setup.md", "README.md",
]))
for path in [
"crates/horizon-client/src/game.rs", "xtask/src/main.rs", "Cargo.lock",
".cargo/config.toml", ".github/workflows/ci.yml", "tools/ci/rust_changes.py",
"research-lock.json", "website/src/tokens.css", "unknown-file",
]:
with self.subTest(path=path):
self.assertTrue(needs_rust(["README.md", path]))
def test_launcher_checks_follow_the_crates_it_builds(self):
for path in ["crates/horizon-client/src/game.rs", "launcher/links.json", "launcher/docs/a.md",
"launcher/README.md", "website/src/index.html", "tools/pr_ready.py"]:
with self.subTest(path=path):
self.assertFalse(needs_launcher([path]))
for path in ["launcher/src/main.rs", "launcher/Cargo.lock", "crates/horizon-port-pack/src/net.rs",
"crates/horizon-theme/src/lib.rs", "Cargo.toml", "Cargo.lock",
".github/workflows/ci.yml"]:
with self.subTest(path=path):
self.assertTrue(needs_launcher(["README.md", path]))
def test_moving_source_into_docs_still_requires_rust(self):
with tempfile.TemporaryDirectory() as directory:
def git(*args):
return subprocess.check_output(["git", "-C", directory, *args])
git("init", "--quiet")
source = Path(directory, "source.rs")
source.write_text("fn main() {}\n")
git("add", ".")
git("-c", "user.name=CI test", "-c", "user.email=ci@example.invalid",
"-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "base")
base = git("rev-parse", "HEAD").decode().strip()
Path(directory, "docs").mkdir()
source.rename(Path(directory, "docs/example.rs"))
git("add", "-A")
git("-c", "user.name=CI test", "-c", "user.email=ci@example.invalid",
"-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "move")
# Exercise the same diff command as CI in the temporary repository.
previous = Path.cwd()
try:
os.chdir(directory)
paths = changed_paths(base, "HEAD")
finally:
os.chdir(previous)
self.assertIn("source.rs", paths)
self.assertTrue(needs_rust(paths))
if __name__ == "__main__":
unittest.main()