Skip to content

Commit ad7dbe4

Browse files
Merge pull request #564 from codeflash-ai/existing-test-pr-comment
PR comment will contain detailed information of existing, replay and concolic tests in separate tables
2 parents 681fa17 + 02d1be3 commit ad7dbe4

File tree

4 files changed

+350
-45
lines changed

4 files changed

+350
-45
lines changed

codeflash/api/cfapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def suggest_changes(
124124
generated_tests: str,
125125
trace_id: str,
126126
coverage_message: str,
127+
replay_tests: str = "",
128+
concolic_tests: str = "",
127129
) -> Response:
128130
"""Suggest changes to a pull request.
129131
@@ -147,6 +149,8 @@ def suggest_changes(
147149
"generatedTests": generated_tests,
148150
"traceId": trace_id,
149151
"coverage_message": coverage_message,
152+
"replayTests": replay_tests,
153+
"concolicTests": concolic_tests,
150154
}
151155
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
152156

@@ -161,6 +165,8 @@ def create_pr(
161165
generated_tests: str,
162166
trace_id: str,
163167
coverage_message: str,
168+
replay_tests: str = "",
169+
concolic_tests: str = "",
164170
) -> Response:
165171
"""Create a pull request, targeting the specified branch. (usually 'main').
166172
@@ -183,6 +189,8 @@ def create_pr(
183189
"generatedTests": generated_tests,
184190
"traceId": trace_id,
185191
"coverage_message": coverage_message,
192+
"replayTests": replay_tests,
193+
"concolicTests": concolic_tests,
186194
}
187195
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
188196

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ def process_review(
11961196
if concolic_test_str:
11971197
generated_tests_str += "\n#------------------------------------------------\n" + concolic_test_str
11981198

1199-
existing_tests = existing_tests_source_for(
1199+
existing_tests, replay_tests, concolic_tests = existing_tests_source_for(
12001200
self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root),
12011201
function_to_all_tests,
12021202
test_cfg=self.test_cfg,
@@ -1237,6 +1237,8 @@ def process_review(
12371237
if self.experiment_id
12381238
else self.function_trace_id,
12391239
"coverage_message": coverage_message,
1240+
"replay_tests": replay_tests,
1241+
"concolic_tests": concolic_tests,
12401242
}
12411243

12421244
if not self.args.no_pr and not self.args.staging_review:

codeflash/result/create_pr.py

Lines changed: 73 additions & 12 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+
) -> tuple[str, str, str]:
3838
test_files = function_to_tests.get(function_qualified_name_with_modules_from_root)
3939
if not test_files:
40-
return ""
41-
output: str = ""
42-
rows = []
40+
return "", "", ""
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,79 @@ def existing_tests_source_for(
99103
* 100
100104
)
101105
if greater:
102-
rows.append(
106+
if "__replay_test_" in str(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 str(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+
]
123+
)
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+
]
132+
)
133+
elif "__replay_test_" in str(print_filename):
134+
rows_replay.append(
103135
[
104136
f"`{print_filename}::{qualified_name}`",
105137
f"{print_original_runtime}",
106138
f"{print_optimized_runtime}",
107-
f"⚠️{perf_gain}%",
139+
f"{perf_gain}%✅",
140+
]
141+
)
142+
elif "codeflash_concolic" in str(print_filename):
143+
rows_concolic.append(
144+
[
145+
f"`{print_filename}::{qualified_name}`",
146+
f"{print_original_runtime}",
147+
f"{print_optimized_runtime}",
148+
f"{perf_gain}%✅",
108149
]
109150
)
110151
else:
111-
rows.append(
152+
rows_existing.append(
112153
[
113154
f"`{print_filename}::{qualified_name}`",
114155
f"{print_original_runtime}",
115156
f"{print_optimized_runtime}",
116-
f"{perf_gain}%",
157+
f"{perf_gain}%",
117158
]
118159
)
119-
output += tabulate( # type: ignore[no-untyped-call]
120-
headers=headers, tabular_data=rows, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
160+
output_existing += tabulate( # type: ignore[no-untyped-call]
161+
headers=headers, tabular_data=rows_existing, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
162+
)
163+
output_existing += "\n"
164+
if len(rows_existing) == 0:
165+
output_existing = ""
166+
output_concolic += tabulate( # type: ignore[no-untyped-call]
167+
headers=headers, tabular_data=rows_concolic, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
168+
)
169+
output_concolic += "\n"
170+
if len(rows_concolic) == 0:
171+
output_concolic = ""
172+
output_replay += tabulate( # type: ignore[no-untyped-call]
173+
headers=headers, tabular_data=rows_replay, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
121174
)
122-
output += "\n"
123-
return output
175+
output_replay += "\n"
176+
if len(rows_replay) == 0:
177+
output_replay = ""
178+
return output_existing, output_replay, output_concolic
124179

125180

126181
def check_create_pr(
@@ -131,6 +186,8 @@ def check_create_pr(
131186
generated_original_test_source: str,
132187
function_trace_id: str,
133188
coverage_message: str,
189+
replay_tests: str,
190+
concolic_tests: str,
134191
git_remote: Optional[str] = None,
135192
) -> None:
136193
pr_number: Optional[int] = env_utils.get_pr_number()
@@ -171,6 +228,8 @@ def check_create_pr(
171228
generated_tests=generated_original_test_source,
172229
trace_id=function_trace_id,
173230
coverage_message=coverage_message,
231+
replay_tests=replay_tests,
232+
concolic_tests=concolic_tests,
174233
)
175234
if response.ok:
176235
logger.info(f"Suggestions were successfully made to PR #{pr_number}")
@@ -218,6 +277,8 @@ def check_create_pr(
218277
generated_tests=generated_original_test_source,
219278
trace_id=function_trace_id,
220279
coverage_message=coverage_message,
280+
replay_tests=replay_tests,
281+
concolic_tests=concolic_tests,
221282
)
222283
if response.ok:
223284
pr_id = response.text

0 commit comments

Comments
 (0)