Skip to content

Commit baf5f0b

Browse files
committed
Stabilize Gemini thinker session test
1 parent 049e836 commit baf5f0b

1 file changed

Lines changed: 45 additions & 38 deletions

File tree

web/src/app/api/v1/chat/completions/__tests__/completions.test.ts

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,47 +1144,54 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11441144
expect(body.error).toBe('session_model_mismatch')
11451145
})
11461146

1147-
it('requires an active session check for the Gemini thinker subagent', async () => {
1148-
const checkFreeModeRateLimitForTest = mock((userId: string) => {
1149-
expect(userId).toBe('user-new-free-gemini')
1150-
return { limited: false as const }
1151-
})
1147+
it(
1148+
'requires an active session check for the Gemini thinker subagent',
1149+
async () => {
1150+
const checkFreeModeRateLimitForTest = mock((userId: string) => {
1151+
expect(userId).toBe('user-new-free-gemini')
1152+
return { limited: false as const }
1153+
})
11521154

1153-
const response = await postChatCompletions({
1154-
req: new NextRequest('http://localhost:3000/api/v1/chat/completions', {
1155-
method: 'POST',
1156-
headers: allowedFreeModeHeaders('test-api-key-new-free-gemini'),
1157-
body: JSON.stringify({
1158-
model: FREEBUFF_GEMINI_PRO_MODEL_ID,
1159-
stream: false,
1160-
codebuff_metadata: {
1161-
run_id: 'run-gemini-thinker-child',
1162-
client_id: 'test-client-id-123',
1163-
cost_mode: 'free',
1164-
freebuff_instance_id: 'inst-123',
1155+
const response = await postChatCompletions({
1156+
req: new NextRequest(
1157+
'http://localhost:3000/api/v1/chat/completions',
1158+
{
1159+
method: 'POST',
1160+
headers: allowedFreeModeHeaders('test-api-key-new-free-gemini'),
1161+
body: JSON.stringify({
1162+
model: FREEBUFF_GEMINI_PRO_MODEL_ID,
1163+
stream: false,
1164+
codebuff_metadata: {
1165+
run_id: 'run-gemini-thinker-child',
1166+
client_id: 'test-client-id-123',
1167+
cost_mode: 'free',
1168+
freebuff_instance_id: 'inst-123',
1169+
},
1170+
}),
11651171
},
1166-
}),
1167-
}),
1168-
getUserInfoFromApiKey: mockGetUserInfoFromApiKey,
1169-
logger: mockLogger,
1170-
trackEvent: mockTrackEvent,
1171-
getUserUsageData: mockGetUserUsageData,
1172-
getAgentRunFromId: mockGetAgentRunFromId,
1173-
fetch: mockFetch,
1174-
insertMessageBigquery: mockInsertMessageBigquery,
1175-
loggerWithContext: mockLoggerWithContext,
1176-
checkSessionAdmissible: async (params) => {
1177-
expect(params.requireActiveSession).toBe(true)
1178-
expect(params.requestedModel).toBe(FREEBUFF_GEMINI_PRO_MODEL_ID)
1179-
expect(params.claimedInstanceId).toBe('inst-123')
1180-
return { ok: true, reason: 'active', remainingMs: 60_000 }
1181-
},
1182-
checkFreeModeRateLimit: checkFreeModeRateLimitForTest,
1183-
})
1172+
),
1173+
getUserInfoFromApiKey: mockGetUserInfoFromApiKey,
1174+
logger: mockLogger,
1175+
trackEvent: mockTrackEvent,
1176+
getUserUsageData: mockGetUserUsageData,
1177+
getAgentRunFromId: mockGetAgentRunFromId,
1178+
fetch: mockFetch,
1179+
insertMessageBigquery: mockInsertMessageBigquery,
1180+
loggerWithContext: mockLoggerWithContext,
1181+
checkSessionAdmissible: async (params) => {
1182+
expect(params.requireActiveSession).toBe(true)
1183+
expect(params.requestedModel).toBe(FREEBUFF_GEMINI_PRO_MODEL_ID)
1184+
expect(params.claimedInstanceId).toBe('inst-123')
1185+
return { ok: true, reason: 'active', remainingMs: 60_000 }
1186+
},
1187+
checkFreeModeRateLimit: checkFreeModeRateLimitForTest,
1188+
})
11841189

1185-
expect(response.status).toBe(200)
1186-
expect(checkFreeModeRateLimitForTest).toHaveBeenCalledTimes(1)
1187-
})
1190+
expect(response.status).toBe(200)
1191+
expect(checkFreeModeRateLimitForTest).toHaveBeenCalledTimes(1)
1192+
},
1193+
FETCH_PATH_TEST_TIMEOUT_MS,
1194+
)
11881195

11891196
it(
11901197
'counts child Gemini thinker requests toward the free-mode request limit',

0 commit comments

Comments
 (0)