Peach: Local-first video metadata scraper and media manager.
refactor(tooling): 分片判断收进预检函数
longmeidao600bef3a9de3
diff --git a/scripts/test_runner.py b/scripts/test_runner.pyindex f6ad787ff..f66b21fad 100644--- a/scripts/test_runner.py+++ b/scripts/test_runner.py@@ -507,13 +507,19 @@ def tools_needed_by(scopes: tuple[str, ...]) -> frozenset[str]:return frozenset(needed)-def environment_preflight(scopes: tuple[str, ...], timings: Path | None = None) -> None:+def environment_preflight(scopes: tuple[str, ...], timings: Path | None = None,+ *, shard_count: int = 1) -> None:"""外部工具若被执行权限挡住,在创建测试分片前给出一条可操作的结论。只有本次真的会用到的工具才判失败。受限环境里 ffmpeg 起不来是事实,但它不该挡住一次只改文档的 `checks`:那一轮一个媒体用例都不加载,硬失败只是把人赶出正式入口。其余工具仍然报出来,免得后面的失败被当成别的原因。++ 分片子进程直接返回:域由父进程定下,它在切片前查过同一套工具,每片各查一遍只会+ 把同一条结论打印 N 遍。"""+ if shard_count > 1:+ returnblocked = test_evidence.unspawnable_tools()if not blocked:return@@ -568,10 +574,7 @@ def main(argv: list[str] | None = None) -> int:paths = changed_files(ROOT, args.base)scopes, explanation = scopes_for_changes(paths, contents=changed_contents(ROOT, args.base, paths))print(explanation, flush=True)- # 只有非分片的这一次预检:域已经定下,父进程在切片前查过同一套工具,每片各查一遍- # 只会把同一条结论打印 N 遍。- if args.shard_count == 1:- environment_preflight(scopes, args.timings)+ environment_preflight(scopes, args.timings, shard_count=args.shard_count)files = {path for scope in scopes for path in selected_files(scope)}print(f"Peach test scope: {' '.join(scopes)} ({len(files)} files)", flush=True)if args.shard_count > 1:diff --git a/tests/test_test_planning.py b/tests/test_test_planning.pyindex 649b453e9..3cdab370c 100644--- a/tests/test_test_planning.py+++ b/tests/test_test_planning.py@@ -47,13 +47,11 @@ class TestPlanningTests(unittest.TestCase):def test_shards_and_the_explicit_switch_skip_the_preflight(self):"""分片子进程的域由父进程定下,父进程已经查过同一套工具;开关留给判断过的人。"""- output = io.StringIO()- with patch.object(runner, 'environment_preflight',- side_effect=AssertionError('分片子进程不应重复预检')), \- patch.object(runner, 'build_suite', return_value=unittest.TestSuite()), \- contextlib.redirect_stdout(output):- self.assertEqual(- runner.main(['--scope', 'checks', '--shard-count', '2', '--shard-index', '1']), 1)+ with patch.object(runner.test_evidence, 'unspawnable_tools', return_value=('git',)), \+ contextlib.redirect_stdout(io.StringIO()):+ runner.environment_preflight(('checks',), shard_count=2)+ with self.assertRaisesRegex(SystemExit, '3'):+ runner.environment_preflight(('checks',), shard_count=1)switched = io.StringIO()with patch.object(runner.test_evidence, 'unspawnable_tools', return_value=('git',)), \patch.dict(os.environ, {'PEACH_SKIP_PREFLIGHT': '1'}), \