|
9 | 9 | from sentry.integrations.cursor.integration import CursorAgentIntegration |
10 | 10 | from sentry.seer.agent.coding_agent_handoff import _resolve_client, launch_coding_agents |
11 | 11 | from sentry.seer.autofix.utils import CodingAgentProviderType, CodingAgentState |
12 | | -from sentry.seer.models import SeerRepoDefinition |
| 12 | +from sentry.seer.models import SeerApiError, SeerRepoDefinition |
13 | 13 | from sentry.seer.models.run import SeerRunCodingAgentHandoff |
14 | 14 | from sentry.shared_integrations.exceptions import ApiError |
15 | 15 | from sentry.testutils.cases import TestCase |
@@ -147,6 +147,31 @@ def test_successful_launch_persists_seer_run_coding_agent_handoff_row( |
147 | 147 | assert handoff.extras["agent_url"] == "https://cursor.sh/agent" |
148 | 148 | assert handoff.status == "pending" |
149 | 149 |
|
| 150 | + @patch("sentry.seer.agent.coding_agent_handoff.store_coding_agent_states_to_seer") |
| 151 | + @patch("sentry.seer.agent.coding_agent_handoff.validate_and_get_integration") |
| 152 | + def test_marks_handoffs_failed_when_seer_storage_errors(self, mock_validate, mock_store): |
| 153 | + """If Seer never learns about a launched agent at all, GitHub Copilot/Claude |
| 154 | + polls will never discover it to check on later -- the row must not sit at |
| 155 | + pending forever, looking like it's still in progress.""" |
| 156 | + self.create_seer_run(self.organization, seer_run_state_id=self.run_id) |
| 157 | + mock_store.side_effect = SeerApiError("Seer unavailable", status=503) |
| 158 | + installation = FakeCodingAgentInstallation(_state("agent-123")) |
| 159 | + mock_validate.return_value = (None, installation) |
| 160 | + |
| 161 | + result = launch_coding_agents( |
| 162 | + organization=self.organization, |
| 163 | + integration_id=1, |
| 164 | + run_id=self.run_id, |
| 165 | + prompt="Fix the bug", |
| 166 | + repos=[_repo("owner", "repo")], |
| 167 | + ) |
| 168 | + |
| 169 | + # The provider launch itself still succeeded -- callers should still see it. |
| 170 | + assert len(result["successes"]) == 1 |
| 171 | + |
| 172 | + handoff = SeerRunCodingAgentHandoff.objects.get(agent_id="agent-123") |
| 173 | + assert handoff.status == "failed" |
| 174 | + |
150 | 175 | @patch("sentry.seer.agent.coding_agent_handoff.store_coding_agent_states_to_seer") |
151 | 176 | @patch("sentry.seer.agent.coding_agent_handoff.validate_and_get_integration") |
152 | 177 | def test_launch_raises_value_error(self, mock_validate, mock_store): |
|
0 commit comments