From 6ea43d76e3a06f9a88a507bb2419de3c30408efd Mon Sep 17 00:00:00 2001 From: cfdaily Date: Fri, 19 Jun 2026 13:53:44 +0800 Subject: [PATCH] =?UTF-8?q?[moz]=20impl(=C2=A717):=20issue=5Fassigned=20st?= =?UTF-8?q?eps=20git=20=E6=93=8D=E4=BD=9C=E5=85=B7=E4=BD=93=E5=8C=96=20+?= =?UTF-8?q?=20ToolchainApiSection=20Git=20=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改动 1: issue_assigned 编码路径 steps 改为具体 git 命令 (checkout main → pull → checkout -b → add/commit → push) 改动 2: ToolchainApiSection 新增 Git 操作说明段落(含开发目录路径) 改动 3: 测试更新(issue_assigned 断言 + 3 个 Git 说明测试) 466 passed --- src/api/toolchain_routes.py | 6 +++--- src/daemon/toolchain_handler.py | 14 +++++++++++++ tests/unit/test_toolchain_handler_v2.py | 27 ++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/api/toolchain_routes.py b/src/api/toolchain_routes.py index 93896ff..3ec70f6 100644 --- a/src/api/toolchain_routes.py +++ b/src/api/toolchain_routes.py @@ -1032,10 +1032,10 @@ async def _handle_issues(payload: Dict[str, Any]) -> None: event_type="issue_assigned", action_type="issue_assigned", steps=[ - f"创建分支 fix/{issue_number}-{brief}", + f"在开发目录执行 git 操作:\n a. git checkout main && git pull origin main\n b. git checkout -b fix/{issue_number}-{brief}", "编码 + 写 UT", - "push → 等 CI", - f"CI 通过后创建 PR(Gitea API: POST /repos/{repo}/pulls)", + f"git add -A && git commit -m \"[moz] fix: {issue_title[:30]}\" && git push origin fix/{issue_number}-{brief}", + f"CI 通过后创建 PR(Gitea API: POST /repos/{repo}/pulls,head: fix/{issue_number}-{brief}, base: main)", "等 Review", "提交 action report(POST http://localhost:8083/api/projects/_toolchain/tasks//comments,comment_type=action_report)", ], diff --git a/src/daemon/toolchain_handler.py b/src/daemon/toolchain_handler.py index 2326b93..201b836 100644 --- a/src/daemon/toolchain_handler.py +++ b/src/daemon/toolchain_handler.py @@ -179,6 +179,20 @@ class ToolchainApiSection: "⚠️ Issue body 必须包含错误来源链接(PR/Commit + CI run),让排查者能直接看到全貌。", "⚠️ label 数字 ID 先 GET /repos/{repo}/labels 查询 type/infrastructure 对应的 ID。", "", + "### Git 操作说明", + "", + "你的工作目录是开发目录(如 ~/.openclaw/sanguo_projects/sanguo_moziplus_v2/)。", + "标准分支操作流程:", + "```bash", + "git checkout main && git pull origin main # 从最新主干开始", + "git checkout -b fix/{branch_name} # 创建功能分支", + "# ... 写代码 ...", + "git add -A && git commit -m 'message' # 提交改动", + "git push origin {branch_name} # 推送到远程", + "```", + "", + "⚠️ 不要在 main 分支上直接 commit。", + "", ] return "\n".join(lines) diff --git a/tests/unit/test_toolchain_handler_v2.py b/tests/unit/test_toolchain_handler_v2.py index 1a9fa17..efde9e7 100644 --- a/tests/unit/test_toolchain_handler_v2.py +++ b/tests/unit/test_toolchain_handler_v2.py @@ -563,7 +563,7 @@ class TestIssueAssignedLabelRouting: def test_normal_issue_keeps_coding_steps(self): source_file = PROJECT_ROOT / "src" / "api" / "toolchain_routes.py" source = source_file.read_text() - assert '创建分支 fix/' in source + assert 'git checkout -b fix/' in source assert 'issue_assigned' in source @@ -593,3 +593,28 @@ class TestRedFlagsInfrastructure: source = source_file.read_text() assert "不是我代码的问题" in source assert "基础设施问题" in source + + +class TestGitOperationGuidance: + """ToolchainApiSection should include Git operation guidance.""" + + def test_has_git_operation_section(self): + source_file = PROJECT_ROOT / "src" / "daemon" / "toolchain_handler.py" + source = source_file.read_text() + assert "Git 操作说明" in source + assert "git checkout main" in source + assert "git pull origin main" in source + assert "git checkout -b" in source + + def test_has_no_main_commit_warning(self): + source_file = PROJECT_ROOT / "src" / "daemon" / "toolchain_handler.py" + source = source_file.read_text() + assert "不要在 main 分支上直接 commit" in source + + def test_issue_assigned_steps_have_git_commands(self): + source_file = PROJECT_ROOT / "src" / "api" / "toolchain_routes.py" + source = source_file.read_text() + assert 'git checkout main && git pull origin main' in source + assert 'git checkout -b fix/' in source + assert 'git add -A && git commit' in source + assert 'git push origin fix/' in source