From 55588fd33fe76730dcf73ab83401d48f35b18e19 Mon Sep 17 00:00:00 2001 From: mashagua <993498039@qq.com> Date: Wed, 2 Dec 2026 11:13:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(catalog):=20=E6=88=AA=E6=96=AD=E8=B6=85?= =?UTF-8?q?=E9=95=BF=20PR=20=E6=AD=A3=E6=96=87=E9=81=BF=E5=85=8D=E8=B6=85?= =?UTF-8?q?=E8=BF=87=20GitHub=2065536=20=E5=AD=97=E7=AC=A6=E4=B8=8A?= =?UTF-8?q?=E9=99=90=20(#422)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 根因 在 [run 46796970818](https://github.com/desirecore/market/actions/runs/46796970818) 中,`gamedev-agent-skills` 包含大量合集子项,每个子项生成的诊断表格行汇总后超过 GitHub PR 正文 65,536 字符上限,导致 `git push` 成功后 `gh pr create` 返回 exit 1,进而留下无 PR 的孤儿分支并在次日触发 `git push` non-fast-forward 失败。 ## 修复 - `scripts/catalog/propose_upstream_updates.py`:新增 `_truncate_pr_body`(上限 60,000 字符,截断处提示完整逐项结果见本次 Workflow 的 `audit-results` artifact),统一应用于新建 PR 与自动草稿转 Ready 两条路径。 - `scripts/catalog/test_propose_upstream_updates.py`:新增单测 `test_oversized_pr_body_is_truncated_below_github_limit`(17 tests OK)。 --- scripts/catalog/propose_upstream_updates.py | 43 ++++++++++++++----- .../catalog/test_propose_upstream_updates.py | 7 +++ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/scripts/catalog/propose_upstream_updates.py b/scripts/catalog/propose_upstream_updates.py index d75a137..a4f6f79 100644 --- a/scripts/catalog/propose_upstream_updates.py +++ b/scripts/catalog/propose_upstream_updates.py @@ -160,6 +160,21 @@ def write_coverage(rows, destination): destination.with_suffix('.md').write_text("\n".join(summary) + "\n") +MAX_PR_BODY_CHARS = 60000 + + +def _truncate_pr_body(text: str, limit: int = MAX_PR_BODY_CHARS) -> str: + """Keep PR body safely below GitHub's 65,536-character API limit.""" + if len(text) <= limit: + return text + notice = ( + "\n\n---\n" + "> 审核详情过长已截断(超过 GitHub PR 正文字符上限);完整逐项结果请见本次 Workflow 的 `audit-results` artifact。\n" + "> Truncated to stay within GitHub's PR body character limit; see the workflow `audit-results` artifact for complete per-item findings.\n" + ) + return text[: max(0, limit - len(notice))].rstrip() + notice + + def _is_automated_draft_only(item_id: str, pr_details: dict) -> bool: """Return True only if every commit and file on the Draft PR is from the automated proposer.""" allowed_headlines = { @@ -267,11 +282,13 @@ def promote_verified_draft_pr( body = Path(tmp) / "body.md" body.write_text( - f"`{item_id}` 上游快照:`{result['ref']}` → `{result['head']}`\n\n" - "已有草稿 PR 已按最新 `main` 策略与专项复核记录重审通过,已同步 `main` 并转为 Ready;审核身份和记录明确标为机器。已运行目录与本条目元数据校验。\n" - "不执行上游代码,不代表软件安全认证或真实运行验收,不自动合并。非结构化依赖和行为变化仍需结合 PR 差异复核。\n\n" - "Automated source/license/metadata re-verification passed under latest main; synced with main and promoted from draft. Not a security certification or runtime acceptance. No auto-merge.\n\n" - + "```json\n" + json.dumps(audit, ensure_ascii=False, indent=2) + "\n```\n", + _truncate_pr_body( + f"`{item_id}` 上游快照:`{result['ref']}` → `{result['head']}`\n\n" + "已有草稿 PR 已按最新 `main` 策略与专项复核记录重审通过,已同步 `main` 并转为 Ready;审核身份和记录明确标为机器。已运行目录与本条目元数据校验。\n" + "不执行上游代码,不代表软件安全认证或真实运行验收,不自动合并。非结构化依赖和行为变化仍需结合 PR 差异复核。\n\n" + "Automated source/license/metadata re-verification passed under latest main; synced with main and promoted from draft. Not a security certification or runtime acceptance. No auto-merge.\n\n" + + "```json\n" + json.dumps(audit, ensure_ascii=False, indent=2) + "\n```\n" + ), encoding="utf-8", ) run("gh", "pr", "edit", str(pr_number), "--repo", repository, "--body-file", str(body), cwd=checkout) @@ -422,12 +439,16 @@ def main() -> None: body = Path(tmp) / "body.md" findings = json.dumps(audit, ensure_ascii=False, indent=2) if audit else reason body.write_text( - f"`{item_id}` 上游快照:`{result['ref']}` → `{result['head']}`\n\n" - + ("自动来源、许可与结构化元数据核验通过;审核身份和记录明确标为机器。已运行目录与本条目元数据校验。\n" - if audit else "自动核验未通过,保留旧审核回执与草稿,不能据此发布新版。\n") - + "不执行上游代码,不代表软件安全认证或真实运行验收,不自动合并。非结构化依赖和行为变化仍需结合 PR 差异复核。\n\n" - + "Automated source/license/metadata verification, not a security certification or runtime acceptance. No auto-merge.\n\n" - + ("```json\n" + str(findings) + "\n```\n" if audit else str(findings) + "\n"), encoding="utf-8") + _truncate_pr_body( + f"`{item_id}` 上游快照:`{result['ref']}` → `{result['head']}`\n\n" + + ("自动来源、许可与结构化元数据核验通过;审核身份和记录明确标为机器。已运行目录与本条目元数据校验。\n" + if audit else "自动核验未通过,保留旧审核回执与草稿,不能据此发布新版。\n") + + "不执行上游代码,不代表软件安全认证或真实运行验收,不自动合并。非结构化依赖和行为变化仍需结合 PR 差异复核。\n\n" + + "Automated source/license/metadata verification, not a security certification or runtime acceptance. No auto-merge.\n\n" + + ("```json\n" + str(findings) + "\n```\n" if audit else str(findings) + "\n") + ), + encoding="utf-8", + ) command = ["gh", "pr", "create", "--repo", repository, "--base", "main", "--head", branch, "--title", f"chore(market): 更新 {item_id} 上游快照", "--body-file", str(body)] if not audit: diff --git a/scripts/catalog/test_propose_upstream_updates.py b/scripts/catalog/test_propose_upstream_updates.py index 2df9809..a04209f 100644 --- a/scripts/catalog/test_propose_upstream_updates.py +++ b/scripts/catalog/test_propose_upstream_updates.py @@ -242,6 +242,13 @@ class CandidateTests(unittest.TestCase): self.assertNotIn(('gh', 'pr', 'ready'), events) self.assertIn('校验未通过', cov[0]['reason']) + def test_oversized_pr_body_is_truncated_below_github_limit(self): + huge = "x" * 80000 + truncated = proposer._truncate_pr_body(huge) + self.assertLessEqual(len(truncated), proposer.MAX_PR_BODY_CHARS) + self.assertLess(len(truncated), 65536) + self.assertIn("audit-results", truncated) + if __name__ == "__main__": unittest.main()