@@ -1104,9 +1104,18 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11041104 it (
11051105 'counts child Gemini thinker requests toward the free-mode request limit' ,
11061106 async ( ) => {
1107- expect ( checkFreeModeRateLimit ( 'user-gemini-rate-limit' ) . limited ) . toBe (
1108- false ,
1109- )
1107+ let rateLimitChecks = 0
1108+ const checkFreeModeRateLimitForTest = mock ( ( userId : string ) => {
1109+ expect ( userId ) . toBe ( 'user-gemini-rate-limit' )
1110+ rateLimitChecks += 1
1111+ return rateLimitChecks === 1
1112+ ? { limited : false as const }
1113+ : {
1114+ limited : true as const ,
1115+ windowName : '1 second' ,
1116+ retryAfterMs : 1_000 ,
1117+ }
1118+ } )
11101119
11111120 const createRequest = ( ) =>
11121121 new NextRequest ( 'http://localhost:3000/api/v1/chat/completions' , {
@@ -1135,6 +1144,7 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11351144 insertMessageBigquery : mockInsertMessageBigquery ,
11361145 loggerWithContext : mockLoggerWithContext ,
11371146 checkSessionAdmissible : mockCheckSessionAdmissibleAllow ,
1147+ checkFreeModeRateLimit : checkFreeModeRateLimitForTest ,
11381148 } )
11391149
11401150 const firstResponse = await postChatCompletions ( createPostParams ( ) )
@@ -1144,6 +1154,7 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11441154 expect ( limitedResponse . status ) . toBe ( 429 )
11451155 const body = await limitedResponse . json ( )
11461156 expect ( body . error ) . toBe ( 'free_mode_rate_limited' )
1157+ expect ( checkFreeModeRateLimitForTest ) . toHaveBeenCalledTimes ( 2 )
11471158 } ,
11481159 FETCH_PATH_TEST_TIMEOUT_MS ,
11491160 )
0 commit comments