Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(web): 将首启浏览器用例交给专用服务执行

longmeidaob1f8fefcebf1
diff --git a/docs/TESTING.md b/docs/TESTING.md
index cf4778c87..a9da300fa 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 个文件,串行批每批一个文件,各自取得完整 TAP 结果。测量动画、密度切换与等待态替换的文件(`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`,包括子目录。`setup.test.ts` 由 `SetupE2ETests` 在首次设置服务上执行,其余文件在已配置的演示库服务上按文件并发、文件内串行。并发数取 `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/setup.test.ts b/frontend/e2e/setup.test.ts
index 2d31d0581..d01a4f27b 100644
--- a/frontend/e2e/setup.test.ts
+++ b/frontend/e2e/setup.test.ts
@@ -3,7 +3,7 @@
* 跑在 `peach serve --setup` 上,不是路由冒烟那台已配置的服务:服务与临时数据根由
* `tests/test_web_e2e.py` 的 `SetupE2ETests` 准备,经 PEACH_E2E_SETUP_ORIGIN、
* PEACH_E2E_SETUP_DATA(临时数据根)和 PEACH_E2E_SETUP_MEDIA(一个已建好的空媒体目录)传进来。
- * 路由冒烟那几批没有这几个变量,本文件整组跳过。 */
+ * 本文件由首启专用入口执行;单独执行时缺少这些变量则整组跳过。 */
import assert from 'node:assert/strict';
import { readFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.py
index 943426ab0..c680f14ed 100644
--- a/tests/test_web_e2e.py
+++ b/tests/test_web_e2e.py
@@ -47,6 +47,7 @@ BROWSER_LOGS = ROOT / "build" / "agent-verification" / "browser"
SERVER_START_SECONDS = 60
E2E_SECONDS = 600
E2E_BATCH_FILES = 12
+SETUP_SUITE = "e2e/setup.test.ts"
def chrome_executable() -> str | None:
@@ -120,10 +121,10 @@ 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 秒。
+ """把已配置服务的 `*.test.ts`(含子目录)分批,每批带自己的并发数,限时 600 秒。
并发批最多 12 个文件,串行批每批一个文件。并发批之后运行时序敏感的串行批;并发为 1 时,
- 按设计决定、交互回归与路由冒烟分组。
+ 按设计决定、交互回归与路由冒烟分组。首启用例由 `SetupE2ETests` 在专用服务执行。
"""
files = tuple(sorted(path.relative_to(frontend).as_posix()
for path in (frontend / "e2e").rglob("*.test.ts")))
@@ -134,6 +135,7 @@ def e2e_batches(frontend: Path, concurrency: int, selected: tuple[str, ...] = ()
if missing:
raise AssertionError(f"浏览器用例不存在:{sorted(missing)}")
files = tuple(path for path in files if path in selected)
+ files = tuple(path for path in files if path != SETUP_SUITE)
if concurrency == 1:
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")
@@ -317,7 +319,9 @@ class WebE2ESmokeTests(unittest.TestCase):
stale.unlink()
concurrency = e2e_concurrency(os.environ.get("PEACH_E2E_CONCURRENCY", "").strip())
selected = tuple(json.loads(os.environ.get("PEACH_E2E_FILES", "[]")))
- for index, (batch, lanes) in enumerate(e2e_batches(FRONTEND, concurrency, selected), 1):
+ batches = e2e_batches(FRONTEND, concurrency, selected)
+ for index, (batch, lanes) in enumerate(batches, 1):
+ print(f"浏览器批次 {index}/{len(batches)}:{', '.join(batch)}", flush=True)
log_path = BROWSER_LOGS / f"batch-{index}.tap"
try:
completed = subprocess.run(
@@ -341,7 +345,7 @@ class SetupE2ETests(unittest.TestCase):
"""首次运行页跑在 `serve --setup` 上:临时数据根里还没有设置文件,提交成功后才有。
托盘拉起引导服务用的就是这组参数(`tray.build_setup_service_specs`)。页面那一侧是
- `frontend/e2e/setup.test.ts`,路由冒烟的几批里它因为缺变量整组跳过。
+ `frontend/e2e/setup.test.ts`,只由本组在首启服务执行。
"""
@classmethod
@@ -417,7 +421,7 @@ class SetupE2ETests(unittest.TestCase):
log_path = BROWSER_LOGS / "setup.tap"
try:
completed = subprocess.run(
- e2e_command(self.node, 1, ("e2e/setup.test.ts",)),
+ e2e_command(self.node, 1, (SETUP_SUITE,)),
capture_output=True, text=True, encoding="utf-8", errors="replace",
cwd=str(FRONTEND), env=env, timeout=E2E_SECONDS, check=False)
except subprocess.TimeoutExpired as expired:
@@ -535,6 +539,21 @@ class MissingPrerequisiteTests(unittest.TestCase):
with self.assertRaisesRegex(AssertionError, "没有浏览器用例"):
e2e_batches(Path(folder).resolve(), 4)
+ def test_setup_suite_is_owned_by_the_first_run_service(self):
+ paths = (*self.PATHS, SETUP_SUITE)
+ for concurrency in (1, 4):
+ with self.subTest(concurrency=concurrency):
+ self.assertEveryFileOnce(self.batches_for(concurrency, paths=paths))
+ with tempfile.TemporaryDirectory() as folder:
+ frontend = Path(folder).resolve()
+ for name in paths:
+ path = frontend / name
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.touch()
+ self.assertEqual(e2e_batches(frontend, 1, (SETUP_SUITE,)), ())
+ self.assertEqual(e2e_batches(frontend, 1, (SETUP_SUITE, self.PATHS[0])),
+ (((self.PATHS[0],), 1),))
+
def test_focused_batches_only_collect_named_browser_files(self):
with tempfile.TemporaryDirectory() as folder:
frontend = Path(folder).resolve()