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([ "docs/setup.md", "docs/media/banner.html", "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", "crates/horizon-theme/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()