Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

ci(test): 按选测规模拆分 Windows auto 回归

longmeidaoc51b1a75bc9a
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 72f61316a..fd59fa16e 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -94,7 +94,7 @@ Python 静态检查使用开发依赖 Ruff,随每个正式测试域扫描全
| wheel | Windows 与 macOS 各一次 Python 3.14 独立最小安装 |
| Release | 复用同 SHA 主线成功 CI;Windows 独立 EXE 与 Apple Silicon、Intel DMG 分别构建和验收 |
-Python 全量按文件稳定分片,Windows 四片、macOS 两片,每片使用独立 runner;汇总任务要求所有分片和计划选择的任务成功。分片子进程不签发记录。
+Python 全量按文件稳定分片,Windows 四片、macOS 两片。`auto` 按影响域选择文件;唯一选测文件达到 150 个时,Windows 复用四片分配,macOS 仍用单片;更小的 `auto` 两端均用单片。每片使用独立 runner,仍按同一基线和影响域运行,汇总任务要求所有分片和计划选择的任务成功。分片子进程不签发记录。
Test 工作流的 `web-bundle` 在 Ubuntu 上统一执行 tsc、lint、Vitest、构建及产物差异检查;lint 同时检查无诊断且扫描文件数大于零。CI 的 Python 任务把这三个工具用例交给前端任务,把两个真实浏览器用例交给浏览器矩阵;同模块的契约测试仍执行。任务身份由固定工作流与 job 名识别,未知任务和本机保留完整测试。承担部分 CI 职责的运行不签发本机测试记录。
diff --git a/scripts/ci_plan.py b/scripts/ci_plan.py
index 923ae9a71..2280619d6 100644
--- a/scripts/ci_plan.py
+++ b/scripts/ci_plan.py
@@ -12,6 +12,7 @@ if not __package__:
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
__package__ = "scripts"
ROOT = Path(__file__).resolve().parents[1]
+AUTO_SHARD_FILES = 150
def browser_matrix(root: Path = ROOT, count: int = 6) -> dict:
@@ -74,11 +75,13 @@ def plan(event: str, paths: list[str], contents: dict | None = None) -> dict:
scopes, _ = runner.scopes_for_changes(paths, contents=contents)
wide = event == "workflow_dispatch" or "full" in scopes
runtime_tools = wide or scopes != ("checks",)
+ selected_count = len({path for scope in scopes for path in runner.selected_files(scope)}) if not wide else 0
rows = []
for system in ("macos-latest", "windows-latest"):
scope = "full" if wide else "auto"
# 独立 runner 承担分片,避免共享文件、端口和全量证据锁。
- shards = (4 if system == "windows-latest" else 2) if scope == "full" else 1
+ split = wide or (system == "windows-latest" and selected_count >= AUTO_SHARD_FILES)
+ shards = (4 if system == "windows-latest" else 2) if split else 1
for index in range(shards):
rows.append({"os": system, "python": "3.14", "scope": scope,
"runtime_tools": runtime_tools,
diff --git a/tests/test_test_planning.py b/tests/test_test_planning.py
index 28e84248f..6caa3b599 100644
--- a/tests/test_test_planning.py
+++ b/tests/test_test_planning.py
@@ -293,6 +293,37 @@ class TestPlanningTests(unittest.TestCase):
costs = [row['estimated_seconds'] for row in matrix]
self.assertLess(max(costs) - min(costs), 60)
+ def test_broad_auto_matrix_keeps_each_selected_test_once(self):
+ for paths in (['src/peach/mp4repair.py', 'src/peach/web_media_repair.py'],
+ ['src/peach/web_catalog.py']):
+ with self.subTest(paths=paths):
+ scopes, _ = runner.scopes_for_changes(paths)
+ plan = ci_plan.plan('push', paths)
+ windows = [row for row in plan['matrix']['include'] if row['os'] == 'windows-latest']
+ self.assertFalse(plan['wide'])
+ self.assertEqual(len(windows), 4)
+ self.assertEqual(len([row for row in plan['matrix']['include']
+ if row['os'] == 'macos-latest']), 1)
+ self.assertTrue(all(row['scope'] == 'auto' for row in windows))
+ with patch.dict(os.environ, CIFrontendOwnershipTests.CI):
+ serial = list(CIFrontendOwnershipTests.ids(runner.build_suite(*scopes)))
+ collected = [name for row in windows for name in CIFrontendOwnershipTests.ids(
+ runner.build_suite(*scopes, shard_index=row['shard_index'],
+ shard_count=row['shard_count']))]
+ self.assertTrue(serial)
+ self.assertEqual(len(serial), len(set(serial)))
+ self.assertCountEqual(serial, collected)
+
+ def test_auto_partition_threshold_counts_unique_selected_files(self):
+ for count, expected in ((149, 1), (150, 4)):
+ with self.subTest(count=count), patch.object(runner, 'selected_files', return_value=tuple(
+ runner.TESTS / f'test_selected_{index}.py' for index in range(count))):
+ plan = ci_plan.plan('pull_request', ['src/peach/web_catalog.py'])
+ windows = [row for row in plan['matrix']['include'] if row['os'] == 'windows-latest']
+ self.assertFalse(plan['wide'])
+ self.assertEqual(len(windows), expected)
+ self.assertTrue(all(row['scope'] == 'auto' for row in windows))
+
def test_document_changes_avoid_optional_jobs_and_unknown_changes_require_them(self):
documents = ci_plan.plan('pull_request', ['docs/TESTING.md'])
self.assertEqual(documents['required_jobs'], ['plan', 'python', 'workflow-lint', 'frontend-ready'])