diff --git a/.github/workflows/e2e-topological-sort.yaml b/.github/workflows/e2e-topological-sort.yaml index 9cc7d5174..7bfa74684 100644 --- a/.github/workflows/e2e-topological-sort.yaml +++ b/.github/workflows/e2e-topological-sort.yaml @@ -1,4 +1,4 @@ -name: E2E - Topological Sort +name: E2E - Topological Sort (Worktree) on: pull_request: @@ -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 @@ -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 diff --git a/codeflash/code_utils/git_worktree_utils.py b/codeflash/code_utils/git_worktree_utils.py index c41637c8d..5ab160c5e 100644 --- a/codeflash/code_utils/git_worktree_utils.py +++ b/codeflash/code_utils/git_worktree_utils.py @@ -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", "bot@codeflash.ai") + repository.git.add(".") repository.git.commit("-m", commit_message, "--no-verify") diff --git a/tests/scripts/end_to_end_test_topological_sort.py b/tests/scripts/end_to_end_test_topological_sort.py deleted file mode 100644 index a5ba2c58c..000000000 --- a/tests/scripts/end_to_end_test_topological_sort.py +++ /dev/null @@ -1,29 +0,0 @@ -import os -import pathlib - -from codeflash.code_utils.code_utils import add_addopts_to_pyproject -from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries - - -def run_test(expected_improvement_pct: int) -> bool: - with add_addopts_to_pyproject(): - config = TestConfig( - file_path="topological_sort.py", - function_name="Graph.topologicalSort", - test_framework="pytest", - min_improvement_x=0.05, - 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)))) diff --git a/tests/scripts/end_to_end_test_topological_sort_worktree.py b/tests/scripts/end_to_end_test_topological_sort_worktree.py new file mode 100644 index 000000000..7d5a3fec5 --- /dev/null +++ b/tests/scripts/end_to_end_test_topological_sort_worktree.py @@ -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)))) diff --git a/tests/scripts/end_to_end_test_utilities.py b/tests/scripts/end_to_end_test_utilities.py index e4c634450..afd74823d 100644 --- a/tests/scripts/end_to_end_test_utilities.py +++ b/tests/scripts/end_to_end_test_utilities.py @@ -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: @@ -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