Peach: Local-first video metadata scraper and media manager.
test(deps): 共用当前锁文件的桥安装夹具
longmeidaob6e8d9acc243
diff --git a/.gitlab-ci.yml b/.gitlab-ci.ymlindex 58c83633b..17cbc32eb 100644--- a/.gitlab-ci.yml+++ b/.gitlab-ci.yml@@ -225,7 +225,7 @@ build-windows:# 本机 Windows runner 就是开发机:构建、冒烟与镜像作业和本机测试排同一把整机重负载锁# (scripts/machine_lock.py)。runner 的系统 Python 没有 filelock,用 uv 起一个只带它的临时环境,# 不碰作业里会被 uv sync 改写的 .venv。验证作业经测试入口,入口自己拿这把锁。- - uv run --no-project --with filelock==4.2.0 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./scripts/ci_windows.ps1 build+ - uv run --no-project --with filelock==4.2.4 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./scripts/ci_windows.ps1 build- if ($LASTEXITCODE -ne 0) { throw 'Windows 构建失败' }- python scripts/ci_r2_artifacts.py push windows-release- if ($LASTEXITCODE -ne 0) { throw 'Windows 产物暂存失败' }@@ -267,7 +267,7 @@ smoke-windows:- python scripts/ci_r2_artifacts.py pull windows-release- if ($LASTEXITCODE -ne 0) { throw 'Windows 产物下载校验失败' }script:- - uv run --no-project --with filelock==4.2.0 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./release/ci_windows.ps1 smoke+ - uv run --no-project --with filelock==4.2.4 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./release/ci_windows.ps1 smoke- if ($LASTEXITCODE -ne 0) { throw 'Windows 独立制品验收失败' }# 镜像先构建、冒烟,留在这台 runner 上;推送放在 publish-release 成功之后(publish-docker),@@ -281,7 +281,7 @@ docker-build:name: releaseaction: preparescript:- - uv run --no-project --with filelock==4.2.0 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./scripts/ci_windows.ps1 docker-build+ - uv run --no-project --with filelock==4.2.4 --python 3.14 python -X utf8 scripts/machine_lock.py -- pwsh -NoProfile -File ./scripts/ci_windows.ps1 docker-build- if ($LASTEXITCODE -ne 0) { throw 'Docker 镜像构建或验收失败' }publish-docker:diff --git a/tests/support/amane.py b/tests/support/amane.pynew file mode 100644index 000000000..bc46479ce--- /dev/null+++ b/tests/support/amane.py@@ -0,0 +1,21 @@+"""为测试准备与当前锁文件一致的 amane 安装元数据。"""+from __future__ import annotations++import json++from peach import metadata_amane+++def write_amane_metadata(tools, version=None, *, ready=False):+ version = version or metadata_amane.locked_version()+ home = metadata_amane.bridge_home(tools)+ package = home / ".venv" / "Lib" / "site-packages" / f"amane-{version}.dist-info"+ package.mkdir(parents=True, exist_ok=True)+ (package / "METADATA").write_text(+ f"Metadata-Version: 2.1\nName: amane\nVersion: {version}\n", encoding="utf-8")+ (package / "direct_url.json").write_text(json.dumps({+ "vcs_info": {"commit_id": metadata_amane.pinned_revision()}}), encoding="utf-8")+ if ready:+ (home / "installed.json").write_text(json.dumps({+ "revision": metadata_amane.pinned_revision(), "version": version,+ "lock_sha256": metadata_amane.lock_fingerprint(metadata_amane.BRIDGE_ROOT)}), encoding="utf-8")diff --git a/tests/test_background_issues.py b/tests/test_background_issues.pyindex f698f020a..a30470c94 100644--- a/tests/test_background_issues.py+++ b/tests/test_background_issues.py@@ -17,8 +17,9 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))from peach import background_issues # noqa: E402from peach.background_issues import IssueLog # noqa: E402from peach.follow_scheduler import FollowUpdateScheduler # noqa: E402-from peach.metadata_amane import bridge_home, bridge_python, pinned_revision # noqa: E402+from peach.metadata_amane import bridge_python # noqa: E402from peach.tunnel import TunnelSnapshot # noqa: E402+from support.amane import write_amane_metadata # noqa: E402class Clock:@@ -39,14 +40,6 @@ def write_bridge_python(tools):python.write_bytes(b"")-def write_amane_metadata(tools):- package = bridge_home(tools) / ".venv" / "Lib" / "site-packages" / "amane-0.20.0.dist-info"- package.mkdir(parents=True)- (package / "METADATA").write_text("Metadata-Version: 2.1\nName: amane\nVersion: 0.20.0\n", encoding="utf-8")- (bridge_home(tools) / 'installed.json').write_text(json.dumps({- 'revision': pinned_revision(), 'version': '0.20.0'}), encoding='utf-8')--class BackgroundIssueTests(unittest.TestCase):def setUp(self):temporary = tempfile.TemporaryDirectory()@@ -57,7 +50,7 @@ class BackgroundIssueTests(unittest.TestCase):# amane 桥装好的样子,其余用例才不会被它多出来的一项干扰。self.tools = self.root / "tools"write_bridge_python(self.tools)- write_amane_metadata(self.tools)+ write_amane_metadata(self.tools, ready=True)self.contract = SimpleNamespace(tools_root=self.tools, follow_scheduler=None,feed_scheduler=None, downloads=None)self.state = SimpleNamespace()diff --git a/tests/test_fastapi_api.py b/tests/test_fastapi_api.pyindex 03c96025c..095af3480 100644--- a/tests/test_fastapi_api.py+++ b/tests/test_fastapi_api.py@@ -18,6 +18,7 @@ from types import SimpleNamespacefrom urllib.parse import parse_qs, quote, urlsplitfrom peach import __version__+from support.amane import write_amane_metadatafrom support.ledger import fresh_ledgerfrom support.mp4 import minimal_mp4@@ -431,16 +432,12 @@ class FastApiContractTests(unittest.IsolatedAsyncioTestCase):self.assertEqual(served["build_commit"], "c0ffee1234")async def test_background_issues_reads_app_and_contract_services_behind_auth(self):- from peach.metadata_amane import bridge_home, bridge_python, pinned_revision+ from peach.metadata_amane import bridge_python# amane 桥装好的样子:解释器与包元数据都在,「需要处理」里才不会多出未安装那一项。python = bridge_python(self.root / "tools")python.parent.mkdir(parents=True)python.write_bytes(b"")- package = bridge_home(self.root / "tools") / ".venv" / "Lib" / "site-packages" / "amane-0.20.0.dist-info"- package.mkdir(parents=True)- (package / "METADATA").write_text("Metadata-Version: 2.1\nName: amane\nVersion: 0.20.0\n", encoding="utf-8")- (bridge_home(self.root / 'tools') / 'installed.json').write_text(json.dumps({- 'revision': pinned_revision(), 'version': '0.20.0'}), encoding='utf-8')+ write_amane_metadata(self.root / "tools", ready=True)self.app.state.web_contract.tools_root = self.root / "tools"# 夹具账本没有云下载那张表;云下载的判据由 test_background_issues 单独覆盖。self.app.state.web_contract.downloads = Nonediff --git a/tests/test_metadata_amane.py b/tests/test_metadata_amane.pyindex cd825342a..e310c0eff 100644--- a/tests/test_metadata_amane.py+++ b/tests/test_metadata_amane.py@@ -1,7 +1,6 @@"""amane 桥的 Peach 一侧:起子进程、翻 payload、失败分档、冷却动作,以及采集链上那一档。"""from __future__ import annotations-import hashlibimport importlib.utilimport jsonimport os@@ -23,6 +22,7 @@ from peach.metadata_policy import SOURCE_SPECSfrom peach.metadata_routes import AMANE_OFFICIAL_STAGE, AMANE_STAGEfrom peach.scraping_access import SourcePaused, cooldown_state, paused_until, pause_sourcefrom peach.sources import REASON_KINDS, FailureReason, SiteRecord+from support.amane import write_amane_metadataROOT = Path(__file__).resolve().parents[1]@@ -31,18 +31,6 @@ def completed(stdout, returncode=0, stderr=""):return subprocess.CompletedProcess(args=[], returncode=returncode, stdout=stdout, stderr=stderr)-def write_amane_metadata(tools, version, *, ready=False):- package = metadata_amane.bridge_home(tools) / ".venv" / "Lib" / "site-packages" / f"amane-{version}.dist-info"- package.mkdir(parents=True, exist_ok=True)- (package / "METADATA").write_text(f"Metadata-Version: 2.1\nName: amane\nVersion: {version}\n", encoding="utf-8")- (package / "direct_url.json").write_text(json.dumps({- "vcs_info": {"commit_id": metadata_amane.pinned_revision()}}), encoding="utf-8")- if ready:- (metadata_amane.bridge_home(tools) / 'installed.json').write_text(json.dumps({- 'revision': metadata_amane.pinned_revision(), 'version': version,- 'lock_sha256': hashlib.sha256((metadata_amane.BRIDGE_ROOT / 'uv.lock').read_bytes()).hexdigest()}), encoding='utf-8')--def report(**sites):return json.dumps({"number": "FC2-PPV-1234567", "language": "jp", "sites": sites,"amane": {"version": "0.16.1"}}, ensure_ascii=False)