fix: commit agent changes before opening PR

This commit is contained in:
2026-05-06 16:00:31 +08:00
parent c7d972e5cd
commit 61c194de37
5 changed files with 70 additions and 22 deletions

View File

@@ -136,6 +136,10 @@ class FakeWorkspaceManager:
def push_branch(self, workspace, branch_name):
self.pushed.append(branch_name)
def commit_changes(self, workspace, message):
self.commit_message = message
return "abc1234"
def cleanup(self, workspace):
pass
@@ -150,12 +154,16 @@ class FakeRunner:
if role == self.fail_role:
return AgentResult(exit_code=1, stdout="", stderr="failed")
if role == "implementer":
(Path(cwd) / "AGENT_IMPLEMENTATION_REPORT.md").write_text(
output_dir = Path(cwd) / ".agent-output"
output_dir.mkdir(exist_ok=True)
(output_dir / "AGENT_IMPLEMENTATION_REPORT.md").write_text(
"## Summary\nImplemented\n\n## Test commands run\npytest\n",
encoding="utf-8",
)
if role == "reviewer":
(Path(cwd) / "AGENT_REVIEW_REPORT.md").write_text(
output_dir = Path(cwd) / ".agent-output"
output_dir.mkdir(exist_ok=True)
(output_dir / "AGENT_REVIEW_REPORT.md").write_text(
"## Verdict\nAPPROVE\n\n## Suggested PR Comment\nLooks good.\n",
encoding="utf-8",
)
@@ -196,11 +204,12 @@ def test_run_task_success_posts_review_comments(db, tmp_path):
return httpx.Response(201, json={"id": 1})
return httpx.Response(404)
workspace_manager = FakeWorkspaceManager(tmp_path / "work")
task = TaskRunner(
db=db,
config=config,
gitea=make_client(handler),
workspace_manager=FakeWorkspaceManager(tmp_path / "work"),
workspace_manager=workspace_manager,
command_runner=FakeRunner(),
worker_id="worker",
).run_once()
@@ -208,6 +217,11 @@ def test_run_task_success_posts_review_comments(db, tmp_path):
assert task is not None
assert task.state == TaskState.HUMAN_REVIEW_READY
assert task.pr_number == 5
assert workspace_manager.pushed == ["agent/issue-1-ready-issue"]
assert workspace_manager.commit_message == "agent: implement issue #1 - Ready issue"
pull_requests = [payload for _, path, payload in requests if path == "/api/v1/repos/acme/service/pulls"]
assert pull_requests[0]["title"] == "代理实现Ready issue"
assert "代理实现报告" in pull_requests[0]["body"]
command = json.loads(db.list_agent_runs(task.id)[0]["command_json"])
assert command[1] == "--cd"
assert Path(command[2]).is_absolute()