Peach: Local-first video metadata scraper and media manager.
test(tooling): 域映射漏登记在本地就红
longmeidaof43150d44608
diff --git a/docs/PRODUCT_BACKLOG.md b/docs/PRODUCT_BACKLOG.mdindex b5fd24789..199423f53 100644--- a/docs/PRODUCT_BACKLOG.md+++ b/docs/PRODUCT_BACKLOG.md@@ -63,7 +63,7 @@合计:**31 项开放需求**,其中 6 项已有骨架,25 项尚未实现。已完成的需求不在这里留痕,去 Git 历史查。-## 待执行的操作(36 项)+## 待执行的操作(37 项)需要另行授权、外部条件或人工判断才能做的具体操作与复核批次,比上面的需求细一层;做完就删,不在这里留痕。待办只放这一处:`docs/STATUS.md` 每次会话开头都要读,队列不该常驻在那种入口文件里。@@ -109,4 +109,5 @@> 3. What can be simplified now that unnecessary pieces are gone?> Then make the changes. Prefer deleting over simplifying, simplifying over optimizing, and optimizing over automating.> It might be done too - you don't HAVE to go and make changes. If it's good, leave it alone.-36. `test_desktop_settings.test_native_shortcut_round_trip_in_temporary_directory` 只在 GitHub 的 windows-latest runner 上失败,本机 Windows 每次都过:2026-09-06 10:48、20:14 与 09-07 01:45 的 full/0 分片各红一次,抛的都是 `desktop_startup.shortcut()` 那句 `OSError`。根因未取得——那句消息此前把 PowerShell 的 stderr 一起丢掉了,权限不足、`WScript.Shell` COM 起不来、路径没落地和扩展名校验不通过在日志里长得一模一样。消息已补上 stderr 第一行(`0.28.1`);下一次 runner 上这一步失败时读 `gh run view --job <id> --log-failed` 就能分辨是哪一种,再按那个原因决定是修实现还是给这个用例加 `skipUnless` 判据。在拿到那行原因之前不要凭猜改 `_SHORTCUT_SCRIPT`:它是写生产启动项的路径。+36. `test_desktop_settings.test_native_shortcut_round_trip_in_temporary_directory` 只在 GitHub 的 windows-latest runner 上失败,本机 Windows 每次都过:2026-09-06 10:48、20:14 与 09-07 01:45、10:20 的 full/0 分片各红一次,抛的都是 `desktop_startup.shortcut()` 那句 `OSError`。根因未取得。`_SHORTCUT_SCRIPT` 现在把结论写成 stdout 上一行 JSON,失败那一支带 `error`、异常类型和行号,`shortcut()` 照这个 payload 判成败;退出码和 stderr 都不作判据。下一次 runner 上这一步失败时读 `gh run view --job <id> --log-failed`,消息里就是脚本自报的那一行原因,再按它决定是修实现还是给这个用例加 `skipUnless` 判据。拿到那行原因之前不要凭猜改脚本本体:它是写生产启动项的路径。+37. 域映射门槛只覆盖 `web/` 与 `frontend/`。同一个漏洞在别的前缀上照样成立:`tests/test_babepedia_match.py` 读 `scripts/match_babepedia_creators.py` 却只登记在 metadata 域,改那个脚本时 `auto` 选的是 tooling;`tests/test_frontend_build.py` 读 `docs/CLOUDDRIVE.md`,而 `.md` 一律归 checks。按 `test_runner.repository_paths_read_by` 全树扫一遍,`scripts/`、`docs/`、`.github/`、`resources/` 四类共约三十处。要补的是 `AUTO_SCOPE_PREFIXES` 本身——把逐个脚本映射到它真正的域,像 `scripts/localize_performer_names.py` 那两条那样——补完再把 `tests/test_test_planning.py` 那条门槛的前缀白名单去掉。diff --git a/scripts/test_runner.py b/scripts/test_runner.pyindex 3a1cbdf2d..b722e26cf 100644--- a/scripts/test_runner.py+++ b/scripts/test_runner.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport argparseimport fnmatchimport importlib+import reimport subprocessimport sysimport time@@ -82,8 +83,14 @@ SCOPES: dict[str, tuple[str, ...]] = {# 播放器按需加载的断言读 `web/app.js`(web),改任一侧都该被本域拦住。# `test_copy_final_state.py` 两个域都登记:它扫全树,而界面字串是它最常拦到的# 一面,改 `web/` 的人必须在本域就撞上它。+ # 后面七个文件的主体不在这一层,但各有一段断言读 `web/` 或 `frontend/` 的源码,+ # 所以本域也要登记它们:改了 `web/app.js` 却漏跑读它的测试,`test_test_planning.py`+ # 的域映射门槛会在本地就红。"web": ("test_frontend_build.py", "test_web_ui.py", "test_web_js.py",- "test_web_perf.py", "test_copy_final_state.py"),+ "test_web_perf.py", "test_copy_final_state.py",+ "test_agency_entity.py", "test_dependency_policy.py", "test_desktop_settings.py",+ "test_fastapi_api.py", "test_follow_web.py", "test_metadata_library.py",+ "test_studio_icon_variants.py", "test_web_settings.py"),"core": ("test_access.py", "test_auth.py", "test_config.py", "test_migrations.py","test_platform.py", "test_mount.py", "test_tray.py", "test_certs.py","test_folder_picker.py", "test_fsutil.py", "test_runtime_consistency.py",@@ -171,6 +178,41 @@ def scopes_of_module(stem: str) -> tuple[str, ...]:for pattern in patterns))+def scope_of_path(path: str) -> str:+ """一个非测试源码文件按 `AUTO_SCOPE_PREFIXES` 落在哪个域;映射不到返回空串。"""+ normalized = path.replace("\\", "/").strip("/")+ for prefix, scope in AUTO_SCOPE_PREFIXES:+ if normalized.startswith(prefix):+ return scope+ return ""+++#: `<某个 Path> / "a" / "b/c.js"` 这种拼接。要求左边有个 `/`,是为了把「路径当字符串+#: 参数传进去」的写法排除掉:`scopes_for_changes(["web/app.js"])` 喂的是假清单,+#: 不读真文件,不该因为字面量长得像路径就被算成读了它。+_PATH_CHAIN = re.compile(r"""/\s*((?:["'][^"'\n]+["']\s*/\s*)*["'][^"'\n]+["'])""")+_SEGMENT = re.compile(r"""["']([^"'\n]+)["']""")+#: 测试文件顶上的 `FRONTEND = ROOT / "frontend"` 这类别名,用来还原下面链式拼接的前缀。+_ROOT_ALIAS = re.compile(r"""^\w+\s*=\s*\w+(?:\[\d+\])?\s*/\s*["']([\w./-]+)["']\s*$""", re.M)+++def repository_paths_read_by(source: str) -> tuple[str, ...]:+ """一段测试源码实际读到的仓库文件,仓库相对路径。++ 只认拼在某个 Path 后面、且在仓库里真的存在的那一档。判据是「文件存在」而不是+ 「长得像路径」:不存在的字面量是别的东西,存在的才是这个测试真正依赖的输入。+ """+ prefixes = {"", *(alias.strip("/") for alias in _ROOT_ALIAS.findall(source))}+ found: set[str] = set()+ for chain in _PATH_CHAIN.findall(source):+ joined = "/".join(segment.strip("/") for segment in _SEGMENT.findall(chain))+ for prefix in prefixes:+ candidate = f"{prefix}/{joined}".strip("/")+ if (ROOT / candidate).is_file():+ found.add(candidate)+ return tuple(sorted(found))++def unclassified_files() -> tuple[Path, ...]:classified = set()for scope in SCOPES:diff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex c2c254b87..8af27955e 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -333,7 +333,10 @@ class OperationalScriptTests(unittest.TestCase):# 模块名 ↔ 测试文件名推断,登记在几个域就跑几个域。self.assertEqual(pick(["src/peach/media.py"])[0], ("media",))self.assertEqual(pick(["src/peach/jobs.py"])[0], ("media", "tooling"))- self.assertEqual(pick(["src/peach/metadata.py"])[0], ("metadata",))+ # `test_metadata_library.py` 也登记在 web 域(它有一段读 `web/app.js`),+ # 名字又落在 `test_metadata_` 这一族里,于是这个模块把 web 域一起带上。+ # 宽一档是安全的那一侧,web 域全是源码文本断言,代价只有几秒。+ self.assertEqual(pick(["src/peach/metadata.py"])[0], ("metadata", "web"))# 测试文件按自己的文件名归域;公共门槛文件归 tooling。self.assertEqual(pick(["tests/test_certs.py"])[0], ("sync", "tooling"))self.assertEqual(pick(["tests/test_context_budget.py"])[0], ("tooling",))diff --git a/tests/test_test_planning.py b/tests/test_test_planning.pyindex a938c7f26..1800b5ab3 100644--- a/tests/test_test_planning.py+++ b/tests/test_test_planning.py@@ -86,6 +86,27 @@ class TestPlanningTests(unittest.TestCase):patch.object(runner.test_evidence, 'inputs', side_effect=AssertionError('分片不能签发证据')):self.assertEqual(runner.main(['--scope', 'full', '--shard-count', '2']), 0)+ def test_a_test_reading_a_web_source_runs_when_that_source_changes(self):+ """断言 `web/`、`frontend/` 文件的测试,必须登记在改那个文件会选到的域里。++ 域表是人手维护的,漏登记不会报错,只会在 CI 上红:`tests/test_follow_web.py` 读+ `web/app.js`,却只登记在 follow 域,于是改了 `web/app.js` 跑 `auto` 时它根本不在+ 选中的文件里。这一条按测试源码里真实存在的路径拼接反查,把漏登记变成本地就红。++ 判据只覆盖这两个前缀:域表对它们是按目录映射的,除此以外没有第二条路让测试被选+ 中。`src/peach/` 有按模块名的推断,`scripts/`、`docs/` 那些落在 tooling 与 checks+ 的兜底上,同一个漏洞在那边也成立,但要补的是域表本身,不在本条范围内。+ """+ watched = ('web/', 'frontend/')+ for path in sorted((runner.ROOT / 'tests').glob('test_*.py')):+ read = [item for item in runner.repository_paths_read_by(path.read_text(encoding='utf-8'))+ if item.startswith(watched)+ and not any(item.startswith(prefix) for prefix in runner.FULL_ONLY_PREFIXES)]+ for item in read:+ scopes, why = runner.scopes_for_changes([item])+ selected = {chosen.name for scope in scopes for chosen in runner.selected_files(scope)}+ self.assertIn(path.name, selected, f'{path.name} 读 {item},但 {why} 选不到它')+def test_template_copies_have_independent_data(self):with tempfile.TemporaryDirectory() as directory:root = Path(directory).resolve()