@@ -1324,3 +1324,52 @@ def test_link_comment_timeout_preserves_claim_prevents_duplicate(tmp_path) -> No
13241324 assert client .post .call_count == 1
13251325 assert storage .was_notification_sent ("pr_opened_github_link:Gitcord-GithubDiscordBot:42" )
13261326
1327+
1328+ def test_batch_pr_opened_notifications_sent_oldest_first () -> None :
1329+ """Batch sync must post channel PR-open notices in created_at order (not API newest-first)."""
1330+ from ghdcbot .engine .orchestrator import _send_notifications_for_new_events
1331+
1332+ storage = MockStorage ()
1333+ discord_writer = MockDiscordWriter ()
1334+ config = NotificationConfig (enabled = True , pr_opened = True )
1335+ policy = MutationPolicy (
1336+ mode = RunMode .ACTIVE , github_write_allowed = True , discord_write_allowed = True
1337+ )
1338+ channels = {"Gitcord-GithubDiscordBot" : "1465995983791063140" }
1339+
1340+ newer = ContributionEvent (
1341+ github_user = "alice" ,
1342+ event_type = "pr_opened" ,
1343+ repo = "Gitcord-GithubDiscordBot" ,
1344+ created_at = datetime (2026 , 8 , 4 , 18 , 57 , tzinfo = UTC ),
1345+ payload = {"pr_number" : 42 , "title" : "Week 11 remote config" },
1346+ )
1347+ older = ContributionEvent (
1348+ github_user = "alice" ,
1349+ event_type = "pr_opened" ,
1350+ repo = "Gitcord-GithubDiscordBot" ,
1351+ created_at = datetime (2026 , 8 , 4 , 18 , 13 , tzinfo = UTC ),
1352+ payload = {"pr_number" : 41 , "title" : "CI mock fix" },
1353+ )
1354+
1355+ # Newest-first (GitHub list order) — notifications should still post #41 then #42.
1356+ events = [newer , older ]
1357+ _send_notifications_for_new_events (
1358+ events ,
1359+ storage ,
1360+ discord_writer ,
1361+ policy ,
1362+ config ,
1363+ "AOSSIE-Org" ,
1364+ channels ,
1365+ )
1366+
1367+ # Notification pass must not mutate the caller's ingestion list.
1368+ assert events [0 ] is newer
1369+ assert events [1 ] is older
1370+ assert events == [newer , older ]
1371+
1372+ assert len (discord_writer .messages_sent ) == 2
1373+ assert "#41" in discord_writer .messages_sent [0 ][1 ]
1374+ assert "#42" in discord_writer .messages_sent [1 ][1 ]
1375+
0 commit comments