Peach: Local-first video metadata scraper and media manager.
fix(tooling): 提交时校验署名与 README trailer 格式
longmeidao79828fb6164d
diff --git a/.claude/skills/peach-worktree/SKILL.md b/.claude/skills/peach-worktree/SKILL.mdindex a58903a92..e03040731 100644--- a/.claude/skills/peach-worktree/SKILL.md+++ b/.claude/skills/peach-worktree/SKILL.md@@ -5,7 +5,7 @@ description: 在用户说并行、工作树、暂存、提交、ready、集成# 并行 worktree 与提交边界-最后复核:2026-09-27+最后复核:2026-10-02证据来源:`docs/HANDOFF.md`「并行智能体与 Git 工作树」、`README.md`、ADR-0015、ADR-0017、本机工作树与沙箱工具记录。## 是否委派与何时使用@@ -55,7 +55,7 @@ description: 在用户说并行、工作树、暂存、提交、ready、集成- 提交前核对 README 影响;交付分支最后提交加 `README-Impact: updated; 说明` 或 `README-Impact: none; 原因`。它与 `Co-Authored-By` 等 trailer 连续写在消息末尾同一块里,中间隔一个空行就只算正文,解析不到。- 触发面、格式、中英文同批与例外见 `docs/README_MAINTENANCE.md`;`ready/integrate` 拒收缺失或矛盾声明。+ `commit-msg` 检查署名与已有声明格式;`ready/integrate` 核对交付差异,细节见 `docs/README_MAINTENANCE.md`。- 分支上每个提交都要署名,形态是 `Co-Authored-By: 工具 (模型 版本) <厂商 noreply>`:`Claude Code (Opus 5) <[email protected]>`、`Codex (GPT-5.5) <[email protected]>`。diff --git a/docs/PRODUCT_BACKLOG.md b/docs/PRODUCT_BACKLOG.mdindex 8c303336b..8e2411cfe 100644--- a/docs/PRODUCT_BACKLOG.md+++ b/docs/PRODUCT_BACKLOG.md@@ -8,7 +8,7 @@| 顺序 | 优先级与范围 | 剩余工作与依赖 || --- | --- | --- |-| 1 | P1 开发流程 | commit-msg 校验 trailer;操作 40 的首次导入超时 |+| 1 | P1 开发流程 | 操作 40 的首次导入超时 || 2 | P1 搜索与下载 | 43 的资源搜索接已有云下载,同批做 64 的来源性质标注;42 与 57 的本地下载、续传依赖操作 12 的流量与磁盘预算;骨架 1 还缺 51 的相似匹配、去重与人工替换确认 || 3 | P1 诊断 | 46 挂载探测 → 21 doctor 与分级健康检查 → 26 诊断页;12 的生产异常场景验收单列 || 4 | P2 元数据质量 | 44 → 操作 36 → 54 → 29;45 的回放与 58 的来源缺陷记录随解析器做;65、61 先核对成本与预算 |@@ -18,11 +18,11 @@### 已核对的实施状态-本轮以主线 `e22486f3` 为代码基线,已对照 Claude 文档整理的合入提交 `f215289f` 与后续修订 `e092470c`。下表只覆盖已取得证据的项目,其余条目保留待办状态,不能据此视为逐项验收通过。+待办核对覆盖主线 `e22486f3` 及后续合入,已对照 Claude 文档整理的合入提交 `f215289f` 与后续修订 `e092470c`。下表只覆盖已取得证据的项目,其余条目保留待办状态,不能据此视为逐项验收通过。| 项目 | 核对结果 | 证据 || --- | --- | --- |-| 测试入口 | 隔离工作树自动同步 Python 依赖,主检出只读核对;commit-msg 钩子仍待设置 | `scripts/test_environment.py`、`scripts/test.ps1`、`scripts/test.sh`、`scripts/githooks/` |+| 开发流程 | 隔离工作树自动同步 Python 依赖,主检出只读核对;commit-msg 检查署名、已有 README 声明和分段 | `scripts/test_environment.py`、`scripts/test.ps1`、`scripts/test.sh`、`scripts/check_commit_message.py`、`scripts/githooks/` || 操作 40 | 首次导入没有单独超时;本轮未重新触发偶发超时 | `frontend/test/islands.test.ts` 的三个 beforeAll || 42、43、64 | 云下载模型已具备;本地下载器、资源搜索与来源性质标注仍待接入 | `src/peach/downloads.py`、`src/peach/web_downloads.py`、前端下载设置 || 21、26、46 | 已有数据库就绪检查;doctor、统一诊断页与周期挂载探测仍待实现 | `src/peach/health.py`、CLI 与路由登记 |diff --git a/docs/README_MAINTENANCE.md b/docs/README_MAINTENANCE.mdindex 23640c4ef..4251111df 100644--- a/docs/README_MAINTENANCE.md+++ b/docs/README_MAINTENANCE.md@@ -29,7 +29,7 @@ README 迭代绑定 Codex 与 Claude 共用的工作树交付流程。每次提声明与 `Co-Authored-By` 等其它 trailer 连续写在提交消息末尾的同一块里,彼此之间不留空行。同一块里的署名形态见 `.claude/skills/peach-worktree/SKILL.md`「暂存与提交」。`git interpret-trailers --parse` 只解析末尾那一块,被空行隔开的 `README-Impact` 属于正文段落,-`ready` 报「交付提交须有唯一 README-Impact」,而提交消息本身看不出哪一行不合格。+`commit-msg` 会指出不在末尾同一块的字段,`ready` 也会拒绝未取得唯一声明的交付。`scripts/check_readme_impact.py` 读取目标分支到交付 HEAD 的实际差异,并使用`git interpret-trailers --parse` 读取最后提交的声明。涉及运行时代码、前端、迁移、资源、@@ -38,8 +38,10 @@ README 改动必须包含两种语言;`updated` 必须对应两份实际差异提交后的暂存内容不能满足要求。原因的真实性仍由代码审阅负责,脚本不代替语义判断。`agent_worktree.py ready/integrate` 在接受测试记录前执行这一门槛。检查覆盖本次分支交付,-不追溯主线历史提交;允许在最后交付提交统一核对整批差异。它不是 Git 全局 hook,-直接 Git 提交不会触发,但未通过的分支不能经项目入口集成。+允许在最后交付提交统一核对整批差异。仓库 `scripts/githooks/commit-msg` 在 `agent/*`+分支提交时检查署名,以及消息中已有 README 声明的格式与分段;中间提交可以不写 README 声明。+合并消息免除署名检查,amend 使用同一套字段判据;钩子只读消息。README 声明与整个分支差异+的一致性由交付门槛检查,未通过的分支不能经项目入口集成。无需定时任务、账号专属 hook 或额外模型调用。Python 下限、文案和快照校验继续复用现有测试。结构或品牌调整时重读已登记的参考快照,上游变化只作为参考,计划功能不得写成已实现。diff --git a/docs/REUSE.md b/docs/REUSE.mdindex f35f7e92a..6a2383da4 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -90,6 +90,8 @@ JAV 默认封面(官方封面/预览图)与视频默认大小(大图/测试与集成用 `test_runner.py`、`agent_worktree.py`,进程互斥用开发依赖 `filelock` 的 [`FileLock`](https://py-filelock.readthedocs.io/en/stable/tutorials.html)。全量验证与集成共用一把锁、最多等待 30 分钟;验证持锁至记录写入完成。临时 Git 仓库回归覆盖互斥、等待和释放;代码、环境和范围记录属于 Peach 的集成约束。记录失效返回 `4`,Windows 托盘据此最多重试三轮,用例失败返回 `1`。两端测试入口通过 `test_environment.py` 复用现有 `find_uv` 与主检出 `Dependencies.check`;隔离工作树使用 uv 官方锁文件同步,不新增包管理实现或运行依赖。同步失败停止测试,主检出只读检查;策略与行为回归见 `test_test_environment.py`。+提交消息复用 Git 的 [`interpret-trailers --parse`](https://git-scm.com/docs/git-interpret-trailers),署名与 README 声明判据由 `co_author.py`、`check_readme_impact.py` 共用;`check_commit_message.py` 接到仓库 `commit-msg` 钩子。Git 自身处理注释与多行 trailer,Peach 只检查字段形态和分段。Windows Git 2.55.0.windows.3 的临时仓库回归覆盖拒绝提交、保留暂存、多署名、amend 和合并消息;不新增解析依赖。具体触发范围见 [README 维护](README_MAINTENANCE.md)。+### 播放、采集、发布与打包各条的实测与取证见 [复用取证记录](SOURCING.md#播放与控件实证)。diff --git a/scripts/check_commit_message.py b/scripts/check_commit_message.pynew file mode 100644index 000000000..756ca25f4--- /dev/null+++ b/scripts/check_commit_message.py@@ -0,0 +1,49 @@+"""agent/* 分支提交时的 trailer 形态检查。"""+from __future__ import annotations++import argparse+import subprocess+import sys+from pathlib import Path++if not __package__:+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+ __package__ = "scripts"+from . import check_readme_impact, co_author+++def check(repo: Path, message: str) -> list[str]:+ parsed = check_readme_impact.trailers(repo, message)+ problems = co_author.problems("待提交", parsed.get("co-authored-by", []))+ for name in ("Co-Authored-By", "README-Impact"):+ mentioned = sum(line.partition(":")[0].casefold() == name.casefold()+ for line in message.splitlines())+ values = parsed.get(name.casefold(), [])+ if mentioned != len(values):+ problems.append(f"{name} 须连续放在提交消息末尾的同一块,中间不要留空行。")+ if name == "README-Impact" and (mentioned or values):+ problems.extend(check_readme_impact.declaration(values)[1])+ return problems+++def main(argv=None) -> int:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("message_file", type=Path)+ args = parser.parse_args(argv)+ repo = Path.cwd()+ try:+ branch = check_readme_impact.git(repo, "branch", "--show-current").strip()+ merge = check_readme_impact.git(repo, "rev-parse", "--git-path", "MERGE_HEAD").strip()+ if not branch.startswith("agent/") or (repo / merge).exists():+ return 0+ problems = check(repo, args.message_file.read_text(encoding="utf-8"))+ except (OSError, UnicodeError, subprocess.CalledProcessError) as error:+ print(f"未取得提交校验结果:{error}", file=sys.stderr)+ return 1+ for problem in problems:+ print(problem, file=sys.stderr)+ return 1 if problems else 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/scripts/check_readme_impact.py b/scripts/check_readme_impact.pyindex 9d1add131..5f337e253 100644--- a/scripts/check_readme_impact.py+++ b/scripts/check_readme_impact.py@@ -39,6 +39,26 @@ def unpublished(repo: Path) -> list[str]:return [f"^{PUBLISHED_REF}"]+def trailers(repo: Path, message: str) -> dict[str, list[str]]:+ """Git 解析提交末尾的 trailer;每个字段保留全部取值。"""+ result: dict[str, list[str]] = {}+ trailers = git(repo, "interpret-trailers", "--parse", message=message)+ for line in trailers.splitlines():+ name, _, value = line.partition(":")+ result.setdefault(name.casefold(), []).append(value.strip())+ return result+++def declaration(values: list[str]) -> tuple[str, list[str]]:+ """检查声明形态;与 README 文件差异的关系由交付检查核对。"""+ if len(values) != 1:+ return "", ["交付提交须有唯一 README-Impact: updated; 说明 或 README-Impact: none; 原因"]+ status, separator, reason = values[0].partition(";")+ if status not in {"updated", "none"} or not separator or not reason.strip():+ return "", ["README-Impact 需使用 updated/none,并在英文分号后写具体原因"]+ return status, []++def check(repo: Path, base: str, head: str = "HEAD") -> list[str]:"""以实际交付差异和最后提交的 Git trailer 为依据。"""paths = set(git(repo, "diff", "--name-only", "--no-renames", "-z",@@ -48,14 +68,9 @@ def check(repo: Path, base: str, head: str = "HEAD") -> list[str]:if not touched and not relevant:return []message = git(repo, "show", "-s", "--format=%B", head)- trailers = git(repo, "interpret-trailers", "--parse", message=message)- values = [line.partition(":")[2].strip() for line in trailers.splitlines()- if line.partition(":")[0].casefold() == "readme-impact"]- if len(values) != 1:- return ["交付提交须有唯一 README-Impact: updated; 说明 或 README-Impact: none; 原因"]- status, separator, reason = values[0].partition(";")- if status not in {"updated", "none"} or not separator or not reason.strip():- return ["README-Impact 需使用 updated/none,并在英文分号后写具体原因"]+ status, problems = declaration(trailers(repo, message).get("readme-impact", []))+ if problems:+ return problemsif touched and touched != READMES:return ["README.md 与 README.en.md 必须同批维护"]if status == "updated" and touched != READMES:diff --git a/scripts/co_author.py b/scripts/co_author.pyindex e87674b3b..b87bb38eb 100644--- a/scripts/co_author.py+++ b/scripts/co_author.py@@ -5,7 +5,7 @@ from __future__ import annotationsimport refrom pathlib import Path-from .check_readme_impact import git, unpublished+from .check_readme_impact import git, trailers, unpublished#: 已登记的工具与它厂商的 noreply 地址。换用别的智能体就在这里加一行,别散着写。VENDORS = {@@ -24,9 +24,7 @@ EXAMPLE = "Co-Authored-By: Claude Code (Opus 5) <[email protected]>"def values(repo: Path, head: str = "HEAD") -> list[str]:"""交付提交末尾那一块里的 Co-Authored-By,原样取值。"""message = git(repo, "show", "-s", "--format=%B", head)- trailers = git(repo, "interpret-trailers", "--parse", message=message)- return [line.partition(":")[2].strip() for line in trailers.splitlines()- if line.partition(":")[0].casefold() == "co-authored-by"]+ return trailers(repo, message).get("co-authored-by", [])def commits(repo: Path, base: str, head: str = "HEAD") -> list[tuple[str, str]]:@@ -36,7 +34,7 @@ def commits(repo: Path, base: str, head: str = "HEAD") -> list[tuple[str, str]]:for line in output.splitlines() if line.strip()]-def _problems(commit: str, label: str, found: list[str]) -> list[str]:+def problems(label: str, found: list[str]) -> list[str]:if not found:return [f"提交「{label}」须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}"]problems = []@@ -65,7 +63,7 @@ def check(repo: Path, base: str, head: str = "HEAD") -> list[str]:等于只要收尾那次签对了,前面写代码的几次签成谁都放行——而要追的恰恰是写出那一行的提交。合进来的 merge 不算分支自己的产出,跳过。"""- problems = []+ found_problems = []for commit, label in commits(repo, base, head):- problems += _problems(commit, label, values(repo, commit))- return problems+ found_problems += problems(label, values(repo, commit))+ return found_problemsdiff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msgnew file mode 100755index 000000000..4f5dfa1e2--- /dev/null+++ b/scripts/githooks/commit-msg@@ -0,0 +1,18 @@+#!/bin/sh+# 解析与字段判据由 Python 检查器和交付门槛共用。+root=$(git rev-parse --show-toplevel) || exit 1+common=$(git rev-parse --path-format=absolute --git-common-dir) || exit 1+main=$(dirname "$common")+for candidate in "$root/.venv/Scripts/python.exe" "$root/.venv/bin/python" \+ "$main/.venv/Scripts/python.exe" "$main/.venv/bin/python"; do+ if [ -x "$candidate" ]; then+ exec "$candidate" -B -X utf8 "$root/scripts/check_commit_message.py" "$1"+ fi+done+for candidate in python python3; do+ if command -v "$candidate" >/dev/null 2>&1; then+ exec "$candidate" -B -X utf8 "$root/scripts/check_commit_message.py" "$1"+ fi+done+echo "未取得 Python,无法校验提交 trailer。" >&2+exit 1diff --git a/tests/test_agent_worktree.py b/tests/test_agent_worktree.pyindex fc9638a07..ef1fbd6a9 100644--- a/tests/test_agent_worktree.py+++ b/tests/test_agent_worktree.py@@ -17,6 +17,23 @@ from support.gitrepo import seed_repository#: 仓库里版本化的 git hook,测试原样装进临时仓库。HOOKS = Path(__file__).resolve().parents[1] / agent_worktree.HOOKS_PATH+AUTHOR = "Co-Authored-By: Codex (GPT-6) <[email protected]>"+++def install_commit_hooks(repo: Path) -> None:+ hooks = repo / agent_worktree.HOOKS_PATH+ hooks.mkdir(parents=True)+ sources = list(HOOKS.iterdir())+ sources += [HOOKS.parent / name for name in+ ("check_commit_message.py", "check_readme_impact.py", "co_author.py")+ if (HOOKS.parent / name).is_file()]+ for source in sources:+ relative = source.relative_to(HOOKS.parent.parent)+ target = repo / relative+ shutil.copyfile(source, target)+ target.chmod(0o755)+ _git(repo, "add", relative.as_posix())+ _git(repo, "commit", "-m", "hooks")#: 版本号的唯一来源,`src/peach/__init__.py` 在测试仓库里的最小复刻。VERSION_SEED = b'"""Peach application package."""\n\n__version__ = "0.7.14"\n'@@ -112,18 +129,15 @@ class MasterCommitGuardTests(_WorktreeCase):def setUp(self):super().setUp()- hooks = self.repo / agent_worktree.HOOKS_PATH- hooks.mkdir(parents=True)- for source in HOOKS.iterdir():- target = hooks / source.name- shutil.copyfile(source, target)- target.chmod(0o755)- _git(self.repo, "add", target.relative_to(self.repo).as_posix())- _git(self.repo, "commit", "-m", "hooks")+ install_commit_hooks(self.repo)+ environment = mock.patch.dict(os.environ, {"PATH": str(Path(sys.executable).parent)+ + os.pathsep + os.environ.get("PATH", "")})+ environment.start()+ self.addCleanup(environment.stop)result = create(self.repo, "Claude", "guarded", self.root / "worktrees")self.worker, self.branch = Path(result["path"]), str(result["branch"])(self.worker / "worker.txt").write_text("worker\n", encoding="utf-8")- commit(self.worker, "worker change")+ commit(self.worker, "test: worker change\n\n" + AUTHOR)def test_create_points_the_repository_at_the_versioned_hooks(self):self.assertEqual(_git(self.repo, "config", "core.hooksPath").stdout.strip(),@@ -143,6 +157,7 @@ class MasterCommitGuardTests(_WorktreeCase):self.assertEqual(_git(self.repo, "rev-parse", "HEAD").stdout, before)def test_integrate_still_merges_the_worker_branch(self):+ self.assertEqual(_git(self.worker, "status", "--porcelain").stdout, "")integrate(self.repo, self.branch)self.assertEqual((self.repo / "worker.txt").read_text(encoding="utf-8"), "worker\n")@@ -154,6 +169,78 @@ class MasterCommitGuardTests(_WorktreeCase):self.assertEqual(_git(self.repo, "log", "-1", "--format=%s").stdout.strip(), "release")+class CommitMessageGuardTests(_WorktreeCase):+ def setUp(self):+ super().setUp()+ install_commit_hooks(self.repo)+ environment = mock.patch.dict(os.environ, {"PATH": str(Path(sys.executable).parent)+ + os.pathsep + os.environ.get("PATH", "")})+ environment.start()+ self.addCleanup(environment.stop)+ result = create(self.repo, "codex", "message", self.root / "worktrees with spaces")+ self.worker = Path(result["path"])+ (self.worker / "worker.txt").write_text("worker\n", encoding="utf-8")+ _git(self.worker, "add", "worker.txt")++ def attempt(self, message):+ path = self.worker / "message.txt"+ path.write_text(message, encoding="utf-8")+ return _git(self.worker, "commit", "-F", str(path), check=False)++ def test_a_missing_or_invalid_author_refuses_the_commit_and_keeps_the_index(self):+ before = _git(self.worker, "rev-parse", "HEAD").stdout+ for trailer in ("", "Co-Authored-By: Codex <[email protected]>",+ "Co-Authored-By: Codex (GPT-6) <[email protected]>"):+ with self.subTest(trailer=trailer):+ result = self.attempt("test: check\n\n" + trailer)+ self.assertNotEqual(result.returncode, 0)+ self.assertIn("署名" if trailer else "Co-Authored-By", result.stderr)+ self.assertEqual(_git(self.worker, "rev-parse", "HEAD").stdout, before)+ self.assertEqual(_git(self.worker, "diff", "--cached", "--name-only").stdout.strip(),+ "worker.txt")++ def test_separated_or_malformed_readme_declarations_refuse_the_commit(self):+ for declaration in ("README-Impact: none; 内部测试\n\n", "README-Impact: none\n",+ "README-Impact: none; 内部测试\nREADME-Impact: updated; 文档\n"):+ with self.subTest(declaration=declaration):+ result = self.attempt("test: check\n\n" + declaration + AUTHOR)+ self.assertNotEqual(result.returncode, 0)+ self.assertIn("README-Impact", result.stderr)++ def test_valid_trailers_and_amend_preserve_the_message(self):+ message = ("test: 中文提交\n\nREADME-Impact: updated; 两种语言\n" + AUTHOR+ + "\nCo-Authored-By: Claude Code (Opus 5) <[email protected]>\n")+ result = self.attempt(message)+ self.assertEqual(result.returncode, 0, result.stderr)+ amended = _git(self.worker, "commit", "--amend", "--no-edit", check=False)+ self.assertEqual(amended.returncode, 0, amended.stderr)+ self.assertEqual(_git(self.worker, "show", "-s", "--format=%B").stdout.strip(), message.strip())++ def test_intermediate_commit_can_leave_readme_scope_for_delivery_check(self):+ result = self.attempt("test: intermediate\n\n" + AUTHOR)+ self.assertEqual(result.returncode, 0, result.stderr)++ def test_author_lines_separated_into_different_blocks_are_rejected(self):+ result = self.attempt("test: authors\n\n" + AUTHOR + "\n\n"+ "Co-Authored-By: Claude Code (Opus 5) <[email protected]>")+ self.assertNotEqual(result.returncode, 0)+ self.assertIn("Co-Authored-By", result.stderr)++ def test_git_comment_lines_do_not_count_as_declarations(self):+ result = self.attempt("test: comments\n\n" + AUTHOR + "\n\n# README-Impact: example\n")+ self.assertEqual(result.returncode, 0, result.stderr)++ def test_merge_messages_are_exempt_from_authorship_trailers(self):+ result = self.attempt("test: worker\n\n" + AUTHOR)+ self.assertEqual(result.returncode, 0, result.stderr)+ _git(self.repo, "switch", "-c", "parallel")+ (self.repo / "tracked.txt").write_text("parallel\n", encoding="utf-8")+ _git(self.repo, "add", "tracked.txt")+ _git(self.repo, "commit", "-m", "test: parallel")+ merged = _git(self.worker, "merge", "--no-ff", "-m", "Merge parallel", "parallel", check=False)+ self.assertEqual(merged.returncode, 0, merged.stderr)++if __name__ == "__main__":unittest.main()