Peach: Local-first video metadata scraper and media manager.
perf(ci): 集中执行前端工具检查并隔离验证记录
longmeidao5f5fa61a4038
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 3290e39b6..73237b85d 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -172,7 +172,10 @@ jobs:cache-dependency-path: frontend/package-lock.json- run: npm --prefix frontend ci- run: npm --prefix frontend run typecheck- - run: npm --prefix frontend run lint+ - name: 前端 lint 与扫描范围+ run: |+ npm --prefix frontend run lint --silent -- --format=json > frontend-lint.json+ node --input-type=module -e 'import { readFileSync } from "node:fs"; import assert from "node:assert/strict"; const report = JSON.parse(readFileSync("frontend-lint.json", "utf8")); assert.deepEqual(report.diagnostics, []); assert.ok(report.number_of_files > 0, "lint 必须扫描文件");'- run: npm --prefix frontend test- run: npm --prefix frontend run build# 产物提交进 Git,因为运行时和打包都没有 Node(ADR-0022)。一旦源码改了却忘了diff --git a/docs/TESTING.md b/docs/TESTING.mdindex 1b41759f9..e94acf815 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -68,6 +68,8 @@ Python 静态检查使用开发依赖 Ruff,随每个正式测试域扫描全全量在两个独立 runner 按测试文件稳定分片;汇总任务要求所有分片和必需任务成功。分片子进程不签发记录。+Test 工作流的 `web-bundle` 在 Ubuntu 上统一执行 tsc、lint、Vitest、构建及产物差异检查;lint 同时检查无诊断且扫描文件数大于零。`python` 与 `web-e2e` 任务仅从 Python 测试集合中移交这三个工具用例,产物契约、系统功能和浏览器回归照常执行。任务身份由 GitHub Actions 的固定工作流与 job 名识别,未知任务和本机完整保留三个用例。承担部分 CI 职责的运行不签发本机测试记录,最终结果由必须依赖 `web-bundle` 的 `verified` 任务汇总。+浏览器冒烟与设计决定断言(`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 日志。diff --git a/scripts/test_runner.py b/scripts/test_runner.pyindex b0ba81dc6..5ea7713b8 100644--- a/scripts/test_runner.py+++ b/scripts/test_runner.py@@ -479,6 +479,31 @@ def resolve_auto_scope() -> tuple[tuple[str, ...], str]:return scopes_for_changes(paths, contents=changed_contents(ROOT, "master", paths))+CI_FRONTEND_TESTS = frozenset({+ "test_frontend_build.VitestTests.test_the_frontend_sources_typecheck",+ "test_frontend_build.VitestTests.test_frontend_sources_and_tests_pass_lint",+ "test_frontend_build.VitestTests.test_the_island_suite_passes",+})+++def ci_frontend_delegated() -> bool:+ """Test 工作流的 Python 与浏览器任务由 web-bundle 承担前端工具检查。"""+ return (os.environ.get("GITHUB_ACTIONS") == "true"+ and os.environ.get("GITHUB_WORKFLOW") == "Test"+ and os.environ.get("GITHUB_JOB") in {"python", "web-e2e"})+++def without_ci_frontend_tests(suite: unittest.TestSuite) -> unittest.TestSuite:+ """按完整用例 ID 分配 CI 职责,保留同模块的产物与样式契约。"""+ selected = unittest.TestSuite()+ for test in suite:+ if isinstance(test, unittest.TestSuite):+ selected.addTests(without_ci_frontend_tests(test))+ elif test.id() not in CI_FRONTEND_TESTS:+ selected.addTest(test)+ return selected++def build_suite(*scopes: str, shard_index: int = 0, shard_count: int = 1) -> unittest.TestSuite:loader = unittest.defaultTestLoadersuite = unittest.TestSuite()@@ -496,7 +521,7 @@ def build_suite(*scopes: str, shard_index: int = 0, shard_count: int = 1) -> unisuite.addTests(loader.loadTestsFromName(test_id))finally:del sys.path[:2]- return suite+ return without_ci_frontend_tests(suite) if ci_frontend_delegated() else suiteclass TimedResult(unittest.TextTestResult):@@ -717,6 +742,10 @@ def main(argv: list[str] | None = None) -> int:args.timings.write_text(json.dumps({"success": success, "count": result.testsRun,"timings": result.timings}), encoding="utf-8")return 0 if success else 1+ if ci_frontend_delegated():+ print("CI 前端工具检查由 web-bundle 验证;本次不签发本机测试记录。", flush=True)+ success, count, _ = run_local_suite(scopes, args.jobs)+ return 0 if success and count > 0 else 1try:guard = test_evidence.held(test_evidence.evidence_dir(ROOT) / "full-suite.lock",wait_seconds=args.lock_timeout,diff --git a/tests/test_frontend_build.py b/tests/test_frontend_build.pyindex 3546f652e..609815fda 100644--- a/tests/test_frontend_build.py+++ b/tests/test_frontend_build.py@@ -9,7 +9,8 @@ ADR-0022 的取舍是「构建产物进 Git」:运行时的 Python 服务、Py精确钉版本、共享客户端是否唯一。这些在任何机器上都跑。- **需要 Node 的**:tsc、lint 与 vitest。npm 或 `frontend/node_modules` 不在时本机显式跳过——本机可能根本没装 Node,让整个测试域红掉只会让人绕过入口,而不是去装 Node。- CI(`GITHUB_ACTIONS=true`)里判失败:工作流负责装齐,跳过等于这几道门槛在 CI 里从不执行。+ CI 的 Test 工作流由 `web-bundle` 统一执行三个工具;其他任务与本机经正式入口运行。+ CI 实际执行工具的任务缺前置条件时判失败。「产物是否由当前源码构建出来」这一条不在这里:不装 Node 就无法重建,无从比较。那道门槛在 CI 的 `web-bundle` job 里,`npm run build` 之后 `git diff --exit-code web/dist`。@@ -412,10 +413,11 @@ class BrowserSuiteWorkflowTests(unittest.TestCase):"PEACH_E2E_CHROME=", "& .\\scripts\\test.ps1 -Scope web"):self.assertIn(step, job, f"web-e2e job 缺了 {step}")- def test_the_summary_requires_the_browser_job(self):+ def test_the_summary_requires_browser_and_frontend_jobs(self):needs = re.search(r"(?ms)^ verified:\n.*?^ needs: \[([^\]]*)\]", self.workflow)self.assertIsNotNone(needs, "verified job 没有 needs 列表")- self.assertIn("web-e2e", [name.strip() for name in needs.group(1).split(",")])+ for required in ("web-e2e", "web-bundle"):+ self.assertIn(required, [name.strip() for name in needs.group(1).split(",")])def test_the_browser_job_yields_to_a_wide_matrix_that_already_runs_the_web_scope(self):"""全量矩阵的 Windows 行本身就跑 `web` 域,`web-e2e` 再跑就是同一批用例两遍。diff --git a/tests/test_test_evidence.py b/tests/test_test_evidence.pyindex cce121215..84c657c7c 100644--- a/tests/test_test_evidence.py+++ b/tests/test_test_evidence.py@@ -48,6 +48,8 @@ class ParallelShardTests(unittest.TestCase):class VerificationTests(unittest.TestCase):def setUp(self):+ # 这组用例模拟本机验收,运行它的 CI job 身份不属于临时仓库。+ self.enterContext(mock.patch.dict(os.environ, {"GITHUB_ACTIONS": "false"}))temporary = tempfile.TemporaryDirectory()self.addCleanup(temporary.cleanup)self.root = Path(temporary.name).resolve()diff --git a/tests/test_test_planning.py b/tests/test_test_planning.pyindex a3be13b8c..4de9977e5 100644--- a/tests/test_test_planning.py+++ b/tests/test_test_planning.py@@ -15,6 +15,70 @@ from scripts import ci_plan, test_runner as runnerfrom support.ledger import fresh_ledger+class CIFrontendOwnershipTests(unittest.TestCase):+ CI = {'GITHUB_ACTIONS': 'true', 'GITHUB_WORKFLOW': 'Test', 'GITHUB_JOB': 'python'}++ @staticmethod+ def ids(suite):+ for test in suite:+ if isinstance(test, unittest.TestSuite):+ yield from CIFrontendOwnershipTests.ids(test)+ else:+ yield test.id()++ def frontend_ids(self, environment, **shard):+ with patch.dict(os.environ, environment, clear=True), \+ patch.object(runner, 'selected_files', return_value=(runner.TESTS / 'test_frontend_build.py',)):+ return list(self.ids(runner.build_suite('web', **shard)))++ def test_only_known_ci_jobs_delegate_exactly_three_frontend_tools(self):+ local = set(self.frontend_ids({}))+ delegated = {f'test_frontend_build.VitestTests.{name}' for name in (+ 'test_the_frontend_sources_typecheck', 'test_frontend_sources_and_tests_pass_lint',+ 'test_the_island_suite_passes')}+ self.assertLessEqual(delegated, local)+ for job in ('python', 'web-e2e'):+ with self.subTest(job=job):+ selected = set(self.frontend_ids({**self.CI, 'GITHUB_JOB': job}))+ self.assertEqual(local - selected, delegated)+ self.assertEqual(selected - local, set())+ self.assertIn('test_frontend_build.VitestTests.test_the_island_suite_has_a_bounded_worker_pool', selected)+ for environment in ({}, {'GITHUB_ACTIONS': 'true'},+ {**self.CI, 'GITHUB_ACTIONS': 'false'},+ {**self.CI, 'GITHUB_WORKFLOW': 'Release'},+ {**self.CI, 'GITHUB_JOB': 'another-job'}):+ with self.subTest(environment=environment):+ self.assertEqual(set(self.frontend_ids(environment)), local)++ def test_delegated_shards_cover_all_remaining_tests_once(self):+ serial = self.frontend_ids(self.CI)+ shards = [self.frontend_ids(self.CI, shard_index=index, shard_count=2) for index in range(2)]+ self.assertFalse(set(shards[0]) & set(shards[1]))+ self.assertCountEqual(serial, shards[0] + shards[1])+ self.assertEqual(len(serial), len(set(serial)))++ def test_delegated_ci_returns_results_without_local_evidence(self):+ for scope in ('web', 'full'):+ for success, count, expected in ((True, 3, 0), (False, 3, 1), (True, 0, 1)):+ with self.subTest(scope=scope, success=success, count=count), \+ patch.dict(os.environ, self.CI, clear=True), \+ patch.object(runner, 'environment_preflight'), \+ patch.object(runner, 'run_local_suite', return_value=(success, count, [])), \+ patch.object(runner, 'verified_run', side_effect=AssertionError('CI 不签本机记录')), \+ patch.object(runner.test_evidence, 'held', side_effect=AssertionError('CI 不取本机证据锁')), \+ patch.object(runner.test_evidence, 'write', side_effect=AssertionError('CI 不写本机记录')), \+ contextlib.redirect_stdout(io.StringIO()):+ self.assertEqual(runner.main(['--scope', scope]), expected)++ def test_local_runs_use_the_verification_path(self):+ with patch.dict(os.environ, {}, clear=True), \+ patch.object(runner, 'environment_preflight'), \+ patch.object(runner, 'verified_run', return_value=0) as verify, \+ contextlib.redirect_stdout(io.StringIO()):+ self.assertEqual(runner.main(['--scope', 'web']), 0)+ verify.assert_called_once()++class TestPlanningTests(unittest.TestCase):def test_every_supplementary_test_id_names_a_real_test(self):"""域的补充用例按名字装载:被引用的用例改名后,装进来的是一个必然报错的占位用例,