Skip to content

Commit 5af9d9c

Browse files
author
Codeflash Bot
committed
correctly resolve test paths for tests runtime comments
1 parent fe82617 commit 5af9d9c

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import re
66
from pathlib import Path
7-
from typing import TYPE_CHECKING
7+
from typing import TYPE_CHECKING, Optional
88

99
import libcst as cst
1010
from libcst import MetadataWrapper
@@ -149,15 +149,16 @@ def leave_SimpleStatementSuite(
149149
return updated_node
150150

151151

152-
def unique_inv_id(inv_id_runtimes: dict[InvocationId, list[int]]) -> dict[str, int]:
152+
def unique_inv_id(inv_id_runtimes: dict[InvocationId, list[int]], tests_project_rootdir: Path) -> dict[str, int]:
153153
unique_inv_ids: dict[str, int] = {}
154154
for inv_id, runtimes in inv_id_runtimes.items():
155155
test_qualified_name = (
156156
inv_id.test_class_name + "." + inv_id.test_function_name # type: ignore[operator]
157157
if inv_id.test_class_name
158158
else inv_id.test_function_name
159159
)
160-
abs_path = str(Path(inv_id.test_module_path.replace(".", os.sep)).with_suffix(".py").resolve().with_suffix(""))
160+
abs_path = tests_project_rootdir / Path(inv_id.test_module_path.replace(".", os.sep)).with_suffix(".py")
161+
abs_path = str(abs_path.resolve().with_suffix(""))
161162
if "__unit_test_" not in abs_path:
162163
continue
163164
key = test_qualified_name + "#" + abs_path # type: ignore[operator]
@@ -174,10 +175,11 @@ def add_runtime_comments_to_generated_tests(
174175
generated_tests: GeneratedTestsList,
175176
original_runtimes: dict[InvocationId, list[int]],
176177
optimized_runtimes: dict[InvocationId, list[int]],
178+
tests_project_rootdir: Optional[Path] = None,
177179
) -> GeneratedTestsList:
178180
"""Add runtime performance comments to function calls in generated tests."""
179-
original_runtimes_dict = unique_inv_id(original_runtimes)
180-
optimized_runtimes_dict = unique_inv_id(optimized_runtimes)
181+
original_runtimes_dict = unique_inv_id(original_runtimes, tests_project_rootdir or Path())
182+
optimized_runtimes_dict = unique_inv_id(optimized_runtimes, tests_project_rootdir or Path())
181183
# Process each generated test
182184
modified_tests = []
183185
for test in generated_tests.generated_tests:

codeflash/lsp/beta.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,12 @@ def initialize_function_optimization(
270270
if server.optimizer is None:
271271
_initialize_optimizer_if_api_key_is_valid(server)
272272

273-
server.optimizer.worktree_mode()
274-
275-
original_args, _ = server.optimizer.original_args_and_test_cfg
276-
273+
server.optimizer.args.file = file_path
277274
server.optimizer.args.function = params.functionName
278-
original_relative_file_path = file_path.relative_to(original_args.project_root)
279-
server.optimizer.args.file = server.optimizer.current_worktree / original_relative_file_path
280275
server.optimizer.args.previous_checkpoint_functions = False
281276

277+
server.optimizer.worktree_mode()
278+
282279
server.show_message_log(
283280
f"Args set - function: {server.optimizer.args.function}, file: {server.optimizer.args.file}", "Info"
284281
)

codeflash/optimization/function_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def process_review(
13751375
)
13761376

13771377
generated_tests = add_runtime_comments_to_generated_tests(
1378-
generated_tests, original_runtime_by_test, optimized_runtime_by_test
1378+
generated_tests, original_runtime_by_test, optimized_runtime_by_test, self.test_cfg.tests_project_rootdir
13791379
)
13801380

13811381
generated_tests_str = "\n#------------------------------------------------\n".join(

0 commit comments

Comments
 (0)