Peach: Local-first video metadata scraper and media manager.
test(ci): Linux 上按平台口径造夹具,修 verify-linux 的 24 条失败
longmeidao0cee04e88592
diff --git a/tests/test_data_storage.py b/tests/test_data_storage.pyindex d7da34b63..baa07e212 100644--- a/tests/test_data_storage.py+++ b/tests/test_data_storage.py@@ -140,7 +140,10 @@ class DataStorageTests(unittest.TestCase):def test_rename_moves_everything_rewrites_ledger_paths_and_points_both_locators(self):snapshot = str(self.data / "generated" / "snapshots" / "local" / "aa" / "x.jpg")evidence = str(self.data / "sources" / "follow" / "page.html")- make_ledger(self.data / "database" / "ledger.db", snapshot=snapshot.upper(), evidence=evidence)+ # 路径比较按本机 normcase:折叠大小写的系统上,账本里换了大小写的旧路径也要认出来。+ folds_case = os.path.normcase("A") == "a"+ make_ledger(self.data / "database" / "ledger.db",+ snapshot=snapshot.upper() if folds_case else snapshot, evidence=evidence)write(self.data / "generated" / "covers" / "ABC-001.jpg")bootstrap = self.base / "default" / "peach-data"target = self.base / "new" / "peach-data"diff --git a/tests/test_feeds_web.py b/tests/test_feeds_web.pyindex 5fd63dab6..78cb4a382 100644--- a/tests/test_feeds_web.py+++ b/tests/test_feeds_web.py@@ -16,7 +16,7 @@ from unittest.mock import patchsys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))sys.path.insert(0, str(Path(__file__).resolve().parent))-from peach import feed_followup, feeds, web_feeds, web_settings # noqa: E402+from peach import feed_followup, feeds, web_feeds, web_settings, web_state # noqa: E402from peach.http import HttpResponse # noqa: E402from peach.web_contract import WebContract # noqa: E402from peach.web_router import dispatch_api_get, dispatch_api_post # noqa: E402@@ -185,7 +185,10 @@ class FeedWebTest(FeedWebFixture):self.assertFalse(self.contract.has_cover('SSIS-950'))self.assertIsNone(self.contract.cover_path('SSIS-950'))atomic_write_text(evidence, json.dumps({'source_url': 'https://pics.dmm.co.jp/a.jpg'}))- self.assertTrue(self.contract.has_cover('SSIS-950'))+ # 两次换名可能落在同一个时钟刻度,目录时间不变;刚写过的目录索引过了静置时效才重扫。+ later = web_state.time.monotonic() + web_state.SETTLE_TTL + 1+ with patch.object(web_state.time, 'monotonic', return_value=later):+ self.assertTrue(self.contract.has_cover('SSIS-950'))self.assertEqual(self.contract.cover_path('SSIS-950'), target)def test_known_discovery_without_cover_address_has_no_javdb_image_fallback(self):diff --git a/tests/test_macos_media.py b/tests/test_macos_media.pyindex 119169388..7f25883d8 100644--- a/tests/test_macos_media.py+++ b/tests/test_macos_media.py@@ -103,8 +103,9 @@ class MacMediaBundleTests(unittest.TestCase):else executable.parent / name)path.parent.mkdir(exist_ok=True, parents=True)path.write_bytes(b"fixture")+ # 应用包布局只在 macOS 生效,Linux runner 上按 macOS 解析同一套 POSIX 文件名。with patch.object(sys, "executable", str(executable)), patch.object(sys, "frozen", True, create=True), \- patch.dict("os.environ", {"PATH": ""}, clear=True):+ patch.object(sys, "platform", "darwin"), patch.dict("os.environ", {"PATH": ""}, clear=True):resolver = FFmpegResolver(self.root / "missing")self.assertEqual(resolver.ffmpeg().source, "peach-bundled")self.assertEqual(resolver.ffprobe().path, executable.parent.parent / "Resources/tools/ffmpeg/bin/ffprobe")diff --git a/tests/test_onboarding.py b/tests/test_onboarding.pyindex 5b6ae7678..7b20fe526 100644--- a/tests/test_onboarding.py+++ b/tests/test_onboarding.py@@ -1,8 +1,9 @@"""`peach.onboarding`:首次运行问答的题目、校验与落盘,纯逻辑、可注入。CLI 与将来的托盘设置页共用这一层,所以这里只用脚本化答案驱动,不碰 stdin;平台由-`windows=` 注入。只有一处例外:媒体目录题要收一个真实存在的目录,而那个目录是不是盘符-路径由测试机决定,所以走到这道题的用例按 `NATIVE_WINDOWS` 用本机形态。+`windows=` 注入。例外是真实目录:媒体目录题要收一个真实存在的目录,写回设置文件的+真实目录要配上账本口径的声明根,而那个目录是不是盘符路径由测试机决定,所以这些用例+按 `NATIVE_WINDOWS` 用本机形态。"""from __future__ import annotations@@ -23,6 +24,18 @@ NATIVE_WINDOWS = os.name == "nt"HAS_HTTP_DEPS = all(importlib.util.find_spec(name) for name in ("fastapi", "httpx"))+def local_media(*directories: Path) -> tuple[dict, dict]:+ """本机真实目录对应的 `[media.locations]` 与 `[media.mounts]`。++ 声明根在所有系统上都是账本口径的 Windows 路径:Windows 直接用这些目录;+ 其他系统按 `peach init` 的写法用 `R:\\media` 起的声明根,真实目录按顺序进 `[media.mounts]`。+ """+ actual = tuple(str(directory) for directory in directories)+ if NATIVE_WINDOWS:+ return {"local": actual}, {}+ return {"local": onboarding.posix_declared_roots(len(actual))}, {"local": actual}++def scripted(*answers: str):"""按顺序吐答案,并把每一题的题目与默认值记下来。"""queue = list(answers)@@ -245,13 +258,12 @@ class ConfigureTests(_Case):def test_the_written_file_reads_back_with_only_the_declared_source(self):"""`[media.locations]` 里只有 local:内建默认的示例盘符不得从旁边混进来。"""- prepared = onboarding.configure(self.config, self._answers(), windows=True)+ prepared = onboarding.configure(self.config, self._answers(), windows=NATIVE_WINDOWS)settings_file.write(prepared)loaded = settings_file.load_config(project_root=self.root / "app", environ={"PEACH_DATA_ROOT": str(self.root / "peach-data")})self.assertTrue(loaded.present)- self.assertEqual(loaded.locations, {"local": (str(self.media),)})- self.assertEqual(loaded.mounts, {})+ self.assertEqual((loaded.locations, loaded.mounts), local_media(self.media))self.assertFalse(loaded.replication.enabled)@@ -910,8 +922,9 @@ class StandaloneConfigurationTests(_Case):def setUp(self):super().setUp()from dataclasses import replace- self.config = replace(self.config, locations={"local": (str(self.media),)},- mounts={}, server=settings_file.ServerSettings(port=9123))+ locations, mounts = local_media(self.media)+ self.config = replace(self.config, locations=locations, mounts=mounts,+ server=settings_file.ServerSettings(port=9123))settings_file.write(self.config)self.config = settings_file.load_config(environ={"PEACH_DATA_ROOT": str(self.config.data_root)})self.addCleanup(mock.patch.stopall)@@ -1046,8 +1059,10 @@ class StandaloneConfigurationTests(_Case):"""摘要卡的媒体库数量由服务端给出:库名相同的目录算一个库,跨来源也一样。"""from dataclasses import replacefrom peach import media_libraries- first, second, third = (str(self.media / name) for name in ("a", "b", "c"))- self.config = replace(self.config, locations={"local": (first, second), "115": (third,)},+ # 只数媒体库,声明根不必有实际目录;非 Windows 照样用账本口径的 Windows 路径。+ first, second, third = (str(self.media / name) if NATIVE_WINDOWS else ntpath.join("R:\\media", name)+ for name in ("a", "b", "c"))+ self.config = replace(self.config, locations={"local": (first, second), "115": (third,)}, mounts={},library_names={first: "电影", third: "电影"}, library_catalog={}, storage_roots={})settings_file.write(self.config, force=True)with self.client() as client: