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..c31fcd74 100644 --- a/webhook_server/tests/test_issue_comment_handler.py +++ b/webhook_server/tests/test_issue_comment_handler.py @@ -1485,3 +1485,29 @@ 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: + 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()