Peach: Local-first video metadata scraper and media manager.
test(web): 按设计与交互分批执行浏览器回归
longmeidaoa4d6956efbcc
diff --git a/docs/TESTING.md b/docs/TESTING.mdindex bf47927cf..4aa8b1b0f 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -64,6 +64,8 @@ Dependabot 的 PR 一律在本地接管,不在网页上合:浏览器冒烟与设计决定断言(`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 跳过照样算红。+浏览器用例分为设计检查和交互回归两批,每批限时 600 秒。两批及批内文件默认串行执行,覆盖 `frontend/e2e` 下全部 `*.test.ts`,包括子目录;任一批失败,整轮验证失败。+需要外部前置条件(Node、ffmpeg、Chrome 等)的用例,本机缺条件时跳过,在 CI(`GITHUB_ACTIONS=true`)里判失败,判定集中在 `tests/support/conditions.py` 的 `missing_prerequisite`。所以 `python` 矩阵里 `core` 以外的行也装 Node,Windows 行另装 ffmpeg 与 Chrome。本机默认并行:入口传 `--jobs auto`(Windows `-Jobs`),运行器按同一套稳定分片切成并发数四倍的片,最多四个子进程各领一片、先完成的接着领下一片,父进程汇总成败、用例数与逐用例耗时后按原口径签发一份记录,一片红整轮红。`-Jobs 1` 退回串行。测试之间没有共享的端口或全局目录,账本与仓库夹具都在各自的临时目录里,并行才是安全的;新增测试保持这一点。diff --git a/frontend/e2e/follow-feed.test.ts b/frontend/e2e/follow-feed.test.tsindex 39353fa85..e8f0aca58 100644--- a/frontend/e2e/follow-feed.test.ts+++ b/frontend/e2e/follow-feed.test.ts@@ -237,6 +237,7 @@ describe('关注页岛', () => {const page = opened.page;await page.locator('[data-follow-older]').click();await page.locator('[data-follow-older][aria-busy="true"]').waitFor();+ await page.locator('[data-follow-older]').filter({ hasText: '抓取中' }).waitFor();assert.match(await page.locator('[data-follow-older]').innerText(), /抓取中/);await page.locator('[data-follow-recheck][aria-busy="true"]').waitFor();assert.deepEqual(opened.stub.writes, [{ url: '/api/follow/check', body: { older: true, background: true } }]);diff --git a/frontend/e2e/home-loading.test.ts b/frontend/e2e/home-loading.test.tsindex afb83d832..ca2a00b30 100644--- a/frontend/e2e/home-loading.test.ts+++ b/frontend/e2e/home-loading.test.ts@@ -28,6 +28,7 @@ describe('首页加载结构',()=>{}).observe(document,{childList:true,subtree:true});},{hasFeed});const page=await context.newPage();+ page.setDefaultTimeout(8000);const scopes:string[]=[];await page.route('**/api/sources',route=>route.fulfill({json:{ok:true,sources:[{location:'local',online:true},{location:'115',online:false}]}}));await page.route(/\/api\/facets\?/,async route=>{diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.pyindex a0fc8b35d..80aa1fabb 100644--- a/tests/test_web_e2e.py+++ b/tests/test_web_e2e.py@@ -87,7 +87,7 @@ def refuse_network(*args, **kwargs):raise AssertionError("演示库的 process 不应向任何外部来源发请求")-def e2e_command(node: str, concurrency: str = "") -> list[str]:+def e2e_command(node: str, concurrency: str = "", files: tuple[str, ...] = ()) -> list[str]:"""串行跑是浏览器进程预算:每条用例的 Chrome 只给两个渲染进程(`e2e/harness.ts`)。直接启动 Node 也省掉资源守卫内的一层 npm 进程。@@ -96,7 +96,18 @@ def e2e_command(node: str, concurrency: str = "") -> list[str]:if not selected.isdecimal() or int(selected) < 1:raise AssertionError("PEACH_E2E_CONCURRENCY 必须是正整数")return [node, "--test", f"--test-concurrency={int(selected)}",- "--test-reporter=tap", "e2e/**/*.test.ts"]+ "--test-reporter=tap", *(files or ("e2e/**/*.test.ts",))]+++def e2e_batches(frontend: Path) -> tuple[tuple[str, ...], ...]:+ """设计检查与交互回归各占一批,所有文件串行执行,每批限时 600 秒。"""+ files = tuple(sorted(path.relative_to(frontend).as_posix()+ for path in (frontend / "e2e").rglob("*.test.ts")))+ if not files:+ raise AssertionError("frontend/e2e 没有浏览器用例")+ design = tuple(path for path in files if path == "e2e/design.test.ts")+ interactions = tuple(path for path in files if path not in design)+ return tuple(batch for batch in (design, interactions) if batch)@windows_ledger_roots@@ -237,26 +248,48 @@ class WebE2ESmokeTests(unittest.TestCase):def test_every_route_holds_the_layout_and_runtime_invariants(self):env = dict(os.environ, PEACH_E2E_ORIGIN=self.origin, PEACH_E2E_ITEM=str(self.item),PEACH_E2E_CHROME=self.chrome)- try:- completed = subprocess.run(- e2e_command(self.node, os.environ.get("PEACH_E2E_CONCURRENCY", "").strip()),- 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:- # 已经跑完的那几条 TAP 行指出卡在哪一条之后;只报超时等于什么都没说。- partial = expired.stdout or ""- if isinstance(partial, bytes):- partial = partial.decode("utf-8", errors="replace")- self.fail(f"{E2E_SECONDS} 秒内没跑完,已输出:\n{partial[-4000:]}")- output = f"{completed.stdout}\n{completed.stderr}"- self.assertEqual(completed.returncode, 0, f"{output}\n--- serve.log ---\n{self._server_log()}")- self.assertRegex(output, r"# pass [1-9]\d*", output)- self.assertRegex(output, r"# fail 0\b", output)+ for batch in e2e_batches(FRONTEND):+ with self.subTest(files=batch):+ try:+ completed = subprocess.run(+ e2e_command(self.node, os.environ.get("PEACH_E2E_CONCURRENCY", "").strip(), batch),+ 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:+ # TAP 行指出超时前的最后一条用例。+ partial = expired.stdout or ""+ if isinstance(partial, bytes):+ partial = partial.decode("utf-8", errors="replace")+ self.fail(f"本批 {E2E_SECONDS} 秒内没跑完,已输出:\n{partial[-4000:]}")+ output = f"{completed.stdout}\n{completed.stderr}"+ self.assertEqual(completed.returncode, 0, f"{output}\n--- serve.log ---\n{self._server_log()}")+ self.assertRegex(output, r"# pass [1-9]\d*", output)+ self.assertRegex(output, r"# fail 0\b", output)class MissingPrerequisiteTests(unittest.TestCase):"""CI 里浏览器用例只能执行或失败,不能静默跳过;工作流那一半由 `test_frontend_build.py` 守。"""+ def test_browser_batches_cover_every_file_once_and_include_nested_suites(self):+ with tempfile.TemporaryDirectory() as folder:+ frontend = Path(folder).resolve()+ paths = ("e2e/design.test.ts", "e2e/smoke.test.ts", "e2e/nested/feature.test.ts")+ for name in paths:+ path = frontend / name+ path.parent.mkdir(parents=True, exist_ok=True)+ path.touch()+ batches = e2e_batches(frontend)+ self.assertEqual(batches[0], ("e2e/design.test.ts",))+ flattened = tuple(path for batch in batches for path in batch)+ self.assertCountEqual(flattened, paths)+ self.assertEqual(len(flattened), len(set(flattened)))+ self.assertEqual(e2e_command("node", files=batches[1])[-2:], list(batches[1]))++ def test_browser_batches_require_at_least_one_suite(self):+ with tempfile.TemporaryDirectory() as folder:+ with self.assertRaisesRegex(AssertionError, "没有浏览器用例"):+ e2e_batches(Path(folder).resolve())+def test_headless_browser_stays_within_the_resource_guard_process_budget(self):harness = (FRONTEND / "e2e" / "harness.ts").read_text(encoding="utf-8")self.assertIn("args: ['--renderer-process-limit=2']", harness)