mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 16:41:11 -07:00
fix(core): ensure retry sets defaults for nullish values passed into options (#9540)
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
This commit is contained in:
@@ -116,6 +116,23 @@ describe('retryWithBackoff', () => {
|
||||
expect(mockFn).toHaveBeenCalledTimes(5);
|
||||
});
|
||||
|
||||
it('should default to 5 maxAttempts if options.maxAttempts is undefined', async () => {
|
||||
// This function will fail more than 5 times to ensure all retries are used.
|
||||
const mockFn = createFailingFunction(10);
|
||||
|
||||
const promise = retryWithBackoff(mockFn, { maxAttempts: undefined });
|
||||
|
||||
// Expect it to fail with the error from the 5th attempt.
|
||||
// eslint-disable-next-line vitest/valid-expect
|
||||
const assertionPromise = expect(promise).rejects.toThrow(
|
||||
'Simulated error attempt 5',
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await assertionPromise;
|
||||
|
||||
expect(mockFn).toHaveBeenCalledTimes(5);
|
||||
});
|
||||
|
||||
it('should not retry if shouldRetry returns false', async () => {
|
||||
const mockFn = vi.fn(async () => {
|
||||
throw new NonRetryableError('Non-retryable error');
|
||||
|
||||
@@ -78,6 +78,10 @@ export async function retryWithBackoff<T>(
|
||||
throw new Error('maxAttempts must be a positive number.');
|
||||
}
|
||||
|
||||
const cleanOptions = options
|
||||
? Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null))
|
||||
: {};
|
||||
|
||||
const {
|
||||
maxAttempts,
|
||||
initialDelayMs,
|
||||
@@ -87,7 +91,7 @@ export async function retryWithBackoff<T>(
|
||||
shouldRetry,
|
||||
} = {
|
||||
...DEFAULT_RETRY_OPTIONS,
|
||||
...options,
|
||||
...cleanOptions,
|
||||
};
|
||||
|
||||
let attempt = 0;
|
||||
|
||||
Reference in New Issue
Block a user