Skip to content

Commit 587c80c

Browse files
committed
todo modify tests, modify js side
1 parent 553a192 commit 587c80c

File tree

3 files changed

+83
-23
lines changed

3 files changed

+83
-23
lines changed

codeflash/api/cfapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def suggest_changes(
119119
generated_tests: str,
120120
trace_id: str,
121121
coverage_message: str,
122+
replay_tests: str,
123+
concolic_tests: str,
122124
) -> Response:
123125
"""Suggest changes to a pull request.
124126
@@ -142,6 +144,8 @@ def suggest_changes(
142144
"generatedTests": generated_tests,
143145
"traceId": trace_id,
144146
"coverage_message": coverage_message,
147+
"replay_tests":replay_tests,
148+
"concolic_tests":concolic_tests
145149
}
146150
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
147151

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def find_and_process_best_optimization(
10211021
generated_tests_str = "\n\n".join(
10221022
[test.generated_original_test_source for test in generated_tests.generated_tests]
10231023
)
1024-
existing_tests = existing_tests_source_for(
1024+
existing_tests, replay_tests, concolic_tests = existing_tests_source_for(
10251025
qualified_name,
10261026
function_to_all_tests,
10271027
test_cfg=self.test_cfg,
@@ -1042,6 +1042,8 @@ def find_and_process_best_optimization(
10421042
else self.function_trace_id,
10431043
coverage_message=coverage_message,
10441044
git_remote=self.args.git_remote,
1045+
replay_tests_source=replay_tests,
1046+
concolic_tests_source=concolic_tests,
10451047
)
10461048
if (
10471049
self.args.all

codeflash/result/create_pr.py

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ def existing_tests_source_for(
3434
test_cfg: TestConfig,
3535
original_runtimes_all: dict[InvocationId, list[int]],
3636
optimized_runtimes_all: dict[InvocationId, list[int]],
37-
) -> str:
37+
) -> list[str]:
3838
test_files = function_to_tests.get(function_qualified_name_with_modules_from_root)
3939
if not test_files:
4040
return ""
41-
output: str = ""
42-
rows = []
41+
output_existing: str = ""
42+
output_concolic: str = ""
43+
output_replay: str = ""
44+
rows_existing = []
45+
rows_concolic = []
46+
rows_replay = []
4347
headers = ["Test File::Test Function", "Original ⏱️", "Optimized ⏱️", "Speedup"]
4448
tests_root = test_cfg.tests_root
4549
original_tests_to_runtimes: dict[Path, dict[str, int]] = {}
@@ -99,28 +103,74 @@ def existing_tests_source_for(
99103
* 100
100104
)
101105
if greater:
102-
rows.append(
103-
[
104-
f"`{print_filename}::{qualified_name}`",
105-
f"{print_original_runtime}",
106-
f"{print_optimized_runtime}",
107-
f"⚠️{perf_gain}%",
108-
]
106+
if '__replay_test_' in print_filename:
107+
rows_replay.append(
108+
[
109+
f"`{print_filename}::{qualified_name}`",
110+
f"{print_original_runtime}",
111+
f"{print_optimized_runtime}",
112+
f"⚠️{perf_gain}%",
113+
]
114+
)
115+
elif 'codeflash_concolic' in print_filename:
116+
rows_concolic.append(
117+
[
118+
f"`{print_filename}::{qualified_name}`",
119+
f"{print_original_runtime}",
120+
f"{print_optimized_runtime}",
121+
f"⚠️{perf_gain}%",
122+
]
109123
)
110-
else:
111-
rows.append(
112-
[
113-
f"`{print_filename}::{qualified_name}`",
114-
f"{print_original_runtime}",
115-
f"{print_optimized_runtime}",
116-
f"✅{perf_gain}%",
117-
]
124+
else:
125+
rows_existing.append(
126+
[
127+
f"`{print_filename}::{qualified_name}`",
128+
f"{print_original_runtime}",
129+
f"{print_optimized_runtime}",
130+
f"⚠️{perf_gain}%",
131+
]
118132
)
119-
output += tabulate( # type: ignore[no-untyped-call]
120-
headers=headers, tabular_data=rows, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
133+
else:
134+
if '__replay_test_' in print_filename:
135+
rows_replay.append(
136+
[
137+
f"`{print_filename}::{qualified_name}`",
138+
f"{print_original_runtime}",
139+
f"{print_optimized_runtime}",
140+
f"✅{perf_gain}%",
141+
]
142+
)
143+
elif 'codeflash_concolic' in print_filename:
144+
rows_concolic.append(
145+
[
146+
f"`{print_filename}::{qualified_name}`",
147+
f"{print_original_runtime}",
148+
f"{print_optimized_runtime}",
149+
f"✅{perf_gain}%",
150+
]
151+
)
152+
else:
153+
rows_existing.append(
154+
[
155+
f"`{print_filename}::{qualified_name}`",
156+
f"{print_original_runtime}",
157+
f"{print_optimized_runtime}",
158+
f"✅{perf_gain}%",
159+
]
160+
)
161+
output_existing += tabulate( # type: ignore[no-untyped-call]
162+
headers=headers, tabular_data=rows_existing, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
163+
)
164+
output_existing += "\n"
165+
output_concolic += tabulate( # type: ignore[no-untyped-call]
166+
headers=headers, tabular_data=rows_concolic, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
167+
)
168+
output_concolic += "\n"
169+
output_replay += tabulate( # type: ignore[no-untyped-call]
170+
headers=headers, tabular_data=rows_replay, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
121171
)
122-
output += "\n"
123-
return output
172+
output_replay += "\n"
173+
return output_existing, output_replay, output_concolic
124174

125175

126176
def check_create_pr(
@@ -131,6 +181,8 @@ def check_create_pr(
131181
generated_original_test_source: str,
132182
function_trace_id: str,
133183
coverage_message: str,
184+
replay_tests: str,
185+
concolic_tests: str,
134186
git_remote: Optional[str] = None,
135187
) -> None:
136188
pr_number: Optional[int] = env_utils.get_pr_number()
@@ -171,6 +223,8 @@ def check_create_pr(
171223
generated_tests=generated_original_test_source,
172224
trace_id=function_trace_id,
173225
coverage_message=coverage_message,
226+
replay_tests=replay_tests,
227+
concolic_tests=concolic_tests,
174228
)
175229
if response.ok:
176230
logger.info(f"Suggestions were successfully made to PR #{pr_number}")

0 commit comments

Comments
 (0)