@@ -133,6 +133,48 @@ def test_prompt_with_both_artifacts(self):
133133 assert "## Proposed Solution" in prompt
134134 assert "Fix the handler" in prompt
135135
136+ def test_prompt_with_short_id (self ):
137+ """Test that short_id is included in prompt when provided."""
138+ state = SeerRunState (
139+ run_id = 123 ,
140+ blocks = [],
141+ status = "completed" ,
142+ updated_at = "2024-01-01T00:00:00Z" ,
143+ )
144+
145+ prompt = generate_autofix_handoff_prompt (state , short_id = "AIML-2301" )
146+
147+ assert "Include 'Fixes AIML-2301' in the pull request description" in prompt
148+
149+ def test_prompt_without_short_id (self ):
150+ """Test that 'Fixes' is not in prompt when short_id is None."""
151+ state = SeerRunState (
152+ run_id = 123 ,
153+ blocks = [],
154+ status = "completed" ,
155+ updated_at = "2024-01-01T00:00:00Z" ,
156+ )
157+
158+ prompt = generate_autofix_handoff_prompt (state , short_id = None )
159+
160+ assert "Fixes" not in prompt
161+
162+ def test_prompt_with_short_id_and_instruction (self ):
163+ """Test that both short_id and instruction are included."""
164+ state = SeerRunState (
165+ run_id = 123 ,
166+ blocks = [],
167+ status = "completed" ,
168+ updated_at = "2024-01-01T00:00:00Z" ,
169+ )
170+
171+ prompt = generate_autofix_handoff_prompt (
172+ state , instruction = "Focus on performance" , short_id = "PROJ-123"
173+ )
174+
175+ assert "Include 'Fixes PROJ-123' in the pull request description" in prompt
176+ assert "Focus on performance" in prompt
177+
136178
137179class TestBuildStepPrompt (TestCase ):
138180 def setUp (self ):
@@ -501,3 +543,56 @@ def test_trigger_coding_agent_handoff_no_preferences_returns_failure(
501543 assert len (result ["failures" ]) == 1
502544 assert "No repositories configured" in result ["failures" ][0 ]["error_message" ]
503545 mock_client .launch_coding_agents .assert_not_called ()
546+
547+ @patch ("sentry.seer.autofix.autofix_agent.get_project_seer_preferences" )
548+ @patch ("sentry.seer.autofix.autofix_agent.SeerExplorerClient" )
549+ def test_trigger_coding_agent_handoff_includes_short_id_when_auto_create_pr_enabled (
550+ self , mock_client_class , mock_get_prefs
551+ ):
552+ """Test that short_id is included in prompt when auto_create_pr is True."""
553+ mock_client = MagicMock ()
554+ mock_client_class .return_value = mock_client
555+ mock_client .get_run .return_value = self ._make_run_state ()
556+ mock_client .launch_coding_agents .return_value = {"successes" : [], "failures" : []}
557+
558+ # Set up preferences with auto_create_pr=True
559+ mock_get_prefs .return_value = self ._make_preference_response (auto_create_pr = True )
560+
561+ trigger_coding_agent_handoff (
562+ group = self .group ,
563+ run_id = 123 ,
564+ integration_id = 456 ,
565+ )
566+
567+ call_kwargs = mock_client .launch_coding_agents .call_args .kwargs
568+ prompt = call_kwargs ["prompt" ]
569+ # Prompt should contain "Fixes {short_id}" instruction
570+ assert (
571+ f"Include 'Fixes { self .group .qualified_short_id } ' in the pull request description"
572+ in prompt
573+ )
574+
575+ @patch ("sentry.seer.autofix.autofix_agent.get_project_seer_preferences" )
576+ @patch ("sentry.seer.autofix.autofix_agent.SeerExplorerClient" )
577+ def test_trigger_coding_agent_handoff_excludes_short_id_when_auto_create_pr_disabled (
578+ self , mock_client_class , mock_get_prefs
579+ ):
580+ """Test that short_id is NOT included in prompt when auto_create_pr is False."""
581+ mock_client = MagicMock ()
582+ mock_client_class .return_value = mock_client
583+ mock_client .get_run .return_value = self ._make_run_state ()
584+ mock_client .launch_coding_agents .return_value = {"successes" : [], "failures" : []}
585+
586+ # Set up preferences with auto_create_pr=False (default)
587+ mock_get_prefs .return_value = self ._make_preference_response (auto_create_pr = False )
588+
589+ trigger_coding_agent_handoff (
590+ group = self .group ,
591+ run_id = 123 ,
592+ integration_id = 456 ,
593+ )
594+
595+ call_kwargs = mock_client .launch_coding_agents .call_args .kwargs
596+ prompt = call_kwargs ["prompt" ]
597+ # Prompt should NOT contain "Fixes" instruction
598+ assert "Fixes" not in prompt
0 commit comments