Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/e2e-topological-sort.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E - Topological Sort
name: E2E - Topological Sort (Worktree)

on:
pull_request:
Expand All @@ -8,7 +8,7 @@ on:
workflow_dispatch:

jobs:
topological-sort-optimization:
topological-sort-worktree-optimization:
# Dynamically determine if environment is needed only when workflow files change and contributor is external
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' || '' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -90,4 +90,4 @@ jobs:
- name: Run Codeflash to optimize code
id: optimize_code
run: |
uv run python tests/scripts/end_to_end_test_topological_sort.py
uv run python tests/scripts/end_to_end_test_topological_sort_worktree.py
6 changes: 6 additions & 0 deletions codeflash/code_utils/git_worktree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def get_git_project_id() -> str:

def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None:
repository = git.Repo(worktree_dir, search_parent_directories=True)
with repository.config_writer() as cw:
if not cw.has_option("user", "name"):
cw.set_value("user", "name", "Codeflash Bot")
if not cw.has_option("user", "email"):
cw.set_value("user", "email", "[email protected]")

repository.git.add(".")
repository.git.commit("-m", commit_message, "--no-verify")

Expand Down
29 changes: 0 additions & 29 deletions tests/scripts/end_to_end_test_topological_sort.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/scripts/end_to_end_test_topological_sort_worktree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import pathlib

from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries


def run_test(expected_improvement_pct: int) -> bool:
config = TestConfig(
file_path="topological_sort.py",
function_name="Graph.topologicalSort",
test_framework="pytest",
min_improvement_x=0.05,
use_worktree=True,
coverage_expectations=[
CoverageExpectation(
function_name="Graph.topologicalSort",
expected_coverage=100.0,
expected_lines=[25, 26, 27, 28, 29, 30, 31],
)
],
)
cwd = (pathlib.Path(__file__).parent.parent.parent / "code_to_optimize").resolve()
return_var = run_codeflash_command(cwd, config, expected_improvement_pct)
return return_var


if __name__ == "__main__":
exit(run_with_retries(run_test, int(os.getenv("EXPECTED_IMPROVEMENT_PCT", 5))))
3 changes: 3 additions & 0 deletions tests/scripts/end_to_end_test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TestConfig:
coverage_expectations: list[CoverageExpectation] = field(default_factory=list)
benchmarks_root: Optional[pathlib.Path] = None
enable_async: bool = False
use_worktree: bool = False


def clear_directory(directory_path: str | pathlib.Path) -> None:
Expand Down Expand Up @@ -137,6 +138,8 @@ def build_command(
base_command.extend(["--benchmark", "--benchmarks-root", str(benchmarks_root)])
if config.enable_async:
base_command.append("--async")
if config.use_worktree:
base_command.append("--worktree")
return base_command


Expand Down
Loading