-
Notifications
You must be signed in to change notification settings - Fork 13.1k
feat(evals): add reliability harvester and 500/503 retry support #23626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20004fb
feat(evals): add reliability harvester and 500/503 retry support
alisa-alisa d3e33af
Merge branch 'main' into alisa/five_hundred_api_error_2
alisa-alisa e35dc89
feat(scripts): improve error reporting in reliability harvester with …
alisa-alisa 4f4f373
Remove retry from vitest config
alisa-alisa 33762f3
Merge branch 'main' into alisa/five_hundred_api_error_2
alisa-alisa 36a290d
Cleaning up some old code.
alisa-alisa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { internalEvalTest } from './test-helper.js'; | ||
| import { TestRig } from '@google/gemini-cli-test-utils'; | ||
|
|
||
| // Mock TestRig to control API success/failure | ||
| vi.mock('@google/gemini-cli-test-utils', () => { | ||
| return { | ||
| TestRig: vi.fn().mockImplementation(() => ({ | ||
| setup: vi.fn(), | ||
| run: vi.fn(), | ||
| cleanup: vi.fn(), | ||
| readToolLogs: vi.fn().mockReturnValue([]), | ||
| _lastRunStderr: '', | ||
| })), | ||
| }; | ||
| }); | ||
|
|
||
| describe('evalTest reliability logic', () => { | ||
| const LOG_DIR = path.resolve(process.cwd(), 'evals/logs'); | ||
| const RELIABILITY_LOG = path.join(LOG_DIR, 'api-reliability.jsonl'); | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| if (fs.existsSync(RELIABILITY_LOG)) { | ||
| fs.unlinkSync(RELIABILITY_LOG); | ||
| } | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (fs.existsSync(RELIABILITY_LOG)) { | ||
| fs.unlinkSync(RELIABILITY_LOG); | ||
| } | ||
| }); | ||
|
|
||
| it('should retry 3 times on 500 INTERNAL error and then SKIP', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
|
|
||
| // Simulate permanent 500 error | ||
| mockRig.run.mockRejectedValue(new Error('status: INTERNAL - API Down')); | ||
|
|
||
| // Execute the test function directly | ||
| await internalEvalTest({ | ||
| name: 'test-api-failure', | ||
| prompt: 'do something', | ||
| assert: async () => {}, | ||
| }); | ||
|
|
||
| // Verify retries: 1 initial + 3 retries = 4 setups/runs | ||
| expect(mockRig.run).toHaveBeenCalledTimes(4); | ||
|
|
||
| // Verify log content | ||
| const logContent = fs | ||
| .readFileSync(RELIABILITY_LOG, 'utf-8') | ||
| .trim() | ||
| .split('\n'); | ||
| expect(logContent.length).toBe(4); | ||
|
|
||
| const entries = logContent.map((line) => JSON.parse(line)); | ||
| expect(entries[0].status).toBe('RETRY'); | ||
| expect(entries[0].attempt).toBe(0); | ||
| expect(entries[3].status).toBe('SKIP'); | ||
| expect(entries[3].attempt).toBe(3); | ||
| expect(entries[3].testName).toBe('test-api-failure'); | ||
| }); | ||
|
|
||
| it('should fail immediately on non-500 errors (like assertion failures)', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
|
|
||
| // Simulate a real logic error/bug | ||
| mockRig.run.mockResolvedValue('Success'); | ||
| const assertError = new Error('Assertion failed: expected foo to be bar'); | ||
|
|
||
| // Expect the test function to throw immediately | ||
| await expect( | ||
| internalEvalTest({ | ||
| name: 'test-logic-failure', | ||
| prompt: 'do something', | ||
| assert: async () => { | ||
| throw assertError; | ||
| }, | ||
| }), | ||
| ).rejects.toThrow('Assertion failed'); | ||
|
|
||
| // Verify NO retries: only 1 attempt | ||
| expect(mockRig.run).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Verify NO reliability log was created (it's not an API error) | ||
| expect(fs.existsSync(RELIABILITY_LOG)).toBe(false); | ||
| }); | ||
|
|
||
| it('should recover if a retry succeeds', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
|
|
||
| // Fail once, then succeed | ||
| mockRig.run | ||
| .mockRejectedValueOnce(new Error('status: INTERNAL')) | ||
| .mockResolvedValueOnce('Success'); | ||
|
|
||
| await internalEvalTest({ | ||
| name: 'test-recovery', | ||
| prompt: 'do something', | ||
| assert: async () => {}, | ||
| }); | ||
|
|
||
| // Ran twice: initial (fail) + retry 1 (success) | ||
| expect(mockRig.run).toHaveBeenCalledTimes(2); | ||
|
|
||
| // Log should only have the one RETRY entry | ||
| const logContent = fs | ||
| .readFileSync(RELIABILITY_LOG, 'utf-8') | ||
| .trim() | ||
| .split('\n'); | ||
| expect(logContent.length).toBe(1); | ||
| expect(JSON.parse(logContent[0]).status).toBe('RETRY'); | ||
| }); | ||
|
|
||
| it('should retry 3 times on 503 UNAVAILABLE error and then SKIP', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
|
|
||
| // Simulate permanent 503 error | ||
| mockRig.run.mockRejectedValue( | ||
| new Error('status: UNAVAILABLE - Service Busy'), | ||
| ); | ||
|
|
||
| await internalEvalTest({ | ||
| name: 'test-api-503', | ||
| prompt: 'do something', | ||
| assert: async () => {}, | ||
| }); | ||
|
|
||
| expect(mockRig.run).toHaveBeenCalledTimes(4); | ||
|
|
||
| const logContent = fs | ||
| .readFileSync(RELIABILITY_LOG, 'utf-8') | ||
| .trim() | ||
| .split('\n'); | ||
| const entries = logContent.map((line) => JSON.parse(line)); | ||
| expect(entries[0].errorCode).toBe('503'); | ||
| expect(entries[3].status).toBe('SKIP'); | ||
| }); | ||
|
|
||
| it('should throw if an absolute path is used in files', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
| mockRig.testDir = path.resolve(process.cwd(), 'test-dir-tmp'); | ||
| if (!fs.existsSync(mockRig.testDir)) { | ||
| fs.mkdirSync(mockRig.testDir, { recursive: true }); | ||
| } | ||
|
|
||
| try { | ||
| await expect( | ||
| internalEvalTest({ | ||
| name: 'test-absolute-path', | ||
| prompt: 'do something', | ||
| files: { | ||
| '/etc/passwd': 'hacked', | ||
| }, | ||
| assert: async () => {}, | ||
| }), | ||
| ).rejects.toThrow('Invalid file path in test case: /etc/passwd'); | ||
| } finally { | ||
| if (fs.existsSync(mockRig.testDir)) { | ||
| fs.rmSync(mockRig.testDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('should throw if directory traversal is detected in files', async () => { | ||
| const mockRig = new TestRig() as any; | ||
| (TestRig as any).mockReturnValue(mockRig); | ||
| mockRig.testDir = path.resolve(process.cwd(), 'test-dir-tmp'); | ||
|
|
||
| // Create a mock test-dir | ||
| if (!fs.existsSync(mockRig.testDir)) { | ||
| fs.mkdirSync(mockRig.testDir, { recursive: true }); | ||
| } | ||
|
|
||
| try { | ||
| await expect( | ||
| internalEvalTest({ | ||
| name: 'test-traversal', | ||
| prompt: 'do something', | ||
| files: { | ||
| '../sensitive.txt': 'hacked', | ||
| }, | ||
| assert: async () => {}, | ||
| }), | ||
| ).rejects.toThrow('Invalid file path in test case: ../sensitive.txt'); | ||
| } finally { | ||
| if (fs.existsSync(mockRig.testDir)) { | ||
| fs.rmSync(mockRig.testDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.