Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(tooling): 署名门槛逐个提交判,不只判分支尖端

longmeidao1f845ccfb244
diff --git a/.claude/skills/peach-worktree/SKILL.md b/.claude/skills/peach-worktree/SKILL.md
index 2ae150410..f0f82def3 100644
--- a/.claude/skills/peach-worktree/SKILL.md
+++ b/.claude/skills/peach-worktree/SKILL.md
@@ -52,11 +52,12 @@ description: 在用户说并行、工作树、暂存、提交、ready、集成
它与 `Co-Authored-By` 等 trailer 连续写在消息末尾同一块里,中间隔一个空行就只算正文,解析不到。
触发面、格式、中英文同批与例外见 `docs/HANDOFF.md`「README 维护」;`ready/integrate` 拒收缺失或矛盾声明。
-- 每个交付提交都要署名,形态是 `Co-Authored-By: 工具 (模型 版本) <厂商 noreply>`:
+- 分支上每个提交都要署名,形态是 `Co-Authored-By: 工具 (模型 版本) <厂商 noreply>`:
`Claude Code (Opus 5) <[email protected]>`、`Codex (GPT-5.5) <[email protected]>`。
括号里那一段是重点——事后翻这一行是要知道哪个模型写的,同一个工具换代模型,写出来的
代码差别比换工具本身还大。工具与地址的名单在 `scripts/co_author.py` 的 `VENDORS`,
- `ready` / `integrate` 拒收缺失、形态不对、工具未登记和地址与工具不配四种。
+ `ready` / `integrate` 逐个提交判(合进来的 merge 不算),拒收缺失、形态不对、工具未
+ 登记和地址与工具不配四种。
一个提交由两个智能体接力写成时,两条并列署名都写上。
- 禁止 `git add .`、`git add -A`、目录路径或 glob。只暂存任务明确拥有的文件。
diff --git a/scripts/agent_worktree.py b/scripts/agent_worktree.py
index f29882e23..3dbbc6256 100644
--- a/scripts/agent_worktree.py
+++ b/scripts/agent_worktree.py
@@ -116,7 +116,7 @@ def require_verified(worker: Path, target_branch: str, paths: Iterable[str]) ->
if _git(worker, "merge-base", "--is-ancestor", target_branch, "HEAD", check=False).returncode:
raise WorkspaceError("目标分支已前进;请在工作树 rebase 后运行 auto 验证")
problems = (check_readme_impact.check(worker, target_branch)
- + co_author.check(worker)
+ + co_author.check(worker, target_branch)
+ commit_subject.check(worker, target_branch))
if problems:
raise WorkspaceError("; ".join(problems))
diff --git a/scripts/co_author.py b/scripts/co_author.py
index ecb8d62c1..a14b5f9de 100644
--- a/scripts/co_author.py
+++ b/scripts/co_author.py
@@ -29,26 +29,43 @@ def values(repo: Path, head: str = "HEAD") -> list[str]:
if line.partition(":")[0].casefold() == "co-authored-by"]
-def check(repo: Path, head: str = "HEAD") -> list[str]:
- """交付提交至少要有一条署名,且每一条都合规。
+def commits(repo: Path, base: str, head: str = "HEAD") -> list[tuple[str, str]]:
+ """分支自己的提交:(取值用的 hash, 给人看的 `短 hash 主题`),不含合进来的 merge。"""
+ output = git(repo, "log", "--no-merges", "--format=%H%x00%h %s", f"{base}..{head}")
+ return [(line.partition("\0")[0], line.partition("\0")[2])
+ for line in output.splitlines() if line.strip()]
- 署名是事后追责唯一的入手处:出问题的那一行是哪个工具的哪个模型写的,只能从这里看。
- 所以缺了、形态不对、工具没登记、地址与工具不配,四种都拒收。多条并列是允许的,
- 一个提交确实可能由两个智能体接力写成。
- """
- found = values(repo, head)
+
+def _problems(commit: str, label: str, found: list[str]) -> list[str]:
if not found:
- return [f"交付提交须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}"]
+ return [f"提交「{label}」须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}"]
problems = []
for value in found:
parsed = FORM.fullmatch(value)
if parsed is None:
- problems.append(f"署名「{value}」形态不对,须为 工具 (模型 版本) "
+ problems.append(f"提交「{label}」的署名「{value}」形态不对,须为 工具 (模型 版本) "
f"<厂商 noreply>,如 {EXAMPLE}")
elif parsed["tool"] not in VENDORS:
- problems.append(f"署名里的工具「{parsed['tool']}」未登记,"
+ problems.append(f"提交「{label}」的署名里,工具「{parsed['tool']}」未登记,"
"已登记:" + "、".join(VENDORS))
elif parsed["mail"] != VENDORS[parsed["tool"]]:
- problems.append(f"{parsed['tool']} 的署名地址须是 "
+ problems.append(f"提交「{label}」里 {parsed['tool']} 的署名地址须是 "
f"{VENDORS[parsed['tool']]},不是 {parsed['mail']}")
return problems
+
+
+def check(repo: Path, base: str, head: str = "HEAD") -> list[str]:
+ """分支上每个非 merge 提交都要有署名,且每一条都合规。
+
+ 署名是事后追责唯一的入手处:出问题的那一行是哪个工具的哪个模型写的,只能从这里看。
+ 所以缺了、形态不对、工具没登记、地址与工具不配,四种都拒收。多条并列是允许的,
+ 一个提交确实可能由两个智能体接力写成。
+
+ 判据落在每个提交上,不是落在分支尖端:一次交付常常是好几个提交,只看最后一个
+ 等于只要收尾那次签对了,前面写代码的几次签成谁都放行——而要追的恰恰是写出那
+ 一行的提交。合进来的 merge 不算分支自己的产出,跳过。
+ """
+ problems = []
+ for commit, label in commits(repo, base, head):
+ problems += _problems(commit, label, values(repo, commit))
+ return problems
diff --git a/tests/test_agent_worktree.py b/tests/test_agent_worktree.py
index 65f339d70..9a11d548e 100644
--- a/tests/test_agent_worktree.py
+++ b/tests/test_agent_worktree.py
@@ -437,7 +437,7 @@ class CoAuthorTests(unittest.TestCase):
def signed(self, *trailers):
git(self.repo, "commit", "--allow-empty", "-m", "测试", "-m", "\n".join(trailers))
- return co_author.check(self.repo)
+ return co_author.check(self.repo, "master")
def test_an_unsigned_commit_cannot_be_traced_back_to_a_model(self):
self.assertTrue(self.signed())
@@ -465,6 +465,28 @@ class CoAuthorTests(unittest.TestCase):
self.signed("Co-Authored-By: Claude Code (Opus 5) <[email protected]>",
"Co-Authored-By: Codex (GPT-5.5) <[email protected]>"), [])
+ def test_every_commit_on_the_branch_is_checked_not_only_head(self):
+ """一次交付常常是好几个提交。只判尖端等于只判收尾那一次签得对不对,
+ 而要追的恰恰是写出某一行的那个提交,所以问题里要报出它的短 hash 和主题。
+ """
+ self.signed("Co-Authored-By: Gemini CLI (3.5) <[email protected]>")
+ problems = self.signed(
+ "Co-Authored-By: Claude Code (Opus 5) <[email protected]>")
+ self.assertEqual(len(problems), 1)
+ self.assertIn(git(self.repo, "log", "-1", "--format=%h", "HEAD~1").strip(),
+ problems[0])
+ self.assertIn("Gemini CLI", problems[0])
+
+ def test_merges_from_the_target_branch_are_not_the_worker_s_commits(self):
+ """目标分支上的提交由它自己那次交付负责,合进来不等于这个分支重写了一遍。"""
+ git(self.repo, "checkout", "master")
+ git(self.repo, "commit", "--allow-empty", "-m", "上游的提交")
+ git(self.repo, "checkout", "worker")
+ self.signed("Co-Authored-By: Claude Code (Opus 5) <[email protected]>")
+ git(self.repo, "merge", "--no-ff", "-m", "Merge branch 'master' into worker",
+ "master")
+ self.assertEqual(co_author.check(self.repo, "master"), [])
+
def test_the_signature_gate_runs_before_the_test_evidence_is_read(self):
"""署名和 README 影响面在同一处拒收,都不必等到去读测试记录。"""
(self.repo / "tests").mkdir()