Fixed a few stupid mistakes
This commit is contained in:
@@ -93,6 +93,47 @@ def test_webhook_accepts_review_and_queues(monkeypatch) -> None:
|
||||
assert queued.trigger_comment_body == "@codex review security"
|
||||
|
||||
|
||||
def test_webhook_uses_latest_pr_head_sha_when_config_lookup_fails(monkeypatch) -> None:
|
||||
posted_comments: list[str] = []
|
||||
|
||||
def _post_issue_comment(self, repo: str, pr_number: int, body: str) -> int:
|
||||
posted_comments.append(body)
|
||||
return 100
|
||||
|
||||
monkeypatch.setattr("gitea_codex_bot.services.gitea.GiteaClient.post_issue_comment", _post_issue_comment)
|
||||
monkeypatch.setattr(
|
||||
"gitea_codex_bot.services.gitea.GiteaClient.get_pull_request",
|
||||
lambda *_args, **_kwargs: type("PR", (), {"head_sha": "newsha123"})(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"gitea_codex_bot.services.gitea.GiteaClient.get_file_content",
|
||||
lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("config unavailable")),
|
||||
)
|
||||
|
||||
client = TestClient(app)
|
||||
payload_obj = _payload("@codex review", username="alice", comment_id=112)
|
||||
payload_obj["pull_request"]["head"]["sha"] = "oldsha999"
|
||||
raw = json.dumps(payload_obj).encode()
|
||||
|
||||
response = client.post(
|
||||
"/webhook/gitea",
|
||||
content=raw,
|
||||
headers={
|
||||
"X-Gitea-Event": "issue_comment",
|
||||
"X-Gitea-Delivery": "d-2b",
|
||||
"X-Gitea-Signature": _sign(raw),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "queued"
|
||||
assert any("`newsha1`" in body for body in posted_comments)
|
||||
session_factory = get_session_factory()
|
||||
with session_factory() as session:
|
||||
queued = session.execute(select(ReviewJob).where(ReviewJob.trigger_comment_id == 112)).scalar_one()
|
||||
assert queued.head_sha == "newsha123"
|
||||
|
||||
|
||||
def test_webhook_logs_when_no_codex_review_command(monkeypatch) -> None:
|
||||
messages: list[str] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user