Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(e2e): 限定串行浏览器批次的文件数

longmeidao9ea8f8ed2a5f
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 64d1e177c..1052c3aaa 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -69,7 +69,7 @@ Python 静态检查使用开发依赖 Ruff,随每个正式测试域扫描全
浏览器冒烟与设计决定断言(`tests/test_web_e2e.py`)由 `web-e2e` job 在 `windows-latest` 上执行 `web` 域。它装 Node 24、`frontend/node_modules`、ffmpeg,并经 `PEACH_E2E_CHROME` 指定 runner 自带的 Chrome。矩阵扩成全量(`plan` 输出的 `wide`)时,Windows 全量行本身就跑 `web` 域,这个 job 按条件跳过;`verified` 只在这种情况接受它的 skipped,别的 job 跳过照样算红。
-浏览器用例覆盖 `frontend/e2e` 下全部 `*.test.ts`,包括子目录,按文件并发、文件内串行。并发数取 `PEACH_E2E_CONCURRENCY`;未设时本机取逻辑核数的四分之一、上限 4,CI(`GITHUB_ACTIONS=true`)为 1。并发时分两批:其余文件一次并发跑完,断言帧数或动画中途位置的文件(`tests/test_web_e2e.py` 的 `CPU_SENSITIVE_SUITES`)随后串行;并发为 1 时按设计决定、交互回归和路由冒烟分三批。每批限时 600 秒,任一批失败,整轮验证失败。并发的文件共用一个服务和演示库:用例触发的写请求只能落在别的用例不断言的状态上,否则用 `page.route` 拦下或归进串行批。完整 TAP 日志与服务访问日志 `serve.log` 保存在 `build/agent-verification/browser/`,CI 在测试结束后上传其中的 TAP 日志。
+浏览器用例覆盖 `frontend/e2e` 下全部 `*.test.ts`,包括子目录,按文件并发、文件内串行。并发数取 `PEACH_E2E_CONCURRENCY`;未设时本机取逻辑核数的四分之一、上限 4,CI(`GITHUB_ACTIONS=true`)为 1。并发时分两批:其余文件一次并发跑完,断言帧数或动画中途位置的文件(`tests/test_web_e2e.py` 的 `CPU_SENSITIVE_SUITES`)随后串行;并发为 1 时按设计决定、交互回归和路由冒烟分组,每批最多 12 个文件。每批限时 600 秒,任一批失败,整轮验证失败。并发的文件共用一个服务和演示库:用例触发的写请求只能落在别的用例不断言的状态上,否则用 `page.route` 拦下或归进串行批。完整 TAP 日志与服务访问日志 `serve.log` 保存在 `build/agent-verification/browser/`,CI 在测试结束后上传其中的 TAP 日志。
需要外部前置条件(Node、ffmpeg、Chrome 等)的用例,本机缺条件时跳过,在 CI(`GITHUB_ACTIONS=true`)里判失败,判定集中在 `tests/support/conditions.py` 的 `missing_prerequisite`。所以 `python` 矩阵里 `core` 以外的行也装 Node,Windows 行另装 ffmpeg 与 Chrome。
diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.py
index d61787f11..d9cb98177 100644
--- a/tests/test_web_e2e.py
+++ b/tests/test_web_e2e.py
@@ -46,6 +46,7 @@ FRONTEND = ROOT / "frontend"
BROWSER_LOGS = ROOT / "build" / "agent-verification" / "browser"
SERVER_START_SECONDS = 60
E2E_SECONDS = 600
+SERIAL_E2E_BATCH_FILES = 12
def chrome_executable() -> str | None:
@@ -120,7 +121,7 @@ def e2e_batches(frontend: Path, concurrency: int) -> tuple[tuple[tuple[str, ...]
"""把 `frontend/e2e` 下全部 `*.test.ts`(含子目录)分批,每批带自己的并发数,限时 600 秒。
并发时分两批:其余文件一次并发跑完,CPU 敏感的文件随后串行。并发为 1 时整轮是串行的,
- 按设计决定、交互回归与路由冒烟分三批,每批都落在限时之内。
+ 按设计决定、交互回归与路由冒烟分组,每批最多 12 个文件。
"""
files = tuple(sorted(path.relative_to(frontend).as_posix()
for path in (frontend / "e2e").rglob("*.test.ts")))
@@ -130,7 +131,9 @@ def e2e_batches(frontend: Path, concurrency: int) -> tuple[tuple[tuple[str, ...]
design = tuple(path for path in files if path.startswith("e2e/design-"))
routes = tuple(path for path in files if path == "e2e/smoke.test.ts")
interactions = tuple(path for path in files if path not in design + routes)
- return tuple((batch, 1) for batch in (design, interactions, routes) if batch)
+ return tuple((group[start:start + SERIAL_E2E_BATCH_FILES], 1)
+ for group in (design, interactions, routes)
+ for start in range(0, len(group), SERIAL_E2E_BATCH_FILES))
sensitive = tuple(path for path in files if path in CPU_SENSITIVE_SUITES)
shared = tuple(path for path in files if path not in sensitive)
return tuple(batch for batch in ((shared, concurrency), (sensitive, 1)) if batch[0])
@@ -464,10 +467,10 @@ class MissingPrerequisiteTests(unittest.TestCase):
PATHS = ("e2e/design-cards.test.ts", "e2e/design-detail.test.ts", "e2e/smoke.test.ts",
"e2e/nested/feature.test.ts", "e2e/sidebar-motion.test.ts")
- def batches_for(self, concurrency: int):
+ def batches_for(self, concurrency: int, paths=None):
with tempfile.TemporaryDirectory() as folder:
frontend = Path(folder).resolve()
- for name in (*self.PATHS, "e2e/harness.ts"):
+ for name in (*(self.PATHS if paths is None else paths), "e2e/harness.ts"):
path = frontend / name
path.parent.mkdir(parents=True, exist_ok=True)
path.touch()
@@ -496,6 +499,15 @@ class MissingPrerequisiteTests(unittest.TestCase):
])
self.assertEqual({lanes for _, lanes in batches}, {1})
+ def test_serial_batches_bound_large_groups_and_run_each_file_once(self):
+ paths = (tuple(f"e2e/design-{index:02}.test.ts" for index in range(13))
+ + tuple(f"e2e/feature-{index:02}.test.ts" for index in range(25))
+ + ("e2e/smoke.test.ts",))
+ batches = self.batches_for(1, paths=paths)
+ self.assertCountEqual(tuple(path for files, _ in batches for path in files), paths)
+ self.assertEqual([len(files) for files, _ in batches], [12, 1, 12, 12, 1, 1])
+ self.assertEqual({lanes for _, lanes in batches}, {1})
+
def test_browser_batches_require_at_least_one_suite(self):
with tempfile.TemporaryDirectory() as folder:
with self.assertRaisesRegex(AssertionError, "没有浏览器用例"):