@@ -927,12 +927,50 @@ def test_without_feature_flag(self, mock_budget, mock_state, mock_rate, mock_tri
927927 assert mock_trigger .call_args [1 ]["stopping_point" ] is None
928928
929929 @patch ("sentry.seer.autofix.issue_summary._trigger_autofix_task.delay" )
930- def test_missing_fixability_score_returns_early (self , mock_trigger ):
931- """Test that _run_automation returns early when fixability score is None."""
930+ @patch ("sentry.seer.autofix.issue_summary._generate_fixability_score" )
931+ def test_missing_fixability_score_generates_and_fails (
932+ self , mock_generate_fixability , mock_trigger
933+ ):
934+ """Test that _run_automation tries to generate fixability score when None and fails if generation fails."""
932935 assert self .group .seer_fixability_score is None
933- _run_automation (self .group , self .user , self .event , SeerAutomationSource .ALERT )
936+ mock_generate_fixability .side_effect = Exception ("Fixability generation failed" )
937+
938+ with pytest .raises (Exception , match = "Fixability generation failed" ):
939+ _run_automation (self .group , self .user , self .event , SeerAutomationSource .ALERT )
940+
941+ mock_generate_fixability .assert_called_once_with (self .group )
934942 mock_trigger .assert_not_called ()
935943
944+ @patch ("sentry.seer.autofix.issue_summary._trigger_autofix_task.delay" )
945+ @patch (
946+ "sentry.seer.autofix.issue_summary.is_seer_autotriggered_autofix_rate_limited" ,
947+ return_value = False ,
948+ )
949+ @patch ("sentry.seer.autofix.issue_summary._generate_fixability_score" )
950+ @patch ("sentry.seer.autofix.issue_summary.get_autofix_state" , return_value = None )
951+ @patch ("sentry.quotas.backend.has_available_reserved_budget" , return_value = True )
952+ def test_missing_fixability_score_generates_and_succeeds (
953+ self , mock_budget , mock_state , mock_generate_fixability , mock_rate_limit , mock_trigger
954+ ):
955+ """Test that _run_automation generates fixability score when None and continues if generation succeeds."""
956+ assert self .group .seer_fixability_score is None
957+ self .project .update_option ("sentry:autofix_automation_tuning" , "always" )
958+ mock_generate_fixability .return_value = SummarizeIssueResponse (
959+ group_id = str (self .group .id ),
960+ headline = "h" ,
961+ whats_wrong = "w" ,
962+ trace = "t" ,
963+ possible_cause = "c" ,
964+ scores = SummarizeIssueScores (fixability_score = 0.80 ),
965+ )
966+
967+ _run_automation (self .group , self .user , self .event , SeerAutomationSource .ALERT )
968+
969+ mock_generate_fixability .assert_called_once_with (self .group )
970+ mock_trigger .assert_called_once ()
971+ self .group .refresh_from_db ()
972+ assert self .group .seer_fixability_score == 0.80
973+
936974
937975class TestFetchUserPreference :
938976 @patch ("sentry.seer.autofix.issue_summary.sign_with_seer_secret" , return_value = {})
0 commit comments