1- from unittest .mock import patch
1+ from unittest .mock import MagicMock , patch
22
33from django .utils import timezone
44
1414from sentry .testutils .cases import SnubaTestCase , TestCase
1515from sentry .testutils .helpers .datetime import before_now
1616from sentry .testutils .pytest .fixtures import django_db_all
17+ from sentry .utils import json
18+
19+
20+ def _mock_llm_response (group_ids : list [int ], action : str = "autofix" ) -> MagicMock :
21+ verdicts = [{"group_id" : gid , "action" : action , "reason" : "test" } for gid in group_ids ]
22+ content = json .dumps ({"verdicts" : verdicts })
23+ response = MagicMock ()
24+ response .status = 200
25+ response .data = json .dumps ({"content" : content }).encode ()
26+ return response
1727
1828
1929@django_db_all
@@ -152,7 +162,13 @@ def test_selects_candidates_and_skips_triggered(self) -> None:
152162 seer_autofix_last_triggered = timezone .now (),
153163 )
154164
155- with patch ("sentry.tasks.seer.night_shift.cron.logger" ) as mock_logger :
165+ with (
166+ patch (
167+ "sentry.tasks.seer.night_shift.agentic_triage.make_llm_generate_request" ,
168+ return_value = _mock_llm_response ([high_fix .id , low_fix .id ]),
169+ ),
170+ patch ("sentry.tasks.seer.night_shift.cron.logger" ) as mock_logger ,
171+ ):
156172 run_night_shift_for_org (org .id )
157173
158174 call_extra = mock_logger .info .call_args .kwargs ["extra" ]
@@ -175,7 +191,13 @@ def test_global_ranking_across_projects(self) -> None:
175191 project_b , "high-group" , seer_fixability_score = 0.95
176192 )
177193
178- with patch ("sentry.tasks.seer.night_shift.cron.logger" ) as mock_logger :
194+ with (
195+ patch (
196+ "sentry.tasks.seer.night_shift.agentic_triage.make_llm_generate_request" ,
197+ return_value = _mock_llm_response ([high_group .id , low_group .id ]),
198+ ),
199+ patch ("sentry.tasks.seer.night_shift.cron.logger" ) as mock_logger ,
200+ ):
179201 run_night_shift_for_org (org .id )
180202
181203 candidates = mock_logger .info .call_args .kwargs ["extra" ]["candidates" ]
0 commit comments