Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(jav): 完善联合验收入口与测试影响域

longmeidao9f1b211288af
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index 7942ae42f..75c790ef7 100644
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -174,6 +174,8 @@ SCOPE_TEST_IDS: dict[str, tuple[str, ...]] = {
# 一个文件可以落到多个域:读它的测试登记在哪个域,改它就得跑到哪个域。
# `tests/test_test_planning.py` 按测试源码里真实读到的路径反查这两张表,漏一条本地就红。
AUTO_SCOPE_FILES: dict[str, tuple[str, ...]] = {
+ "frontend/e2e/jav-userscript-contract.mjs": ("catalog", "web"),
+ "web/integrations/peach-jav.user.js": ("catalog", "web"),
"scripts/build_macos_media.py": ("tooling", "packaging"),
"scripts/setup_macos_media_tools.py": ("tooling", "packaging"),
"scripts/smoke_macos_media.py": ("tooling", "packaging"),
diff --git a/tests/support/browser.py b/tests/support/browser.py
new file mode 100644
index 000000000..32d80c57f
--- /dev/null
+++ b/tests/support/browser.py
@@ -0,0 +1,26 @@
+"""浏览器验收共用的本机 Chrome 定位。"""
+import os
+import shutil
+import sys
+from pathlib import Path
+
+
+def chrome_executable() -> str | None:
+ """读取显式浏览器路径,否则查找各平台安装位置。"""
+ explicit = os.environ.get("PEACH_E2E_CHROME", "").strip()
+ if explicit:
+ return explicit if Path(explicit).is_file() else None
+ candidates: list[Path] = []
+ if os.name == "nt":
+ for variable in ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA"):
+ base = os.environ.get(variable)
+ if base:
+ candidates.append(Path(base) / "Google" / "Chrome" / "Application" / "chrome.exe")
+ elif sys.platform == "darwin":
+ candidates.append(Path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"))
+ else:
+ for name in ("google-chrome", "google-chrome-stable"):
+ found = shutil.which(name)
+ if found:
+ candidates.append(Path(found))
+ return next((str(path) for path in candidates if path.is_file()), None)
diff --git a/tests/test_downloads_jav_browser.py b/tests/test_downloads_jav_browser.py
index 8ea62e3ec..890fce5a6 100644
--- a/tests/test_downloads_jav_browser.py
+++ b/tests/test_downloads_jav_browser.py
@@ -20,6 +20,7 @@ from peach.config import PROJECT_ROOT, PeachSettings
from peach.jav_browser import CREDENTIAL, JavBrowser, code_key, identify_source, source_page, source_sites
from support.ledger import fresh_ledger
from support.conditions import missing_prerequisite
+from support.browser import chrome_executable
HASH = "c9e15763f722f23e98a29decdfae341b98d53056"
MAGNET = f"magnet:?xt=urn:btih:{HASH}&dn=ABC-123"
@@ -399,7 +400,6 @@ class BrowserTests(unittest.TestCase):
self.assertEqual(response.json()["code"], code)
def test_complete_userscript_uses_the_real_identification_endpoint(self):
- from test_web_e2e import chrome_executable
node, chrome = shutil.which("node"), chrome_executable()
if not node or not chrome or not (PROJECT_ROOT / "frontend/node_modules/playwright-core").is_dir():
missing_prerequisite("用户脚本联合验收需要 Node、Chrome 和前端锁定依赖")
diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.py
index 84ef13b84..484831ed3 100644
--- a/tests/test_web_e2e.py
+++ b/tests/test_web_e2e.py
@@ -44,6 +44,7 @@ from peach.config import FFMPEG_DIR
from peach.ffmpeg import FFmpegResolver
from peach.library_processing import process_library
from support.conditions import missing_prerequisite, windows_ledger_roots
+from support.browser import chrome_executable
from support.ledger import fresh_ledger
from support.demo import seed_metadata_cache
from scripts import test_history
@@ -59,27 +60,6 @@ E2E_TIMINGS = ROOT / "scripts" / "ci-browser-timings.json"
E2E_DEFAULT_SECONDS = 30.0
-def chrome_executable() -> str | None:
- """本机 Chrome 的可执行文件;找不到返回 None。"""
- explicit = os.environ.get("PEACH_E2E_CHROME", "").strip()
- if explicit:
- return explicit if Path(explicit).is_file() else None
- candidates: list[Path] = []
- if os.name == "nt":
- for variable in ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA"):
- base = os.environ.get(variable)
- if base:
- candidates.append(Path(base) / "Google" / "Chrome" / "Application" / "chrome.exe")
- elif sys.platform == "darwin":
- candidates.append(Path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"))
- else:
- for name in ("google-chrome", "google-chrome-stable"):
- found = shutil.which(name)
- if found:
- candidates.append(Path(found))
- return next((str(path) for path in candidates if path.is_file()), None)
-
-
def load_demo_script():
path = ROOT / "scripts" / "demo_dataset.py"
spec = importlib.util.spec_from_file_location("peach_script_demo_dataset_e2e", path)