* Ensures that the agent is frugal in its use of context by relying
* primarily on ranged reads when the line number is known, and combining
* nearby ranges into a single contiguous read to save tool calls.
*/
evalTest('USUALLY_PASSES',{
name:'should use ranged read when nearby lines are targeted',
files:{
'package.json':JSON.stringify({
name:'test-project',
version:'1.0.0',
type:'module',
}),
'eslint.config.mjs':`export default [
{
files: ["**/*.ts"],
rules: {
"no-var": "error"
}
}
];`,
'linter_mess.ts':(()=>{
constlines=[];
for(leti=0;i<1000;i++){
if(i===500||i===510||i===520){
lines.push(`var oldVar${i} = "needs fix";`);
}else{
lines.push(`const goodVar${i} = "clean";`);
}
}
returnlines.join('\n');
})(),
},
prompt:
'Fix all linter errors in linter_mess.ts manually by editing the file. Run eslint directly (using "npx --yes eslint") to find them. Do not run the file.',
expect(covered,`Agent should have read around line ${line}`).toBe(
true,
);
}
consteditCalls=logs.filter(
(log)=>log.toolRequest?.name===EDIT_TOOL_NAME,
);
consttargetEditCalls=editCalls.filter((call)=>{
constargs=JSON.parse(call.toolRequest.args);
returnargs.file_path.includes('linter_mess.ts');
});
expect(
targetEditCalls.length,
'Agent should have made replacement calls on the target file',
).toBeGreaterThanOrEqual(3);
},
});
/**
* Ensures the agent uses multiple ranged reads when the targets are far
* apart to avoid the need to read the whole file.
*/
evalTest('USUALLY_PASSES',{
name:'should use ranged read when targets are far apart',
files:{
'package.json':JSON.stringify({
name:'test-project',
version:'1.0.0',
type:'module',
}),
'eslint.config.mjs':`export default [
{
files: ["**/*.ts"],
rules: {
"no-var": "error"
}
}
];`,
'far_mess.ts':(()=>{
constlines=[];
for(leti=0;i<1000;i++){
if(i===100||i===900){
lines.push(`var oldVar${i} = "needs fix";`);
}else{
lines.push(`const goodVar${i} = "clean";`);
}
}
returnlines.join('\n');
})(),
},
prompt:
'Fix all linter errors in far_mess.ts manually by editing the file. Run eslint directly (using "npx --yes eslint") to find them. Do not run the file.',
* Validates that the agent reads the entire file if there are lots of matches
* (e.g.: 10), as it's more efficient than many small ranged reads.
*/
evalTest('USUALLY_PASSES',{
name:'should read the entire file when there are many matches',
files:{
'package.json':JSON.stringify({
name:'test-project',
version:'1.0.0',
type:'module',
}),
'eslint.config.mjs':`export default [
{
files: ["**/*.ts"],
rules: {
"no-var": "error"
}
}
];`,
'many_mess.ts':(()=>{
constlines=[];
for(leti=0;i<1000;i++){
if(i%100===0){
lines.push(`var oldVar${i} = "needs fix";`);
}else{
lines.push(`const goodVar${i} = "clean";`);
}
}
returnlines.join('\n');
})(),
},
prompt:
'Fix all linter errors in many_mess.ts manually by editing the file. Run eslint directly (using "npx --yes eslint") to find them. Do not run the file.',