Skip to content

Commit 925075a

Browse files
Merge pull request #802 from codeflash-ai/e2e/worktree-test
[E2E] Worktree test
2 parents a62405d + 619f04a commit 925075a

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

.github/workflows/e2e-topological-sort.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: E2E - Topological Sort
1+
name: E2E - Topological Sort (Worktree)
22

33
on:
44
pull_request:
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
topological-sort-optimization:
11+
topological-sort-worktree-optimization:
1212
# Dynamically determine if environment is needed only when workflow files change and contributor is external
1313
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
1414
runs-on: ubuntu-latest
@@ -90,4 +90,4 @@ jobs:
9090
- name: Run Codeflash to optimize code
9191
id: optimize_code
9292
run: |
93-
uv run python tests/scripts/end_to_end_test_topological_sort.py
93+
uv run python tests/scripts/end_to_end_test_topological_sort_worktree.py

codeflash/code_utils/git_worktree_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def get_git_project_id() -> str:
3434

3535
def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None:
3636
repository = git.Repo(worktree_dir, search_parent_directories=True)
37+
with repository.config_writer() as cw:
38+
if not cw.has_option("user", "name"):
39+
cw.set_value("user", "name", "Codeflash Bot")
40+
if not cw.has_option("user", "email"):
41+
cw.set_value("user", "email", "bot@codeflash.ai")
42+
3743
repository.git.add(".")
3844
repository.git.commit("-m", commit_message, "--no-verify")
3945

tests/scripts/end_to_end_test_topological_sort.py

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import pathlib
3+
4+
from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries
5+
6+
7+
def run_test(expected_improvement_pct: int) -> bool:
8+
config = TestConfig(
9+
file_path="topological_sort.py",
10+
function_name="Graph.topologicalSort",
11+
test_framework="pytest",
12+
min_improvement_x=0.05,
13+
use_worktree=True,
14+
coverage_expectations=[
15+
CoverageExpectation(
16+
function_name="Graph.topologicalSort",
17+
expected_coverage=100.0,
18+
expected_lines=[25, 26, 27, 28, 29, 30, 31],
19+
)
20+
],
21+
)
22+
cwd = (pathlib.Path(__file__).parent.parent.parent / "code_to_optimize").resolve()
23+
return_var = run_codeflash_command(cwd, config, expected_improvement_pct)
24+
return return_var
25+
26+
27+
if __name__ == "__main__":
28+
exit(run_with_retries(run_test, int(os.getenv("EXPECTED_IMPROVEMENT_PCT", 5))))

tests/scripts/end_to_end_test_utilities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TestConfig:
2828
coverage_expectations: list[CoverageExpectation] = field(default_factory=list)
2929
benchmarks_root: Optional[pathlib.Path] = None
3030
enable_async: bool = False
31+
use_worktree: bool = False
3132

3233

3334
def clear_directory(directory_path: str | pathlib.Path) -> None:
@@ -137,6 +138,8 @@ def build_command(
137138
base_command.extend(["--benchmark", "--benchmarks-root", str(benchmarks_root)])
138139
if config.enable_async:
139140
base_command.append("--async")
141+
if config.use_worktree:
142+
base_command.append("--worktree")
140143
return base_command
141144

142145

0 commit comments

Comments
 (0)