Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(tooling): auto 选域按脚本与文档的真实归属

longmeidaoccff791adf77
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index 96dbd2541..4c158125b 100644
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -125,25 +125,61 @@ SCOPE_TEST_IDS: dict[str, tuple[str, ...]] = {
),
}
-# `auto` 域按改动文件选域:每个文件按下面这张「路径前缀 → 域」表取第一个命中的前缀,
-# 多个文件取并集。表里没有的 `tests/test_*.py` 直接按文件名归域,`src/peach/` 下的
-# 其余模块按「模块名 ↔ 测试文件名」推断(`media.py` → `test_media.py` → media)。
-# 仓库根的 Markdown 归 tooling:入口文件、README 与待办的门槛都在那个域里。
-AUTO_SCOPE_PREFIXES: tuple[tuple[str, str], ...] = (
+# `auto` 域按改动文件选域:每个文件先查 `AUTO_SCOPE_FILES` 的整路径,再按
+# `AUTO_SCOPE_PREFIXES` 取第一个命中的前缀,多个文件取并集。表里没有的
+# `tests/test_*.py` 直接按文件名归域,`src/peach/` 下的其余模块按「模块名 ↔ 测试文件名」
+# 推断(`media.py` → `test_media.py` → media)。Markdown 归 checks。
+#
+# 一个文件可以落到多个域:读它的测试登记在哪个域,改它就得跑到哪个域。
+# `tests/test_test_planning.py` 按测试源码里真实读到的路径反查这两张表,漏一条本地就红。
+AUTO_SCOPE_FILES: dict[str, tuple[str, ...]] = {
+ # 路由页面同时被目录、工具与前端三个域的测试读源码。
+ "src/peach/routes_pages.py": ("catalog", "tooling", "web"),
+ # 托盘既是 sync 域的服务编排,也被版本与桌面设置那些 tooling 测试读源码。
+ "src/peach/tray.py": ("sync", "tooling"),
+ "src/peach/jav_poster_crop.py": ("metadata", "web"),
+ # 入口页共用件的测试住在首启与配置来源那两份 tooling 测试里。
+ "src/peach/web_entry.py": ("catalog", "tooling", "web"),
+ # 这几份文档有测试在读它们的正文:改文档也要跑到那条测试。
+ "README.md": ("checks", "tooling"),
+ "README.en.md": ("checks", "tooling"),
+ "docs/STATUS.md": ("checks", "tooling"),
+ "docs/CLOUDDRIVE.md": ("checks", "web"),
+ "docs/OPERATIONS.md": ("checks", "web"),
+ ".github/dependabot.yml": ("tooling", "web"),
+}
+
+# 脚本默认归 tooling;有自己领域测试的脚本两边都跑:领域测试验它的判据,
+# tooling 里的脚本策略门槛验它的形态。
+AUTO_SCOPE_PREFIXES: tuple[tuple[str, str | tuple[str, ...]], ...] = (
("src/peach/media.py", "media"),
("src/peach/desktop_startup.py", "tooling"),
("src/peach/desktop_uninstall.py", "tooling"),
("src/peach/peach_proxy.py", "tooling"),
("src/peach/gfriends.py", "metadata"),
- ("scripts/localize_performer_names.py", "metadata"),
- ("scripts/localize_series_names.py", "metadata"),
+ ("scripts/localize_performer_names.py", ("metadata", "tooling")),
+ ("scripts/localize_series_names.py", ("metadata", "tooling")),
+ ("scripts/localize_studio_names.py", ("metadata", "tooling")),
+ ("scripts/match_babepedia_creators.py", ("metadata", "tooling")),
+ ("scripts/audit_code_creators.py", ("metadata", "tooling")),
+ ("scripts/audit_fc2_similarity.py", ("metadata", "tooling")),
+ ("scripts/poster_crop_boxes.py", ("metadata", "tooling")),
+ ("scripts/rediscover_entity_links.py", ("metadata", "tooling")),
+ ("scripts/fetch_studio_avatar_candidates.py", ("metadata", "tooling")),
+ ("scripts/scrape_codes.py", ("metadata", "tooling")),
+ ("scripts/merge_studio_name_variants.py", ("metadata", "tooling")),
+ ("scripts/harvest_", ("metadata", "tooling")),
+ ("scripts/sync_brand_marks.py", ("catalog", "tooling")),
+ ("scripts/detect_cover_faces.py", ("web", "tooling")),
+ ("scripts/vendor_web_dependencies.mjs", ("web", "tooling")),
+ ("scripts/audit_video_endcards.py", ("media", "tooling")),
+ ("scripts/setup_macos_port80.sh", ("sync", "tooling")),
("src/peach/follow", "follow"),
("src/peach/fanbox.py", "follow"),
("src/peach/web_follow.py", "follow"),
("src/peach/sync", "sync"),
("src/peach/platform.py", "sync"),
("src/peach/mount.py", "sync"),
- ("src/peach/tray.py", "sync"),
("src/peach/mdns.py", "sync"),
("src/peach/netwatch.py", "sync"),
("src/peach/certs.py", "sync"),
@@ -274,16 +310,16 @@ def scopes_for_changes(paths: Iterable[str], *, contents: dict | None = None) ->
full_reasons.append(f"{path} 属于必须 full 的面")
continue
scopes: tuple[str, ...] = ()
- if path.startswith("tests/test_") and path.endswith(".py"):
+ if path in AUTO_SCOPE_FILES:
+ scopes = AUTO_SCOPE_FILES[path]
+ elif path.startswith("tests/test_") and path.endswith(".py"):
scopes = scopes_of_test_file(name)
elif path.endswith(".md"):
scopes = ("checks",)
- elif path == "src/peach/routes_pages.py":
- scopes = ("catalog", "tooling", "web")
else:
for prefix, scope in AUTO_SCOPE_PREFIXES:
if path.startswith(prefix):
- scopes = (scope,)
+ scopes = (scope,) if isinstance(scope, str) else scope
break
if not scopes and path.startswith("src/peach/") and path.endswith(".py"):
scopes = scopes_of_module(name.removesuffix(".py"))
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index 422e9e08f..16d7219f8 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -440,11 +440,11 @@ class OperationalScriptTests(unittest.TestCase):
pick = runner.scopes_for_changes
# 前缀表:多个文件取并集,反斜杠路径也认。
self.assertEqual(pick(["src/peach/follow_store.py", "web/app.js"])[0], ("follow", "web"))
- self.assertEqual(pick(["src\\peach\\tray.py"])[0], ("sync",))
+ self.assertEqual(pick(["src\\peach\\tray.py"])[0], ("sync", "tooling"))
self.assertEqual(pick(["scripts/probe.py", "pyproject.toml", ".github/workflows/test.yml"])[0],
("full",))
self.assertEqual(pick(["README.md", "docs/STATUS.md", ".claude/skills/x/SKILL.md"])[0],
- ("checks",))
+ ("checks", "tooling"))
self.assertEqual(pick(["src/peach/web_entity.py", "src/peach/routes_pages.py"])[0],
("catalog", "tooling", "web"))
self.assertEqual(pick(["src/peach/web_follow.py"])[0], ("follow",))
diff --git a/tests/test_test_evidence.py b/tests/test_test_evidence.py
index e3977cb71..576970b07 100644
--- a/tests/test_test_evidence.py
+++ b/tests/test_test_evidence.py
@@ -42,7 +42,7 @@ class VerificationTests(unittest.TestCase):
"Co-Authored-By: Codex (GPT-5.5) <[email protected]>")
return worker, item["branch"]
- def certify(self, worker, scopes=("checks",), success=True):
+ def certify(self, worker, scopes=("checks", "tooling"), success=True):
state = evidence.key(worker)
evidence.write(worker, state, scopes, success=success, elapsed=1, slowest=[], count=1)
return state
@@ -281,7 +281,7 @@ class VerificationTests(unittest.TestCase):
mock.patch.object(runner, "build_suite", return_value=unittest.TestSuite([
unittest.FunctionTestCase(lambda: None)])) as build:
self.assertEqual(runner.main(["--scope", "auto"]), 0)
- build.assert_called_once_with("checks")
+ build.assert_called_once_with("checks", "tooling")
record = evidence.read(self.repo, evidence.key(self.repo))
self.assertEqual(record["baseline"], original)
self.assertEqual(record["validated"]["full"], stamp)
diff --git a/tests/test_test_planning.py b/tests/test_test_planning.py
index 1842ea99e..aca2f6018 100644
--- a/tests/test_test_planning.py
+++ b/tests/test_test_planning.py
@@ -48,7 +48,9 @@ class TestPlanningTests(unittest.TestCase):
rows = ci_plan.plan('pull_request', ['src/peach/follow_store.py'])['matrix']['include']
self.assertTrue(any(r['scope'] == 'auto' for r in rows))
self.assertFalse(any(r['scope'] == 'full' for r in rows))
- self.assertEqual(runner.scopes_for_changes(['scripts/localize_performer_names.py'])[0], ('metadata',))
+ self.assertEqual(runner.scopes_for_changes(['scripts/localize_performer_names.py'])[0],
+ ('metadata', 'tooling'))
+ self.assertEqual(runner.scopes_for_changes(['README.md'])[0], ('checks', 'tooling'))
def test_missing_git_base_selects_wide_matrix(self):
with patch.object(sys, 'argv', ['ci_plan.py', '--event', 'push', '--base', 'missing']), \
@@ -153,21 +155,21 @@ class TestPlanningTests(unittest.TestCase):
with self.subTest(bad=bad), self.assertRaises(runner.argparse.ArgumentTypeError):
runner.resolve_jobs(bad)
- def test_a_test_reading_a_web_source_runs_when_that_source_changes(self):
- """断言 `web/`、`frontend/` 文件的测试,必须登记在改那个文件会选到的域里。
+ def test_a_test_reading_a_repository_file_runs_when_that_file_changes(self):
+ """读了仓库里某个文件的测试,必须登记在改那个文件会选到的域里。
域表是人手维护的,漏登记不会报错,只会在 CI 上红:`tests/test_follow_web.py` 读
`web/app.js`,却只登记在 follow 域,于是改了 `web/app.js` 跑 `auto` 时它根本不在
选中的文件里。这一条按测试源码里真实存在的路径拼接反查,把漏登记变成本地就红。
- 判据只覆盖这两个前缀:域表对它们是按目录映射的,除此以外没有第二条路让测试被选
- 中。`src/peach/` 有按模块名的推断,`scripts/`、`docs/` 那些落在 tooling 与 checks
- 的兜底上,同一个漏洞在那边也成立,但要补的是域表本身,不在本条范围内。
+ 判据覆盖整棵树。同一个漏洞在 `scripts/` 与 `docs/` 上一样成立:`test_babepedia_match.py`
+ 读 `scripts/match_babepedia_creators.py` 却只登记在 metadata 域,改那个脚本时 `auto`
+ 选的是 tooling。补法是 `AUTO_SCOPE_FILES` 与 `AUTO_SCOPE_PREFIXES` 让一个文件落到多个域,
+ 而不是把测试重复登记到不相干的域里。
"""
- 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)
+ if not item.startswith('tests/')
and not any(item.startswith(prefix) for prefix in runner.FULL_ONLY_PREFIXES)]
for item in read:
scopes, why = runner.scopes_for_changes([item])