Skip to content

Commit d355a25

Browse files
committed
update: push test files
1 parent 228bc17 commit d355a25

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

apps/open-swe/langbench/evaluator.eval.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Daytona, Sandbox } from "@daytonaio/sdk";
44
import { createLogger, LogLevel } from "../src/utils/logger.js";
55
import { DEFAULT_SANDBOX_CREATE_PARAMS } from "../src/constants.js";
66
import { readFileSync } from "fs";
7-
import { cloneRepo, checkoutFilesFromCommit } from "../src/utils/github/git.js";
7+
import { cloneRepo, checkoutFilesFromCommit, pushEmptyCommit } from "../src/utils/github/git.js";
88
import { GraphState, TargetRepository } from "@open-swe/shared/open-swe/types";
99
import { getRepoAbsolutePath } from "@open-swe/shared/git";
1010
import { setupEnv } from "../src/utils/env-setup.js";
@@ -264,6 +264,38 @@ async function runOpenSWEWithStreamTracking(inputs: {
264264
return result;
265265
}
266266

267+
/**
268+
* Add and commit files to remote branch
269+
*/
270+
async function addCommitAndPush(
271+
sandbox: Sandbox,
272+
repoDir: string,
273+
targetRepository: TargetRepository,
274+
githubToken: string
275+
): Promise<void> {
276+
const status = await sandbox.process.executeCommand(
277+
`git status`,
278+
repoDir,
279+
undefined,
280+
60000,
281+
);
282+
logger.info(`Git status: ${status.result}`);
283+
284+
logger.info("Adding checked-out test files to the branch");
285+
await sandbox.process.executeCommand(
286+
`git add .`,
287+
repoDir,
288+
undefined,
289+
60000,
290+
);
291+
292+
logger.info("Committing and pushing test files to remote branch");
293+
await pushEmptyCommit(targetRepository, sandbox, {
294+
githubInstallationToken: githubToken,
295+
});
296+
logger.info("Successfully committed and pushed test files to remote branch");
297+
}
298+
267299
/**
268300
* Process a single PR
269301
*/
@@ -316,7 +348,7 @@ async function processPR(prData: PRData): Promise<PRProcessResult> {
316348
if (!githubToken) {
317349
throw new Error("GITHUB_PAT environment variable is required");
318350
}
319-
351+
320352
await cloneRepo(sandbox, targetRepository, {
321353
githubInstallationToken: githubToken,
322354
});
@@ -348,6 +380,26 @@ async function processPR(prData: PRData): Promise<PRProcessResult> {
348380
logger.warn("Failed to setup Python environment, continuing anyway");
349381
}
350382

383+
// Checkout test files from merge commit before running open-swe
384+
if (testFiles.length > 0) {
385+
logger.info(
386+
`Checking out test files from merge commit before running open-swe: ${prData.mergeCommitSha}`,
387+
);
388+
await checkoutFilesFromCommit({
389+
sandbox,
390+
repoDir,
391+
commitSha: prData.mergeCommitSha,
392+
filePaths: testFiles,
393+
});
394+
395+
logger.info(`Successfully checked out ${testFiles.length} test files`);
396+
397+
// Add, commit and push the checked-out test files
398+
await addCommitAndPush(sandbox, repoDir, targetRepository, githubToken);
399+
} else {
400+
logger.info(`No test files found for PR #${prData.prNumber}`);
401+
}
402+
351403
// Run open-swe instance with the pre-merge commit and track streams
352404
logger.info("Starting open-swe...");
353405
const openSWEResults = await runOpenSWEWithStreamTracking({
@@ -358,21 +410,15 @@ async function processPR(prData: PRData): Promise<PRProcessResult> {
358410
});
359411
result.openSWEResults = openSWEResults;
360412

361-
// Only proceed with test checkout and execution if open-swe was successful and created a branch
413+
// Run tests if open-swe was successful and created a branch
362414
if (
363415
openSWEResults.success &&
364416
openSWEResults.branchName &&
365417
testFiles.length > 0
366418
) {
367419
logger.info(
368-
`Open-swe completed successfully with branch: ${openSWEResults.branchName}. Checking out test files from merge commit: ${prData.mergeCommitSha}`,
420+
`Open-swe completed successfully with branch: ${openSWEResults.branchName}. Running tests on checked out files.`,
369421
);
370-
await checkoutFilesFromCommit({
371-
sandbox,
372-
repoDir,
373-
commitSha: prData.mergeCommitSha,
374-
filePaths: testFiles,
375-
});
376422

377423
const testResults = await runPytestOnFiles({
378424
sandbox,

0 commit comments

Comments
 (0)