Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(web): 串行浏览器验收按文件取得完整结果

longmeidaocbb10de2c190
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 6de632543..cf4778c87 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -72,7 +72,7 @@ Test 工作流的 `web-bundle` 在 Ubuntu 上统一执行 tsc、lint、Vitest、
浏览器冒烟与设计决定断言(`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。每批最多 12 个文件,测量动画、密度切换与等待态替换的文件(`tests/test_web_e2e.py` 的 `TIMING_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。并发批最多 12 个文件,串行批每批一个文件,各自取得完整 TAP 结果。测量动画、密度切换与等待态替换的文件(`tests/test_web_e2e.py` 的 `TIMING_SENSITIVE_SUITES`)在并发批之后串行;并发为 1 时按设计决定、交互回归和路由冒烟排序。每批限时 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/frontend/e2e/design-controls.test.ts b/frontend/e2e/design-controls.test.ts
index d47cde115..7e2e3389b 100644
--- a/frontend/e2e/design-controls.test.ts
+++ b/frontend/e2e/design-controls.test.ts
@@ -2,7 +2,7 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type { Browser } from 'playwright-core';
-import { settle } from './harness.ts';
+import { expectBody, settle } from './harness.ts';
import { ITEM, openItemPage } from './item-fixture.ts';
import {
DESKTOP, MOBILE, tokenColor, openAccess, settledRun, openActivity, qualityGoal, openQualityGoals,
@@ -369,7 +369,7 @@ describe('设计决定:控件、状态与首页顶部', () => {
const opened = await openProcessing(browser, '/data-cleanup', FAILED_JOB);
try {
const alert = opened.page.locator('#libraryProcessing [role="alert"]');
- await alert.waitFor({ state: 'visible', timeout: 15_000 });
+ await expectBody(opened.page, '/data-cleanup 处理失败提示', [alert]);
await alert.locator('summary').click();
const list = alert.locator('ul');
await list.waitFor({ state: 'visible', timeout: 5_000 });
diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.py
index 28e357308..943426ab0 100644
--- a/tests/test_web_e2e.py
+++ b/tests/test_web_e2e.py
@@ -122,7 +122,7 @@ def e2e_command(node: str, concurrency: int, files: tuple[str, ...]) -> list[str
def e2e_batches(frontend: Path, concurrency: int, selected: tuple[str, ...] = ()) -> tuple[tuple[tuple[str, ...], int], ...]:
"""把 `frontend/e2e` 下全部 `*.test.ts`(含子目录)分批,每批带自己的并发数,限时 600 秒。
- 每批最多 12 个文件。并发批之后运行时序敏感的串行批;并发为 1 时,
+ 并发批最多 12 个文件,串行批每批一个文件。并发批之后运行时序敏感的串行批;并发为 1 时,
按设计决定、交互回归与路由冒烟分组。
"""
files = tuple(sorted(path.relative_to(frontend).as_posix()
@@ -138,14 +138,17 @@ def e2e_batches(frontend: Path, concurrency: int, selected: 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((group[start:start + E2E_BATCH_FILES], 1)
- for group in (design, interactions, routes)
- for start in range(0, len(group), E2E_BATCH_FILES))
- sensitive = tuple(path for path in files if path in TIMING_SENSITIVE_SUITES)
- shared = tuple(path for path in files if path not in sensitive)
- return tuple((group[start:start + E2E_BATCH_FILES], lanes)
- for group, lanes in ((shared, concurrency), (sensitive, 1))
- for start in range(0, len(group), E2E_BATCH_FILES))
+ groups = ((design, 1), (interactions, 1), (routes, 1))
+ else:
+ sensitive = tuple(path for path in files if path in TIMING_SENSITIVE_SUITES)
+ shared = tuple(path for path in files if path not in sensitive)
+ groups = ((shared, concurrency), (sensitive, 1))
+ batches = []
+ for group, lanes in groups:
+ size = E2E_BATCH_FILES if lanes > 1 else 1
+ batches.extend((group[start:start + size], lanes)
+ for start in range(0, len(group), size))
+ return tuple(batches)
@windows_ledger_roots
@@ -494,18 +497,18 @@ class MissingPrerequisiteTests(unittest.TestCase):
def test_concurrent_run_puts_timing_sensitive_suites_in_a_trailing_serial_batch(self):
batches = self.batches_for(4)
self.assertEveryFileOnce(batches)
- (shared, lanes), (serial, serial_lanes) = batches
+ (shared, lanes), *serial = batches
self.assertEqual(lanes, 4)
- self.assertEqual(serial, ("e2e/design-cards.test.ts", "e2e/sidebar-motion.test.ts"))
- self.assertEqual(serial_lanes, 1)
+ self.assertEqual(serial, [(("e2e/design-cards.test.ts",), 1),
+ (("e2e/sidebar-motion.test.ts",), 1)])
self.assertIn("e2e/nested/feature.test.ts", shared)
def test_serial_run_splits_design_interactions_and_routes_to_stay_within_the_time_limit(self):
batches = self.batches_for(1)
self.assertEveryFileOnce(batches)
self.assertEqual([files for files, _ in batches], [
- ("e2e/design-cards.test.ts", "e2e/design-detail.test.ts"),
- ("e2e/nested/feature.test.ts", "e2e/sidebar-motion.test.ts"),
+ ("e2e/design-cards.test.ts",), ("e2e/design-detail.test.ts",),
+ ("e2e/nested/feature.test.ts",), ("e2e/sidebar-motion.test.ts",),
("e2e/smoke.test.ts",),
])
self.assertEqual({lanes for _, lanes in batches}, {1})
@@ -516,7 +519,7 @@ class MissingPrerequisiteTests(unittest.TestCase):
+ ("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([len(files) for files, _ in batches], [1] * len(paths))
self.assertEqual({lanes for _, lanes in batches}, {1})
def test_concurrent_batches_cover_large_groups_once_with_the_requested_concurrency(self):
@@ -524,8 +527,8 @@ class MissingPrerequisiteTests(unittest.TestCase):
+ ("e2e/smoke.test.ts", "e2e/design-cards.test.ts", "e2e/sidebar-motion.test.ts"))
batches = self.batches_for(4, paths=paths)
self.assertCountEqual(tuple(path for files, _ in batches for path in files), paths)
- self.assertEqual([len(files) for files, _ in batches], [12, 12, 2, 2])
- self.assertEqual([lanes for _, lanes in batches], [4, 4, 4, 1])
+ self.assertEqual([len(files) for files, _ in batches], [12, 12, 2, 1, 1])
+ self.assertEqual([lanes for _, lanes in batches], [4, 4, 4, 1, 1])
def test_browser_batches_require_at_least_one_suite(self):
with tempfile.TemporaryDirectory() as folder: