perf(cliproxy): overlap gemini quota metadata fetches

This commit is contained in:
Tam Nhu Tran
2026-04-03 19:56:31 -04:00
parent 71c4b184f9
commit c9bbc58dd4
2 changed files with 43 additions and 5 deletions
+6 -5
View File
@@ -639,6 +639,11 @@ async function fetchWithAuthData(
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const supplementaryPromise = fetchGeminiCliSupplementary(
authData.accessToken,
authData.projectId,
verbose
);
try {
const response = await fetch(GEMINI_CLI_QUOTA_URL, {
@@ -668,11 +673,7 @@ async function fetchWithAuthData(
const data = (await response.json()) as GeminiCliQuotaResponse;
const rawBuckets = data.buckets || [];
const buckets = buildGeminiCliBuckets(rawBuckets);
const supplementary = await fetchGeminiCliSupplementary(
authData.accessToken,
authData.projectId,
verbose
);
const supplementary = await supplementaryPromise;
if (verbose) console.error(`[i] Gemini CLI buckets found: ${buckets.length}`);
@@ -448,6 +448,43 @@ describe('Gemini CLI Quota Fetcher', () => {
expect(result.creditBalance).toBeNull();
expect(result.buckets[0].remainingPercent).toBe(75);
});
it('keeps base quota success when supplementary metadata throws a network error', async () => {
writeActiveGeminiAccount('supplementary-network@example.com');
mockFetch([
{
url: GEMINI_QUOTA_URL,
method: 'POST',
status: 200,
response: {
buckets: [{ model_id: 'gemini-3-flash-preview', remaining_fraction: 0.75 }],
},
},
]);
const mockedFetch = globalThis.fetch;
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
const url =
typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
if (url === GEMINI_CODE_ASSIST_URL) {
throw new TypeError('supplementary network down');
}
return mockedFetch(input, init);
}) as typeof fetch;
try {
const result = await fetchGeminiCliQuota('supplementary-network@example.com');
expect(result.success).toBe(true);
expect(result.tierLabel).toBeNull();
expect(result.tierId).toBeNull();
expect(result.creditBalance).toBeNull();
expect(result.buckets[0].remainingPercent).toBe(75);
} finally {
globalThis.fetch = mockedFetch;
}
});
});
describe('fetchGeminiCliQuota failure metadata', () => {