Files
solidcraft/scripts/ci/test_affected.py
T
jyvikoandClaude Opus 5.5 948c208db9 CI: run only what a change needs, on pull requests and on main
- Pushes to main use the same code/no-code rule as pull requests (`touches_code` in Select
  checks): a push changing only documentation, packaging, other workflows or the bots' scripts
  runs the repository checks only. With the merge queue off, every push to main ran the full suite
  and the Windows jobs, docs-only ones included.
- affected.py: test data under tests/ selects the packages that read it (robustness, hole matrix,
  projection, taper: solidcraft-engine; oracle: the CLI, the kernel, xtask; action matrix: the
  CLI, the engine, xtask), and a vendored crate the packages that use it (truck: the kernel and up;
  egui-wgpu: the UI and the apps), instead of the whole workspace. tests/tools and unknown vendored
  crates still select everything.
- Docker (the web app image) skips pushes touching only docs, test data or bot scripts; Pages skips
  test data and bot scripts; Generated files runs only when the manifests, lockfile, command
  registry, CLI or xtask change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QWhMwdqJYQKQq8RCLSL1LT
2026-10-19 16:42:11 -04:00

120 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""Self-test for affected.py. Run: python3 -I scripts/ci/test_affected.py (from the repo root).
Uses a small synthetic workspace, then the real one (`cargo metadata --no-deps`).
"""
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import affected # noqa: E402
R = "/ws"
def pkg(name, dir_, deps=()):
return {
"name": name,
"manifest_path": f"{R}/{dir_}/Cargo.toml",
"dependencies": [{"name": d, "path": f"{R}/{p}"} for d, p in deps] + [{"name": "serde"}],
}
SYNTH = {
"workspace_root": R,
"packages": [
pkg("base", "crates/base"),
pkg("mid", "crates/mid", [("base", "crates/base")]),
pkg("top", "apps/top", [("mid", "crates/mid")]),
pkg("alone", "crates/alone"),
],
}
class Synthetic(unittest.TestCase):
def test_leaf_selects_only_itself(self):
self.assertEqual(affected.select(SYNTH, ["apps/top/src/main.rs"]), (False, ["top"]))
def test_reverse_dependencies_are_added(self):
self.assertEqual(affected.select(SYNTH, ["crates/base/src/lib.rs"]), (False, ["base", "mid", "top"]))
def test_unrelated_package_is_not_selected(self):
full, pk = affected.select(SYNTH, ["crates/mid/Cargo.toml"])
self.assertEqual((full, pk), (False, ["mid", "top"]))
def test_full_triggers(self):
for p in ["Cargo.lock", "Cargo.toml", ".cargo/config.toml", ".config/nextest.toml", "rust-toolchain.toml",
".github/workflows/ci.yml", "vendor/x/lib.rs", "tests/oracle/a.json", "assets/a.png",
"scripts/ci/affected.py", "unknown.txt"]:
self.assertEqual(affected.select(SYNTH, ["crates/alone/a.rs", p]), (True, []), p)
def test_docs_only_selects_nothing(self):
self.assertEqual(affected.select(SYNTH, ["docs/book/a.md", "README.md", "packaging/x.yml"]), (False, []))
class RealWorkspace(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.meta = affected.load_metadata(None)
def test_render_change_selects_render_and_dependents_not_kernel(self):
full, pk = affected.select(self.meta, ["crates/render/src/lib.rs"])
self.assertFalse(full)
self.assertIn("solidcraft-render", pk)
self.assertGreater(len(pk), 1)
self.assertNotIn("solidcraft-kernel", pk)
def test_cargo_lock_selects_full(self):
self.assertEqual(affected.select(self.meta, ["Cargo.lock"]), (True, []))
def test_docs_only_selects_nothing(self):
self.assertEqual(affected.select(self.meta, ["docs/book/src/dev/testing.md", "CONTRIBUTING.md"]), (False, []))
def test_goldens_select_the_engine_and_its_dependents_not_the_kernel(self):
full, pk = affected.select(self.meta, ["tests/robustness/goldens.json"])
self.assertFalse(full)
self.assertIn("solidcraft-engine", pk)
self.assertNotIn("solidcraft-kernel", pk)
self.assertNotIn("solidcraft-render", pk)
def test_oracle_cases_select_the_cli_and_xtask(self):
full, pk = affected.select(self.meta, ["tests/oracle/box/recipe.json"])
self.assertFalse(full)
self.assertIn("solidcraft-cli", pk)
self.assertIn("xtask", pk)
def test_unmapped_test_data_selects_full(self):
self.assertEqual(affected.select(self.meta, ["tests/tools/x.json"]), (True, []))
def test_vendored_truck_selects_the_kernel_and_up_not_render(self):
full, pk = affected.select(self.meta, ["vendor/truck-shapeops/src/lib.rs"])
self.assertFalse(full)
self.assertIn("solidcraft-kernel", pk)
self.assertIn("solidcraft-engine", pk)
self.assertNotIn("solidcraft-render", pk)
self.assertNotIn("solidcraft-geom", pk)
def test_vendored_egui_wgpu_selects_the_ui_and_apps_not_the_kernel(self):
full, pk = affected.select(self.meta, ["vendor/egui-wgpu/src/winit.rs"])
self.assertFalse(full)
self.assertIn("solidcraft-ui-egui", pk)
self.assertIn("solidcraft", pk)
self.assertNotIn("solidcraft-kernel", pk)
self.assertNotIn("solidcraft-engine", pk)
def test_vendor_readme_alone_selects_nothing(self):
self.assertEqual(affected.select(self.meta, ["vendor/README.md"]), (False, []))
def test_translation_selects_the_ui_and_xtask_not_the_kernel(self):
full, pk = affected.select(self.meta, ["assets/locales/ja.json", "assets/locales/it.json"])
self.assertFalse(full)
self.assertIn("solidcraft-ui-egui", pk)
self.assertIn("xtask", pk)
self.assertNotIn("solidcraft-kernel", pk)
self.assertNotIn("solidcraft-engine", pk)
if __name__ == "__main__":
unittest.main()