@@ -1234,6 +1234,12 @@ def setUp(self):
12341234 external_id = "ext123" ,
12351235 name = "test-org/test-repo" ,
12361236 )
1237+ self .repo2 = self .create_repo (
1238+ project = self .project ,
1239+ provider = "integrations:github" ,
1240+ external_id = "ext456" ,
1241+ name = "test-org/other-repo" ,
1242+ )
12371243
12381244 def test_unconfigured_project_returns_none (self ):
12391245 result = read_preference_from_sentry_db (self .project )
@@ -1252,20 +1258,29 @@ def test_project_with_repos_only(self):
12521258 tag_value = "production" ,
12531259 branch_name = "release" ,
12541260 )
1261+ SeerProjectRepository .objects .create (
1262+ project = self .project ,
1263+ repository = self .repo2 ,
1264+ branch_name = "develop" ,
1265+ )
12551266
12561267 result = read_preference_from_sentry_db (self .project )
12571268 assert result is not None
12581269 assert result .project_id == self .project .id
12591270 assert result .organization_id == self .organization .id
1260- assert len (result .repositories ) == 1
1261- assert result .repositories [0 ].owner == "test-org"
1262- assert result .repositories [0 ].name == "test-repo"
1263- assert result .repositories [0 ].branch_name == "main"
1264- assert result .repositories [0 ].instructions == "Be helpful"
1265- assert len (result .repositories [0 ].branch_overrides ) == 1
1266- assert result .repositories [0 ].branch_overrides [0 ].tag_name == "environment"
1267- assert result .repositories [0 ].branch_overrides [0 ].tag_value == "production"
1268- assert result .repositories [0 ].branch_overrides [0 ].branch_name == "release"
1271+ assert len (result .repositories ) == 2
1272+ repo_by_name = {r .name : r for r in result .repositories }
1273+ assert repo_by_name ["test-repo" ].owner == "test-org"
1274+ assert repo_by_name ["test-repo" ].branch_name == "main"
1275+ assert repo_by_name ["test-repo" ].instructions == "Be helpful"
1276+ assert len (repo_by_name ["test-repo" ].branch_overrides ) == 1
1277+ assert repo_by_name ["test-repo" ].branch_overrides [0 ].tag_name == "environment"
1278+ assert repo_by_name ["test-repo" ].branch_overrides [0 ].tag_value == "production"
1279+ assert repo_by_name ["test-repo" ].branch_overrides [0 ].branch_name == "release"
1280+ assert repo_by_name ["other-repo" ].owner == "test-org"
1281+ assert repo_by_name ["other-repo" ].branch_name == "develop"
1282+ assert repo_by_name ["other-repo" ].instructions is None
1283+ assert repo_by_name ["other-repo" ].branch_overrides == []
12691284 assert result .automated_run_stopping_point == "code_changes"
12701285 assert result .automation_handoff is None
12711286
@@ -1294,6 +1309,58 @@ def test_project_with_handoff_only(self):
12941309 assert result .automation_handoff .integration_id == 42
12951310 assert result .automation_handoff .auto_create_pr is True
12961311
1312+ def test_project_with_repos_and_options (self ):
1313+ SeerProjectRepository .objects .create (
1314+ project = self .project ,
1315+ repository = self .repo ,
1316+ branch_name = "main" ,
1317+ )
1318+ SeerProjectRepository .objects .create (
1319+ project = self .project ,
1320+ repository = self .repo2 ,
1321+ branch_name = "develop" ,
1322+ )
1323+ self .project .update_option ("sentry:seer_automated_run_stopping_point" , "open_pr" )
1324+ self .project .update_option ("sentry:seer_automation_handoff_point" , "root_cause" )
1325+ self .project .update_option (
1326+ "sentry:seer_automation_handoff_target" , "cursor_background_agent"
1327+ )
1328+ self .project .update_option ("sentry:seer_automation_handoff_integration_id" , 42 )
1329+
1330+ result = read_preference_from_sentry_db (self .project )
1331+ assert result is not None
1332+ assert len (result .repositories ) == 2
1333+ assert result .automated_run_stopping_point == "open_pr"
1334+ assert result .automation_handoff is not None
1335+ assert result .automation_handoff .handoff_point == "root_cause"
1336+ assert result .automation_handoff .target == "cursor_background_agent"
1337+ assert result .automation_handoff .integration_id == 42
1338+ assert result .automation_handoff .auto_create_pr is False
1339+
1340+ def test_excludes_other_projects_data (self ):
1341+ other_project = self .create_project (organization = self .organization )
1342+ other_repo = self .create_repo (
1343+ project = other_project ,
1344+ provider = "integrations:github" ,
1345+ external_id = "ext789" ,
1346+ name = "test-org/other-project-repo" ,
1347+ )
1348+ SeerProjectRepository .objects .create (
1349+ project = other_project , repository = other_repo , branch_name = "main"
1350+ )
1351+ other_project .update_option ("sentry:seer_automated_run_stopping_point" , "open_pr" )
1352+
1353+ SeerProjectRepository .objects .create (
1354+ project = self .project , repository = self .repo , branch_name = "develop"
1355+ )
1356+ self .project .update_option ("sentry:seer_automated_run_stopping_point" , "root_cause" )
1357+
1358+ result = read_preference_from_sentry_db (self .project )
1359+ assert result is not None
1360+ assert len (result .repositories ) == 1
1361+ assert result .repositories [0 ].name == "test-repo"
1362+ assert result .automated_run_stopping_point == "root_cause"
1363+
12971364 def test_partial_handoff_returns_none_handoff (self ):
12981365 self .project .update_option ("sentry:seer_automation_handoff_point" , "root_cause" )
12991366
@@ -1315,6 +1382,12 @@ def setUp(self):
13151382 external_id = "ext123" ,
13161383 name = "test-org/test-repo" ,
13171384 )
1385+ self .repo2 = self .create_repo (
1386+ project = self .project1 ,
1387+ provider = "integrations:github" ,
1388+ external_id = "ext456" ,
1389+ name = "test-org/other-repo" ,
1390+ )
13181391
13191392 def test_empty_project_ids_returns_empty (self ):
13201393 result = bulk_read_preferences_from_sentry_db (self .organization .id , [])
@@ -1328,6 +1401,9 @@ def test_bulk_returns_correct_preferences(self):
13281401 SeerProjectRepository .objects .create (
13291402 project = self .project1 , repository = self .repo , branch_name = "main"
13301403 )
1404+ SeerProjectRepository .objects .create (
1405+ project = self .project1 , repository = self .repo2 , branch_name = "develop"
1406+ )
13311407 self .project2 .update_option ("sentry:seer_automated_run_stopping_point" , "open_pr" )
13321408 self .project2 .update_option ("sentry:seer_automation_handoff_point" , "root_cause" )
13331409 self .project2 .update_option (
@@ -1342,8 +1418,8 @@ def test_bulk_returns_correct_preferences(self):
13421418
13431419 pref1 = result [self .project1 .id ]
13441420 assert pref1 is not None
1345- assert len (pref1 .repositories ) == 1
1346- assert pref1 .repositories [ 0 ]. branch_name == "main"
1421+ assert len (pref1 .repositories ) == 2
1422+ assert { r . branch_name for r in pref1 .repositories } == { "main" , "develop" }
13471423 assert pref1 .automated_run_stopping_point == "code_changes"
13481424 assert pref1 .automation_handoff is None
13491425
0 commit comments