Defer protected app data reads until user action (#1370)
This commit is contained in:
@@ -175,18 +175,12 @@ describe('fetchGeminiRateLimits fallback oauth creds', () => {
|
||||
expect(result.error).toContain('Gemini project ID not found')
|
||||
})
|
||||
|
||||
it('returns unavailable when geminiCliOAuthEnabled=false and no google entry in auth.json', async () => {
|
||||
readFileMock.mockImplementation(async (filePath: string) => {
|
||||
if (filePath.includes('auth.json')) {
|
||||
return JSON.stringify({ 'opencode-go': { type: 'api', key: 'k' } })
|
||||
}
|
||||
throw { code: 'ENOENT' }
|
||||
})
|
||||
|
||||
it('returns unavailable without reading OAuth files when geminiCliOAuthEnabled=false', async () => {
|
||||
const result = await fetchGeminiRateLimits(false)
|
||||
|
||||
expect(result.status).toBe('unavailable')
|
||||
expect(result.error).toContain('disabled')
|
||||
expect(readFileMock).not.toHaveBeenCalled()
|
||||
// No network calls should have been made.
|
||||
expect(netFetchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -203,22 +203,25 @@ async function fetchViaOauthCreds(
|
||||
export async function fetchGeminiRateLimits(
|
||||
geminiCliOAuthEnabled = false
|
||||
): Promise<ProviderRateLimits> {
|
||||
if (!geminiCliOAuthEnabled) {
|
||||
// Why: the OAuth sources include other apps' data folders on macOS.
|
||||
// Do not touch them during background polling unless the user opts in.
|
||||
return {
|
||||
provider: 'gemini',
|
||||
session: null,
|
||||
weekly: null,
|
||||
updatedAt: Date.now(),
|
||||
error: 'Gemini CLI OAuth is disabled in settings',
|
||||
status: 'unavailable'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const authJson = await readAuthJson()
|
||||
const result =
|
||||
authJson?.google?.type === 'oauth'
|
||||
? await fetchViaAuthJson(authJson.google, geminiCliOAuthEnabled)
|
||||
: await (async () => {
|
||||
if (!geminiCliOAuthEnabled) {
|
||||
return {
|
||||
provider: 'gemini',
|
||||
session: null,
|
||||
weekly: null,
|
||||
updatedAt: Date.now(),
|
||||
error: 'Gemini CLI OAuth is disabled in settings',
|
||||
status: 'unavailable'
|
||||
} as ProviderRateLimits
|
||||
}
|
||||
const creds = await readGeminiCredentials()
|
||||
return !creds
|
||||
? ({
|
||||
|
||||
Reference in New Issue
Block a user