5252 "Copilot was unable to review this pull request because the user who "
5353 "requested the review has reached their quota limit."
5454)
55+ INSUFFICIENT_QUOTA_FAILURE_BODY = (
56+ "Copilot was unable to review this pull request because the user who "
57+ "requested the review has insufficient remaining quota."
58+ )
5559ERROR_BODY = (
5660 "Copilot encountered an error and was unable to review this pull request. "
5761 "You can try again by re-requesting a review."
@@ -203,6 +207,17 @@ def test_quota_failure_requires_the_copilot_actor_and_exact_notice(self) -> None
203207 self .assertFalse (is_copilot_quota_failure (
204208 replace (failure , actor = actor ("reviewer" ))
205209 ))
210+ insufficient = replace (failure , body = INSUFFICIENT_QUOTA_FAILURE_BODY )
211+ self .assertTrue (is_copilot_quota_failure (insufficient ))
212+ self .assertTrue (is_copilot_quota_failure (
213+ replace (insufficient , body = f"\n { INSUFFICIENT_QUOTA_FAILURE_BODY } \n " )
214+ ))
215+ self .assertFalse (is_copilot_quota_failure (
216+ replace (insufficient , actor = actor ("reviewer" ))
217+ ))
218+ self .assertFalse (is_copilot_quota_failure (
219+ replace (insufficient , body = f"> { INSUFFICIENT_QUOTA_FAILURE_BODY } " )
220+ ))
206221 self .assertFalse (is_copilot_quota_failure (
207222 replace (failure , body = f"Handle this failure:\n > { QUOTA_FAILURE_BODY } " )
208223 ))
@@ -226,6 +241,11 @@ def test_quota_failures_do_not_count_as_completed_reviews(self) -> None:
226241 (replace (quota_failure , body = f"\n { QUOTA_FAILURE_BODY } \n " ),),
227242 (False , False ),
228243 ),
244+ (
245+ "insufficient_quota" ,
246+ (replace (quota_failure , body = INSUFFICIENT_QUOTA_FAILURE_BODY ),),
247+ (False , False ),
248+ ),
229249 (
230250 "current_review_then_failure" ,
231251 (completed_review , quota_failure ),
@@ -418,12 +438,12 @@ def enqueue(self, *, quota_exhausted: bool = False) -> None:
418438 NOW ,
419439 )
420440
421- def quota_notice (self , review_id : int ) -> dict :
441+ def quota_notice (self , review_id : int , body : str = QUOTA_FAILURE_BODY ) -> dict :
422442 return {
423443 "id" : review_id ,
424444 "user" : {"login" : "copilot" },
425445 "commit_id" : "current-head" ,
426- "body" : QUOTA_FAILURE_BODY ,
446+ "body" : body ,
427447 }
428448
429449 def error_notice (self , review_id : int ) -> dict :
@@ -438,6 +458,19 @@ def error_notice(self, review_id: int) -> dict:
438458 def deliver (self ) -> list [str ]:
439459 return deliver_copilot_review_requests ("open-telemetry/example" , NOW )
440460
461+ def test_insufficient_quota_notice_triggers_the_fallback_token (self ) -> None :
462+ self .enqueue ()
463+ self .reviews = [
464+ self .quota_notice (10 , INSUFFICIENT_QUOTA_FAILURE_BODY ),
465+ self .quota_notice (11 ),
466+ ]
467+ self .assertEqual ([], self .deliver ())
468+ self .assertEqual (
469+ CopilotReviewFallback ((10 , 11 ), format_ts (NOW )),
470+ load_copilot_review_fallbacks ()["7" ],
471+ )
472+ self .request .assert_called_with ("PR_node" , token = "request-token" )
473+
441474 def test_uses_app_until_a_live_quota_notice_arrives (self ) -> None :
442475 self .assertEqual ([], self .deliver ())
443476 self .request .assert_called_once_with ("PR_node" )
0 commit comments