-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_code_repair_language_guard.py
More file actions
40 lines (29 loc) · 1.45 KB
/
test_code_repair_language_guard.py
File metadata and controls
40 lines (29 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Test that code_repair is only called for Python, not JS/TS.
This tests the language guard added to prevent calling Python-only /ai/code_repair
endpoint for JavaScript/TypeScript functions.
"""
from codeflash.languages.language_enum import Language
def test_code_repair_should_only_run_for_python():
"""
Verify that the language check logic correctly identifies when code_repair should run.
Code repair uses Python-specific tools (libcst) and should only run for Python code.
"""
# This test documents the expected behavior:
# code_repair should only be attempted for Python functions
assert Language.PYTHON == "python"
assert Language.JAVASCRIPT == "javascript"
assert Language.TYPESCRIPT == "typescript"
# The actual fix will add this check in maybe_repair_optimization():
# if self.function_to_optimize.language == "python":
# self.future_all_code_repair.append(self.repair_optimization(...))
# For non-Python languages, repair should be skipped
# This test serves as documentation of the intended behavior
def test_language_enum_values():
"""Ensure Language enum has the expected values for the fix."""
assert hasattr(Language, 'PYTHON')
assert hasattr(Language, 'JAVASCRIPT')
assert hasattr(Language, 'TYPESCRIPT')
# String comparison works for the language check
assert Language.PYTHON == "python"
assert Language.JAVASCRIPT != "python"
assert Language.TYPESCRIPT != "python"