Peach: Local-first video metadata scraper and media manager.
fix(tray): locate repository for update checks
longmeidao7606f0a5b47d
diff --git a/docs/STATUS.md b/docs/STATUS.mdindex 88bbc3c2b..2c63971cc 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -125,7 +125,7 @@479 项测试通过。服务启动/浏览/退出不再同步;marker.device 指定唯一写入端,另一台 POST返回409;托盘只在显式同步或接管时复制。- Windows 品牌资源已统一为附件生成的 `1024x1024` 正方形蜜桃图:`resources/peach-logo.png`、`resources/peach.ico`;Web favicon、托盘图标和 EXE 内嵌图标共用该资源。PyInstaller 打包产物为 `dist/Peach/Peach.exe`,桌面和 Startup 的 `Peach.lnk` 均按 FlowLens 的 `exe,0` 方式指向它;该 exe 只打包托盘自身,服务进程仍由项目 venv 承担,不是可移动的独立发行版。-- 版本唯一来源为 `src/peach/__init__.py::__version__`;Windows 当前部署和本地代码为 `0.6.4`,Mac 最近一次已核验部署为 `0.6.2`。没有 Git remote 时只报告本地开发版,不伪造更新能力。+- 版本唯一来源为 `src/peach/__init__.py::__version__`;Windows 当前部署和本地代码为 `0.6.4`,Mac 最近一次已核验部署为 `0.6.2`。打包托盘会从 `dist/Peach/Peach.exe` 向上定位实际 Git 仓库再检查更新,不再把 PyInstaller 临时资源目录误判为「未配置更新源」;复制到仓库外时仍只报告本地开发版,不伪造更新能力。- 本地 CA HTTPS 已部署。CA 包含 critical `CA:TRUE` 和签名用途并通过 OpenSSL 链验证。macOS/iOS 只安装 `peach-local-ca.crt`;不得传播任何私钥。- 2026-08-24 安全与架构加固:TLS 目录 ACL 已备份,CA key/server key 禁用继承,只保留 `longm`、SYSTEM、Administrators;托盘仍由 `longm` 运行,80/443 与严格 CA HTTPS 复验通过。配置口令后使用 `/login` POST 设置 HttpOnly cookie,旧 `?t=` 只做一次兼容重定向。异常 500 不再把类型/消息外发;HLS 计划与长转码使用有界执行器,session 取消会终止 FFmpeg。- Web 数据边界已开始分域:`LedgerDatabase` 由 `WebContract` 与 `LedgerRepository` 共用,事务统一回滚/关闭;活动写入与纯逻辑已拆到 `web_activity.py`、`web_logic.py`,JSON contract 使用显式 handler 注册表。回收站永久删除先同目录隔离媒体,SQLite commit 失败会恢复原名。diff --git a/src/peach/versioning.py b/src/peach/versioning.pyindex 3309e95fb..f31266e5a 100644--- a/src/peach/versioning.py+++ b/src/peach/versioning.py@@ -2,6 +2,7 @@ from __future__ import annotationsimport osimport subprocess+import sysfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Callable@@ -10,6 +11,24 @@ from . import __version__from .config import PROJECT_ROOT+def discover_repository_root(+ resource_root: Path = PROJECT_ROOT,+ *,+ executable: Path | None = None,+) -> Path:+ """Find the source repository used by the tray without inventing one."""++ resource_root = resource_root.resolve()+ if (resource_root / ".git").exists():+ return resource_root++ executable = (executable or Path(sys.executable)).resolve()+ for parent in executable.parents:+ if (parent / ".git").exists():+ return parent+ return resource_root++@dataclass(frozen=True)class VersionSnapshot:package_version: str@@ -47,11 +66,11 @@ class VersionManager:def __init__(self,- root: Path = PROJECT_ROOT,+ root: Path | None = None,*,execute: Callable[..., subprocess.CompletedProcess[str]] = subprocess.run,) -> None:- self.root = root.resolve()+ self.root = (root if root is not None else discover_repository_root()).resolve()self._execute = executedef _git(self, *args: str, timeout: float = 8.0) -> subprocess.CompletedProcess[str]:diff --git a/tests/test_versioning.py b/tests/test_versioning.pyindex 47406555c..e2321aa4f 100644--- a/tests/test_versioning.py+++ b/tests/test_versioning.py@@ -5,7 +5,7 @@ import unittestfrom pathlib import Pathfrom unittest import mock-from peach.versioning import VersionManager+from peach.versioning import VersionManager, discover_repository_rootdef git(path: Path, *args: str) -> subprocess.CompletedProcess[str]:@@ -25,6 +25,42 @@ def initialize_repo(path: Path) -> None:class VersionManagerTests(unittest.TestCase):+ def test_repository_discovery_prefers_source_resource_root(self):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ repo = root / "repo"+ initialize_repo(repo)+ executable = root / "elsewhere" / "Peach.exe"++ self.assertEqual(+ discover_repository_root(repo, executable=executable),+ repo.resolve(),+ )++ def test_repository_discovery_finds_repo_above_packaged_executable(self):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ repo = root / "repo"+ initialize_repo(repo)+ bundle_root = root / "pyinstaller" / "_MEI12345"+ executable = repo / "dist" / "Peach" / "Peach.exe"++ self.assertEqual(+ discover_repository_root(bundle_root, executable=executable),+ repo.resolve(),+ )++ def test_repository_discovery_does_not_invent_remote_for_portable_copy(self):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ bundle_root = root / "pyinstaller" / "_MEI12345"+ executable = root / "portable" / "Peach.exe"++ self.assertEqual(+ discover_repository_root(bundle_root, executable=executable),+ bundle_root.resolve(),+ )+def test_local_development_version_is_readable_without_remote(self):with tempfile.TemporaryDirectory() as directory:repo = Path(directory) / "repo"