Skip to content

Commit 14636eb

Browse files
authored
Merge branch 'main' into generated-tests-markdown
2 parents 021ae54 + 0598150 commit 14636eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3862
-777
lines changed

.github/workflows/e2e-init-optimization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
COLUMNS: 110
2020
MAX_RETRIES: 3
2121
RETRY_DELAY: 5
22-
EXPECTED_IMPROVEMENT_PCT: 30
22+
EXPECTED_IMPROVEMENT_PCT: 10
2323
CODEFLASH_END_TO_END: 1
2424
steps:
2525
- name: 🛎️ Checkout

.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

.github/workflows/unit-tests.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
14+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
1515
continue-on-error: true
1616
runs-on: ubuntu-latest
1717
steps:
@@ -28,5 +28,9 @@ jobs:
2828
- name: install dependencies
2929
run: uv sync
3030

31+
- name: Install test-only dependencies (Python 3.13)
32+
if: matrix.python-version == '3.13'
33+
run: uv sync --group tests
34+
3135
- name: Unit tests
32-
run: uv run pytest tests/
36+
run: uv run pytest tests/

codeflash/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Business Source License 1.1
33
Parameters
44

55
Licensor: CodeFlash Inc.
6-
Licensed Work: Codeflash Client version 0.17.x
6+
Licensed Work: Codeflash Client version 0.18.x
77
The Licensed Work is (c) 2024 CodeFlash Inc.
88

99
Additional Use Grant: None. Production use of the Licensed Work is only permitted
@@ -13,7 +13,7 @@ Additional Use Grant: None. Production use of the Licensed Work is only permitte
1313
Platform. Please visit codeflash.ai for further
1414
information.
1515

16-
Change Date: 2029-09-23
16+
Change Date: 2029-10-21
1717

1818
Change License: MIT
1919

codeflash/api/aiservice.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def optimize_python_code( # noqa: D417
144144
logger.info("!lsp|Generating optimized candidates…")
145145
console.rule()
146146
try:
147-
response = self.make_ai_service_request("/optimize", payload=payload, timeout=600)
147+
response = self.make_ai_service_request("/optimize", payload=payload, timeout=60)
148148
except requests.exceptions.RequestException as e:
149149
logger.exception(f"Error generating optimized candidates: {e}")
150150
ph("cli-optimize-error-caught", {"error": str(e)})
@@ -209,7 +209,7 @@ def optimize_python_code_line_profiler( # noqa: D417
209209
console.rule()
210210
return []
211211
try:
212-
response = self.make_ai_service_request("/optimize-line-profiler", payload=payload, timeout=600)
212+
response = self.make_ai_service_request("/optimize-line-profiler", payload=payload, timeout=60)
213213
except requests.exceptions.RequestException as e:
214214
logger.exception(f"Error generating optimized candidates: {e}")
215215
ph("cli-optimize-error-caught", {"error": str(e)})
@@ -261,7 +261,7 @@ def optimize_python_code_refinement(self, request: list[AIServiceRefinerRequest]
261261
logger.debug(f"Refining {len(request)} optimizations…")
262262
console.rule()
263263
try:
264-
response = self.make_ai_service_request("/refinement", payload=payload, timeout=600)
264+
response = self.make_ai_service_request("/refinement", payload=payload, timeout=120)
265265
except requests.exceptions.RequestException as e:
266266
logger.exception(f"Error generating optimization refinements: {e}")
267267
ph("cli-optimize-error-caught", {"error": str(e)})
@@ -509,7 +509,7 @@ def generate_regression_tests( # noqa: D417
509509
"is_async": function_to_optimize.is_async,
510510
}
511511
try:
512-
response = self.make_ai_service_request("/testgen", payload=payload, timeout=600)
512+
response = self.make_ai_service_request("/testgen", payload=payload, timeout=90)
513513
except requests.exceptions.RequestException as e:
514514
logger.exception(f"Error generating tests: {e}")
515515
ph("cli-testgen-error-caught", {"error": str(e)})
@@ -535,7 +535,7 @@ def generate_regression_tests( # noqa: D417
535535
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": response.text})
536536
return None
537537

538-
def get_optimization_impact(
538+
def get_optimization_review(
539539
self,
540540
original_code: dict[Path, str],
541541
new_code: dict[Path, str],
@@ -547,8 +547,9 @@ def get_optimization_impact(
547547
replay_tests: str,
548548
root_dir: Path,
549549
concolic_tests: str, # noqa: ARG002
550+
calling_fn_details: str,
550551
) -> str:
551-
"""Compute the optimization impact of current Pull Request.
552+
"""Compute the optimization review of current Pull Request.
552553
553554
Args:
554555
original_code: dict -> data structure mapping file paths to function definition for original code
@@ -561,10 +562,11 @@ def get_optimization_impact(
561562
replay_tests: str -> replay test table
562563
root_dir: Path -> path of git directory
563564
concolic_tests: str -> concolic_tests (not used)
565+
calling_fn_details: str -> filenames and definitions of functions which call the function_to_optimize
564566
565567
Returns:
566568
-------
567-
- 'high' or 'low' optimization impact
569+
- 'high', 'medium' or 'low' optimization review
568570
569571
"""
570572
diff_str = "\n".join(
@@ -580,7 +582,7 @@ def get_optimization_impact(
580582
]
581583
)
582584
code_diff = f"```diff\n{diff_str}\n```"
583-
logger.info("!lsp|Computing Optimization Impact…")
585+
logger.info("!lsp|Computing Optimization Review…")
584586
payload = {
585587
"code_diff": code_diff,
586588
"explanation": explanation.raw_explanation_message,
@@ -595,22 +597,23 @@ def get_optimization_impact(
595597
"optimized_runtime": humanize_runtime(explanation.best_runtime_ns),
596598
"original_runtime": humanize_runtime(explanation.original_runtime_ns),
597599
"codeflash_version": codeflash_version,
600+
"calling_fn_details": calling_fn_details,
598601
}
599602
console.rule()
600603
try:
601-
response = self.make_ai_service_request("/optimization_impact", payload=payload, timeout=600)
604+
response = self.make_ai_service_request("/optimization_review", payload=payload, timeout=120)
602605
except requests.exceptions.RequestException as e:
603606
logger.exception(f"Error generating optimization refinements: {e}")
604607
ph("cli-optimize-error-caught", {"error": str(e)})
605608
return ""
606609

607610
if response.status_code == 200:
608-
return cast("str", response.json()["impact"])
611+
return cast("str", response.json()["review"])
609612
try:
610613
error = cast("str", response.json()["error"])
611614
except Exception:
612615
error = response.text
613-
logger.error(f"Error generating impact candidates: {response.status_code} - {error}")
616+
logger.error(f"Error generating optimization review: {response.status_code} - {error}")
614617
ph("cli-optimize-error-response", {"response_status_code": response.status_code, "error": error})
615618
console.rule()
616619
return ""

codeflash/api/cfapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828

2929
if os.environ.get("CODEFLASH_CFAPI_SERVER", "prod").lower() == "local":
3030
CFAPI_BASE_URL = "http://localhost:3001"
31+
CFWEBAPP_BASE_URL = "http://localhost:3000"
3132
logger.info(f"Using local CF API at {CFAPI_BASE_URL}.")
3233
console.rule()
3334
else:
3435
CFAPI_BASE_URL = "https://app.codeflash.ai"
36+
CFWEBAPP_BASE_URL = "https://app.codeflash.ai"
3537

3638

3739
def make_cfapi_request(
@@ -130,6 +132,7 @@ def suggest_changes(
130132
coverage_message: str,
131133
replay_tests: str = "",
132134
concolic_tests: str = "",
135+
optimization_review: str = "",
133136
) -> Response:
134137
"""Suggest changes to a pull request.
135138
@@ -155,6 +158,7 @@ def suggest_changes(
155158
"coverage_message": coverage_message,
156159
"replayTests": replay_tests,
157160
"concolicTests": concolic_tests,
161+
"optimizationReview": optimization_review, # impact keyword left for legacy reasons, touches js/ts code
158162
}
159163
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
160164

@@ -171,6 +175,7 @@ def create_pr(
171175
coverage_message: str,
172176
replay_tests: str = "",
173177
concolic_tests: str = "",
178+
optimization_review: str = "",
174179
) -> Response:
175180
"""Create a pull request, targeting the specified branch. (usually 'main').
176181
@@ -195,6 +200,7 @@ def create_pr(
195200
"coverage_message": coverage_message,
196201
"replayTests": replay_tests,
197202
"concolicTests": concolic_tests,
203+
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
198204
}
199205
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
200206

@@ -210,6 +216,7 @@ def create_staging(
210216
replay_tests: str,
211217
concolic_tests: str,
212218
root_dir: Path,
219+
optimization_review: str = "",
213220
) -> Response:
214221
"""Create a staging pull request, targeting the specified branch. (usually 'staging').
215222
@@ -250,6 +257,7 @@ def create_staging(
250257
"coverage_message": coverage_message,
251258
"replayTests": replay_tests,
252259
"concolicTests": concolic_tests,
260+
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
253261
}
254262

255263
return make_cfapi_request(endpoint="/create-staging", method="POST", payload=payload)

codeflash/benchmarking/instrument_codeflash_trace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from typing import TYPE_CHECKING, Optional, Union
44

5-
import isort
65
import libcst as cst
76

7+
from codeflash.code_utils.formatter import sort_imports
8+
89
if TYPE_CHECKING:
910
from pathlib import Path
1011

@@ -107,7 +108,7 @@ def instrument_codeflash_trace_decorator(file_to_funcs_to_optimize: dict[Path, l
107108
original_code = file_path.read_text(encoding="utf-8")
108109
new_code = add_codeflash_decorator_to_code(original_code, functions_to_optimize)
109110
# Modify the code
110-
modified_code = isort.code(code=new_code, float_to_top=True)
111+
modified_code = sort_imports(code=new_code, float_to_top=True)
111112

112113
# Write the modified code back to the file
113114
file_path.write_text(modified_code, encoding="utf-8")

codeflash/benchmarking/replay_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING, Any
88

9-
import isort
10-
119
from codeflash.cli_cmds.console import logger
10+
from codeflash.code_utils.formatter import sort_imports
1211
from codeflash.discovery.functions_to_optimize import inspect_top_level_functions_or_methods
1312
from codeflash.verification.verification_utils import get_test_file_path
1413

@@ -299,7 +298,7 @@ def generate_replay_test(
299298
test_framework=test_framework,
300299
max_run_count=max_run_count,
301300
)
302-
test_code = isort.code(test_code)
301+
test_code = sort_imports(code=test_code)
303302
output_file = get_test_file_path(
304303
test_dir=Path(output_dir), function_name=benchmark_module_path, test_type="replay"
305304
)

codeflash/cli_cmds/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from codeflash.cli_cmds.cli_common import apologize_and_exit
99
from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions
1010
from codeflash.cli_cmds.console import logger
11+
from codeflash.cli_cmds.extension import install_vscode_extension
1112
from codeflash.code_utils import env_utils
1213
from codeflash.code_utils.code_utils import exit_with_message
1314
from codeflash.code_utils.config_parser import parse_config_file
@@ -22,6 +23,8 @@ def parse_args() -> Namespace:
2223
init_parser = subparsers.add_parser("init", help="Initialize Codeflash for a Python project.")
2324
init_parser.set_defaults(func=init_codeflash)
2425

26+
subparsers.add_parser("vscode-install", help="Install the Codeflash VSCode extension")
27+
2528
init_actions_parser = subparsers.add_parser("init-actions", help="Initialize GitHub Actions workflow")
2629
init_actions_parser.set_defaults(func=install_github_actions)
2730

@@ -122,9 +125,15 @@ def process_and_validate_cmd_args(args: Namespace) -> Namespace:
122125
logging_config.set_level(logging.DEBUG, echo_setting=not is_init)
123126
else:
124127
logging_config.set_level(logging.INFO, echo_setting=not is_init)
128+
125129
if args.version:
126130
logger.info(f"Codeflash version {version}")
127131
sys.exit()
132+
133+
if args.command == "vscode-install":
134+
install_vscode_extension()
135+
sys.exit()
136+
128137
if not check_running_in_git_repo(module_root=args.module_root):
129138
if not confirm_proceeding_with_no_git_repo():
130139
exit_with_message("No git repository detected and user aborted run. Exiting...", error_on_exit=True)

0 commit comments

Comments
 (0)