Peach: Local-first video metadata scraper and media manager.
test(web): 页面契约扫描覆盖应用域模块
longmeidaob75d4fed8fc4
diff --git a/tests/test_copy_final_state.py b/tests/test_copy_final_state.pyindex 72bb702e7..aac23e10c 100644--- a/tests/test_copy_final_state.py+++ b/tests/test_copy_final_state.py@@ -65,7 +65,7 @@ class CopyFinalStateTests(unittest.TestCase):"""扫描面写死成 glob 就会漏掉新目录,所以直接核对它收到了哪些文件。"""picked = {path.relative_to(ROOT).as_posix() for path in checker.targets(ROOT)}for required in ("AGENTS.md", "README.md", "docs/HANDOFF.md",- "web/app.js", "web/index.html", "web/js/core.js",+ "web/index.html", "frontend/src/application/composition.js", "frontend/src/core/index.ts","src/peach/web_entity.py","tests/test_web_ui.py",".claude/skills/peach-worktree/SKILL.md"):diff --git a/tests/test_follow_assets.py b/tests/test_follow_assets.pyindex 290ec5a8d..26bd8b96f 100644--- a/tests/test_follow_assets.py+++ b/tests/test_follow_assets.py@@ -325,8 +325,10 @@ class SourceIconTableTests(unittest.TestCase):self.assertEqual(listed, set(follow_assets.SOURCE_ICON_URLS))# 页面里没有任何一条站点图标的远端地址:图标全部经 Peach 落盘后再给页面,# 图标地址怎么拼在 `frontend/test/react/follow-marks.test.ts`。- for page in (listing, (root / "web" / "app.js").read_text(encoding="utf-8")):- self.assertNotIn("favicon.ico'", page)+ for path in sorted((root / "frontend" / "src").rglob("*")):+ if path.suffix in {".js", ".ts", ".tsx"}:+ with self.subTest(path=path):+ self.assertNotIn("favicon.ico'", path.read_text(encoding="utf-8"))if __name__ == "__main__":diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 7c0363e1e..66906bd70 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -2962,7 +2962,7 @@ class LegacyHistoryEndPayloadTests(unittest.TestCase):class FollowShellDecisionTests(unittest.TestCase):- """壳层 `web/app.js` 里两条关注页决定:组件用例驱动不了壳,浏览器用例也没碰到它们。"""+ """应用默认导航的关注入口与换一批策略。"""def test_follow_sits_before_immerse_and_neither_follow_page_joins_the_refresh(self):"""左栏「关注」排在沉浸模式前面;顶栏换一批不重画两个关注页。@@ -2971,13 +2971,15 @@ class FollowShellDecisionTests(unittest.TestCase):`refresh: 'skip'` 跳过它们。两页都登记在 `ROUTE_META`,由`frontend/test/history/history.test.ts` 钉住。"""- page = (ROOT / "web" / "app.js").read_text(encoding="utf-8")- rail = page[page.index("const SIDEBAR_ITEMS=["):]- keys = re.findall(r"\['([a-z]*)'", rail[:rail.index("];")])+ application = ROOT / 'frontend/src/application'+ page = (application / 'layout.js').read_text(encoding="utf-8")+ rail = re.search(r'\bSIDEBAR_ITEMS\s*=\s*\[(.*?)\];', page, re.S).group(1)+ keys = re.findall(r"\['([a-z]*)'", rail)self.assertIn("follow", keys)self.assertEqual(keys[keys.index("follow") + 1], "immerse","关注入口应当排在沉浸模式前面")- self.assertIn("if(refresh==='skip')return;", page)+ preferences = (application / 'preferences.js').read_text(encoding='utf-8')+ self.assertIn("if(refresh==='skip')return;", preferences)class FollowItemProjectionTests(unittest.TestCase):diff --git a/tests/test_legacy_shell_routes.py b/tests/test_legacy_shell_routes.pyindex c93d4b2d8..c79a84c50 100644--- a/tests/test_legacy_shell_routes.py+++ b/tests/test_legacy_shell_routes.py@@ -1,13 +1,8 @@-"""旧壳 `web/app.js` 的路由表只许减不许增:新页面做成 `frontend/` 的 island 或路由树的元素。+"""页面全集由 React 路由注册表和覆盖组共同声明。-ADR-0022 的迁移方向是逐屏搬出 app.js,可 2026-09-13 盘点时它已长到 10818 行,比立项-时多出四成——每一轮新功能都往旧壳里加一屏。行数拦不住这种增长(拦住的只是注释),-拦得住的是「旧壳里登记了哪些页面」。--冻结的是页面全集,按归属分成三列:壳打开的(app.js 里 `ROUTES` 表的字面 match,这张表已经没有了,这一列-是空的)、路由树用元素画的(`managed-routes.tsx` 各张路由表里带 `element` 的条目;目录表按页面分键,带了元素-就算 `CATALOG_PATHS` 那几条路径)、覆盖组按真实地址匹配的详情与队列(`OVERLAY_PATHS`)。三列互不相交、-并起来仍是这张全集;壳那一列不许再长出来。+`managed-routes.tsx` 的页面元素按真实地址注册,目录表展开到 `CATALOG_PATHS`。+详情与队列使用 `OVERLAY_PATHS`;两类路径互不相交、共同覆盖固定页面全集。+实体资料页另按种类登记模式路径,筛选态沿用 `STATE_ROUTES` 的目录身份。"""import pathlibimport re@@ -43,12 +38,6 @@ def without_comments(source: str) -> str:return _STRING_OR_COMMENT.sub(lambda hit: hit.group(1) or "", source)-def routes_table(source: str) -> str:- """app.js 里 `ROUTES` 表的正文;没有这张表时是空串。"""- start = source.find("const ROUTES=[")- return "" if start < 0 else source[start:source.index("\n];", start)]--def braced(source: str, start: int) -> str:"""`source[start]` 是 `{`,取到与它配对的 `}` 为止(含两端)。"""depth = 0@@ -108,35 +97,28 @@ def tree_routes(source: str) -> set[str]:class LegacyShellRouteTests(unittest.TestCase):def setUp(self):- self.source = APP.read_text(encoding="utf-8")- self.table = routes_table(self.source)self.overlay = quoted_list(OVERLAY.read_text(encoding="utf-8"), "OVERLAY_PATHS")tree = tree_routes(ROUTE_TABLES.read_text(encoding="utf-8"))self.patterns = {path for path in tree if path.endswith("/*")}state_routes = CORE.read_text(encoding="utf-8").split("const STATE_ROUTES", 1)[1].split("};", 1)[0]self.tree = tree - self.patterns - set(re.findall(r":'([^']*)'", state_routes))- self.shell = set(re.findall(r"match:\s*'([^']*)'", self.table)) - self.overlay- def test_the_three_owners_partition_the_frozen_pages(self):- self.assertEqual(sorted(self.shell & self.tree), [],- "这些页面已经由路由树的元素画,请从 app.js 的 ROUTES 里删掉")+ def test_the_route_registry_and_overlays_partition_the_frozen_pages(self):self.assertEqual(sorted(self.tree & self.overlay), [], "覆盖组的路径不该在页面组里再登记元素")- union = self.shell | self.tree | self.overlay+ union = self.tree | self.overlayadded = sorted(union - FROZEN_ROUTES)self.assertEqual(added, [],"多出了页面;新页面请做成 frontend/ 的 island 或路由树的元素,""并把它加进 FROZEN_ROUTES:" + "、".join(added))gone = sorted(FROZEN_ROUTES - union)- self.assertEqual(gone, [], "这些页面三列里都找不到了,删掉了的话请从 FROZEN_ROUTES 里删掉:" + "、".join(gone))+ self.assertEqual(gone, [], "注册表缺少页面:" + "、".join(gone))def test_the_tree_registers_exactly_the_entity_patterns(self):self.assertEqual(sorted(self.patterns), sorted(TREE_PATTERNS),"路由树按模式登记的页面变了;新增一种同样算加页面")- def test_the_shell_opens_no_page_by_itself(self):- self.assertEqual(sorted(self.shell), [], "app.js 不再有自己打开的页面:页面做成路由树的元素")- self.assertEqual(len(re.findall(r"\bregisterRoute\(", self.source)), 0,- "app.js 不登记页面:页面做成路由树的元素")+ def test_the_application_has_no_unbundled_shell_entry(self):+ self.assertFalse(APP.exists(), "主页面入口应为固定的 peach-app 构建产物")if __name__ == "__main__":diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.pyindex 233b6cb17..c49b958aa 100644--- a/tests/test_metadata_library.py+++ b/tests/test_metadata_library.py@@ -1763,7 +1763,7 @@ class LibraryNfoTests(unittest.TestCase):def test_management_controls_keep_credentials_and_empty_sections_visible(self):root = Path(__file__).resolve().parents[1]- source = (root / 'web/app.js').read_text(encoding='utf-8')+ source = (root / 'frontend/src/application/catalog.js').read_text(encoding='utf-8')# 关注管理那一屏在 React 里:能加来源的站才进候选,缺必填凭据的那一行默认展开,# 一个站都没配也照样把整块列出来(空清单不等于这块不存在)。follow = root / 'frontend/src/react/follow-manage'diff --git a/tests/test_studio_icon_variants.py b/tests/test_studio_icon_variants.pyindex 627c2f267..c11c24b4e 100644--- a/tests/test_studio_icon_variants.py+++ b/tests/test_studio_icon_variants.py@@ -363,15 +363,17 @@ class PageSourceTests(unittest.TestCase):@classmethoddef setUpClass(cls):- cls.source = (ROOT / "web" / "app.js").read_text(encoding="utf-8")+ cls.application = ROOT / 'frontend/src/application'def test_the_studio_hero_asks_for_the_wordmark(self):"""大位和小位共用一条取图链,变体由调用方按位置给:大位默认就是字标。取图链本身(默认变体与地址)由 `frontend/test/card-art/markup.test.ts` 验。"""- self.assertIn("logo:company&&d.has_logo?d.canonical_name:'',", self.source)+ source = (self.application / 'entity.js').read_text(encoding='utf-8')+ self.assertIn("logo:company&&d.has_logo?d.canonical_name:'',", source)def test_every_small_surface_asks_for_the_icon(self):+ source = (self.application / 'catalog.js').read_text(encoding='utf-8')for snippet in ("logoUrl(x.k,'icon',x.logo_version)",):@@ -381,7 +383,7 @@ class PageSourceTests(unittest.TestCase):# 声明式的,不存在按 `img.dataset.studio` 换图的第三处。「不许漏 variant」# 由下面那条按行扫描的断言守。with self.subTest(snippet=snippet):- self.assertIn(snippet, self.source)+ self.assertIn(snippet, source)def test_one_disk_has_one_mark_wherever_it_shows_up(self):"""网盘的图形只有一份,不因为取图入口不同而长成两枚。@@ -391,15 +393,18 @@ class PageSourceTests(unittest.TestCase):读出来像两个来源;而厂牌那条取图链本来就不认网盘,115 能从那里取到只是名字碰巧撞上了一个厂牌文件名。"""- self.assertIn('\'115\':`<img class="source-icon" src="${MEDIA_SOURCE_ICONS[\'115\']}" alt="">`,',- self.source)- self.assertIn('pikpak:`<img class="source-icon" src="${MEDIA_SOURCE_ICONS.pikpak}" alt="">`,',- self.source)- self.assertNotIn("studio=115", self.source)+ source = (self.application / 'preferences.js').read_text(encoding='utf-8')+ self.assertIn('\'115\':`<img class="source-icon" src="${MEDIA_SOURCE_ICONS[\'115\']}" alt="">`,', source)+ self.assertIn('pikpak:`<img class="source-icon" src="${MEDIA_SOURCE_ICONS.pikpak}" alt="">`,', source)+ for path in sorted((ROOT / 'frontend/src').rglob('*')):+ if path.suffix in {'.js', '.ts', '.tsx'}:+ self.assertNotIn("studio=115", path.read_text(encoding='utf-8'))def test_no_logo_request_is_left_without_a_variant(self):"""漏掉一处就会在那个位置继续显示补白字标,而且没人会注意到。"""- bare = [line.strip() for line in self.source.splitlines()+ bare = [(path.relative_to(ROOT).as_posix(), line.strip())+ for path in sorted((ROOT / 'frontend/src').rglob('*')) if path.suffix in {'.js', '.ts', '.tsx'}+ for line in path.read_text(encoding='utf-8').splitlines()if "/logo?studio=" in line and "variant=" not in line]self.assertEqual(bare, [])diff --git a/tests/test_web_settings.py b/tests/test_web_settings.pyindex 7ad6cbcb8..2d1e0ca4d 100644--- a/tests/test_web_settings.py+++ b/tests/test_web_settings.py@@ -275,15 +275,17 @@ class ContractRegistrationTests(unittest.TestCase):def test_initial_history_choices_are_in_settings_and_match_the_server(self):import reroot = Path(__file__).resolve().parents[1]- page = (root / 'web/app.js').read_text(encoding='utf-8')- options = re.search(r'const FOLLOW_INITIAL_RANGE_OPTIONS=\[(.*?)\];', page, re.S).group(1)+ page = (root / 'frontend/src/application/lifecycle.js').read_text(encoding='utf-8')+ options = re.search(r'\bFOLLOW_INITIAL_RANGE_OPTIONS\s*=\s*\[(.*?)\];', page, re.S).group(1)self.assertEqual(tuple(int(value) for value in re.findall(r"\['(\d+)',", options)),web_settings.FOLLOW_INITIAL_DAYS)# 设置面板那一格在 `settings-panel` 岛里,选项由壳递进 `followInitialRanges`,选完写账本。panel = (root / 'frontend/src/react/settings-panel/settings-panel.tsx').read_text(encoding='utf-8')- self.assertIn('followInitialRanges:FOLLOW_INITIAL_RANGE_OPTIONS,', page)+ layout = (root / 'frontend/src/application/layout.js').read_text(encoding='utf-8')+ self.assertIn('followInitialRanges:followState.FOLLOW_INITIAL_RANGE_OPTIONS,', layout)self.assertIn('initial.mutate({ followInitialDays: value }', panel)- self.assertNotIn('data-follow-unread-days', page + panel)+ for source in (page, layout, panel):+ self.assertNotIn('data-follow-unread-days', source)if __name__ == "__main__":unittest.main()diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 410496fe0..494cef87e 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -89,23 +89,20 @@ class WebUiPolicyTests(unittest.TestCase):def setUpClass(cls):root = Path(__file__).resolve().parents[1]web = root / "web"- markup = [web / "index.html", web / "app.js", *sorted((web / "js").glob("*.js"))]+ markup = [web / "index.html", *sorted(path for path in (root / "frontend" / "src").rglob("*")+ if path.suffix in {".js", ".ts", ".tsx"})]cls.css = stylesheet_source()- cls.page = "\n".join(path.read_text(encoding="utf-8") for path in markup) + cls.css- markup.extend(sorted((root / "frontend" / "src").rglob("*.ts*")))+ cls.markup_files = markupcls.markup = "\n".join(path.read_text(encoding="utf-8") for path in markup)def test_primary_button_fill_is_owned_by_board_styles(self):# Board 覆盖层统一负责主按钮面色;基样式中的重复规则会竞争层叠优先级。self.assertNotIn(".geist-button.primary{", self.css)- def assertPageContains(self, needle: str, message: str = ""):- if needle not in self.page:- self.fail(f"index.html 缺少:{needle!r}" + (f"({message})" if message else ""))-def assertPageLacks(self, needle: str, message: str = ""):- if needle in self.page:- self.fail(f"index.html 不应再出现:{needle!r}" + (f"({message})" if message else ""))+ for path in self.markup_files:+ with self.subTest(path=path):+ self.assertNotIn(needle, path.read_text(encoding="utf-8"), message)def test_every_font_size_comes_from_the_one_type_scale(self):"""全站只有一套字号刻度,任何写死的像素都要有理由。@@ -261,17 +258,11 @@ class WebUiPolicyTests(unittest.TestCase):self.assertPageLacks('onload="if(this.naturalWidth')def test_image_fallbacks_are_declarative_data_not_inline_handlers(self):- """`<img>` 上不再有内联 `onerror`,回退链改成 `data-*` 声明。-- 内联版的 URL 要同时穿过 HTML 属性转义和 JS 字符串两层,错一层不报错、- 只是这张图从此不再回退;同一条链在 app.js 里还有四种写法。- """- self.assertPageLacks(' onerror="', "模板里不能再出现内联 onerror 属性")- self.assertPageContains("wireImageFallbacks(document.body)")+ """`<img>` 的回退链以 data 属性声明,模板不编译事件处理器。"""+ self.assertPageLacks(' onerror="', "模板不能包含内联 onerror 属性")# 捕获阶段的委托监听与「没有 `data-drop` 的 <img> 一概不动」由# `frontend/test/card-art/image-fallback.test.ts` 跑真元素验收;页面上另有一批# 靠 CSS 或父节点兜底的图(厂牌 `.mk`),把它们删掉反而是错的。壳自己拼的图也走同一套声明。- self.assertPageContains('data-drop="')def test_no_site_icon_is_fetched_by_the_browser_from_the_site_itself(self):"""站点图标全部由本机给:浏览器不向对方站点要图,也不问第三方图标代理。@@ -297,7 +288,9 @@ class WebUiPolicyTests(unittest.TestCase):"""定位源文件的等待态留在按钮里,不往详情里写一行「正在定位…」撑开内容流;按钮保持可聚焦,重复点击由共享 busy 状态挡住。这枚按钮画在壳的照片详情里,组件与浏览器用例都没碰到它。只收 asset id 由 `test_fastapi_api.py` 的定位接口用例保证。"""- reveal = self.page.split("async function revealSource", 1)[1].split("async function syncMissing", 1)[0]+ root = Path(__file__).resolve().parents[1]+ entity = (root / "frontend" / "src" / "application" / "entity.js").read_text(encoding="utf-8")+ reveal = entity.split("async function revealSource", 1)[1].split("async function syncMissing", 1)[0]self.assertNotIn("status.textContent='正在定位…'", reveal,"请求等待态必须留在按钮内,不能撑开详情内容流")self.assertNotIn("button.disabled", reveal,@@ -414,23 +407,20 @@ class BoardStyleIsolationTests(unittest.TestCase):它是盖在 `web/css/` 上的覆盖层,两份一起才画得出一个界面。留一个开关把它摘掉,剩下的是一屏对不上的类名——`.board-*` 那些节点仍在 DOM 里,谁也不给它们样式。- 判据落在三处:入口 HTML 无条件引它、`web/` 下没有 `peach.legacy-ui` 与- `original-design` 的消费者、壳与设置面板都不读第二套界面的开关。设置里那枚+ 判据落在三处:入口 HTML 无条件引它、页面源码没有 `peach.legacy-ui` 与+ `original-design` 的消费者、应用与设置面板都不读第二套界面的开关。设置里那枚「增加对比度」由 `frontend/test/react/settings-panel.test.tsx` 在渲染结果上验。"""root = Path(__file__).resolve().parents[1]html = (root / "web/index.html").read_text(encoding="utf-8")self.assertIn('<link rel="stylesheet" href="/board.css">', html)- for path in sorted((root / "web").rglob("*")):- if path.suffix not in {".js", ".css", ".html"} or "dist" in path.parts:+ paths = [*sorted((root / "web").rglob("*")), *sorted((root / "frontend" / "src").rglob("*"))]+ for path in paths:+ if path.suffix not in {".js", ".css", ".html", ".ts", ".tsx"} or "dist" in path.parts:continuetext = path.read_text(encoding="utf-8")- for token in ("peach.legacy-ui", "original-design"):+ for token in ("peach.legacy-ui", "original-design", "legacyUISetting"):self.assertNotIn(token, text, f"{path.name} 仍在读第二套界面的开关")- app = (root / "web/app.js").read_text(encoding="utf-8")- panel = (root / "frontend/src/react/settings-panel/settings-panel.tsx").read_text(encoding="utf-8")- for source in (app, panel):- self.assertNotIn("legacyUISetting", source)def test_icon_centering_does_not_override_toolbar_visibility(self):root = Path(__file__).resolve().parents[1]