Skip to content

Commit 4863a31

Browse files
committed
fix: address review feedback — tmpdir_path cleanup, args crash, UnboundLocalError
- Delete tmpdir_path in cleanup_temporary_paths to prevent stale refs - Use self.project_root instead of self.args.project_root (args can be None) - Move read_text() before try block to prevent UnboundLocalError in finally
1 parent ad81047 commit 4863a31

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

.claude/rules/architecture.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ codeflash/
1515
├── code_utils/ # Code parsing, git utilities
1616
├── models/ # Pydantic models and types
1717
├── languages/ # Multi-language support (Python, JavaScript/TypeScript)
18-
│ └── python/
19-
│ ├── function_optimizer.py # PythonFunctionOptimizer (Python-specific hooks)
20-
│ └── optimizer.py # Python module preparation & AST resolution
18+
│ ├── code_replacer.py # Language-agnostic code replacement
19+
│ ├── python/
20+
│ │ ├── function_optimizer.py # PythonFunctionOptimizer subclass
21+
│ │ ├── optimizer.py # Python module preparation & AST resolution
22+
│ │ └── normalizer.py # Python code normalization for deduplication
23+
│ └── javascript/
24+
│ ├── function_optimizer.py # JavaScriptFunctionOptimizer subclass
25+
│ ├── optimizer.py # JS project root finding & module preparation
26+
│ └── normalizer.py # JS/TS code normalization for deduplication
2127
├── setup/ # Config schema, auto-detection, first-run experience
2228
├── picklepatch/ # Serialization/deserialization utilities
2329
├── tracing/ # Function call tracing
@@ -35,10 +41,10 @@ codeflash/
3541
|------|------------|
3642
| CLI arguments & commands | `cli_cmds/cli.py` |
3743
| Optimization orchestration | `optimization/optimizer.py``run()` |
38-
| Per-function optimization | `optimization/function_optimizer.py` (base), `languages/python/function_optimizer.py` (Python subclass) |
44+
| Per-function optimization | `optimization/function_optimizer.py` (base), `languages/python/function_optimizer.py`, `languages/javascript/function_optimizer.py` |
3945
| Function discovery | `discovery/functions_to_optimize.py` |
4046
| Context extraction | `languages/<lang>/context/code_context_extractor.py` |
41-
| Test execution | `verification/test_runner.py`, `verification/pytest_plugin.py` |
47+
| Test execution | `languages/<lang>/support.py` (`run_behavioral_tests`, etc.), `verification/pytest_plugin.py` |
4248
| Performance ranking | `benchmarking/function_ranker.py` |
4349
| Domain types | `models/models.py`, `models/function_types.py` |
4450
| Result handling | `either.py` (`Result`, `Success`, `Failure`, `is_successful`) |

codeflash/languages/javascript/function_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def compare_candidate_results(
146146
candidate_sqlite = get_run_tmp_file(Path(f"test_return_values_{optimization_candidate_index}.sqlite"))
147147

148148
if original_sqlite.exists() and candidate_sqlite.exists():
149-
js_root = self.test_cfg.js_project_root or self.args.project_root
149+
js_root = self.test_cfg.js_project_root or self.project_root
150150
match, diffs = self.language_support.compare_test_results(
151151
original_sqlite, candidate_sqlite, project_root=js_root
152152
)
@@ -176,9 +176,9 @@ def line_profiler_step(
176176
logger.warning(f"Language support for {self.language_support.language} doesn't support line profiling")
177177
return {"timings": {}, "unit": 0, "str_out": ""}
178178

179+
original_source = Path(self.function_to_optimize.file_path).read_text()
179180
try:
180181
line_profiler_output_path = get_run_tmp_file(Path("line_profiler_output.json"))
181-
original_source = Path(self.function_to_optimize.file_path).read_text()
182182

183183
success = self.language_support.instrument_source_for_line_profiler(
184184
func_info=self.function_to_optimize, line_profiler_output_file=line_profiler_output_path

codeflash/optimization/optimizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ def cleanup_temporary_paths(self) -> None:
652652
if hasattr(get_run_tmp_file, "tmpdir"):
653653
get_run_tmp_file.tmpdir.cleanup()
654654
del get_run_tmp_file.tmpdir
655+
if hasattr(get_run_tmp_file, "tmpdir_path"):
656+
del get_run_tmp_file.tmpdir_path
655657

656658
# Always clean up concolic test directory
657659
cleanup_paths([self.test_cfg.concolic_test_root_dir])

0 commit comments

Comments
 (0)