Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sentry/integrations/cursor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def launch(self, webhook_url: str, request: CodingAgentLaunchRequest) -> CodingA
),
source=CursorAgentSource(
repository=f"https://github.com/{request.repository.owner}/{request.repository.name}",
ref=request.repository.branch_name,
# Use None for empty branch_name so Cursor uses repo's default branch
ref=request.repository.branch_name or None,
),
webhook=CursorAgentLaunchRequestWebhook(url=webhook_url, secret=self.webhook_secret),
target=CursorAgentLaunchRequestTarget(
Expand Down
99 changes: 99 additions & 0 deletions tests/sentry/integrations/cursor/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,102 @@ def test_launch_default_auto_create_pr(self, mock_post: Mock) -> None:
# Verify the payload contains autoCreatePr=False (the default)
payload = call_kwargs["data"]
assert payload["target"]["autoCreatePr"] is False

@patch.object(CursorAgentClient, "post")
def test_launch_with_empty_branch_name_uses_default(self, mock_post: Mock) -> None:
"""Test that launch() excludes ref when branch_name is empty, allowing Cursor to use repo default"""
# Setup mock response
mock_response = Mock()
mock_response.json = {
"id": "agent_123",
"status": "running",
"name": "Test Agent",
"createdAt": "2023-01-01T00:00:00Z",
"source": {
"repository": "https://github.com/getsentry/sentry",
"ref": "main", # Cursor returns the resolved default branch
},
"target": {
"url": "https://cursor.com/agent/123",
"autoCreatePr": False,
"branchName": "fix-bug-123",
},
}
mock_post.return_value = mock_response

# Create repo definition with empty branch_name
repo_definition_empty_branch = SeerRepoDefinition(
integration_id="111",
provider="github",
owner="getsentry",
name="sentry",
external_id="123456",
branch_name="", # Empty string
)

request = CodingAgentLaunchRequest(
prompt="Fix this bug",
repository=repo_definition_empty_branch,
branch_name="fix-bug-123",
)

# Launch the agent
self.cursor_client.launch(webhook_url=self.webhook_url, request=request)

# Assert that post was called with correct parameters
mock_post.assert_called_once()
call_kwargs = mock_post.call_args[1]

# Verify the payload does NOT contain ref (it's excluded when None)
# This allows Cursor to use the repo's default branch
payload = call_kwargs["data"]
assert "ref" not in payload["source"]

@patch.object(CursorAgentClient, "post")
def test_launch_with_none_branch_name_uses_default(self, mock_post: Mock) -> None:
"""Test that launch() excludes ref when branch_name is None, allowing Cursor to use repo default"""
# Setup mock response
mock_response = Mock()
mock_response.json = {
"id": "agent_123",
"status": "running",
"name": "Test Agent",
"createdAt": "2023-01-01T00:00:00Z",
"source": {
"repository": "https://github.com/getsentry/sentry",
"ref": "main",
},
"target": {
"url": "https://cursor.com/agent/123",
"autoCreatePr": False,
"branchName": "fix-bug-123",
},
}
mock_post.return_value = mock_response

# Create repo definition with None branch_name
repo_definition_none_branch = SeerRepoDefinition(
integration_id="111",
provider="github",
owner="getsentry",
name="sentry",
external_id="123456",
branch_name=None,
)

request = CodingAgentLaunchRequest(
prompt="Fix this bug",
repository=repo_definition_none_branch,
branch_name="fix-bug-123",
)

# Launch the agent
self.cursor_client.launch(webhook_url=self.webhook_url, request=request)

# Assert that post was called with correct parameters
mock_post.assert_called_once()
call_kwargs = mock_post.call_args[1]

# Verify the payload does NOT contain ref
payload = call_kwargs["data"]
assert "ref" not in payload["source"]
Loading