From 5fe14f059a929b0490fd410a9f2a2fec905b9ade Mon Sep 17 00:00:00 2001 From: rnetser Date: Sun, 1 Mar 2026 17:35:09 +0200 Subject: [PATCH 1/2] fix: skip AI analysis on /approve cancel The test oracle was triggered even when the approve label was being removed via /approve cancel. Only trigger AI analysis when approving, not when cancelling. --- .../libs/handlers/issue_comment_handler.py | 2 +- .../tests/test_issue_comment_handler.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/webhook_server/libs/handlers/issue_comment_handler.py b/webhook_server/libs/handlers/issue_comment_handler.py index 34e94185..940fd417 100644 --- a/webhook_server/libs/handlers/issue_comment_handler.py +++ b/webhook_server/libs/handlers/issue_comment_handler.py @@ -355,7 +355,7 @@ async def user_commands( remove=remove, reviewed_user=reviewed_user, ) - if _command == APPROVE_STR: + if _command == APPROVE_STR and not remove: task = asyncio.create_task( call_test_oracle( github_webhook=self.github_webhook, diff --git a/webhook_server/tests/test_issue_comment_handler.py b/webhook_server/tests/test_issue_comment_handler.py index 45ccd992..cf100b63 100644 --- a/webhook_server/tests/test_issue_comment_handler.py +++ b/webhook_server/tests/test_issue_comment_handler.py @@ -1485,3 +1485,27 @@ async def test_approve_command_calls_test_oracle(self, issue_comment_handler: Is ) mock_create_task.assert_called_once() assert asyncio.iscoroutine(mock_create_task.call_args.args[0]) + + @pytest.mark.asyncio + async def test_approve_cancel_does_not_call_test_oracle(self, issue_comment_handler: IssueCommentHandler) -> None: + """Test that /approve cancel does NOT fire call_test_oracle.""" + mock_pull_request = Mock() + mock_pull_request.draft = False + + with patch("asyncio.to_thread", new_callable=AsyncMock, side_effect=lambda f, *a, **k: f(*a, **k)): + with patch.object(issue_comment_handler, "create_comment_reaction", new_callable=AsyncMock): + with patch.object( + issue_comment_handler.labels_handler, "label_by_user_comment", new_callable=AsyncMock + ): + with patch( + "webhook_server.libs.handlers.issue_comment_handler.call_test_oracle", + new_callable=AsyncMock, + ) as mock_oracle: + await issue_comment_handler.user_commands( + pull_request=mock_pull_request, + command=f"{APPROVE_STR} cancel", + reviewed_user="test-user", + issue_comment_id=456, + is_draft=False, + ) + mock_oracle.assert_not_called() From 24e7be6c7072ae730b5d188979508daa2fb56bdc Mon Sep 17 00:00:00 2001 From: rnetser Date: Sun, 1 Mar 2026 18:02:08 +0200 Subject: [PATCH 2/2] test: assert no background task created on /approve cancel Strengthen cancel-path test by also patching asyncio.create_task and asserting it was not called. --- .../tests/test_issue_comment_handler.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/webhook_server/tests/test_issue_comment_handler.py b/webhook_server/tests/test_issue_comment_handler.py index cf100b63..c31fcd74 100644 --- a/webhook_server/tests/test_issue_comment_handler.py +++ b/webhook_server/tests/test_issue_comment_handler.py @@ -1501,11 +1501,13 @@ async def test_approve_cancel_does_not_call_test_oracle(self, issue_comment_hand "webhook_server.libs.handlers.issue_comment_handler.call_test_oracle", new_callable=AsyncMock, ) as mock_oracle: - await issue_comment_handler.user_commands( - pull_request=mock_pull_request, - command=f"{APPROVE_STR} cancel", - reviewed_user="test-user", - issue_comment_id=456, - is_draft=False, - ) - mock_oracle.assert_not_called() + with patch("asyncio.create_task") as mock_create_task: + await issue_comment_handler.user_commands( + pull_request=mock_pull_request, + command=f"{APPROVE_STR} cancel", + reviewed_user="test-user", + issue_comment_id=456, + is_draft=False, + ) + mock_oracle.assert_not_called() + mock_create_task.assert_not_called()