@@ -545,6 +545,54 @@ def test_personal_dispatch_all_paginates_past_first_page(automation_client, db):
545545 assert {log .target for log in logs } == {"acme/demo#100" , "acme/demo#101" }
546546
547547
548+ def test_personal_dispatch_all_paginates_beyond_ten_pages (automation_client , db ):
549+ # 11 pages of 100 inactive workflows, then a final short page holding the only
550+ # two active ones -- the loop must not stop early at an arbitrary page cap.
551+ db .add (User (id = _USER .id , email = _USER .email , name = None , password_hash = None , is_workspace_admin = False ))
552+ db .commit ()
553+ full_page = {
554+ "total_count" : 1102 ,
555+ "workflows" : [{"id" : i , "name" : f"w{ i } " , "path" : "p" , "state" : "disabled_manually" } for i in range (100 )],
556+ }
557+ last_page = {
558+ "total_count" : 1102 ,
559+ "workflows" : [
560+ {"id" : 1100 , "name" : "CI" , "path" : "p" , "state" : "active" },
561+ {"id" : 1101 , "name" : "Release" , "path" : "p" , "state" : "active" },
562+ ],
563+ }
564+ with patch ("src.routers.automation.GitHubClient" ) as mock_client :
565+ mock_client .return_value .request .side_effect = [full_page ] * 11 + [last_page , {}, {}]
566+ resp = automation_client .post (
567+ "/me/repos/acme/demo/workflows/dispatch-all" ,
568+ json = {"token" : "ghp_testtoken123456789012345678901234" , "ref" : "main" },
569+ )
570+ assert resp .status_code == 200
571+ assert resp .json ()["dispatched_count" ] == 2
572+
573+
574+ def test_personal_dispatch_all_stops_at_total_count (automation_client , db ):
575+ # A page that is exactly per_page long but total_count says it's the last:
576+ # the loop must not fetch another (non-existent) page.
577+ db .add (User (id = _USER .id , email = _USER .email , name = None , password_hash = None , is_workspace_admin = False ))
578+ db .commit ()
579+ only_page = {
580+ "total_count" : 100 ,
581+ "workflows" : [{"id" : i , "name" : f"w{ i } " , "path" : "p" , "state" : "disabled_manually" } for i in range (100 )],
582+ }
583+ with patch ("src.routers.automation.GitHubClient" ) as mock_client :
584+ mock_client .return_value .request .side_effect = [only_page ] # exactly one GET, no POSTs
585+ resp = automation_client .post (
586+ "/me/repos/acme/demo/workflows/dispatch-all" ,
587+ json = {"token" : "ghp_testtoken123456789012345678901234" , "ref" : "main" },
588+ )
589+ assert resp .status_code == 200
590+ assert resp .json () == {
591+ "ref" : "main" , "results" : [], "dispatched_count" : 0 , "skipped_count" : 0 , "failed_count" : 0 ,
592+ }
593+ assert mock_client .return_value .request .call_count == 1
594+
595+
548596def test_org_dispatch_all_no_token_returns_400 (db , acme_org ):
549597 client = _org_client (db , acme_org ["admin" ].id , email = acme_org ["admin" ].email )
550598 resp = client .post ("/orgs/acme/repos/acme/demo/workflows/dispatch-all" , json = {"ref" : "main" })
0 commit comments