Skip to content

Commit 6bda49b

Browse files
authored
Merge pull request #1318 from codeflash-ai/fix/js-jest30-loop-runner
fix: add Jest 30 support and fix time limit in loop-runner
2 parents 97c1249 + 5b43dc9 commit 6bda49b

35 files changed

Lines changed: 2156 additions & 707 deletions

code_to_optimize/js/code_to_optimize_js/bubble_sort.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ function bubbleSort(arr) {
1111
const result = arr.slice();
1212
const n = result.length;
1313

14-
for (let i = 0; i < n; i++) {
15-
for (let j = 0; j < n - 1; j++) {
16-
if (result[j] > result[j + 1]) {
17-
const temp = result[j];
18-
result[j] = result[j + 1];
19-
result[j + 1] = temp;
14+
if (n <= 1) return result;
15+
16+
for (let i = 0; i < n - 1; i++) {
17+
let swapped = false;
18+
const limit = n - i - 1;
19+
for (let j = 0; j < limit; j++) {
20+
const a = result[j];
21+
const b = result[j + 1];
22+
if (a > b) {
23+
result[j] = b;
24+
result[j + 1] = a;
25+
swapped = true;
2026
}
2127
}
28+
if (!swapped) break;
2229
}
2330

2431
return result;

code_to_optimize/js/code_to_optimize_vitest/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codeflash/code_utils/code_utils.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,32 @@ def is_glob_pattern(path_str: str) -> bool:
3737

3838

3939
def normalize_ignore_paths(paths: list[str], base_path: Path | None = None) -> list[Path]:
40-
"""Normalize ignore paths, expanding glob patterns and resolving paths.
41-
42-
Accepts a list of path strings that can be either:
43-
- Literal paths (relative or absolute): e.g., "node_modules", "/absolute/path"
44-
- Glob patterns: e.g., "**/*.test.js", "dist/*", "*.log"
45-
46-
Args:
47-
paths: List of path strings (literal paths or glob patterns).
48-
base_path: Base path for resolving relative paths and patterns.
49-
If None, uses current working directory.
50-
51-
Returns:
52-
List of resolved Path objects, deduplicated.
53-
54-
"""
5540
if base_path is None:
5641
base_path = Path.cwd()
5742

5843
base_path = base_path.resolve()
5944
normalized: set[Path] = set()
6045

6146
for path_str in paths:
47+
if not path_str:
48+
continue
49+
50+
path_str = str(path_str)
51+
6252
if is_glob_pattern(path_str):
63-
# It's a glob pattern - expand it
64-
# Use base_path as the root for glob expansion
65-
pattern_path = base_path / path_str
66-
# glob returns an iterator of matching paths
53+
# pathlib requires relative glob patterns
54+
path_str = path_str.removeprefix("./")
55+
if path_str.startswith("/"):
56+
path_str = path_str.lstrip("/")
57+
6758
for matched_path in base_path.glob(path_str):
68-
if matched_path.exists():
69-
normalized.add(matched_path.resolve())
59+
normalized.add(matched_path.resolve())
7060
else:
71-
# It's a literal path
7261
path_obj = Path(path_str)
7362
if not path_obj.is_absolute():
7463
path_obj = base_path / path_obj
7564
if path_obj.exists():
7665
normalized.add(path_obj.resolve())
77-
# Silently skip non-existent literal paths (e.g., .next, dist before build)
7866

7967
return list(normalized)
8068

codeflash/code_utils/time_utils.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
from __future__ import annotations
22

3-
import datetime as dt
4-
import re
5-
6-
import humanize
7-
83

94
def humanize_runtime(time_in_ns: int) -> str:
105
runtime_human: str = str(time_in_ns)
@@ -14,22 +9,32 @@ def humanize_runtime(time_in_ns: int) -> str:
149

1510
if time_in_ns / 1000 >= 1:
1611
time_micro = float(time_in_ns) / 1000
17-
runtime_human = humanize.precisedelta(dt.timedelta(microseconds=time_micro), minimum_unit="microseconds")
1812

19-
units = re.split(r",|\s", runtime_human)[1]
20-
21-
if units in {"microseconds", "microsecond"}:
13+
# Direct unit determination and formatting without external library
14+
if time_micro < 1000:
2215
runtime_human = f"{time_micro:.3g}"
23-
elif units in {"milliseconds", "millisecond"}:
24-
runtime_human = "%.3g" % (time_micro / 1000)
25-
elif units in {"seconds", "second"}:
26-
runtime_human = "%.3g" % (time_micro / (1000**2))
27-
elif units in {"minutes", "minute"}:
28-
runtime_human = "%.3g" % (time_micro / (60 * 1000**2))
29-
elif units in {"hour", "hours"}: # hours
30-
runtime_human = "%.3g" % (time_micro / (3600 * 1000**2))
16+
units = "microseconds" if time_micro >= 2 else "microsecond"
17+
elif time_micro < 1000000:
18+
time_milli = time_micro / 1000
19+
runtime_human = f"{time_milli:.3g}"
20+
units = "milliseconds" if time_milli >= 2 else "millisecond"
21+
elif time_micro < 60000000:
22+
time_sec = time_micro / 1000000
23+
runtime_human = f"{time_sec:.3g}"
24+
units = "seconds" if time_sec >= 2 else "second"
25+
elif time_micro < 3600000000:
26+
time_min = time_micro / 60000000
27+
runtime_human = f"{time_min:.3g}"
28+
units = "minutes" if time_min >= 2 else "minute"
29+
elif time_micro < 86400000000:
30+
time_hour = time_micro / 3600000000
31+
runtime_human = f"{time_hour:.3g}"
32+
units = "hours" if time_hour >= 2 else "hour"
3133
else: # days
32-
runtime_human = "%.3g" % (time_micro / (24 * 3600 * 1000**2))
34+
time_day = time_micro / 86400000000
35+
runtime_human = f"{time_day:.3g}"
36+
units = "days" if time_day >= 2 else "day"
37+
3338
runtime_human_parts = str(runtime_human).split(".")
3439
if len(runtime_human_parts[0]) == 1:
3540
if runtime_human_parts[0] == "1" and len(runtime_human_parts) > 1:

codeflash/github/PrComment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B
4545
}
4646

4747
if self.original_async_throughput is not None and self.best_async_throughput is not None:
48-
result["original_async_throughput"] = str(self.original_async_throughput)
49-
result["best_async_throughput"] = str(self.best_async_throughput)
48+
result["original_async_throughput"] = self.original_async_throughput
49+
result["best_async_throughput"] = self.best_async_throughput
5050

5151
return result
5252

0 commit comments

Comments
 (0)