Skip to content

Commit 265df6d

Browse files
committed
Use shallow clone
1 parent f963c13 commit 265df6d

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

evals/git-evals2/agent-runner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ export async function runAgentOnCommit({
3636
await withTestRepo(
3737
{
3838
repoUrl,
39-
commitSha: commit.sha,
39+
parentSha: commit.parentSha,
4040
initCommand,
41-
checkoutPrevious: true,
4241
},
4342
async (repoDir) => {
4443
const agentsPath = path.join(__dirname, '../../.agents')

evals/subagents/eval-planner.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const evalPlannerAgent = async (params: {
1515
agentDefinitions: Array<AgentDefinition>
1616
spec: string
1717
repoUrl: string
18-
commitSha: string
18+
parentSha: string
1919
initCommand?: string
2020
fileStates: Array<{
2121
path: string
@@ -29,13 +29,13 @@ export const evalPlannerAgent = async (params: {
2929
agentDefinitions,
3030
spec,
3131
repoUrl,
32-
commitSha,
32+
parentSha,
3333
initCommand,
3434
fileStates,
3535
} = params
3636
const plannerStartTime = Date.now()
3737
const result = await withTestRepo(
38-
{ repoUrl, commitSha, initCommand, checkoutPrevious: true },
38+
{ repoUrl, parentSha, initCommand },
3939
async (cwd) => {
4040
// Run the agent with the test repository as cwd
4141
console.log(`Running agent ${agentId} with prompt: ${spec}...`)
@@ -206,6 +206,7 @@ type EvalData = {
206206
initCommand?: string
207207
evalCommits: Array<{
208208
sha: string
209+
parentSha: string
209210
spec: string
210211
fileStates: Array<{
211212
path: string
@@ -262,7 +263,7 @@ async function main() {
262263

263264
// Loop through each eval task
264265
for (const evalCommit of evalCommits) {
265-
const { sha, spec, fileStates } = evalCommit
266+
const { sha, parentSha, spec, fileStates } = evalCommit
266267

267268
console.log(`\n=== Running eval for commit ${sha} ===`)
268269
console.log(`Spec: ${spec.substring(0, 100)}...\n`)
@@ -274,7 +275,7 @@ async function main() {
274275
agentDefinitions: localAgentDefinitions,
275276
spec,
276277
repoUrl,
277-
commitSha: sha,
278+
parentSha,
278279
initCommand,
279280
fileStates,
280281
})
@@ -372,7 +373,8 @@ async function main() {
372373

373374
if (stats.plannerLatencies.length > 0) {
374375
const avgPlannerLatency =
375-
stats.plannerLatencies.reduce((a, b) => a + b, 0) / stats.plannerLatencies.length
376+
stats.plannerLatencies.reduce((a, b) => a + b, 0) /
377+
stats.plannerLatencies.length
376378
const minPlannerLatency = Math.min(...stats.plannerLatencies)
377379
const maxPlannerLatency = Math.max(...stats.plannerLatencies)
378380
const medianPlannerLatency = stats.plannerLatencies.sort((a, b) => a - b)[

evals/subagents/test-repo-utils.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,30 @@ import { execSync } from 'child_process'
1010
export const withTestRepo = async <T>(
1111
repoConfig: {
1212
repoUrl: string
13-
commitSha: string
13+
// The sha of the commit to checkout. If you have a commit with changes to replicate, you would check out the parent commit.
14+
parentSha: string
1415
initCommand?: string
15-
checkoutPrevious?: boolean
1616
},
1717
fn: (cwd: string) => Promise<T>,
1818
): Promise<T> => {
19-
const { repoUrl, commitSha, initCommand, checkoutPrevious } = repoConfig
19+
const { repoUrl, parentSha, initCommand } = repoConfig
2020

2121
// Create a temporary directory for the test repo
2222
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codebuff-eval-'))
2323
const repoDir = path.join(tempDir, 'repo')
2424

2525
try {
26-
// Clone the repository
27-
console.log(`Cloning repository ${repoUrl} to ${repoDir}...`)
28-
execSync(`git clone ${repoUrl} ${repoDir}`, { stdio: 'ignore' })
26+
console.log(
27+
`Cloning repository ${repoUrl} at commit ${parentSha} to ${repoDir} (shallow)...`,
28+
)
29+
execSync(`git clone --depth 1 ${repoUrl} ${repoDir}`, { stdio: 'ignore' })
2930

30-
// Checkout the specific commit or the previous commit
31-
if (checkoutPrevious) {
32-
const previousCommitSha = getPreviousCommitSha(commitSha, repoDir)
33-
console.log(`Checking out previous commit ${previousCommitSha}...`)
34-
execSync(`git checkout ${previousCommitSha}`, {
35-
cwd: repoDir,
36-
stdio: 'ignore',
37-
})
38-
} else {
39-
console.log(`Checking out commit ${commitSha}...`)
40-
execSync(`git checkout ${commitSha}`, { cwd: repoDir, stdio: 'ignore' })
41-
}
31+
execSync(`git fetch --depth 1 origin ${parentSha}`, {
32+
cwd: repoDir,
33+
stdio: 'ignore',
34+
})
35+
execSync(`git checkout ${parentSha}`, { cwd: repoDir, stdio: 'ignore' })
4236

43-
// Run initialization command if provided
4437
if (initCommand) {
4538
console.log(`Running init command: ${initCommand}...`)
4639
execSync(initCommand, { cwd: repoDir, stdio: 'ignore' })
@@ -50,22 +43,10 @@ export const withTestRepo = async <T>(
5043
return await fn(repoDir)
5144
} finally {
5245
// Clean up the temporary directory
53-
console.log(`Cleaning up temporary directory ${tempDir}...`)
5446
try {
5547
fs.rmSync(tempDir, { recursive: true, force: true })
5648
} catch (error) {
5749
console.warn(`Failed to clean up temporary directory: ${error}`)
5850
}
5951
}
6052
}
61-
62-
/**
63-
* Gets the previous commit SHA (parent) of a given commit
64-
*/
65-
const getPreviousCommitSha = (commitSha: string, repoDir: string): string => {
66-
const previousSha = execSync(`git rev-parse ${commitSha}^`, {
67-
cwd: repoDir,
68-
encoding: 'utf-8',
69-
}).trim()
70-
return previousSha
71-
}

0 commit comments

Comments
 (0)