mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 20:44:46 -07:00
Use grep over large files.
This commit is contained in:
@@ -141,4 +141,80 @@ describe('Frugal Search', () => {
|
||||
).toBe(true);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Ensure that the agent makes use of either grep or ranged reads in fulfilling this task.
|
||||
* The task is specifically phrased to not evoke "view" or "search" specifically because
|
||||
* the model implicitly understands that such tasks are searches. This covers the case of
|
||||
* an unexpectedly large file benefitting from frugal approaches to viewing, like grep, or
|
||||
* ranged reads.
|
||||
*/
|
||||
evalTest('ALWAYS_PASSES', {
|
||||
name: 'should use grep or ranged read for large files',
|
||||
prompt: 'What year was legacy_processor.ts written?',
|
||||
files: {
|
||||
'src/utils.ts': 'export const add = (a, b) => a + b;',
|
||||
'src/types.ts': 'export type ID = string;',
|
||||
'src/legacy_processor.ts': [
|
||||
'// Copyright 2005 Legacy Systems Inc.',
|
||||
...Array.from(
|
||||
{ length: 5000 },
|
||||
(_, i) =>
|
||||
`// Legacy code block ${i} - strictly preserved for backward compatibility`,
|
||||
),
|
||||
].join('\\n'),
|
||||
'README.md': '# Project documentation',
|
||||
},
|
||||
assert: async (rig) => {
|
||||
const toolCalls = rig.readToolLogs();
|
||||
const getParams = (call: any) => {
|
||||
let args = call.toolRequest.args;
|
||||
if (typeof args === 'string') {
|
||||
try {
|
||||
args = JSON.parse(args);
|
||||
} catch (e) {
|
||||
// Ignore parse errors
|
||||
}
|
||||
}
|
||||
return args;
|
||||
};
|
||||
|
||||
// Check for wasteful full file reads
|
||||
const fullReads = toolCalls.filter((call) => {
|
||||
if (call.toolRequest.name !== 'read_file') return false;
|
||||
const args = getParams(call);
|
||||
return (
|
||||
args.file_path === 'src/legacy_processor.ts' &&
|
||||
(args.limit === undefined || args.limit === null)
|
||||
);
|
||||
});
|
||||
|
||||
expect(
|
||||
fullReads.length,
|
||||
'Agent should not attempt to read the entire large file at once',
|
||||
).toBe(0);
|
||||
|
||||
// Check that it actually tried to find it using appropriate tools
|
||||
const validAttempts = toolCalls.filter((call) => {
|
||||
const args = getParams(call);
|
||||
if (
|
||||
call.toolRequest.name === 'grep_search' &&
|
||||
(args.total_max_matches || args.max_matches_per_file)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
call.toolRequest.name === 'read_file' &&
|
||||
args.file_path === 'src/legacy_processor.ts' &&
|
||||
args.limit !== undefined
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
expect(validAttempts.length).toBeGreaterThan(0);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user