-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Fix issue where Gemini CLI creates tests in a new file #18409
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
14 commits
Select commit
Hold shift + click to select a range
2e5dbe5
Eval for writing test to the right place.
gundermanc d794b5e
Prompt and slash cmd updates.
gundermanc e84ef63
Fix the tests.
gundermanc ec76e2e
Fix tests.
gundermanc 2e3731d
Stabilize the test.
gundermanc 2eb0fd5
Merge remote-tracking branch 'origin/main' into gundermanc/stop-dupli…
gundermanc 2a8b307
Revert.
gundermanc 3973661
Update eval.
gundermanc ae62135
Only run on nightly.
gundermanc ff82292
Testing mandate.
gundermanc 69c5560
Update baseline.
gundermanc 172f28c
Merge remote-tracking branch 'origin/main' into gundermanc/stop-dupli…
gundermanc 71aed2f
Merge remote-tracking branch 'origin/main' into gundermanc/stop-dupli…
gundermanc 233a3ff
Fix test.
gundermanc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, expect } from 'vitest'; | ||
| import { evalTest } from './test-helper.js'; | ||
|
|
||
| describe('Edits location eval', () => { | ||
| /** | ||
| * Ensure that Gemini CLI always updates existing test files, if present, | ||
| * instead of creating a new one. | ||
| */ | ||
| evalTest('USUALLY_PASSES', { | ||
| name: 'should update existing test file instead of creating a new one', | ||
| files: { | ||
| 'package.json': JSON.stringify( | ||
| { | ||
| name: 'test-location-repro', | ||
| version: '1.0.0', | ||
| scripts: { | ||
| test: 'vitest run', | ||
| }, | ||
| devDependencies: { | ||
| vitest: '^1.0.0', | ||
| typescript: '^5.0.0', | ||
| }, | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| 'src/math.ts': ` | ||
| export function add(a: number, b: number): number { | ||
| return a + b; | ||
| } | ||
|
|
||
| export function subtract(a: number, b: number): number { | ||
| return a - b; | ||
| } | ||
|
|
||
| export function multiply(a: number, b: number): number { | ||
| return a + b; | ||
| } | ||
| `, | ||
| 'src/math.test.ts': ` | ||
| import { expect, test } from 'vitest'; | ||
| import { add, subtract } from './math'; | ||
|
|
||
| test('add adds two numbers', () => { | ||
| expect(add(2, 3)).toBe(5); | ||
| }); | ||
|
|
||
| test('subtract subtracts two numbers', () => { | ||
| expect(subtract(5, 3)).toBe(2); | ||
| }); | ||
| `, | ||
| 'src/utils.ts': ` | ||
| export function capitalize(s: string): string { | ||
| return s.charAt(0).toUpperCase() + s.slice(1); | ||
| } | ||
| `, | ||
| 'src/utils.test.ts': ` | ||
| import { expect, test } from 'vitest'; | ||
| import { capitalize } from './utils'; | ||
|
|
||
| test('capitalize capitalizes the first letter', () => { | ||
| expect(capitalize('hello')).toBe('Hello'); | ||
| }); | ||
| `, | ||
| }, | ||
| prompt: 'Fix the bug in src/math.ts. Do not run the code.', | ||
| timeout: 180000, | ||
| assert: async (rig) => { | ||
| const toolLogs = rig.readToolLogs(); | ||
| const replaceCalls = toolLogs.filter( | ||
| (t) => t.toolRequest.name === 'replace', | ||
| ); | ||
| const writeFileCalls = toolLogs.filter( | ||
| (t) => t.toolRequest.name === 'write_file', | ||
| ); | ||
|
|
||
| expect(replaceCalls.length).toBeGreaterThan(0); | ||
| expect( | ||
| writeFileCalls.some((file) => | ||
| file.toolRequest.args.includes('.test.ts'), | ||
| ), | ||
| ).toBe(false); | ||
|
|
||
| const targetFiles = replaceCalls.map((t) => { | ||
| try { | ||
| return JSON.parse(t.toolRequest.args).file_path; | ||
| } catch { | ||
| return null; | ||
| } | ||
| }); | ||
|
|
||
| console.log('DEBUG: targetFiles', targetFiles); | ||
|
|
||
| expect( | ||
| new Set(targetFiles).size, | ||
| 'Expected only two files changed', | ||
| ).greaterThanOrEqual(2); | ||
| expect(targetFiles.some((f) => f?.endsWith('src/math.ts'))).toBe(true); | ||
| expect(targetFiles.some((f) => f?.endsWith('src/math.test.ts'))).toBe( | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion message 'Expected only two files changed' suggests an exact check, but
greaterThanOrEqual(2)allows for more than two files to be changed. To make the test stricter and align with the stated expectation, you should check for an exact size of 2.