1414
1515from codeflash .code_utils .git_utils import git_root_dir , mirror_path
1616from codeflash .discovery .functions_to_optimize import FunctionToOptimize
17- from codeflash .languages .base import CodeContext , FunctionFilterCriteria , HelperFunction , Language , TestInfo , TestResult
17+ from codeflash .languages .base import (
18+ CodeContext ,
19+ FunctionFilterCriteria ,
20+ HelperFunction ,
21+ Language ,
22+ SetupError ,
23+ TestInfo ,
24+ TestResult ,
25+ )
1826from codeflash .languages .javascript .treesitter import TreeSitterAnalyzer , TreeSitterLanguage , get_analyzer_for_file
1927from codeflash .languages .registry import register_language
2028from codeflash .models .models import FunctionParent
@@ -1950,7 +1958,7 @@ def prepare_module(
19501958
19511959 return prepare_javascript_module (module_code , module_path )
19521960
1953- def setup_test_config (self , test_cfg : TestConfig , file_path : Path , current_worktree : Path | None ) -> None :
1961+ def setup_test_config (self , test_cfg : TestConfig , file_path : Path , current_worktree : Path | None ) -> bool :
19541962 from codeflash .languages .javascript .optimizer import verify_js_requirements
19551963 from codeflash .languages .javascript .test_runner import find_node_project_root
19561964
@@ -1970,7 +1978,11 @@ def setup_test_config(self, test_cfg: TestConfig, file_path: Path, current_workt
19701978 original_root_node_modules = original_js_root / "node_modules"
19711979 if original_root_node_modules .exists () and not worktree_root_node_modules .exists ():
19721980 worktree_root_node_modules .symlink_to (original_root_node_modules )
1973- verify_js_requirements (test_cfg )
1981+ setup_errors = verify_js_requirements (test_cfg )
1982+ if any (e .should_abort for e in setup_errors ):
1983+ return False
1984+
1985+ return True
19741986
19751987 def adjust_test_config_for_discovery (self , test_cfg : TestConfig ) -> None :
19761988 test_cfg .tests_project_rootdir = test_cfg .tests_root
@@ -2216,7 +2228,7 @@ def get_module_path(self, source_file: Path, project_root: Path, tests_root: Pat
22162228 rel_path = source_file .relative_to (project_root )
22172229 return "../" + rel_path .with_suffix ("" ).as_posix ()
22182230
2219- def verify_requirements (self , project_root : Path , test_framework : str = "jest" ) -> tuple [bool , list [str ]]:
2231+ def verify_requirements (self , project_root : Path , test_framework : str = "jest" ) -> tuple [bool , list [SetupError ]]:
22202232 """Verify that all JavaScript requirements are met.
22212233
22222234 Checks for:
@@ -2242,21 +2254,34 @@ def verify_requirements(self, project_root: Path, test_framework: str = "jest")
22422254 try :
22432255 result = subprocess .run (["node" , "--version" ], check = False , capture_output = True , text = True , timeout = 10 )
22442256 if result .returncode != 0 :
2245- errors .append ("Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" )
2257+ errors .append (
2258+ SetupError (
2259+ "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" ,
2260+ should_abort = True ,
2261+ )
2262+ )
22462263 except FileNotFoundError :
2247- errors .append ("Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" )
2264+ errors .append (
2265+ SetupError (
2266+ "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" , should_abort = True
2267+ )
2268+ )
22482269 except Exception as e :
2249- errors .append (f"Failed to check Node.js: { e } " )
2270+ errors .append (SetupError ( f"Failed to check Node.js: { e } " , should_abort = True ) )
22502271
22512272 # Check npm
22522273 try :
22532274 result = subprocess .run (["npm" , "--version" ], check = False , capture_output = True , text = True , timeout = 10 )
22542275 if result .returncode != 0 :
2255- errors .append ("npm is not available. Please ensure npm is installed with Node.js." )
2276+ errors .append (
2277+ SetupError ("npm is not available. Please ensure npm is installed with Node.js." , should_abort = True )
2278+ )
22562279 except FileNotFoundError :
2257- errors .append ("npm is not available. Please ensure npm is installed with Node.js." )
2280+ errors .append (
2281+ SetupError ("npm is not available. Please ensure npm is installed with Node.js." , should_abort = True )
2282+ )
22582283 except Exception as e :
2259- errors .append (f"Failed to check npm: { e } " )
2284+ errors .append (SetupError ( f"Failed to check npm: { e } " , should_abort = True ) )
22602285
22612286 # Check test framework is installed (with monorepo support)
22622287 # Uses find_node_modules_with_package which searches up the directory tree
@@ -2270,12 +2295,17 @@ def verify_requirements(self, project_root: Path, test_framework: str = "jest")
22702295 local_node_modules = project_root / "node_modules"
22712296 if not local_node_modules .exists ():
22722297 errors .append (
2273- f"node_modules not found in { project_root } . Please run 'npm install' to install dependencies."
2298+ SetupError (
2299+ f"node_modules not found in { project_root } . Please run 'npm install' to install dependencies." ,
2300+ should_abort = True ,
2301+ )
22742302 )
22752303 else :
22762304 errors .append (
2277- f"{ test_framework } is not installed. "
2278- f"Please run 'npm install --save-dev { test_framework } ' to install it."
2305+ SetupError (
2306+ f"{ test_framework } is not installed. Please run 'npm install --save-dev { test_framework } ' to install it." ,
2307+ should_abort = True ,
2308+ )
22792309 )
22802310
22812311 return len (errors ) == 0 , errors
0 commit comments