"""scripts/check-worktree.py 的组件物化参数:逐个 submodule 物化,并以 --jobs 8 并行拉取。""" import importlib.util import subprocess import unittest from pathlib import Path from unittest import mock SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "check-worktree.py" spec = importlib.util.spec_from_file_location("check_worktree", SCRIPT) check_worktree = importlib.util.module_from_spec(spec) spec.loader.exec_module(check_worktree) class MaterializeTests(unittest.TestCase): def test_submodule_update_uses_parallel_jobs_per_component(self): repo = Path("/fixture/repo") child = repo / "modules" / "core" calls = [] def fake_submodules(path): return [(child, "a" * 40)] if path == repo else [] def fake_run(argv, *args, **kwargs): calls.append(argv) return subprocess.CompletedProcess(argv, 0) with mock.patch.object(check_worktree, "submodules", fake_submodules), \ mock.patch.object(check_worktree, "check_children", lambda *a: None), \ mock.patch.object(check_worktree.subprocess, "run", fake_run): check_worktree.materialize(repo) self.assertEqual(calls, [["git", "-C", str(repo), "submodule", "update", "--init", "--jobs", "8", "--checkout", "--", "modules/core"]]) if __name__ == "__main__": unittest.main()