Skip to content

Commit 44295f1

Browse files
committed
fix merge conflicts
1 parent 6fd4aff commit 44295f1

File tree

1 file changed

+55
-48
lines changed

1 file changed

+55
-48
lines changed

tests/sentry/seer/code_review/test_webhooks.py

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -802,21 +802,6 @@ def _build_issue_comment_event(
802802
}
803803
return orjson.dumps(event)
804804

805-
@patch("sentry.seer.code_review.webhooks.task.schedule_task")
806-
def test_skips_when_code_review_not_enabled(self, mock_schedule: MagicMock) -> None:
807-
"""Test that issue_comment skips when preflight requirements are not met."""
808-
event = self._build_issue_comment_event(f"Please {SENTRY_REVIEW_COMMAND} this PR")
809-
self._send_issue_comment_event(event, enable_code_review=False)
810-
mock_schedule.assert_not_called()
811-
812-
@patch("sentry.seer.code_review.webhooks.task.schedule_task")
813-
def test_skips_when_no_review_command(self, mock_schedule: MagicMock) -> None:
814-
"""Test that issue_comment skips when the comment doesn't contain the review command."""
815-
event = self._build_issue_comment_event("This is a regular comment without the command")
816-
self._send_issue_comment_event(event, enable_code_review=True)
817-
mock_schedule.assert_not_called()
818-
819-
@patch("sentry.seer.code_review.webhooks.task.schedule_task")
820805
def test_skips_when_code_review_features_are_missing(self) -> None:
821806
"""Test that processing is skipped when code review features are missing."""
822807
with self.code_review_setup(features={}): # Missing on purpose
@@ -828,29 +813,20 @@ def test_skips_when_code_review_features_are_missing(self) -> None:
828813

829814
self.mock_seer.assert_not_called()
830815

816+
def test_skips_when_no_review_command(self) -> None:
817+
"""Test that processing is skipped when comment doesn't contain review command."""
818+
with self.code_review_setup():
819+
event = self._build_issue_comment_event("This is a regular comment without the command")
820+
821+
with self.tasks():
822+
response = self._send_issue_comment_event(event)
823+
assert response.status_code == 204
824+
825+
self.mock_seer.assert_not_called()
826+
831827
def test_runs_when_code_review_beta_flag_disabled_but_pr_review_test_generation_enabled(
832828
self,
833829
) -> None:
834-
"""Test that code review works via legacy option even without the beta feature flag."""
835-
# Only enable gen-ai-features flag, not code-review-beta
836-
with self.options({"github.webhook.issue-comment": False}):
837-
event = self._build_issue_comment_event(f"Please {SENTRY_REVIEW_COMMAND} this PR")
838-
self._send_issue_comment_event(
839-
event,
840-
enable_code_review=True,
841-
features={"organizations:gen-ai-features"},
842-
)
843-
844-
@patch("sentry.seer.code_review.webhooks.task.make_seer_request")
845-
@patch("sentry.integrations.github.client.GitHubApiClient.create_comment_reaction")
846-
def test_adds_reaction_and_forwards_when_valid(
847-
self, mock_create_reaction: MagicMock, mock_seer: MagicMock
848-
) -> None:
849-
with self.options({"github.webhook.issue-comment": False}):
850-
event = self._build_issue_comment_event(f"Please {SENTRY_REVIEW_COMMAND} this PR")
851-
852-
with self.tasks():
853-
self._send_issue_comment_event(event, enable_code_review=True)
854830
"""Test that processing runs with gen-ai-features flag alone when org option is enabled."""
855831
with self.options(
856832
{"organizations:code-review-beta": False, "github.webhook.issue-comment": False}
@@ -864,24 +840,55 @@ def test_adds_reaction_and_forwards_when_valid(
864840

865841
self.mock_seer.assert_called_once()
866842

843+
def test_adds_reaction_and_forwards_when_valid(self) -> None:
844+
"""Test successful PR review command processing with reaction and Seer request."""
845+
with self.code_review_setup():
846+
event = self._build_issue_comment_event(f"Please {SENTRY_REVIEW_COMMAND} this PR")
847+
848+
with self.tasks():
849+
response = self._send_issue_comment_event(event)
850+
assert response.status_code == 204
851+
852+
self.mock_reaction.assert_called_once_with(
853+
"owner/repo", "123456789", GitHubReaction.EYES
854+
)
855+
self.mock_seer.assert_called_once()
856+
857+
call_args = self.mock_seer.call_args
858+
assert call_args[1]["path"] == "/v1/automation/overwatch-request"
859+
payload = call_args[1]["payload"]
860+
assert payload["request_type"] == "pr-review"
861+
assert payload["data"]["repo"]["base_commit_sha"] == "abc123"
862+
867863
@patch("sentry.seer.code_review.webhooks.issue_comment._add_eyes_reaction_to_comment")
868-
@patch("sentry.seer.code_review.webhooks.task.schedule_task")
869-
def test_skips_reaction_when_no_comment_id(
870-
self, mock_schedule: MagicMock, mock_reaction: MagicMock
871-
) -> None:
872-
with self.options({"github.webhook.issue-comment": False}):
864+
def test_skips_reaction_when_no_comment_id(self, mock_reaction: MagicMock) -> None:
865+
"""Test that reaction is skipped when comment has no ID, but processing continues."""
866+
with self.code_review_setup():
873867
event = self._build_issue_comment_event(SENTRY_REVIEW_COMMAND, comment_id=None)
874-
self._send_issue_comment_event(event, enable_code_review=True)
868+
869+
with self.tasks():
870+
response = self._send_issue_comment_event(event)
871+
assert response.status_code == 204
872+
873+
mock_reaction.assert_not_called()
874+
self.mock_seer.assert_called_once()
875875

876876
@patch("sentry.seer.code_review.webhooks.issue_comment._add_eyes_reaction_to_comment")
877-
@patch("sentry.seer.code_review.webhooks.task.schedule_task")
878-
def test_skips_processing_when_option_is_true(
879-
self, mock_schedule: MagicMock, mock_reaction: MagicMock
880-
) -> None:
881-
"""Test that when github.webhook.issue-comment option is True (default), no processing occurs."""
882-
with self.options({"github.webhook.issue-comment": True}):
877+
def test_skips_processing_when_option_is_true(self, mock_reaction: MagicMock) -> None:
878+
"""Test that when github.webhook.issue-comment option is True (kill switch), no processing occurs."""
879+
self._enable_code_review()
880+
with (
881+
self.feature(CODE_REVIEW_FEATURES),
882+
self.options({"github.webhook.issue-comment": True}),
883+
):
883884
event = self._build_issue_comment_event(f"Please {SENTRY_REVIEW_COMMAND} this PR")
884-
self._send_issue_comment_event(event, enable_code_review=True)
885+
886+
with self.tasks():
887+
response = self._send_issue_comment_event(event)
888+
assert response.status_code == 204
889+
890+
mock_reaction.assert_not_called()
891+
self.mock_seer.assert_not_called()
885892

886893
def test_validates_seer_request_contains_trigger_metadata(self) -> None:
887894
"""Test that Seer request includes trigger metadata from the comment."""

0 commit comments

Comments
 (0)